From: Apple Date: Thu, 10 Mar 2005 04:35:33 +0000 (+0000) Subject: network_cmds-245.tar.gz X-Git-Tag: mac-os-x-104^0 X-Git-Url: https://git.saurik.com/apple/network_cmds.git/commitdiff_plain/2b484d24084b903459c5b416c06cd77b48c748b9?ds=sidebyside network_cmds-245.tar.gz --- diff --git a/Makefile b/Makefile index 9bfbff8..a8d381a 100644 --- a/Makefile +++ b/Makefile @@ -20,8 +20,7 @@ TOOLS = arp.tproj domainname.tproj \ nfsd.tproj nfsiod.tproj nfsstat.tproj ping.tproj rarpd.tproj\ rcp.tproj rexecd.tproj rlogin.tproj rlogind.tproj\ route.tproj routed.tproj rpcinfo.tproj rsh.tproj rshd.tproj\ - ruptime.tproj rwho.tproj rwhod.tproj slattach.tproj\ - spray.tproj syslogd.tproj\ + ruptime.tproj rwho.tproj rwhod.tproj slattach.tproj spray.tproj\ talk.tproj talkd.tproj telnet.tproj telnetd.tproj tftp.tproj\ tftpd.tproj traceroute.tproj trpt.tproj wall.tproj\ ypbind.tproj ypcat.tproj ypmatch.tproj yppoll.tproj\ diff --git a/PB.project b/PB.project index ca2c5e7..c634242 100644 --- a/PB.project +++ b/PB.project @@ -33,7 +33,6 @@ rwhod.tproj, slattach.tproj, spray.tproj, - syslogd.tproj, talk.tproj, talkd.tproj, telnet.tproj, diff --git a/alias/alias.c b/alias/alias.c index 1d3cd05..561245a 100644 --- a/alias/alias.c +++ b/alias/alias.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/alias/alias.h b/alias/alias.h index f6df7fc..a84dd6c 100644 --- a/alias/alias.h +++ b/alias/alias.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/alias/alias_cuseeme.c b/alias/alias_cuseeme.c index fcf0d0d..a19be96 100644 --- a/alias/alias_cuseeme.c +++ b/alias/alias_cuseeme.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/alias/alias_db.c b/alias/alias_db.c index 8c8c708..9d6b996 100644 --- a/alias/alias_db.c +++ b/alias/alias_db.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -625,7 +622,6 @@ GetNewPort(struct alias_link *link, int alias_port_param) When this parameter is GET_ALIAS_PORT, it indicates to get a randomly selected port number. */ - if (alias_port_param == GET_ALIAS_PORT) { /* @@ -711,7 +707,6 @@ GetNewPort(struct alias_link *link, int alias_port_param) port_sys += ALIAS_PORT_BASE; port_net = htons(port_sys); } - #ifdef DEBUG fprintf(stderr, "PacketAlias/GetnewPort(): "); fprintf(stderr, "could not find free port\n"); @@ -1115,7 +1110,6 @@ AddLink(struct in_addr src_addr, free(link); return(NULL); } - /* Link-type dependent initialization */ switch(link_type) { @@ -1942,6 +1936,103 @@ FindAliasAddress(struct in_addr original_addr) } } +/* FindAliasPortOut */ +/* external routine for NatPortMap */ +/* return alias port for the src_addr,dst_addr,src_port and proto */ +/* if one doesn't existed, create a mapping with providing pub_port if it's not 0 */ +/* delete mapping if addmapping is not true */ +int +FindAliasPortOut(struct in_addr src_addr, struct in_addr dst_addr, u_short src_port, u_short pub_port, u_char proto, int lifetime, char addmapping) +{ + u_int i; + struct alias_link *link; + int link_type; + + switch (proto) + { + case IPPROTO_UDP: + link_type = LINK_UDP; + break; + case IPPROTO_TCP: + link_type = LINK_TCP; + break; + default: + return NULL; + break; + } + +#ifdef DEBUG + { + int icount; + + printf("PORTMAP::srcaddr = 0x%x.%d, dstaddr = 0x%x.%d link_type = %d, lifetime = %d\n", + src_addr.s_addr, src_port, dst_addr.s_addr, pub_port, link_type, lifetime); + + for (i=0; isrc_addr.s_addr,link->src_port,link->dst_addr.s_addr,link->dst_port, link->alias_addr.s_addr,link->alias_port, + link->link_type); + + link_next = LIST_NEXT(link, list_out); + icount++; + link = link_next; + } + } + + } +#endif + + i = StartPointOut(src_addr, dst_addr, src_port, 0, link_type); +#ifdef DEBUG + printf("PORTMAP::StartPointOut returns %d\n", i); +#endif + LIST_FOREACH(link, &linkTableOut[i], list_out) + { + if (link->src_addr.s_addr == src_addr.s_addr && + link->dst_addr.s_addr == dst_addr.s_addr && + link->src_port == src_port && link->link_type == link_type) + break; + } + + if ( link == NULL && addmapping) + { + struct in_addr alias_addr; +#ifdef DEBUG + printf("PORTMAP:: cannot find mapping, adding mapping private port =%d, public port = %d\n",src_port, pub_port); +#endif + /* address/port in not in list, create new mapping */ + + alias_addr = FindAliasAddress(src_addr); + /* create new mapping */ + if ( !pub_port ) + pub_port = GET_ALIAS_PORT; + link = AddLink(src_addr, dst_addr, alias_addr, + src_port, 0, pub_port, + link_type); + if ( link != NULL ) + /* link was create, set new lifetime */ + SetExpire(link, lifetime); + } + if ( link ) + { + if ( addmapping ) + return( GetAliasPort(link)); + else + { + SetExpire(link, 0); /* delete mapping */ + return 0; + } + } + + return -1; +} + /* External routines for getting or changing link data (external to alias_db.c, but internal to alias*.c) diff --git a/alias/alias_ftp.c b/alias/alias_ftp.c index db53902..7985a95 100644 --- a/alias/alias_ftp.c +++ b/alias/alias_ftp.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/alias/alias_irc.c b/alias/alias_irc.c index 090b430..e33ad75 100644 --- a/alias/alias_irc.c +++ b/alias/alias_irc.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/alias/alias_local.h b/alias/alias_local.h index 2ff5b64..8aeb983 100644 --- a/alias/alias_local.h +++ b/alias/alias_local.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/alias/alias_nbt.c b/alias/alias_nbt.c index 2afc21d..f0b8048 100644 --- a/alias/alias_nbt.c +++ b/alias/alias_nbt.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/alias/alias_pptp.c b/alias/alias_pptp.c index 3e76de4..03e1a22 100644 --- a/alias/alias_pptp.c +++ b/alias/alias_pptp.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/alias/alias_proxy.c b/alias/alias_proxy.c index 70827b1..67299c0 100644 --- a/alias/alias_proxy.c +++ b/alias/alias_proxy.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/alias/alias_smedia.c b/alias/alias_smedia.c index 933c1b2..8937903 100644 --- a/alias/alias_smedia.c +++ b/alias/alias_smedia.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/alias/alias_util.c b/alias/alias_util.c index ef1cf42..28ea257 100644 --- a/alias/alias_util.c +++ b/alias/alias_util.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/arp.tproj/Makefile.postamble b/arp.tproj/Makefile.postamble index 3b11434..a16a7ad 100644 --- a/arp.tproj/Makefile.postamble +++ b/arp.tproj/Makefile.postamble @@ -113,3 +113,6 @@ beforeinstall: install -c -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} arp4.0 \ ${DESTDIR}${MANDIR}4/arp.0 +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 arp.8 $(DSTROOT)/usr/share/man/man8/arp.8 diff --git a/arp.tproj/arp.c b/arp.tproj/arp.c index 43864cd..4835bbd 100644 --- a/arp.tproj/arp.c +++ b/arp.tproj/arp.c @@ -472,7 +472,7 @@ search(u_long addr, void (*action)(struct sockaddr_dl *sdl, for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; sin2 = (struct sockaddr_inarp *)(rtm + 1); - (char *)sdl = (char *)sin2 + ROUNDUP(sin2->sin_len); + sdl = (struct sockaddr_dl*)((char*)sin2 + ROUNDUP(sin2->sin_len)); if (addr) { if (addr != sin2->sin_addr.s_addr) continue; @@ -569,6 +569,7 @@ print_entry(struct sockaddr_dl *sdl, printf(" [firewire]"); break; default: + break; } printf("\n"); diff --git a/bootparams/bootparamd.tproj/bootparam_proc.c b/bootparams/bootparamd.tproj/bootparam_proc.c index ddb6f19..2b6d1ee 100644 --- a/bootparams/bootparamd.tproj/bootparam_proc.c +++ b/bootparams/bootparamd.tproj/bootparam_proc.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootparams/bootparamd.tproj/bootparamd.c b/bootparams/bootparamd.tproj/bootparamd.c index c8da199..e76bd42 100644 --- a/bootparams/bootparamd.tproj/bootparamd.c +++ b/bootparams/bootparamd.tproj/bootparamd.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootparams/bootparams/bootparam_prot.x b/bootparams/bootparams/bootparam_prot.x index e28c544..0339a81 100644 --- a/bootparams/bootparams/bootparam_prot.x +++ b/bootparams/bootparams/bootparam_prot.x @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootparams/bpwhoami.tproj/bpwhoami.c b/bootparams/bpwhoami.tproj/bpwhoami.c index bf43da3..68a4c6d 100644 --- a/bootparams/bpwhoami.tproj/bpwhoami.c +++ b/bootparams/bpwhoami.tproj/bpwhoami.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/domainname.tproj/domainname.c b/domainname.tproj/domainname.c index 57eb463..a229731 100644 --- a/domainname.tproj/domainname.c +++ b/domainname.tproj/domainname.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/eaytest.tproj/crypto_openssl.c b/eaytest.tproj/crypto_openssl.c index c042c33..cbc2e0c 100644 --- a/eaytest.tproj/crypto_openssl.c +++ b/eaytest.tproj/crypto_openssl.c @@ -1,4 +1,4 @@ -/* $KAME: crypto_openssl.c,v 1.69 2001/09/11 13:25:00 sakane Exp $ */ +/* $KAME: crypto_openssl.c,v 1.73 2003/04/24 02:21:22 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -56,6 +56,7 @@ #endif #ifdef HAVE_OPENSSL_X509_H #include +#include #include #endif #include @@ -99,7 +100,8 @@ */ #ifdef HAVE_SIGNING_C -static int cb_check_cert __P((int, X509_STORE_CTX *)); +static int cb_check_cert_local __P((int, X509_STORE_CTX *)); +static int cb_check_cert_remote __P((int, X509_STORE_CTX *)); static void eay_setgentype __P((char *, int *)); static X509 *mem2x509 __P((vchar_t *)); #endif @@ -209,7 +211,7 @@ eay_cmp_asn1dn(n1, n2) i = X509_NAME_cmp(a, b); - end: + end: if (a) X509_NAME_free(a); if (b) @@ -221,9 +223,10 @@ eay_cmp_asn1dn(n1, n2) * this functions is derived from apps/verify.c in OpenSSL0.9.5 */ int -eay_check_x509cert(cert, CApath) +eay_check_x509cert(cert, CApath, local) vchar_t *cert; char *CApath; + int local; { X509_STORE *cert_ctx = NULL; X509_LOOKUP *lookup = NULL; @@ -245,7 +248,11 @@ eay_check_x509cert(cert, CApath) cert_ctx = X509_STORE_new(); if (cert_ctx == NULL) goto end; - X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert); + + if (local) + X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert_local); + else + X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert_remote); lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file()); if (lookup == NULL) @@ -272,6 +279,12 @@ eay_check_x509cert(cert, CApath) if (csc == NULL) goto end; X509_STORE_CTX_init(csc, cert_ctx, x509, NULL); + +#if OPENSSL_VERSION_NUMBER >= 0x00907000L + X509_STORE_CTX_set_flags(csc, X509_V_FLAG_CRL_CHECK); + X509_STORE_CTX_set_flags(csc, X509_V_FLAG_CRL_CHECK_ALL); +#endif + error = X509_verify_cert(csc); X509_STORE_CTX_cleanup(csc); #else @@ -286,7 +299,7 @@ eay_check_x509cert(cert, CApath) */ error = error ? 0 : -1; -end: + end: if (error) printf("%s\n", eay_strerror()); if (cert_ctx != NULL) @@ -299,10 +312,13 @@ end: /* * callback function for verifing certificate. - * this function is derived from cb() in openssl/apps/s_server.c + * Derived from cb() in openssl/apps/s_server.c + * + * This one is called for certificates obtained from + * 'peers_certfile' directive. */ static int -cb_check_cert(ok, ctx) +cb_check_cert_local(ok, ctx) int ok; X509_STORE_CTX *ctx; { @@ -311,42 +327,90 @@ cb_check_cert(ok, ctx) if (!ok) { X509_NAME_oneline( - X509_get_subject_name(ctx->current_cert), + X509_get_subject_name(ctx->current_cert), buf, 256); - /* - * since we are just checking the certificates, it is - * ok if they are self signed. But we should still warn - * the user. - */ - switch (ctx->error) { - case X509_V_ERR_CERT_HAS_EXPIRED: - case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: + /* + * since we are just checking the certificates, it is + * ok if they are self signed. But we should still warn + * the user. + */ + switch (ctx->error) { + case X509_V_ERR_CERT_HAS_EXPIRED: + case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: #if OPENSSL_VERSION_NUMBER >= 0x00905100L - case X509_V_ERR_INVALID_CA: - case X509_V_ERR_PATH_LENGTH_EXCEEDED: - case X509_V_ERR_INVALID_PURPOSE: + case X509_V_ERR_INVALID_PURPOSE: + case X509_V_ERR_UNABLE_TO_GET_CRL: #endif - ok = 1; - log_tag = LLV_WARNING; - break; - default: - log_tag = LLV_ERROR; - } + ok = 1; + log_tag = LLV_WARNING; + break; + + default: + log_tag = LLV_ERROR; + } + + #ifndef EAYDEBUG - plog(log_tag, LOCATION, NULL, - "%s(%d) at depth:%d SubjectName:%s\n", - X509_verify_cert_error_string(ctx->error), - ctx->error, - ctx->error_depth, - buf); + plog(log_tag, LOCATION, NULL, + "%s(%d) at depth:%d SubjectName:%s\n", + X509_verify_cert_error_string(ctx->error), + ctx->error, + ctx->error_depth, + buf); #else - printf("%d: %s(%d) at depth:%d SubjectName:%s\n", - log_tag, - X509_verify_cert_error_string(ctx->error), - ctx->error, - ctx->error_depth, - buf); + printf("%d: %s(%d) at depth:%d SubjectName:%s\n", + log_tag, + X509_verify_cert_error_string(ctx->error), + ctx->error, + ctx->error_depth, + buf); +#endif + } + ERR_clear_error(); + + return ok; +} + +/* + * Similar to cb_check_cert_local() but this one is called + * for certificates obtained from the IKE payload. + */ +static int +cb_check_cert_remote(ok, ctx) + int ok; + X509_STORE_CTX *ctx; +{ + char buf[256]; + int log_tag; + + if (!ok) { + X509_NAME_oneline( + X509_get_subject_name(ctx->current_cert), + buf, + 256); + switch (ctx->error) { + case X509_V_ERR_UNABLE_TO_GET_CRL: + ok = 1; + log_tag = LLV_WARNING; + break; + default: + log_tag = LLV_ERROR; + } +#ifndef EAYDEBUG + plog(log_tag, LOCATION, NULL, + "%s(%d) at depth:%d SubjectName:%s\n", + X509_verify_cert_error_string(ctx->error), + ctx->error, + ctx->error_depth, + buf); +#else + printf("%d: %s(%d) at depth:%d SubjectName:%s\n", + log_tag, + X509_verify_cert_error_string(ctx->error), + ctx->error, + ctx->error_depth, + buf); #endif } ERR_clear_error(); @@ -463,7 +527,7 @@ eay_get_x509subjectaltname(cert, altname, type, pos) sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); goto end; } - strcpy(*altname, cval->value); + strlcpy(*altname, cval->value, len); /* set type of the name */ eay_setgentype(cval->name, type); @@ -686,7 +750,7 @@ eay_check_x509sign(source, sig, cert) { X509 *x509; u_char *bp; - vchar_t pubkey; + EVP_PKEY *evp; bp = cert->v; @@ -698,10 +762,15 @@ eay_check_x509sign(source, sig, cert) return -1; } - pubkey.v = x509->cert_info->key->public_key->data; - pubkey.l = x509->cert_info->key->public_key->length; - - return eay_rsa_verify(source, sig, &pubkey); + evp = X509_get_pubkey(x509); + if (!evp) { +#ifndef EAYDEBUG + plog(LLV_ERROR, LOCATION, NULL, "X509_get_pubkey: %s\n", eay_strerror()); +#endif + return -1; + } + + return eay_rsa_verify(source, sig, evp); } /* @@ -902,22 +971,15 @@ eay_rsa_sign(src, privkey) } int -eay_rsa_verify(src, sig, pubkey) - vchar_t *src, *sig, *pubkey; -{ +eay_rsa_verify(src, sig, evp) + vchar_t *src, *sig; EVP_PKEY *evp; - u_char *bp = pubkey->v; +{ vchar_t *xbuf = NULL; int pad = RSA_PKCS1_PADDING; int len = 0; int error; - evp = d2i_PUBKEY(NULL, &bp, pubkey->l); - if (evp == NULL) -#ifndef EAYDEBUG - return NULL; -#endif - len = RSA_size(evp->pkey.rsa); xbuf = vmalloc(len); @@ -1171,7 +1233,7 @@ eay_bf_keylen(len) return 448; if (len < 40 || len > 448) return -1; - return len + 7 / 8; + return (len + 7) / 8; } #ifdef HAVE_OPENSSL_RC5_H @@ -1236,7 +1298,7 @@ eay_rc5_keylen(len) return 128; if (len < 40 || len > 2040) return -1; - return len + 7 / 8; + return (len + 7) / 8; } #endif @@ -1378,7 +1440,7 @@ eay_cast_keylen(len) return 128; if (len < 40 || len > 128) return -1; - return len + 7 / 8; + return (len + 7) / 8; } /* @@ -1476,6 +1538,13 @@ eay_twofish_keylen(len) return len; } +int +eay_null_keylen(len) + int len; +{ + return 0; +} + /* * HMAC functions */ @@ -1486,6 +1555,7 @@ eay_hmac_init(key, md) { HMAC_CTX *c = racoon_malloc(sizeof(*c)); + HMAC_CTX_init(c); HMAC_Init(c, key->v, key->l, md); return (caddr_t)c; @@ -1535,6 +1605,7 @@ eay_hmacsha2_512_final(c) HMAC_Final((HMAC_CTX *)c, res->v, &l); res->l = l; + HMAC_CTX_cleanup(c); (void)racoon_free(c); if (SHA512_DIGEST_LENGTH != res->l) { @@ -1595,6 +1666,7 @@ eay_hmacsha2_384_final(c) HMAC_Final((HMAC_CTX *)c, res->v, &l); res->l = l; + HMAC_CTX_cleanup(c); (void)racoon_free(c); if (SHA384_DIGEST_LENGTH != res->l) { @@ -1655,6 +1727,7 @@ eay_hmacsha2_256_final(c) HMAC_Final((HMAC_CTX *)c, res->v, &l); res->l = l; + HMAC_CTX_cleanup(c); (void)racoon_free(c); if (SHA256_DIGEST_LENGTH != res->l) { @@ -1715,6 +1788,7 @@ eay_hmacsha1_final(c) HMAC_Final((HMAC_CTX *)c, res->v, &l); res->l = l; + HMAC_CTX_cleanup(c); (void)racoon_free(c); if (SHA_DIGEST_LENGTH != res->l) { @@ -1775,6 +1849,7 @@ eay_hmacmd5_final(c) HMAC_Final((HMAC_CTX *)c, res->v, &l); res->l = l; + HMAC_CTX_cleanup(c); (void)racoon_free(c); if (MD5_DIGEST_LENGTH != res->l) { diff --git a/eaytest.tproj/crypto_openssl.h b/eaytest.tproj/crypto_openssl.h index 51c920f..7139a82 100644 --- a/eaytest.tproj/crypto_openssl.h +++ b/eaytest.tproj/crypto_openssl.h @@ -1,4 +1,4 @@ -/* $KAME: crypto_openssl.h,v 1.23 2001/08/14 12:26:06 sakane Exp $ */ +/* $KAME: crypto_openssl.h,v 1.25 2002/04/25 09:48:32 sakane Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -29,6 +29,10 @@ * SUCH DAMAGE. */ +#ifdef HAVE_OPENSSL_EVP_H +#include +#endif + #ifdef HAVE_SIGNING_C /* X509 Certificate */ #define GENT_OTHERNAME 0 @@ -43,7 +47,7 @@ extern vchar_t *eay_str2asn1dn __P((char *, int)); extern int eay_cmp_asn1dn __P((vchar_t *, vchar_t *)); -extern int eay_check_x509cert __P((vchar_t *, char *)); +extern int eay_check_x509cert __P((vchar_t *, char *, int)); extern vchar_t *eay_get_x509asn1subjectname __P((vchar_t *)); extern int eay_get_x509subjectaltname __P((vchar_t *, char **, int *, int)); extern char *eay_get_x509text __P((vchar_t *)); @@ -54,7 +58,7 @@ extern int eay_check_pkcs7sign __P((vchar_t *, vchar_t *, vchar_t *)); /* RSA */ extern vchar_t *eay_rsa_sign __P((vchar_t *, vchar_t *)); -extern int eay_rsa_verify __P((vchar_t *, vchar_t *, vchar_t *)); +extern int eay_rsa_verify __P((vchar_t *, vchar_t *, EVP_PKEY *)); /* ASN.1 */ extern vchar_t *eay_get_pkcs1privkey __P((char *)); @@ -108,6 +112,7 @@ extern int eay_aes_weakkey __P((vchar_t *)); extern int eay_aes_keylen __P((int)); /* misc */ +extern int eay_null_keylen __P((int)); extern int eay_null_hashlen __P((void)); extern int eay_kpdk_hashlen __P((void)); extern int eay_twofish_keylen __P((int)); diff --git a/eaytest.tproj/eaytest.c b/eaytest.tproj/eaytest.c index 0f046d4..2e3a3c3 100644 --- a/eaytest.tproj/eaytest.c +++ b/eaytest.tproj/eaytest.c @@ -273,7 +273,7 @@ certtest(ac, av) } } - error = eay_check_x509cert(&c, certpath); + error = eay_check_x509cert(&c, certpath, 1); if (error) printf("ERROR: cert is invalid.\n"); printf("\n"); diff --git a/ifconfig.tproj/Makefile b/ifconfig.tproj/Makefile index 0f7f623..fca11ed 100644 --- a/ifconfig.tproj/Makefile +++ b/ifconfig.tproj/Makefile @@ -14,7 +14,7 @@ PROJECT_TYPE = Tool HFILES = ifconfig.h -CFILES = ifconfig.c ifmedia.c ifvlan.c +CFILES = ifconfig.c ifmedia.c ifvlan.c ifbond.c OTHERSRCS = Makefile.preamble Makefile Makefile.dist ifconfig.8\ Makefile.postamble diff --git a/ifconfig.tproj/Makefile.preamble b/ifconfig.tproj/Makefile.preamble index 7100e37..1c986d6 100644 --- a/ifconfig.tproj/Makefile.preamble +++ b/ifconfig.tproj/Makefile.preamble @@ -1,3 +1,3 @@ OTHER_GENERATED_OFILES = $(VERS_OFILE) -include ../Makefile.include -OTHER_CFLAGS += -DUSE_IF_MEDIA -DINET6 -DNO_IPX -DUSE_VLANS +OTHER_CFLAGS += -DUSE_IF_MEDIA -DINET6 -DNO_IPX -DUSE_VLANS -DUSE_BONDS diff --git a/ifconfig.tproj/PB.project b/ifconfig.tproj/PB.project index e5cc832..fd2be15 100644 --- a/ifconfig.tproj/PB.project +++ b/ifconfig.tproj/PB.project @@ -5,7 +5,7 @@ H_FILES = (ifconfig.h); M_FILES = (); OTHER_LIBS = (); - OTHER_LINKED = (ifconfig.c, ifmedia.c, ifvlan.c); + OTHER_LINKED = (ifconfig.c, ifmedia.c, ifvlan.c, ifbond.c); OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.dist, ifconfig.8, Makefile.postamble); PRECOMPILED_HEADERS = (); PROJECT_HEADERS = (); diff --git a/ifconfig.tproj/ifbond.c b/ifconfig.tproj/ifbond.c new file mode 100644 index 0000000..6a3fc5b --- /dev/null +++ b/ifconfig.tproj/ifbond.c @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * ifbond.c + * - add and remove interfaces from a bond interface + */ + +/* + * Modification History: + * + * July 14, 2004 Dieter Siegmund (dieter@apple.com) + * - created + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "ifconfig.h" +extern int bond_details; + +#define EA_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x" +#define EA_CH(e, i) ((u_char)((u_char *)(e))[(i)]) +#define EA_LIST(ea) EA_CH(ea,0),EA_CH(ea,1),EA_CH(ea,2),EA_CH(ea,3),EA_CH(ea,4),EA_CH(ea,5) + +static __inline__ const char * +selected_state_string(u_char s) +{ + static const char * names[] = { "unselected", "selected", "standby" }; + + if (s <= IF_BOND_STATUS_SELECTED_STATE_STANDBY) { + return (names[s]); + } + return (""); +} + +static void +bond_print_details(struct if_bond_status * ibs_p, int count) + +{ + int i; + struct if_bond_status * scan_p = ibs_p; + + for (i = 0; i < count; i++, scan_p++) { + struct if_bond_partner_state * ps; + ps = &scan_p->ibs_partner_state; + printf("\tbond interface: %s priority: 0x%04x " + "state: 0x%02x partner system: 0x%04x," + EA_FORMAT " " + "key: 0x%04x port: 0x%04x priority: 0x%04x " + "state: 0x%02x\n", + scan_p->ibs_if_name, scan_p->ibs_port_priority, + scan_p->ibs_state, ps->ibps_system_priority, + EA_LIST(&ps->ibps_system), ps->ibps_key, + ps->ibps_port, ps->ibps_port_priority, + ps->ibps_state); + } + return; +} + +void +bond_status(int s, struct rt_addrinfo * info __unused) +{ + int i; + struct if_bond_req ibr; + struct if_bond_status * ibs_p; + struct if_bond_status_req * ibsr_p; + + bzero((char *)&ibr, sizeof(ibr)); + ibr.ibr_op = IF_BOND_OP_GET_STATUS; + ibsr_p = &ibr.ibr_ibru.ibru_status; + ibsr_p->ibsr_version = IF_BOND_STATUS_REQ_VERSION; + ifr.ifr_data = (caddr_t)&ibr; + + /* how many of them are there? */ + if (ioctl(s, SIOCGIFBOND, (caddr_t)&ifr) < 0) { + return; + } + if (ibsr_p->ibsr_total == 0) { + if (bond_details) { + printf("\tbond key: 0x%04x interfaces: \n", + ibsr_p->ibsr_key); + } + else { + printf("\tbond interfaces: \n"); + } + return; + } + ibsr_p->ibsr_buffer + = (char *)malloc(sizeof(struct if_bond_status) + * ibsr_p->ibsr_total); + ibsr_p->ibsr_count = ibsr_p->ibsr_total; + + /* get the list */ + if (ioctl(s, SIOCGIFBOND, (caddr_t)&ifr) < 0) { + goto done; + } + if (ibsr_p->ibsr_total > 0) { + if (bond_details) { + printf("\tbond key: 0x%04x interfaces:", + ibsr_p->ibsr_key); + } + else { + printf("\tbond interfaces:"); + } + ibs_p = (struct if_bond_status *)ibsr_p->ibsr_buffer; + for (i = 0; i < ibsr_p->ibsr_total; i++, ibs_p++) { + printf(" %s", ibs_p->ibs_if_name); + if (bond_details) { + u_char s = ibs_p->ibs_selected_state; + printf(" (%s)", selected_state_string(s)); + } + } + printf("\n"); + if (bond_details) { + bond_print_details((struct if_bond_status *) + ibsr_p->ibsr_buffer, + ibsr_p->ibsr_total); + } + } + else if (bond_details) { + printf("\tbond key: 0x%04x interfaces: \n", + ibsr_p->ibsr_key); + } + else { + printf("\tbond interfaces: \n"); + } + + done: + free(ibsr_p->ibsr_buffer); + return; +} + +void +setbonddev(const char *val, int d, int s, const struct afswtch * afp) +{ + struct if_bond_req ibr; + + bzero((char *)&ibr, sizeof(ibr)); + if ((unsigned int)snprintf(ibr.ibr_ibru.ibru_if_name, + sizeof(ibr.ibr_ibru.ibru_if_name), + "%s", val) >= IFNAMSIZ) { + errx(1, "interface name too long"); + } + ibr.ibr_op = IF_BOND_OP_ADD_INTERFACE; + ifr.ifr_data = (caddr_t)&ibr; + if (ioctl(s, SIOCSIFBOND, (caddr_t)&ifr) == -1) + err(1, "SIOCSIFBOND add interface"); + + return; +} + +void +unsetbonddev(const char *val, int d, int s, const struct afswtch * afp) +{ + struct if_bond_req ibr; + + bzero((char *)&ibr, sizeof(ibr)); + if ((unsigned int)snprintf(ibr.ibr_ibru.ibru_if_name, + sizeof(ibr.ibr_ibru.ibru_if_name), + "%s", val) >= IFNAMSIZ) { + errx(1, "interface name too long"); + } + ibr.ibr_op = IF_BOND_OP_REMOVE_INTERFACE; + ifr.ifr_data = (caddr_t)&ibr; + if (ioctl(s, SIOCSIFBOND, (caddr_t)&ifr) == -1) + err(1, "SIOCSIFBOND remove interface"); + + return; +} + diff --git a/ifconfig.tproj/ifconfig.8 b/ifconfig.tproj/ifconfig.8 index d9a3c35..348d63b 100644 --- a/ifconfig.tproj/ifconfig.8 +++ b/ifconfig.tproj/ifconfig.8 @@ -32,7 +32,7 @@ .\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94 .\" $FreeBSD: src/sbin/ifconfig/ifconfig.8,v 1.27.2.14 2001/08/23 06:35:38 yar Exp $ .\" -.Dd July 2, 2001 +.Dd July 15, 2004 .Dt IFCONFIG 8 .Os .Sh NAME @@ -67,9 +67,28 @@ .Op Ar address_family .Nm .Op Fl L +.Op Fl b .Op Fl d .Op Fl m .Op Fl u +.Nm +.Ar interface +.Cm vlan +.Ar vlan-tag +.Cm vlandev +.Ar iface +.Nm +.Ar interface +.Cm -vlandev +.Ar iface +.Nm +.Ar interface +.Cm bonddev +.Ar iface +.Nm +.Ar interface +.Cm -bonddev +.Ar iface .Sh DESCRIPTION .Nm Ifconfig is used to assign an address @@ -142,6 +161,10 @@ parameter is a string of the form .Dq name unit , for example, .Dq Li en0 . +.It Ar iface +This parameter has the same encoding as the +.Ar interface +parameter. .El .Pp The following parameters may be set with @@ -190,6 +213,63 @@ addresses and .It Fl arp Disable the use of the Address Resolution Protocol .Pq Xr arp 4 . +.It Cm bonddev Ar iface +If the interface is a bond pseudo device, associate physical interface +.Ar iface +with it. The bond pseudo device conforms +to the IEEE 802.3ad Link Aggregation specification. +.Pp +If this is the first physical interface to be associated with the bond +interface, the bond interface inherits the ethernet address from the +physical interface. Physical interfaces that are added to the bond have +their ethernet address re-programmed so that all members of the bond have +the same ethernet address. If the physical interface is subsequently +removed from the bond using +.Fl bonddev , +a new ethernet address is chosen from the remaining interfaces, and all +interfaces are re-programmed again with the new ethernet address. If no +remaining interfaces exist, the bond interface's ethernet address is cleared. +.Pp +If the specified physical interface +.Ar iface +is not capable of having its ethernet address re-programmed, the +.Cm bonddev +command will fail. +.Pp +Once the physical interface +.Ar iface +is successfully associated with the bond interface, all received packets +are diverted to the bond interface. The physical interface is no longer +useable on its own, and remains that way until it is removed from the bond using +.Fl bonddev . +.Pp +It is possible that the specified interface +.Ar iface +is not capable of aggregating, and may remain unused until the operating +conditions change. +.Pp +The link status of the bond interface depends on the state of link aggregation. +If no active partner is detected, the link status will remain inactive. +.Pp +To monitor the 802.3ad Link Aggregation state, use the +.Fl b +option. +.Pp +A physical interface that is associated with a vlan pseudo device cannot +at the same time be associated with a bond pseudo device. A physical interface +cannot be associated with more than one bond pseudo device at the same time. +.Pp +It is not possible to associate a bond with pseudo interfaces such as vlan. +Only physical ethernet interfaces may be associated with a bond. +.It Fl bonddev Ar iface +If the interface is a bond pseudo device, disassociate the physical interface +.Ar iface +from it. Before the interface is removed from the bond, the bond device +announces to the link partner that the interface is now individual and +no longer aggregatable. +If the physical +.Ar iface +is the last interface in the bond, the bond interface clears its link address. .It Cm broadcast (Inet only.) Specify the address to use to represent broadcasts to the @@ -306,54 +386,6 @@ parameter. Included for .Tn Solaris compatibility. -.It Cm vlan Ar vlan_tag -If the interface is a vlan pseudo interface, set the vlan tag value -to -.Ar vlan_tag . -This value is a 16-bit number which is used to create an 802.1Q -vlan header for packets sent from the vlan interface. -Note that -.Cm vlan -and -.Cm vlandev -must both be set at the same time. -.It Cm vlandev Ar iface -If the interface is a vlan pseudo device, associate physical interface -.Ar iface -with it. -Packets transmitted through the vlan interface will be -diverted to the specified physical interface -.Ar iface -with 802.1Q vlan encapsulation. -Packets with 802.1Q encapsulation received -by the parent interface with the correct vlan tag will be diverted to -the associated vlan pseudo-interface. -The vlan interface is assigned a -copy of the parent interface's flags and the parent's ethernet address. -The -.Cm vlandev -and -.Cm vlan -must both be set at the same time. -If the vlan interface already has -a physical interface associated with it, this command will fail. -To -change the association to another physical interface, the existing -association must be cleared first. -.Pp -Note: if the hardware tagging capability -is set on the vlan interface, the vlan pseudo -interface's behavior changes: -the vlan interface recognizes that the -parent interface supports insertion and extraction of vlan tags on its -own (usually in firmware) and that it should pass packets to and from -the parent unaltered. -.It Fl vlandev Ar iface -If the driver is a vlan pseudo device, disassociate the physical interface -.Ar iface -from it. -This breaks the link between the vlan interface and its parent, -clears its vlan tag, flags and its link address and shuts the interface down. .It Cm metric Ar n Set the routing metric of the interface to .Ar n , @@ -462,6 +494,55 @@ This may be used to enable an interface after an It happens automatically when setting the first address on an interface. If the interface was reset when previously marked down, the hardware will be re-initialized. +.It Cm vlan Ar vlan_tag Cm vlandev Ar iface +If the interface is a vlan pseudo interface, set its vlan tag value +to +.Ar vlan_tag +and associate it with the physical interface +.Ar iface . +.Pp +The +.Ar vlan_tag +value is a 16-bit number that is used to create an 802.1Q +vlan header for packets sent from the vlan interface. +.Pp +A packet that is transmitted through the vlan interface is sent +using the specified physical interface +.Ar iface +with 802.1Q vlan encapsulation with the specified +.Ar vlan_tag . +A packet with 802.1Q encapsulation received by the physical interface +is directed to the associated vlan interface with the matching +.Ar vlan_tag . +If there is no matching vlan interface, the packet is dropped. +.Pp +The vlan interface is assigned a +copy of the parent interface's flags and the parent's ethernet address. +If the vlan interface already has +a physical interface associated with it, this command will fail. +To +change the association to another physical interface, the existing +association must be cleared first using +.Fl vlandev . +.Pp +If the physical interface supports 802.1Q VLAN tagging in hardware, +the vlan pseudo interface does not itself insert or remove the 802.1Q +encapsulation header. Instead, the +.Ar vlan_tag +is passed out of band from the packet data. +.Pp +A physical interface that is associated with a bond pseudo device cannot +at the same time be associated with a vlan interface. However, a physical +interface can be associated with multiple vlan interfaces at the same time, +as long as each of the +.Ar vlan_tag +values are unique. +.It Fl vlandev Ar iface +If the driver is a vlan pseudo device, disassociate the physical interface +.Ar iface +from it. +This breaks the link between the vlan interface and its parent, +clears its vlan tag, flags and its link address. .El .Pp .Nm Ifconfig @@ -471,15 +552,16 @@ If a protocol family is specified, .Nm will report only the details specific to that protocol family. .Pp -If the driver does supports the media selection system, the supported -media list will be included in the output. -.Pp -If the +If the driver supports the media selection system, the supported +media list will be included in the output, regardless of whether the .Fl m -flag is passed before an interface name, -.Nm -will display all -of the supported media for the specified interface. +flag is passed or not. +.Pp +The +.Fl b +option passed before the interface name will print the link aggregation +state for bond pseudo devices. +.Pp If .Fl L flag is supplied, address lifetime is displayed for IPv6 addresses, diff --git a/ifconfig.tproj/ifconfig.c b/ifconfig.tproj/ifconfig.c index 0cc0fb2..09f5c33 100644 --- a/ifconfig.tproj/ifconfig.c +++ b/ifconfig.tproj/ifconfig.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; #endif static const char rcsid[] = - "$Id: ifconfig.c,v 1.6 2003/12/16 23:16:58 lindak Exp $"; + "$Id: ifconfig.c,v 1.8 2004/08/26 23:55:21 lindak Exp $"; #endif /* not lint */ #include @@ -88,7 +88,6 @@ static const char rcsid[] = #include #include -struct ether_addr *ether_aton __P((const char *)); #include "ifconfig.h" @@ -128,6 +127,7 @@ static int ip6lifetime; struct afswtch; +int bond_details = 0; int supmedia = 0; int listcloners = 0; @@ -232,6 +232,10 @@ struct cmd { { "vlandev", NEXTARG, setvlandev }, { "-vlandev", NEXTARG, unsetvlandev }, #endif +#ifdef USE_BONDS + { "bonddev", NEXTARG, setbonddev }, + { "-bonddev", NEXTARG, unsetbonddev }, +#endif #if 0 /* XXX `create' special-cased below */ {"create", 0, clone_create }, @@ -323,6 +327,9 @@ struct afswtch { #ifdef USE_VLANS { "vlan", AF_UNSPEC, vlan_status, NULL, NULL, }, /* XXX not real!! */ #endif +#ifdef USE_BONDS + { "bond", AF_UNSPEC, bond_status, NULL, NULL, }, /* XXX not real!! */ +#endif #ifdef USE_IEEE80211 { "ieee80211", AF_UNSPEC, ieee80211_status, NULL, NULL, }, /* XXX not real!! */ #endif @@ -401,7 +408,7 @@ main(argc, argv) /* Parse leading line options */ all = downonly = uponly = namesonly = 0; - while ((c = getopt(argc, argv, "adlmu" + while ((c = getopt(argc, argv, "abdlmu" #ifdef INET6 "L" #endif @@ -410,6 +417,9 @@ main(argc, argv) case 'a': /* scan all interfaces */ all++; break; + case 'b': /* bond detailed output */ + bond_details++; + break; case 'd': /* restrict scan to "down" interfaces */ downonly++; break; @@ -435,8 +445,8 @@ main(argc, argv) argc -= optind; argv += optind; - /* -l cannot be used with -a or -m */ - if (namesonly && (all || supmedia)) + /* -l cannot be used with -a or -m or -b */ + if (namesonly && (all || supmedia || bond_details)) usage(); /* nonsense.. */ @@ -666,7 +676,7 @@ ifconfig(argc, argv, afp) if (afp->af_ridreq == NULL || afp->af_difaddr == 0) { warnx("interface %s cannot change %s addresses!", name, afp->af_name); - clearaddr = NULL; + clearaddr = 0; } } if (clearaddr) { @@ -683,7 +693,7 @@ ifconfig(argc, argv, afp) if (afp->af_addreq == NULL || afp->af_aifaddr == 0) { warnx("interface %s cannot change %s addresses!", name, afp->af_name); - newaddr = NULL; + newaddr = 0; } } if (newaddr && (setaddr || setmask)) { @@ -1114,6 +1124,10 @@ status(afp, addrcount, sdl, ifm, ifam) if (allfamilies || afp->af_status == vlan_status) vlan_status(s, NULL); #endif +#ifdef USE_BONDS + if (allfamilies || afp->af_status == bond_status) + bond_status(s, NULL); +#endif #ifdef USE_IEEE80211 if (allfamilies || afp->af_status == ieee80211_status) ieee80211_status(s, NULL); diff --git a/ifconfig.tproj/ifconfig.h b/ifconfig.tproj/ifconfig.h index 3688c9f..39fbc02 100644 --- a/ifconfig.tproj/ifconfig.h +++ b/ifconfig.tproj/ifconfig.h @@ -31,7 +31,7 @@ * * so there! * - * $Id: ifconfig.h,v 1.2 2003/12/16 23:16:58 lindak Exp $ + * $Id: ifconfig.h,v 1.3 2004/07/20 05:29:46 lindak Exp $ */ extern struct ifreq ifr; @@ -50,3 +50,6 @@ extern void setvlandev(const char *, int, int, const struct afswtch *rafp); extern void unsetvlandev(const char *, int, int, const struct afswtch *rafp); extern void vlan_status(int s, struct rt_addrinfo *); +extern void setbonddev(const char *, int, int,const struct afswtch * rafp); +extern void unsetbonddev(const char *, int, int, const struct afswtch * rafp); +extern void bond_status(int s, struct rt_addrinfo *); diff --git a/ifconfig.tproj/ifmedia.c b/ifconfig.tproj/ifmedia.c index 1657c21..2ba7a39 100644 --- a/ifconfig.tproj/ifmedia.c +++ b/ifconfig.tproj/ifmedia.c @@ -95,6 +95,8 @@ static int get_media_options __P((int, const char *)); static int lookup_media_word __P((struct ifmedia_description *, const char *)); static void print_media_word __P((int)); +extern int supmedia; + void media_status(s, info) int s; @@ -118,14 +120,6 @@ media_status(s, info) return; } - media_list = (int *)malloc(ifmr.ifm_count * sizeof(int)); - if (media_list == NULL) - err(1, "malloc"); - ifmr.ifm_ulist = media_list; - - if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) - err(1, "SIOCGIFMEDIA"); - printf("\tmedia: "); print_media_word(ifmr.ifm_current); if (ifmr.ifm_active != ifmr.ifm_current) { @@ -160,9 +154,21 @@ media_status(s, info) else printf("inactive"); } - putchar('\n'); +#if 0 + if (supmedia == 0) { + return; + } +#endif 0 + media_list = (int *)malloc(ifmr.ifm_count * sizeof(int)); + if (media_list == NULL) + err(1, "malloc"); + ifmr.ifm_ulist = media_list; + + if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) + err(1, "SIOCGIFMEDIA"); + if (ifmr.ifm_count > 0) { printf("\tsupported media:"); for (i = 0; i < ifmr.ifm_count; i++) { diff --git a/ip6conf.tproj/ip6tool.c b/ip6conf.tproj/ip6tool.c index 37f7846..8d044f9 100644 --- a/ip6conf.tproj/ip6tool.c +++ b/ip6conf.tproj/ip6tool.c @@ -2,22 +2,21 @@ * * @APPLE_LICENSE_HEADER_START@ * -* Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. -* -* This file contains Original Code and/or Modifications of Original Code -* as defined in and that are subject to the Apple Public Source License -* Version 2.0 (the 'License'). You may not use this file except in -* compliance with the License. Please obtain a copy of the License at -* http://www.opensource.apple.com/apsl/ and read it before using this -* file. +* "Portions Copyright (c) 2002 Apple Computer, Inc. All Rights +* Reserved. This file contains Original Code and/or Modifications of +* Original Code as defined in and that are subject to the Apple Public +* Source License Version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. Please obtain a copy of the +* License at http://www.apple.com/publicsource and read it before using +* this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. -* Please see the License for the specific language governing rights and -* limitations under the License. +* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the +* License for the specific language governing rights and limitations +* under the License." * * @APPLE_LICENSE_HEADER_END@ * diff --git a/ipfw.tproj/Makefile b/ipfw.tproj/Makefile index 095923b..f41fe50 100644 --- a/ipfw.tproj/Makefile +++ b/ipfw.tproj/Makefile @@ -28,6 +28,8 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) +HEADER_PATHS =\ + -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/ NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc diff --git a/ipfw.tproj/ipfw2.c b/ipfw.tproj/ipfw2.c index dcf7543..5e7c6c6 100644 --- a/ipfw.tproj/ipfw2.c +++ b/ipfw.tproj/ipfw2.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -197,6 +194,18 @@ static struct _s_x ether_types[] = { { NULL, 0 } }; +static struct _s_x exception_types[] = { + { "to", 1}, + { "dst", 2}, + { "in", 3}, + { "out", 4}, + { "xmit", 5}, + { "recv", 6}, + { "via", 7}, + { "src", 8}, + { NULL, 0} +}; + static void show_usage(void); enum tokens { @@ -562,6 +571,11 @@ strtoport(char *s, char **end, int base, int proto) buf[i++] = *p; buf[i++] = '\0'; + if ( match_token( exception_types, buf) != -1 ){ + free(buf); + return 0; + } + if (proto == IPPROTO_ETHERTYPE) { i = match_token(ether_types, buf); free(buf); diff --git a/ipsec/ipsec_dump_policy.c b/ipsec/ipsec_dump_policy.c index 390852f..200a654 100644 --- a/ipsec/ipsec_dump_policy.c +++ b/ipsec/ipsec_dump_policy.c @@ -34,7 +34,6 @@ #include #include -#include #include #include diff --git a/ipsec/policy_token.l b/ipsec/policy_token.l index 0084c81..2a43057 100644 --- a/ipsec/policy_token.l +++ b/ipsec/policy_token.l @@ -36,7 +36,6 @@ #include #include #include -#include #include #include diff --git a/kdumpd.tproj/Makefile.postamble b/kdumpd.tproj/Makefile.postamble index b71dd48..00ec691 100644 --- a/kdumpd.tproj/Makefile.postamble +++ b/kdumpd.tproj/Makefile.postamble @@ -110,3 +110,7 @@ STRIPFLAGS = # derived files should go. VPATH += :../kdumpd.tproj + +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 644 kdumpd.8 $(DSTROOT)/usr/share/man/man8/kdumpd.8 diff --git a/kdumpd.tproj/Makefile.preamble b/kdumpd.tproj/Makefile.preamble index cecb7c1..0a00836 100644 --- a/kdumpd.tproj/Makefile.preamble +++ b/kdumpd.tproj/Makefile.preamble @@ -119,3 +119,5 @@ OTHER_HELP_DIRS = OTHER_OFILES = -include ../Makefile.include + +AFTER_INSTALL = after_install diff --git a/kdumpd.tproj/kdump.h b/kdumpd.tproj/kdump.h index 0df2702..22b732d 100644 --- a/kdumpd.tproj/kdump.h +++ b/kdumpd.tproj/kdump.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/kdumpd.tproj/kdumpsubs.h b/kdumpd.tproj/kdumpsubs.h index 2bc213e..b7ec1c6 100644 --- a/kdumpd.tproj/kdumpsubs.h +++ b/kdumpd.tproj/kdumpsubs.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/logger.tproj/Makefile.postamble b/logger.tproj/Makefile.postamble index 7823726..2461439 100644 --- a/logger.tproj/Makefile.postamble +++ b/logger.tproj/Makefile.postamble @@ -121,3 +121,7 @@ STRIPFLAGS = # # Note: on MS Windows, executables, have an extension, so rules and dependencies # for generated tools should use $(EXECUTABLE_EXT) on the end. + +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man1 + install -c -m 444 logger.1 $(DSTROOT)/usr/share/man/man1/logger.1 diff --git a/logger.tproj/logger.c b/logger.tproj/logger.c index ba5493d..0ec8b27 100644 --- a/logger.tproj/logger.c +++ b/logger.tproj/logger.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/makedbm.tproj/_db.h b/makedbm.tproj/_db.h index e3e1164..bbcf1a1 100644 --- a/makedbm.tproj/_db.h +++ b/makedbm.tproj/_db.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/makedbm.tproj/db.c b/makedbm.tproj/db.c index 65ede66..f2b8acb 100644 --- a/makedbm.tproj/db.c +++ b/makedbm.tproj/db.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/makedbm.tproj/makedbm.c b/makedbm.tproj/makedbm.c index d34ba0a..8d2f73e 100644 --- a/makedbm.tproj/makedbm.c +++ b/makedbm.tproj/makedbm.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/makedbm.tproj/ypdb.c b/makedbm.tproj/ypdb.c index 9530e42..c9bd178 100644 --- a/makedbm.tproj/ypdb.c +++ b/makedbm.tproj/ypdb.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/makedbm.tproj/ypdb.h b/makedbm.tproj/ypdb.h index 61e9547..45b0a7f 100644 --- a/makedbm.tproj/ypdb.h +++ b/makedbm.tproj/ypdb.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/makedbm.tproj/ypdef.h b/makedbm.tproj/ypdef.h index ade70ef..89970d7 100644 --- a/makedbm.tproj/ypdef.h +++ b/makedbm.tproj/ypdef.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/natd.tproj/icmp.c b/natd.tproj/icmp.c index e05f255..4e62d3f 100644 --- a/natd.tproj/icmp.c +++ b/natd.tproj/icmp.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/natd.tproj/natd.8 b/natd.tproj/natd.8 index 2520d24..d9f687b 100644 --- a/natd.tproj/natd.8 +++ b/natd.tproj/natd.8 @@ -1,5 +1,5 @@ .\" manual page [] for natd 1.4 -.\" $Id: natd.8,v 1.5 2003/02/07 01:19:25 mscopp Exp $ +.\" $Id: natd.8,v 1.6 2004/10/21 21:48:41 vazquez Exp $ .Dd June 27, 2000 .Os Darwin .Dt NATD 8 @@ -40,11 +40,6 @@ with .Xr divert 4 sockets under .Fx . -It is intended for use with NICs - if you want to do NAT on a PPP link, -use the -.Fl nat -switch to -.Xr ppp 8 . .Pp The .Nm diff --git a/natd.tproj/natd.c b/natd.tproj/natd.c index 429c7f4..825473d 100644 --- a/natd.tproj/natd.c +++ b/natd.tproj/natd.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -41,6 +38,8 @@ #include #include +#include +#include #include #include @@ -66,6 +65,8 @@ #include #include #include +#include +#include #include "natd.h" @@ -152,6 +153,92 @@ static int dropIgnoredIncoming; static int logDropped; static int logFacility; +#define NATPORTMAP 1 + +#ifdef NATPORTMAP +#define NATPMPORT 5351 + +#define NATPMVERSION 0 +#define PUBLICADDRREQ 0 +#define MAPUDPREQ 1 +#define MAPTCPREQ 2 +#define MAPUDPTCPREQ 3 +#define SERVERREPLYOP 128 +#define PUBLICADDRRLY SERVERREPLYOP+PUBLICADDRREQ + +#define SUCCESS 0 +#define NOTSUPPORTEDVERSION 1 +#define NOTAUTHORIZED 2 +#define NETWORKFAILURE 3 +#define OUTOFRESOURCES 4 +#define UNSUPPORTEDOPCODE 5 +#define MAXRETRY 10 +#define TIMER_RATE 250 + +#define FAILED -1 + +typedef struct stdportmaprequest{ + char version; + unsigned char opcode; + unsigned short result; + unsigned int epoch; + char data[4]; + }stdportmaprequest; + +typedef struct publicaddrreply{ + char version; + unsigned char opcode; + unsigned short result; + unsigned int epoch; + struct in_addr addr; + }publicaddrreply; +typedef struct publicportreq{ + char version; + unsigned char opcode; + unsigned short result; + unsigned int epoch; + unsigned short privateport; + unsigned short publicport; + int lifetime; /* in second */ + }publicportreq; +typedef struct stderrreply{ + char version; + unsigned char opcode; + unsigned short result; + unsigned int epoch; + }stderrreply; + + +static int enable_natportmap = 0; +static struct in_addr lastassignaliasAddr; +static int portmapSock = -1; +static struct in_addr *forwardedinterfaceaddr; +static char **forwardedinterfacename; +static int numofinterfaces = 0; /* has to be at least one */ +static u_short natPMPport; +static int numoftries=MAXRETRY; +static struct itimerval itval; +static int Natdtimerset = 0; +static double secdivisor; + + +static void HandlePortMap( int fd ); +static void SendPortMapResponse( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, unsigned char origopcode, unsigned short result); +static void SendPublicAddress( int fd, struct sockaddr_in *clientaddr, int clientaddrlen ); +static void SendPublicPortResponse( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, publicportreq *reply, int publicport); +static void Doubletime( struct timeval *tvp); +static void Stoptimer(); +static void Natdtimer(); +static void SendPortMapMulti( ); +static void NotifyPublicAddress(); +static void DoPortMapping( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, publicportreq *req); +static void NatPortMapPInit(); +static u_short get_natportmap_port(void); + +extern int FindAliasPortOut(struct in_addr src_addr, struct in_addr dst_addr, u_short src_port, u_short pub_port, u_char proto, int lifetime, char addmapping); + +#endif + int main (int argc, char** argv) { int divertIn; @@ -181,6 +268,9 @@ int main (int argc, char** argv) running = 1; assignAliasAddr = 0; aliasAddr.s_addr = INADDR_NONE; +#ifdef NATPORTMAP + lastassignaliasAddr.s_addr = INADDR_NONE; +#endif aliasOverhead = 12; dynamicMode = 0; logDropped = 0; @@ -291,8 +381,9 @@ int main (int argc, char** argv) assignAliasAddr = 1; } - else + else{ SetAliasAddressFromIfName (ifName); + } } /* * Create socket for sending ICMP messages. @@ -307,6 +398,33 @@ int main (int argc, char** argv) */ shutdown(icmpSock, SHUT_RD); + +#if NATPORTMAP + if ( enable_natportmap ) + { + /* create socket to listen for port mapping */ + portmapSock = socket( AF_INET, SOCK_DGRAM, 0); + if ( portmapSock != -1 ) + { + natPMPport = get_natportmap_port(); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_port = NATPMPORT; + + if (bind ( portmapSock, + (struct sockaddr*) &addr, + sizeof addr) == -1) + printf("Binding to NATPM port failed!\n"); + + /* NATPORTMAPP initial set up */ + NatPortMapPInit(); + } + if ( !Natdtimerset ){ + Natdtimerset = 1; + signal(SIGALRM, Natdtimer); + } + } +#endif /* * Become a daemon unless verbose mode was requested. */ @@ -324,7 +442,15 @@ int main (int argc, char** argv) * Set alias address if it has been given. */ if (aliasAddr.s_addr != INADDR_NONE) + { PacketAliasSetAddress (aliasAddr); +#ifdef NATPORTMAP + if ( (enable_natportmap) && (aliasAddr.s_addr != lastassignaliasAddr.s_addr) ){ + lastassignaliasAddr.s_addr = aliasAddr.s_addr; + NotifyPublicAddress(); + } +#endif + } /* * We need largest descriptor number for select. */ @@ -343,6 +469,12 @@ int main (int argc, char** argv) if (routeSock > fdMax) fdMax = routeSock; +#ifdef NATPORTMAP + if ( portmapSock > fdMax ) + fdMax = portmapSock; + +#endif + while (running) { if (divertInOut != -1 && !ifName && packetSock == -1) { @@ -386,7 +518,10 @@ int main (int argc, char** argv) */ if (routeSock != -1) FD_SET (routeSock, &readMask); - +#ifdef NATPORTMAP + if ( portmapSock != -1 ) + FD_SET (portmapSock, &readMask); +#endif if (select (fdMax + 1, &readMask, &writeMask, @@ -418,6 +553,11 @@ int main (int argc, char** argv) if (routeSock != -1) if (FD_ISSET (routeSock, &readMask)) HandleRoutingInfo (routeSock); +#ifdef NATPORTMAP + if ( portmapSock != -1) + if (FD_ISSET (portmapSock, &readMask)) + HandlePortMap( portmapSock ); +#endif } if (background) @@ -677,6 +817,357 @@ static void HandleRoutingInfo (int fd) } } +#ifdef NATPORTMAP + +void getdivisor() +{ + struct mach_timebase_info info; + + (void) mach_timebase_info (&info); + + secdivisor = ( (double)info.denom / (double)info.numer) * 1000; + +} + +unsigned int getuptime() +{ + uint64_t now; + unsigned long epochtime; + + now = mach_absolute_time(); + epochtime = (now / secdivisor) /USEC_PER_SEC; + return( epochtime ); + +} + +/* return NATPORTMAP port defined in /etc/servcies if there's one, else use NATPMPORT */ +static u_short get_natportmap_port(void) +{ + struct servent *ent; + + ent = getservbyname( "natportmap", "udp" ); + if (ent != NULL){ + return( ent->s_port ); + } + return( NATPMPORT ); +} + +/* set up neccessary info for doing NatPortMapP */ +static void NatPortMapPInit() +{ + int i; + struct ifaddrs *ifap, *ifa; + + forwardedinterfaceaddr = (struct in_addr *) + malloc(numofinterfaces * sizeof(*forwardedinterfaceaddr)); + bzero(forwardedinterfaceaddr, + numofinterfaces * sizeof(*forwardedinterfaceaddr)); + /* interface address hasn't been set up, get interface address */ + getifaddrs(&ifap); + for ( ifa= ifap; ifa; ifa=ifa->ifa_next) + { + struct sockaddr_in * a; + if (ifa->ifa_addr->sa_family != AF_INET) + { + continue; + } + a = (struct sockaddr_in *)ifa->ifa_addr; + for ( i = 0; i < numofinterfaces; i++ ) + { + if (strcmp(ifa->ifa_name, forwardedinterfacename[i])) + { + continue; + } + if (forwardedinterfaceaddr[i].s_addr == 0) + { + /* copy the first IP address */ + forwardedinterfaceaddr[i] = a->sin_addr; + } + break; + } + } + freeifaddrs( ifap ); + getdivisor(); +} + +/* SendPortMapResponse */ +/* send generic reponses to NATPORTMAP requests */ +static void SendPortMapResponse( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, unsigned char origopcode, unsigned short result) +{ + stderrreply reply; + int bytes; + + reply.version = NATPMVERSION; + reply.opcode = origopcode + SERVERREPLYOP; + reply.result = result; + reply.epoch = getuptime(); + bytes = sendto( fd, (void*)&reply, sizeof(reply), 0, (struct sockaddr*)clientaddr, clientaddrlen ); + if ( bytes != sizeof(reply) ) + printf( "PORTMAP::problem sending portmap reply - opcode %d\n", reply.opcode ); +} + +/* SendPublicAddress */ +/* return public address to requestor */ +static void SendPublicAddress( int fd, struct sockaddr_in *clientaddr, int clientaddrlen ) +{ + + publicaddrreply reply; + int bytes; + + reply.version = NATPMVERSION; + reply.opcode = SERVERREPLYOP + PUBLICADDRREQ; + reply.result = SUCCESS; + reply.addr = lastassignaliasAddr; + reply.epoch = getuptime(); + + bytes = sendto (fd, (void*)&reply, sizeof(reply), 0, (struct sockaddr*)clientaddr, clientaddrlen); + if ( bytes != sizeof(reply) ) + printf( "PORTMAP::problem sending portmap reply - opcode %d\n", reply.opcode ); +} + +/* SendPublicPortResponse */ +/* response for portmap request and portmap removal request */ +/* publicport <= 0 means error */ +static void SendPublicPortResponse( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, publicportreq *reply, int publicport) +{ + + int bytes; + + reply->version = NATPMVERSION; + reply->opcode = SERVERREPLYOP + reply->opcode; + if ( publicport <= 0) + /* error in port mapping */ + reply->result = OUTOFRESOURCES; + else + reply->result = SUCCESS; + reply->epoch = getuptime(); + + if ( reply->lifetime ) /* not delete mapping */ + reply->publicport = publicport; + bytes = sendto (fd, (void*)reply, sizeof(publicportreq), 0, (struct sockaddr*)clientaddr, clientaddrlen); + if ( bytes != sizeof(publicportreq) ) + printf( "PORTMAP::problem sending portmap reply - opcode %d\n", reply->opcode ); +} + +/* SendPortMapMulti */ +/* send multicast to local network for new alias address */ +static void SendPortMapMulti() +{ + + publicaddrreply reply; + int bytes; + struct sockaddr_in multiaddr; + int multisock; + int i; + +#define LOCALGROUP "224.0.0.1" + numoftries++; + memset(&multiaddr,0,sizeof(struct sockaddr_in)); + multiaddr.sin_family=AF_INET; + multiaddr.sin_addr.s_addr=inet_addr(LOCALGROUP); + multiaddr.sin_port=htons(NATPMPORT); + reply.version = NATPMVERSION; + reply.opcode = SERVERREPLYOP + PUBLICADDRREQ; + reply.result = SUCCESS; + reply.addr = lastassignaliasAddr; + reply.epoch = 0; + + /* send multicast to all forwarded interfaces */ + for ( i = 0; i < numofinterfaces; i++) + { + if (forwardedinterfaceaddr[i].s_addr == 0) + { + continue; + } + multisock = socket( AF_INET, SOCK_DGRAM, 0); + + if ( multisock == -1 ) + { + printf("cannot get socket for sending multicast\n"); + return; + } + if (setsockopt(multisock, IPPROTO_IP, IP_MULTICAST_IF, &forwardedinterfaceaddr[i], sizeof(struct in_addr)) < 0) + { + printf("setsockopt failed\n"); + close(multisock); + continue; + } + bytes = sendto (multisock, (void*)&reply, sizeof(reply), 0, (struct sockaddr*)&multiaddr, sizeof(multiaddr)); + if ( bytes != sizeof(reply) ) + printf( "PORTMAP::problem sending multicast alias address - opcode %d\n", reply.opcode ); + close(multisock); + } + +} + +/* double the time value */ +static void Doubletime( struct timeval *tvp) +{ + + if ( tvp->tv_sec ) + tvp->tv_sec *= 2; + if ( tvp->tv_usec ) + tvp->tv_usec *= 2; + if (tvp->tv_usec >= 1000000) { + tvp->tv_sec += tvp->tv_usec / 1000000; + tvp->tv_usec = tvp->tv_usec % 1000000; + } +} + +/* stop running natd timer */ +static void Stoptimer() +{ + itval.it_value.tv_usec = 0; + if (setitimer(ITIMER_REAL, &itval, (struct itimerval *)NULL) < 0) + printf( "setitimer err: %d\n", errno); +} + +/* natdtimer */ +/* timer routine to send new public IP address */ +static void Natdtimer() +{ + if ( !enable_natportmap ) + return; + + SendPortMapMulti(); + + if ( numoftries < MAXRETRY ){ + Doubletime( &itval.it_value); + itval.it_interval = itval.it_value; + if (setitimer(ITIMER_REAL, &itval, (struct itimerval *)NULL) < 0) + printf( "setitimer err: %d\n", errno); + } + else + { + Stoptimer(); + return; + } + +} + +/* NotifyPublicAddress */ +/* Advertise new public address */ +static void NotifyPublicAddress() +{ + if ( numoftries < MAXRETRY) + { + /* there is an old timer running, cancel it */ + Stoptimer(); + } + /* send up new timer */ + numoftries = 0; + SendPortMapMulti(); + itval.it_value.tv_sec = 0; + itval.it_value.tv_usec = TIMER_RATE; + itval.it_interval.tv_sec = 0; + itval.it_interval.tv_usec = TIMER_RATE; + if (setitimer(ITIMER_REAL, &itval, (struct itimerval *)NULL) < 0) + printf( "setitimer err: %d\n", errno); + +} + +/* DoPortMapping */ +/* find/add/remove port mapping from alias manager */ +void DoPortMapping( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, publicportreq *req) +{ + u_char proto = IPPROTO_TCP; + int aliasport; + + if ( req->opcode == MAPUDPREQ) + proto = IPPROTO_UDP; + if ( req->lifetime == 0) + { + /* remove port mapping */ + if ( !FindAliasPortOut( clientaddr->sin_addr, lastassignaliasAddr, req->privateport, req->publicport, proto, req->lifetime, 0)) + /* FindAliasPortOut returns no error, port successfully removed, return no error response to client */ + SendPublicPortResponse( fd, clientaddr, clientaddrlen, req, 1 ); + else + /* deleting port fails, return error */ + SendPublicPortResponse( fd, clientaddr, clientaddrlen, req, -1 ); + } + else + { + /* look for port mapping - public port is ignored in this case */ + /* create port mapping - map provided public port to private port if public port is not 0 */ + aliasport = FindAliasPortOut( clientaddr->sin_addr, lastassignaliasAddr, req->privateport, req->publicport, proto, req->lifetime, 1); + /* aliasport should be non zero if mapping is successfully, else -1 is returned, alias port shouldn't be zero???? */ + SendPublicPortResponse( fd, clientaddr, clientaddrlen, req, aliasport ); + + } +} + +/* HandlePortMap */ +/* handle all packets sent to NATPORTMAP port */ +static void HandlePortMap( int fd ) +{ +#define MAXBUFFERSIZE 100 + + struct sockaddr_in clientaddr; + int clientaddrlen; + unsigned char buffer[MAXBUFFERSIZE]; + int bytes; + unsigned short result = SUCCESS; + struct stdportmaprequest *req; + + clientaddrlen = sizeof( clientaddr ); + bytes = recvfrom( fd, buffer, sizeof(buffer), 0, (struct sockaddr*)&clientaddr, &clientaddrlen); + if ( bytes == -1 ) + { + printf( "Read NATPM port error\n"); + return; + } + req = (struct stdportmaprequest*)buffer; + +#ifdef DEBUG + { + int i; + + for ( i = 0; iversion > NATPMVERSION ) + result = NOTSUPPORTEDVERSION; + else if ( !enable_natportmap ) + /* natd wasn't launched with portmapping enabled */ + result = NOTAUTHORIZED; + + if ( result ) + { + SendPortMapResponse( fd, &clientaddr, clientaddrlen, req->opcode, result ); + return; + } + + switch ( req->opcode ) + { + case PUBLICADDRREQ: + { + SendPublicAddress(fd, &clientaddr, clientaddrlen); + break; + } + + case MAPUDPREQ: + case MAPTCPREQ: + case MAPUDPTCPREQ: + { + DoPortMapping( fd, &clientaddr, clientaddrlen, (publicportreq*)req); + break; + } + + + default: + SendPortMapResponse( fd, &clientaddr, clientaddrlen, req->opcode, UNSUPPORTEDOPCODE ); + } + +} + + +#endif + static void PrintPacket (struct ip* ip) { printf ("%s", FormatPacket (ip)); @@ -830,6 +1321,18 @@ SetAliasAddressFromIfName(const char *ifn) errx(1, "%s: cannot get interface address", ifn); PacketAliasSetAddress(sin->sin_addr); +#ifdef NATPORTMAP + if ( (enable_natportmap) && (sin->sin_addr.s_addr != lastassignaliasAddr.s_addr) ) + { + lastassignaliasAddr.s_addr = sin->sin_addr.s_addr; + /* make sure the timer handler was set before setting timer */ + if ( !Natdtimerset ){ + Natdtimerset = 1; + signal(SIGALRM, Natdtimer); + } + NotifyPublicAddress(); + } +#endif syslog(LOG_INFO, "Aliasing to %s, mtu %d bytes", inet_ntoa(sin->sin_addr), ifMTU); } @@ -897,7 +1400,11 @@ enum Option { ProxyRule, LogDenied, LogFacility, - PunchFW + PunchFW, +#ifdef NATPORTMAP + NATPortMap, + ToInterfaceName +#endif }; enum Param { @@ -1123,7 +1630,26 @@ static struct OptionInfo optionTable[] = { "basenumber:count", "punch holes in the firewall for incoming FTP/IRC DCC connections", "punch_fw", - NULL } + NULL }, + +#ifdef NATPORTMAP + { NATPortMap, + 0, + YesNo, + "[yes|no]", + "enable NATPortMap protocol", + "enable_natportmap", + NULL }, + + { ToInterfaceName, + 0, + String, + "network_if_name", + "take aliasing address to interface", + "natportmap_interface", + NULL }, + +#endif }; static void ParseOption (const char* option, const char* parms) @@ -1311,6 +1837,37 @@ static void ParseOption (const char* option, const char* parms) case PunchFW: SetupPunchFW(strValue); break; + +#ifdef NATPORTMAP + case NATPortMap: + enable_natportmap = yesNoValue; + break; + + + case ToInterfaceName: + { + if (forwardedinterfacename != NULL) + { + if ( realloc(forwardedinterfacename, (numofinterfaces+1) * sizeof(*forwardedinterfacename)) == NULL){ + printf("realloc error, cannot allocate memory for fowarded interface name.\n"); + return; + } + } + else { + if ( (forwardedinterfacename = malloc( sizeof(*forwardedinterfacename) )) == NULL ){ + printf("malloc error, cannot allocate memory for fowarded interface name.\n"); + return; + } + } + + forwardedinterfacename[numofinterfaces] = strdup(strValue); + numofinterfaces++; + + break; + } + +#endif + } } diff --git a/natd.tproj/natd.h b/natd.tproj/natd.h index 204c305..f2c1f26 100644 --- a/natd.tproj/natd.h +++ b/natd.tproj/natd.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/netstat.tproj/Makefile b/netstat.tproj/Makefile index dfb70de..88786fd 100644 --- a/netstat.tproj/Makefile +++ b/netstat.tproj/Makefile @@ -33,7 +33,7 @@ PROF_LIBS = $(LIBS) HEADER_PATHS =\ - -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/bsd/netat + -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/ NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc diff --git a/netstat.tproj/data.c b/netstat.tproj/data.c index 16aeae5..9e0bbe2 100644 --- a/netstat.tproj/data.c +++ b/netstat.tproj/data.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/netstat.tproj/if.c b/netstat.tproj/if.c index 0be2dc8..ecee15d 100644 --- a/netstat.tproj/if.c +++ b/netstat.tproj/if.c @@ -36,11 +36,10 @@ static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95"; */ static const char rcsid[] = - "$Id: if.c,v 1.2 2002/03/05 20:35:13 lindak Exp $"; + "$Id: if.c,v 1.6 2005/01/25 00:10:05 lindak Exp $"; #endif /* not lint */ #include -#include #include #include #include @@ -49,7 +48,10 @@ static const char rcsid[] = #include #include #include +#include #include +#include + #include #include @@ -68,22 +70,33 @@ static const char rcsid[] = #include #include #include +#include +#include #include "netstat.h" #define YES 1 #define NO 0 -static void sidewaysintpr (u_int, u_long); +#define ROUNDUP(a, size) (((a) & ((size) - 1)) ? (1 + ((a)|(size - 1))) : (a)) + +#define NEXT_SA(p) (struct sockaddr *) \ + ((caddr_t)p + (p->sa_len ? ROUNDUP(p->sa_len, sizeof(u_long)) : \ + sizeof(u_long))) + +static void sidewaysintpr (); static void catchalarm (int); #ifdef INET6 -char *netname6 (struct sockaddr_in6 *, struct in6_addr *); +char *netname6 (struct sockaddr_in6 *, struct sockaddr *); static char ntop_buf[INET6_ADDRSTRLEN]; /* for inet_ntop() */ -static int bdg_done; #endif #if 0 +#ifdef INET6 +static int bdg_done; +#endif + /* print bridge statistics */ void bdg_stats(u_long dummy , char *name, int af ) @@ -131,7 +144,7 @@ bdg_stats(u_long dummy , char *name, int af ) * Display a formatted value, or a '-' in the same space. */ static void -show_stat(const char *fmt, int width, u_long value, short showvalue) +show_stat(const char *fmt, int width, u_int64_t value, short showvalue) { char newfmt[32]; @@ -145,63 +158,139 @@ show_stat(const char *fmt, int width, u_long value, short showvalue) } } +size_t +get_rti_info(int addrs, struct sockaddr *sa, struct sockaddr **rti_info) +{ + int i; + size_t len = 0; + + for (i = 0; i < RTAX_MAX; i++) { + if (addrs & (1 << i)) { + rti_info[i] = sa; + if (sa->sa_len < sizeof(struct sockaddr)) + len += sizeof(struct sockaddr); + else + len += sa->sa_len; + sa = NEXT_SA(sa); + } else { + rti_info[i] = NULL; + } + } + return len; +} +static void +multipr(int family, char *buf, char *lim) +{ + char *next; + + for (next = buf; next < lim; ) { + struct ifma_msghdr2 *ifmam = (struct ifma_msghdr2 *)next; + struct sockaddr *rti_info[RTAX_MAX]; + struct sockaddr *sa; + const char *fmt = 0; + + next += ifmam->ifmam_msglen; + if (ifmam->ifmam_type == RTM_IFINFO2) + break; + else if (ifmam->ifmam_type != RTM_NEWMADDR2) + continue; + get_rti_info(ifmam->ifmam_addrs, (struct sockaddr*)(ifmam + 1), rti_info); + sa = rti_info[RTAX_IFA]; + + if (sa->sa_family != family) + continue; + switch (sa->sa_family) { + case AF_INET: { + struct sockaddr_in *sin = (struct sockaddr_in *)sa; + + fmt = routename(sin->sin_addr.s_addr); + break; + } + #ifdef INET6 + case AF_INET6: { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; + + printf("%23s %-19.19s(refs: %d)\n", "", + inet_ntop(AF_INET6, + &sin6->sin6_addr, + ntop_buf, + sizeof(ntop_buf)), + ifmam->ifmam_refcount); + break; + } + #endif /* INET6 */ + case AF_LINK: { + struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa; + + switch (sdl->sdl_type) { + case IFT_ETHER: + case IFT_FDDI: + fmt = ether_ntoa( + (struct ether_addr *) + LLADDR(sdl)); + break; + } + break; + } + } + if (fmt) + printf("%23s %s\n", "", fmt); + } +} /* * Print a description of the network interfaces. */ void -intpr(int interval, u_long ifnetaddr, void (*pfunc)(char *)) +intpr(void (*pfunc)(char *)) { - struct ifnet ifnet; - struct ifnethead ifnethead; - union { - struct ifaddr ifa; - struct in_ifaddr in; -#ifdef INET6 - struct in6_ifaddr in6; -#endif -#if 0 - struct ipx_ifaddr ipx; -#endif -#ifdef NS - struct ns_ifaddr ns; -#endif -#ifdef ISO - struct iso_ifaddr iso; -#endif - } ifaddr; - u_long ifaddraddr; - u_long ifaddrfound; - u_long ifnetfound; - u_long opackets; - u_long ipackets; - u_long obytes; - u_long ibytes; - u_long oerrors; - u_long ierrors; - u_long collisions; - short timer; - int drops; + u_int64_t opackets = 0; + u_int64_t ipackets = 0; + u_int64_t obytes = 0; + u_int64_t ibytes = 0; + u_int64_t oerrors = 0; + u_int64_t ierrors = 0; + u_int64_t collisions = 0; + u_long mtu = 0; + short timer = 0; + int drops = 0; struct sockaddr *sa = NULL; - char name[32], tname[16]; + char name[32]; short network_layer; short link_layer; - - if (ifnetaddr == 0) { - printf("ifnet: symbol not defined\n"); - return; - } + int mib[6]; + char *buf = NULL, *lim, *next; + size_t len; + struct if_msghdr *ifm; + struct sockaddr *rti_info[RTAX_MAX]; + unsigned int ifindex = 0; + if (interval) { - sidewaysintpr((unsigned)interval, ifnetaddr); + sidewaysintpr(); return; } - if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead)) + + if (interface != 0) + ifindex = if_nametoindex(interface); + + mib[0] = CTL_NET; // networking subsystem + mib[1] = PF_ROUTE; // type of information + mib[2] = 0; // protocol (IPPROTO_xxx) + mib[3] = 0; // address family + mib[4] = NET_RT_IFLIST2; // operation + mib[5] = 0; + if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) return; - ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead); - if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) + if ((buf = malloc(len)) == NULL) { + printf("malloc failed\n"); + exit(1); + } + if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { + if (buf) + free(buf); return; - + } if (!pfunc) { printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s", "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs"); @@ -217,27 +306,23 @@ intpr(int interval, u_long ifnetaddr, void (*pfunc)(char *)) printf(" %s", "Drop"); putchar('\n'); } - ifaddraddr = 0; - while (ifnetaddr || ifaddraddr) { - struct sockaddr_in *sin; -#ifdef INET6 - struct sockaddr_in6 *sin6; -#endif - register char *cp; + lim = buf + len; + for (next = buf; next < lim; ) { + char *cp; int n, m; - + network_layer = 0; link_layer = 0; + ifm = (struct if_msghdr *)next; + next += ifm->ifm_msglen; + + if (ifm->ifm_type == RTM_IFINFO2) { + struct if_msghdr2 *if2m = (struct if_msghdr2 *)ifm; + struct sockaddr_dl *sdl = (struct sockaddr_dl *)(if2m + 1); - if (ifaddraddr == 0) { - ifnetfound = ifnetaddr; - if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) || - kread((u_long)ifnet.if_name, tname, 16)) - return; - tname[15] = '\0'; - ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link); - snprintf(name, 32, "%s%d", tname, ifnet.if_unit); - if (interface != 0 && (strcmp(name, interface) != 0)) + strncpy(name, sdl->sdl_data, sdl->sdl_nlen); + name[sdl->sdl_nlen] = 0; + if (interface != 0 && if2m->ifm_index != ifindex) continue; cp = index(name, '\0'); @@ -246,71 +331,71 @@ intpr(int interval, u_long ifnetaddr, void (*pfunc)(char *)) continue; } - if ((ifnet.if_flags&IFF_UP) == 0) + if ((if2m->ifm_flags & IFF_UP) == 0) *cp++ = '*'; *cp = '\0'; - ifaddraddr = (u_long)TAILQ_FIRST(&ifnet.if_addrhead); - } - printf("%-5.5s %-5lu ", name, ifnet.if_mtu); - ifaddrfound = ifaddraddr; - - /* - * Get the interface stats. These may get - * overriden below on a per-interface basis. - */ - opackets = ifnet.if_opackets; - ipackets = ifnet.if_ipackets; - obytes = ifnet.if_obytes; - ibytes = ifnet.if_ibytes; - oerrors = ifnet.if_oerrors; - ierrors = ifnet.if_ierrors; - collisions = ifnet.if_collisions; - timer = ifnet.if_timer; - drops = ifnet.if_snd.ifq_drops; - - if (ifaddraddr == 0) { + + /* + * Get the interface stats. These may get + * overriden below on a per-interface basis. + */ + opackets = if2m->ifm_data.ifi_opackets; + ipackets = if2m->ifm_data.ifi_ipackets; + obytes = if2m->ifm_data.ifi_obytes; + ibytes = if2m->ifm_data.ifi_ibytes; + oerrors =if2m->ifm_data.ifi_oerrors; + ierrors = if2m->ifm_data.ifi_ierrors; + collisions = if2m->ifm_data.ifi_collisions; + timer = if2m->ifm_timer; + drops = if2m->ifm_snd_drops; + mtu = if2m->ifm_data.ifi_mtu; + + get_rti_info(if2m->ifm_addrs, (struct sockaddr*)(if2m + 1), rti_info); + sa = rti_info[RTAX_IFP]; + } else if (ifm->ifm_type == RTM_NEWADDR) { + struct ifa_msghdr *ifam = (struct ifa_msghdr *)ifm; + + if (interface != 0 && ifam->ifam_index != ifindex) + continue; + get_rti_info(ifam->ifam_addrs, (struct sockaddr*)(ifam + 1), rti_info); + sa = rti_info[RTAX_IFA]; + } else + continue; + printf("%-5.5s %-5lu ", name, mtu); + + if (sa == 0) { printf("%-13.13s ", "none"); printf("%-15.15s ", "none"); } else { - if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) { - ifaddraddr = 0; - continue; - } -#define CP(x) ((char *)(x)) - cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) + - CP(&ifaddr); - sa = (struct sockaddr *)cp; switch (sa->sa_family) { case AF_UNSPEC: printf("%-13.13s ", "none"); printf("%-15.15s ", "none"); break; - case AF_INET: - sin = (struct sockaddr_in *)sa; -#ifdef notdef - /* can't use inet_makeaddr because kernel - * keeps nets unshifted. - */ - in = inet_makeaddr(ifaddr.in.ia_subnet, - INADDR_ANY); - printf("%-13.13s ", netname(in.s_addr, - ifaddr.in.ia_subnetmask)); -#else - printf("%-13.13s ", - netname(htonl(ifaddr.in.ia_subnet), - ifaddr.in.ia_subnetmask)); -#endif + case AF_INET: { + struct sockaddr_in *sin = (struct sockaddr_in *)sa; + struct sockaddr_in mask; + + mask.sin_addr.s_addr = 0; + memcpy(&mask, rti_info[RTAX_NETMASK], ((struct sockaddr_in *)rti_info[RTAX_NETMASK])->sin_len); + + printf("%-13.13s ", netname(sin->sin_addr.s_addr & mask.sin_addr.s_addr, + mask.sin_addr.s_addr)); + printf("%-15.15s ", routename(sin->sin_addr.s_addr)); network_layer = 1; break; + } #ifdef INET6 - case AF_INET6: - sin6 = (struct sockaddr_in6 *)sa; + case AF_INET6: { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; + struct sockaddr *mask = (struct sockaddr *)rti_info[RTAX_NETMASK]; + printf("%-11.11s ", - netname6(&ifaddr.in6.ia_addr, - &ifaddr.in6.ia_prefixmask.sin6_addr)); + netname6(sin6, + mask)); printf("%-17.17s ", (char *)inet_ntop(AF_INET6, &sin6->sin6_addr, @@ -318,46 +403,8 @@ intpr(int interval, u_long ifnetaddr, void (*pfunc)(char *)) network_layer = 1; break; + } #endif /*INET6*/ -#if 0 - case AF_IPX: - { - struct sockaddr_ipx *sipx = - (struct sockaddr_ipx *)sa; - u_long net; - char netnum[10]; - - *(union ipx_net *) &net = sipx->sipx_addr.x_net; - sprintf(netnum, "%lx", (u_long)ntohl(net)); - printf("ipx:%-8s ", netnum); -/* printf("ipx:%-8s ", netname(net, 0L)); */ - printf("%-15s ", - ipx_phost((struct sockaddr *)sipx)); - } - break; - - case AF_APPLETALK: - printf("atalk:%-12.12s ",atalk_print(sa,0x10) ); - printf("%-9.9s ",atalk_print(sa,0x0b) ); - break; -#endif -#ifdef NS - case AF_NS: - { - struct sockaddr_ns *sns = - (struct sockaddr_ns *)sa; - u_long net; - char netnum[10]; - - *(union ns_net *) &net = sns->sns_addr.x_net; - sprintf(netnum, "%lxH", ntohl(net)); - upHex(netnum); - printf("ns:%-8s ", netnum); - printf("%-15s ", - ns_phost((struct sockaddr *)sns)); - } - break; -#endif case AF_LINK: { struct sockaddr_dl *sdl = @@ -398,107 +445,51 @@ intpr(int interval, u_long ifnetaddr, void (*pfunc)(char *)) ibytes = ifaddr.in.ia_ifa.if_ibytes; } #endif - ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link); } - show_stat("lu", 8, ipackets, link_layer|network_layer); + show_stat("llu", 8, ipackets, link_layer|network_layer); printf(" "); - show_stat("lu", 5, ierrors, link_layer); + show_stat("llu", 5, ierrors, link_layer); printf(" "); if (bflag) { - show_stat("lu", 10, ibytes, link_layer|network_layer); + show_stat("llu", 10, ibytes, link_layer|network_layer); printf(" "); } - show_stat("lu", 8, opackets, link_layer|network_layer); + show_stat("llu", 8, opackets, link_layer|network_layer); printf(" "); - show_stat("lu", 5, oerrors, link_layer); + show_stat("llu", 5, oerrors, link_layer); printf(" "); if (bflag) { - show_stat("lu", 10, obytes, link_layer|network_layer); + show_stat("llu", 10, obytes, link_layer|network_layer); printf(" "); } - show_stat("lu", 5, collisions, link_layer); + show_stat("llu", 5, collisions, link_layer); if (tflag) { printf(" "); - show_stat("d", 3, timer, link_layer); + show_stat("ll", 3, timer, link_layer); } if (dflag) { printf(" "); - show_stat("d", 3, drops, link_layer); + show_stat("ll", 3, drops, link_layer); } putchar('\n'); - if (aflag && ifaddrfound) { - /* - * Print family's multicast addresses - */ - u_long multiaddr; - struct ifmultiaddr ifma; - union { - struct sockaddr sa; - struct sockaddr_in in; -#ifdef INET6 - struct sockaddr_in6 in6; -#endif /* INET6 */ - struct sockaddr_dl dl; - } msa; - const char *fmt; - - for(multiaddr = (u_long)ifnet.if_multiaddrs.lh_first; - multiaddr; - multiaddr = (u_long)ifma.ifma_link.le_next) { - if (kread(multiaddr, (char *)&ifma, - sizeof ifma)) - break; - if (kread((u_long)ifma.ifma_addr, (char *)&msa, - sizeof msa)) - break; - if (msa.sa.sa_family != sa->sa_family) - continue; - - fmt = 0; - switch (msa.sa.sa_family) { - case AF_INET: - fmt = routename(msa.in.sin_addr.s_addr); - break; -#ifdef INET6 - case AF_INET6: - printf("%23s %-19.19s(refs: %d)\n", "", - inet_ntop(AF_INET6, - &msa.in6.sin6_addr, - ntop_buf, - sizeof(ntop_buf)), - ifma.ifma_refcount); - break; -#endif /* INET6 */ - case AF_LINK: - switch (msa.dl.sdl_type) { - case IFT_ETHER: - case IFT_FDDI: - fmt = ether_ntoa( - (struct ether_addr *) - LLADDR(&msa.dl)); - break; - } - break; - } - if (fmt) - printf("%23s %s\n", "", fmt); - } - } + + if (aflag) + multipr(sa->sa_family, next, lim); } } struct iftot { SLIST_ENTRY(iftot) chain; - char ift_name[16]; /* interface name */ - u_long ift_ip; /* input packets */ - u_long ift_ie; /* input errors */ - u_long ift_op; /* output packets */ - u_long ift_oe; /* output errors */ - u_long ift_co; /* collisions */ - u_int ift_dr; /* drops */ - u_long ift_ib; /* input bytes */ - u_long ift_ob; /* output bytes */ + char ift_name[16]; /* interface name */ + u_int64_t ift_ip; /* input packets */ + u_int64_t ift_ie; /* input errors */ + u_int64_t ift_op; /* output packets */ + u_int64_t ift_oe; /* output errors */ + u_int64_t ift_co; /* collisions */ + u_int64_t ift_dr; /* drops */ + u_int64_t ift_ib; /* input bytes */ + u_int64_t ift_ob; /* output bytes */ }; u_char signalled; /* set if alarm goes off "early" */ @@ -511,61 +502,55 @@ u_char signalled; /* set if alarm goes off "early" */ * XXX - should be rewritten to use ifmib(4). */ static void -sidewaysintpr(unsigned interval, u_long off) +sidewaysintpr() { - struct ifnet ifnet; - u_long firstifnet; - struct ifnethead ifnethead; - struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting; + struct iftot *total, *sum, *interesting; register int line; int oldmask, first; - u_long interesting_off; - - if (kread(off, (char *)&ifnethead, sizeof ifnethead)) - return; - firstifnet = (u_long)TAILQ_FIRST(&ifnethead); - - if ((iftot = malloc(sizeof(struct iftot))) == NULL) { - printf("malloc failed\n"); - exit(1); - } - memset(iftot, 0, sizeof(struct iftot)); - + int name[6]; + size_t len; + unsigned int ifcount, i; + struct ifmibdata *ifmdall = 0; + int interesting_row; + + /* Common OID prefix */ + name[0] = CTL_NET; + name[1] = PF_LINK; + name[2] = NETLINK_GENERIC; + + len = sizeof(int); + name[3] = IFMIB_SYSTEM; + name[4] = IFMIB_IFCOUNT; + if (sysctl(name, 5, &ifcount, &len, 0, 0) == 1) + err(1, "sysctl IFMIB_IFCOUNT"); + + len = ifcount * sizeof(struct ifmibdata); + ifmdall = malloc(len); + if (ifmdall == 0) + err(1, "malloc failed"); + name[3] = IFMIB_IFALLDATA; + name[4] = 0; + name[5] = IFDATA_GENERAL; + if (sysctl(name, 6, ifmdall, &len, (void *)0, 0) == -1) + err(1, "sysctl IFMIB_IFALLDATA"); + interesting = NULL; - interesting_off = 0; - for (off = firstifnet, ip = iftot; off;) { - char name[16], tname[16]; - - if (kread(off, (char *)&ifnet, sizeof ifnet)) - break; - if (kread((u_long)ifnet.if_name, tname, 16)) - break; - tname[15] = '\0'; - snprintf(name, 16, "%s%d", tname, ifnet.if_unit); - if (interface && strcmp(name, interface) == 0) { - interesting = ip; - interesting_off = off; - } - snprintf(ip->ift_name, 16, "(%s)", name);; - if ((ipn = malloc(sizeof(struct iftot))) == NULL) { - printf("malloc failed\n"); - exit(1); + interesting_row = 0; + for (i = 0; i < ifcount; i++) { + struct ifmibdata *ifmd = ifmdall + i; + + if (interface && strcmp(ifmd->ifmd_name, interface) == 0) { + if ((interesting = calloc(ifcount, sizeof(struct iftot))) == NULL) + err(1, "malloc failed"); + interesting_row = i + 1; + snprintf(interesting->ift_name, 16, "(%s)", ifmd->ifmd_name);; } - memset(ipn, 0, sizeof(struct iftot)); - SLIST_NEXT(ip, chain) = ipn; - ip = ipn; - off = (u_long)TAILQ_NEXT(&ifnet, if_link); } - if ((total = malloc(sizeof(struct iftot))) == NULL) { - printf("malloc failed\n"); - exit(1); - } - memset(total, 0, sizeof(struct iftot)); - if ((sum = malloc(sizeof(struct iftot))) == NULL) { - printf("malloc failed\n"); - exit(1); - } - memset(sum, 0, sizeof(struct iftot)); + if ((total = calloc(1, sizeof(struct iftot))) == NULL) + err(1, "malloc failed"); + + if ((sum = calloc(1, sizeof(struct iftot))) == NULL) + err(1, "malloc failed"); (void)signal(SIGALRM, catchalarm); @@ -585,32 +570,61 @@ banner: line = 0; loop: if (interesting != NULL) { - ip = interesting; - if (kread(interesting_off, (char *)&ifnet, sizeof ifnet)) { - printf("???\n"); - exit(1); - }; + struct ifmibdata ifmd; + + len = sizeof(struct ifmibdata); + name[3] = IFMIB_IFDATA; + name[4] = interesting_row; + name[5] = IFDATA_GENERAL; + if (sysctl(name, 6, &ifmd, &len, (void *)0, 0) == -1) + err(1, "sysctl IFDATA_GENERAL %d", interesting_row); + if (!first) { - printf("%10lu %5lu %10lu %10lu %5lu %10lu %5lu", - ifnet.if_ipackets - ip->ift_ip, - ifnet.if_ierrors - ip->ift_ie, - ifnet.if_ibytes - ip->ift_ib, - ifnet.if_opackets - ip->ift_op, - ifnet.if_oerrors - ip->ift_oe, - ifnet.if_obytes - ip->ift_ob, - ifnet.if_collisions - ip->ift_co); + printf("%10llu %5llu %10llu %10llu %5llu %10llu %5llu", + ifmd.ifmd_data.ifi_ipackets - interesting->ift_ip, + ifmd.ifmd_data.ifi_ierrors - interesting->ift_ie, + ifmd.ifmd_data.ifi_ibytes - interesting->ift_ib, + ifmd.ifmd_data.ifi_opackets - interesting->ift_op, + ifmd.ifmd_data.ifi_oerrors - interesting->ift_oe, + ifmd.ifmd_data.ifi_obytes - interesting->ift_ob, + ifmd.ifmd_data.ifi_collisions - interesting->ift_co); if (dflag) - printf(" %5u", ifnet.if_snd.ifq_drops - ip->ift_dr); + printf(" %5llu", ifmd.ifmd_snd_drops - interesting->ift_dr); } - ip->ift_ip = ifnet.if_ipackets; - ip->ift_ie = ifnet.if_ierrors; - ip->ift_ib = ifnet.if_ibytes; - ip->ift_op = ifnet.if_opackets; - ip->ift_oe = ifnet.if_oerrors; - ip->ift_ob = ifnet.if_obytes; - ip->ift_co = ifnet.if_collisions; - ip->ift_dr = ifnet.if_snd.ifq_drops; + interesting->ift_ip = ifmd.ifmd_data.ifi_ipackets; + interesting->ift_ie = ifmd.ifmd_data.ifi_ierrors; + interesting->ift_ib = ifmd.ifmd_data.ifi_ibytes; + interesting->ift_op = ifmd.ifmd_data.ifi_opackets; + interesting->ift_oe = ifmd.ifmd_data.ifi_oerrors; + interesting->ift_ob = ifmd.ifmd_data.ifi_obytes; + interesting->ift_co = ifmd.ifmd_data.ifi_collisions; + interesting->ift_dr = ifmd.ifmd_snd_drops; } else { + unsigned int latest_ifcount; + + len = sizeof(int); + name[3] = IFMIB_SYSTEM; + name[4] = IFMIB_IFCOUNT; + if (sysctl(name, 5, &latest_ifcount, &len, 0, 0) == 1) + err(1, "sysctl IFMIB_IFCOUNT"); + if (latest_ifcount > ifcount) { + ifcount = latest_ifcount; + len = ifcount * sizeof(struct ifmibdata); + free(ifmdall); + ifmdall = malloc(len); + if (ifmdall == 0) + err(1, "malloc failed"); + } else if (latest_ifcount > ifcount) { + ifcount = latest_ifcount; + len = ifcount * sizeof(struct ifmibdata); + } + len = ifcount * sizeof(struct ifmibdata); + name[3] = IFMIB_IFALLDATA; + name[4] = 0; + name[5] = IFDATA_GENERAL; + if (sysctl(name, 6, ifmdall, &len, (void *)0, 0) == -1) + err(1, "sysctl IFMIB_IFALLDATA"); + sum->ift_ip = 0; sum->ift_ie = 0; sum->ift_ib = 0; @@ -619,25 +633,20 @@ loop: sum->ift_ob = 0; sum->ift_co = 0; sum->ift_dr = 0; - for (off = firstifnet, ip = iftot; - off && SLIST_NEXT(ip, chain) != NULL; - ip = SLIST_NEXT(ip, chain)) { - if (kread(off, (char *)&ifnet, sizeof ifnet)) { - off = 0; - continue; - } - sum->ift_ip += ifnet.if_ipackets; - sum->ift_ie += ifnet.if_ierrors; - sum->ift_ib += ifnet.if_ibytes; - sum->ift_op += ifnet.if_opackets; - sum->ift_oe += ifnet.if_oerrors; - sum->ift_ob += ifnet.if_obytes; - sum->ift_co += ifnet.if_collisions; - sum->ift_dr += ifnet.if_snd.ifq_drops; - off = (u_long)TAILQ_NEXT(&ifnet, if_link); + for (i = 0; i < ifcount; i++) { + struct ifmibdata *ifmd = ifmdall + i; + + sum->ift_ip += ifmd->ifmd_data.ifi_ipackets; + sum->ift_ie += ifmd->ifmd_data.ifi_ierrors; + sum->ift_ib += ifmd->ifmd_data.ifi_ibytes; + sum->ift_op += ifmd->ifmd_data.ifi_opackets; + sum->ift_oe += ifmd->ifmd_data.ifi_oerrors; + sum->ift_ob += ifmd->ifmd_data.ifi_obytes; + sum->ift_co += ifmd->ifmd_data.ifi_collisions; + sum->ift_dr += ifmd->ifmd_snd_drops; } if (!first) { - printf("%10lu %5lu %10lu %10lu %5lu %10lu %5lu", + printf("%10llu %5llu %10llu %10llu %5llu %10llu %5llu", sum->ift_ip - total->ift_ip, sum->ift_ie - total->ift_ie, sum->ift_ib - total->ift_ib, @@ -646,7 +655,7 @@ loop: sum->ift_ob - total->ift_ob, sum->ift_co - total->ift_co); if (dflag) - printf(" %5u", sum->ift_dr - total->ift_dr); + printf(" %5llu", sum->ift_dr - total->ift_dr); } *total = *sum; } diff --git a/netstat.tproj/inet.c b/netstat.tproj/inet.c index 325aa4f..53899cb 100644 --- a/netstat.tproj/inet.c +++ b/netstat.tproj/inet.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95"; */ static const char rcsid[] = - "$Id: inet.c,v 1.6 2003/07/08 22:49:49 lindak Exp $"; + "$Id: inet.c,v 1.7 2004/08/26 23:55:22 lindak Exp $"; #endif /* not lint */ #include @@ -44,7 +44,6 @@ static const char rcsid[] = #include #include #include -#include #include #include @@ -63,9 +62,7 @@ static const char rcsid[] = #include #define TCPSTATES #include -#include #include -#include #include #include diff --git a/netstat.tproj/inet6.c b/netstat.tproj/inet6.c index c8bb084..18f7038 100644 --- a/netstat.tproj/inet6.c +++ b/netstat.tproj/inet6.c @@ -45,8 +45,6 @@ static char sccsid[] = "@(#)inet6.c 8.4 (Berkeley) 4/20/94"; #include #include #include -#include -#include #include #include @@ -73,7 +71,6 @@ static char sccsid[] = "@(#)inet6.c 8.4 (Berkeley) 4/20/94"; #ifdef __APPLE__ #define __unused #endif -struct socket sockb; char *inet6name (struct in6_addr *); void inet6print (struct in6_addr *, int, char *, int); @@ -965,14 +962,15 @@ icmp6_ifstats(char *ifname) /* * Dump PIM statistics structure. */ +#ifdef notyet void -pim6_stats(u_long off __unused, char *name, int af __unused) +pim6_stats(void) { struct pim6stat pim6stat; + size_t len = sizeof(struct pim6stat); - if (off == 0) + if (sysctlbyname("net.inet6.ip6.pim6stat", &pim6stat, &len, 0, 0) == -1) return; - kread(off, (char *)&pim6stat, sizeof(pim6stat)); printf("%s:\n", name); #define p(f, m) if (pim6stat.f || sflag <= 1) \ @@ -986,6 +984,7 @@ pim6_stats(u_long off __unused, char *name, int af __unused) p(pim6s_snd_registers, "\t%llu register%s sent\n"); #undef p } +#endif /* * Dump raw ip6 statistics structure. diff --git a/netstat.tproj/ipsec.c b/netstat.tproj/ipsec.c index b686f97..99c87e2 100644 --- a/netstat.tproj/ipsec.c +++ b/netstat.tproj/ipsec.c @@ -76,6 +76,7 @@ static const char rcsid[] = #include #include #include +#include #include @@ -241,10 +242,18 @@ print_ipsecstats(void) void ipsec_stats(u_long off __unused, char *name, int af __unused) { - if (off == 0) + size_t len; + + len = sizeof(struct ipsecstat); + if (strcmp(name, "ipsec") == 0) + if (sysctlbyname("net.inet.ipsec.stats", &ipsecstat, &len, 0, 0) == -1) + return; + else if (strcmp(name, "ipsec6") == 0) + if (sysctlbyname("net.inet6.ipsec6.stats", &ipsecstat, &len, 0, 0) == -1) + return; + else return; printf ("%s:\n", name); - kread(off, (char *)&ipsecstat, sizeof (ipsecstat)); print_ipsecstats(); } @@ -267,11 +276,12 @@ pfkey_stats(u_long off __unused, char *name, int af __unused) { struct pfkeystat pfkeystat; unsigned first, type; - - if (off == 0) + size_t len; + + len = sizeof(struct pfkeystat); + if (sysctlbyname("net.key.pfkeystat", &pfkeystat, &len, 0, 0) == -1) return; printf ("%s:\n", name); - kread(off, (char *)&pfkeystat, sizeof(pfkeystat)); #define p(f, m) if (pfkeystat.f || sflag <= 1) \ printf(m, (CAST)pfkeystat.f, plural(pfkeystat.f)) diff --git a/netstat.tproj/main.c b/netstat.tproj/main.c index 9eea7a3..db882fc 100644 --- a/netstat.tproj/main.c +++ b/netstat.tproj/main.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -66,15 +65,15 @@ char const copyright[] = static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 3/1/94"; #endif static const char rcsid[] = - "$Id: main.c,v 1.5 2003/07/08 22:49:49 lindak Exp $"; + "$Id: main.c,v 1.8 2004/10/14 22:24:09 lindak Exp $"; #endif /* not lint */ #include #include -#include #include #include +#include #include #include @@ -101,11 +100,10 @@ static const char rcsid[] = * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: main.c,v 1.5 2003/07/08 22:49:49 lindak Exp $ + * $Id: main.c,v 1.8 2004/10/14 22:24:09 lindak Exp $ * */ - static struct nlist nl[] = { #define N_IFNET 0 { "_ifnet" }, @@ -145,12 +143,6 @@ static struct nlist nl[] = { { "_nfile" }, #define N_FILE 18 { "_file" }, -#define N_MRTSTAT 19 - { "_mrtstat" }, -#define N_MFCTABLE 20 - { "_mfctable" }, -#define N_VIFTABLE 21 - { "_viftable" }, #define N_IPX 22 { "_ipxpcb"}, #define N_IPXSTAT 23 @@ -197,7 +189,6 @@ static struct nlist nl[] = { }; - struct protox { u_char pr_index; /* index into nlist of cb head */ u_char pr_sindex; /* index into nlist of stat block */ @@ -223,8 +214,8 @@ struct protox { { -1, -1, 1, protopr, igmp_stats, NULL, "igmp", IPPROTO_IGMP }, #ifdef IPSEC - { -1, N_IPSECSTAT, 1, 0, - ipsec_stats, NULL, "ipsec", 0}, + { -1, -1, 1, 0, + ipsec_stats, NULL, "ipsec", IPPROTO_ESP}, #endif #if 0 { -1, -1, 1, 0, @@ -246,14 +237,14 @@ struct protox ip6protox[] = { icmp6_stats, icmp6_ifstats, "icmp6",IPPROTO_ICMPV6 }, #ifdef IPSEC { -1, N_IPSEC6STAT, 1, 0, - ipsec_stats, NULL, "ipsec6",0 }, + ipsec_stats, NULL, "ipsec6",IPPROTO_ESP }, #endif #ifdef notyet { -1, N_PIM6STAT, 1, 0, pim6_stats, NULL, "pim6", 0 }, #endif { -1, -1, 1, 0, - rip6_stats, NULL, "rip6", 0 }, + rip6_stats, NULL, "rip6", IPPROTO_RAW }, #if 0 { -1, -1, 1, 0, bdg_stats, NULL, "bdg", 1 /* bridging... */ }, @@ -266,7 +257,7 @@ struct protox ip6protox[] = { #ifdef IPSEC struct protox pfkeyprotox[] = { { -1, N_PFKEYSTAT, 1, 0, - pfkey_stats, NULL, "pfkey", 0 }, + pfkey_stats, NULL, "pfkey", PF_KEY_V2 }, { -1, -1, 0, 0, 0, NULL, 0, 0 } }; @@ -352,7 +343,9 @@ static struct protox *knownname (char *); extern void _serv_cache_close(); #endif +#if 0 static kvm_t *kvmd; +#endif static char *nlistf = NULL, *memf = NULL; int Aflag; /* show addresses of protocol control block */ @@ -388,7 +381,7 @@ main(argc, argv) af = AF_UNSPEC; - while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rstuWw:")) != -1) + while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rRstuWw:")) != -1) switch(ch) { case 'A': Aflag = 1; @@ -530,16 +523,7 @@ main(argc, argv) setgid(getgid()); if (mflag) { - //if (memf != NULL) { - if (kread(0, 0, 0) == 0) - mbpr(nl[N_MBSTAT].n_value); - //mbpr(nl[N_MBSTAT].n_value, - // nl[N_MBTYPES].n_value, - // nl[N_NMBCLUSTERS].n_value, - // nl[N_NMBUFS].n_value); - //} else - // mbpr(0, 0, 0, 0); - //mbpr(0) ; + mbpr(); exit(0); } #if 0 @@ -557,41 +541,35 @@ main(argc, argv) */ #endif if (iflag && !sflag) { - kread(0, 0, 0); - intpr(interval, nl[N_IFNET].n_value, NULL); + intpr(NULL); exit(0); } if (rflag) { - kread(0, 0, 0); if (sflag) - rt_stats(nl[N_RTSTAT].n_value, nl[N_RTTRASH].n_value); + rt_stats(); else routepr(nl[N_RTREE].n_value); exit(0); } if (gflag) { - kread(0, 0, 0); if (sflag) { if (af == AF_INET || af == AF_UNSPEC) - mrt_stats(nl[N_MRTSTAT].n_value); + mrt_stats(); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) - mrt6_stats(nl[N_MRT6STAT].n_value); + mrt6_stats(); #endif } else { if (af == AF_INET || af == AF_UNSPEC) - mroutepr(nl[N_MFCTABLE].n_value, - nl[N_VIFTABLE].n_value); + mroutepr(); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) - mroute6pr(nl[N_MF6CTABLE].n_value, - nl[N_MIF6TABLE].n_value); + mroute6pr(); #endif } exit(0); } - kread(0, 0, 0); if (tp) { printproto(tp, tp->pr_name); exit(0); @@ -611,7 +589,6 @@ main(argc, argv) #endif /*IPSEC*/ #ifndef __APPLE__ if (af == AF_IPX || af == AF_UNSPEC) { - kread(0, 0, 0); for (tp = ipxprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); } @@ -656,8 +633,7 @@ printproto(tp, name) if (sflag) { if (iflag) { if (tp->pr_istats) - intpr(interval, nl[N_IFNET].n_value, - tp->pr_istats); + intpr(tp->pr_istats); else if (pflag) printf("%s: no per-interface stats routine\n", tp->pr_name); @@ -686,11 +662,14 @@ printproto(tp, name) } if (pr != NULL && (off || af != AF_UNSPEC)) (*pr)(off, name, af); + else + printf("### no stats for %s\n", name); } /* * Read kernel memory, return 0 on success. */ +#if 0 int kread(u_long addr, char *buf, int size) { @@ -727,6 +706,7 @@ kread(u_long addr, char *buf, int size) } return (0); } +#endif char * plural(int n) @@ -788,7 +768,7 @@ name2protox(char *name) static void usage(void) { - (void)fprintf(stderr, "%s\n%s\n%s\n%s\n", + (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n", "usage: netstat [-Aan] [-f address_family] [-M core] [-N system]", " netstat [-bdghimnrs] [-f address_family] [-M core] [-N system]", " netstat [-bdn] [-I interface] [-M core] [-N system] [-w wait]", diff --git a/netstat.tproj/mbuf.c b/netstat.tproj/mbuf.c index 260f6aa..66e96fe 100644 --- a/netstat.tproj/mbuf.c +++ b/netstat.tproj/mbuf.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -57,9 +56,9 @@ #include -#include #include #include +#include #include #include "netstat.h" @@ -106,23 +105,20 @@ bool seen[256]; /* "have we seen this type yet?" */ * Print mbuf statistics. */ void -mbpr(mbaddr) - u_long mbaddr; +mbpr(void) { - register int totmem, totfree, totmbufs; - register int i; - register struct mbtypes *mp; + int totmem, totfree, totmbufs; + int i; + struct mbtypes *mp; + size_t len; if (nmbtypes != 256) { fprintf(stderr, "netstat: unexpected change to mbstat; check source\n"); return; } - if (mbaddr == 0) { - fprintf(stderr, "netstat: mbstat: symbol not in namelist\n"); - return; - } - if (kread(mbaddr, (char *)&mbstat, sizeof (mbstat))) + len = sizeof(mbstat); + if (sysctlbyname("kern.ipc.mbstat", &mbstat, &len, 0, 0) == -1) return; totmbufs = 0; @@ -144,8 +140,11 @@ mbpr(mbaddr) printf("%u/%u mbuf clusters in use\n", (unsigned int)(mbstat.m_clusters - mbstat.m_clfree), (unsigned int)mbstat.m_clusters); - totmem = totmbufs * MSIZE + mbstat.m_clusters * MCLBYTES; - totfree = mbstat.m_clfree * MCLBYTES; + printf("%u/%u mbuf 4KB clusters in use\n", + (unsigned int)(mbstat.m_bigclusters - mbstat.m_bigclfree), + (unsigned int)mbstat.m_bigclusters); + totmem = totmbufs * MSIZE + mbstat.m_clusters * MCLBYTES + mbstat.m_bigclusters * mbstat.m_bigmclbytes; + totfree = mbstat.m_clfree * MCLBYTES + mbstat.m_bigclfree * mbstat.m_bigmclbytes; printf("%u Kbytes allocated to network (%d%% in use)\n", totmem / 1024, (totmem - totfree) * 100 / totmem); printf("%u requests for memory denied\n", diff --git a/netstat.tproj/mroute.c b/netstat.tproj/mroute.c index 4c94d2b..b620589 100644 --- a/netstat.tproj/mroute.c +++ b/netstat.tproj/mroute.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -71,9 +70,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -86,11 +85,9 @@ #include "netstat.h" void -mroutepr(mfcaddr, vifaddr) - u_long mfcaddr, vifaddr; +mroutepr(void) { - u_int mrtproto; - struct mfc *mfctable[MFCTBLSIZ]; + struct mfc **mfctable = 0; struct vif viftable[MAXVIFS]; struct mfc mfc, *m; register struct vif *v; @@ -99,16 +96,17 @@ mroutepr(mfcaddr, vifaddr) register int banner_printed; register int saved_nflag; vifi_t maxvif = 0; + size_t len; + + saved_nflag = nflag; + nflag = 1; - if (mfcaddr == 0 || vifaddr == 0) { + len = MAXVIFS * sizeof(struct vif); + if (sysctlbyname("net.inet.ip.viftable", viftable, &len, 0, 0) == -1) { printf("No IPv4 multicast routing compiled into this system.\n"); return; } - saved_nflag = nflag; - nflag = 1; - - kread(vifaddr, (char *)&viftable, sizeof(viftable)); banner_printed = 0; for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) { if (v->v_lcl_addr.s_addr == 0) @@ -134,13 +132,21 @@ mroutepr(mfcaddr, vifaddr) if (!banner_printed) printf("\nVirtual Interface Table is empty\n"); - kread(mfcaddr, (char *)&mfctable, sizeof(mfctable)); + if (sysctlbyname("net.inet.ip.mfctable", 0, &len, 0, 0) == -1) { + printf("No IPv4 multicast routing compiled into this system.\n"); + return; + } + mfctable = malloc(len); + if (mfctable == 0) + return; + if (sysctlbyname("net.inet.ip.mfctable", mfctable, &len, 0, 0) == -1) { + printf("No IPv4 multicast routing compiled into this system.\n"); + return; + } banner_printed = 0; for (i = 0; i < MFCTBLSIZ; ++i) { m = mfctable[i]; while(m) { - kread((u_long)m, (char *)&mfc, sizeof mfc); - if (!banner_printed) { printf("\nIPv4 Multicast Forwarding Cache\n" " Origin Group " @@ -166,21 +172,22 @@ mroutepr(mfcaddr, vifaddr) printf("\n"); nflag = saved_nflag; + + free(mfctable); } void -mrt_stats(mstaddr) - u_long mstaddr; +mrt_stats() { struct mrtstat mrtstat; + size_t len = sizeof(struct mrtstat); - if (mstaddr == 0) { + if(sysctlbyname("net.inet.ip.mrtstat", &mrtstat, &len, 0, 0) == -1) { printf("No IPv4 multicast routing compiled into this system.\n"); return; } - kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); printf("IPv4 multicast forwarding:\n"); printf(" %10lu multicast forwarding cache lookup%s\n", mrtstat.mrts_mfc_lookups, plural(mrtstat.mrts_mfc_lookups)); diff --git a/netstat.tproj/mroute6.c b/netstat.tproj/mroute6.c index 64c92cb..c37f176 100644 --- a/netstat.tproj/mroute6.c +++ b/netstat.tproj/mroute6.c @@ -72,7 +72,7 @@ #include #include #include -#include +#include #include #include @@ -81,6 +81,8 @@ #include #include +#include +#include #define KERNEL 1 #include @@ -92,12 +94,12 @@ #define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */ void -mroute6pr(u_long mfcaddr, u_long mifaddr) +mroute6pr(void) { - struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp; + struct mf6c **mf6ctable = 0, *mfcp; struct mif6 mif6table[MAXMIFS]; struct mf6c mfc; - struct rtdetq rte, *rtep; + struct rtdetq *rtep; register struct mif6 *mifp; register mifi_t mifi; register int i; @@ -105,17 +107,17 @@ mroute6pr(u_long mfcaddr, u_long mifaddr) register int saved_nflag; mifi_t maxmif = 0; long int waitings; + size_t len; - if (mfcaddr == 0 || mifaddr == 0) { - printf("No IPv6 multicast routing compiled into this" - " system.\n"); + len = sizeof(mif6table); + if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len, 0, 9) == -1) { + printf("No IPv6 multicast routing compiled into this system.\n"); return; } saved_nflag = nflag; nflag = 1; - kread(mifaddr, (char *)&mif6table, sizeof(mif6table)); banner_printed = 0; for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) { struct ifnet ifnet; @@ -124,7 +126,11 @@ mroute6pr(u_long mfcaddr, u_long mifaddr) if (mifp->m6_ifp == NULL) continue; - kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet)); + /* + * m6_ifp should be ifindex instead of ifnet pointer + * + * kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet)); + */ maxmif = mifi; if (!banner_printed) { printf("\nIPv6 Multicast Interface Table\n" @@ -144,12 +150,19 @@ mroute6pr(u_long mfcaddr, u_long mifaddr) if (!banner_printed) printf("\nIPv6 Multicast Interface Table is empty\n"); - kread(mfcaddr, (char *)&mf6ctable, sizeof(mf6ctable)); + len = sizeof(MF6CTBLSIZ * sizeof(struct mf6c)); + mf6ctable = malloc(len); + if (mf6ctable == 0) + return; + if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len, 0, 0) == -1) { + printf("No IPv6 multicast routing compiled into this system.\n"); + free(mf6ctable); + return; + } banner_printed = 0; for (i = 0; i < MF6CTBLSIZ; ++i) { mfcp = mf6ctable[i]; while(mfcp) { - kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)); if (!banner_printed) { printf ("\nIPv6 Multicast Forwarding Cache\n"); printf(" %-*.*s %-*.*s %s", @@ -166,9 +179,12 @@ mroute6pr(u_long mfcaddr, u_long mifaddr) printf(" %9llu", (unsigned long long)mfc.mf6c_pkt_cnt); for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) { + /* The sysctl should return the number of packet waiting + * struct rtdetq rte; + * kread((u_long)rtep, (char *)&rte, sizeof(rte)); + * rtep = rte.next; + */ waitings++; - kread((u_long)rtep, (char *)&rte, sizeof(rte)); - rtep = rte.next; } printf(" %3ld", waitings); @@ -190,20 +206,21 @@ mroute6pr(u_long mfcaddr, u_long mifaddr) printf("\n"); nflag = saved_nflag; + + free(mf6ctable); } void -mrt6_stats(u_long mstaddr) +mrt6_stats(void) { struct mrt6stat mrtstat; + size_t len; - if (mstaddr == 0) { - printf("No IPv6 multicast routing compiled into this" - "system.\n"); + len = sizeof(mrtstat); + if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len, 0, 0) == -1) { + printf("No IPv6 multicast routing compiled into this system\n"); return; } - - kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); printf("IPv6 multicast forwarding:\n"); printf(" %10llu multicast forwarding cache lookup%s\n", (unsigned long long)mrtstat.mrt6s_mfc_lookups, diff --git a/netstat.tproj/netstat.h b/netstat.tproj/netstat.h index 64030ca..cce6d51 100644 --- a/netstat.tproj/netstat.h +++ b/netstat.tproj/netstat.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -82,7 +81,9 @@ extern int unit; /* unit number for above */ extern int af; /* address family */ +#if 0 int kread (u_long addr, char *buf, int size); +#endif char *plural (int); char *plurales (int); @@ -101,15 +102,17 @@ void ip6_stats (u_long, char *, int); void ip6_ifstats (char *); void icmp6_stats (u_long, char *, int); void icmp6_ifstats (char *); +#ifdef notyet void pim6_stats (u_long, char *, int); +#endif void rip6_stats (u_long, char *, int); -void mroute6pr (u_long, u_long); -void mrt6_stats (u_long); +void mroute6pr (void); +void mrt6_stats (void); struct sockaddr_in6; struct in6_addr; char *routename6 (struct sockaddr_in6 *); -char *netname6 (struct sockaddr_in6 *, struct in6_addr *); +char *netname6 (struct sockaddr_in6 *, struct sockaddr *); #endif /*INET6*/ #ifdef IPSEC @@ -118,17 +121,16 @@ void pfkey_stats (u_long, char *, int); void bdg_stats (u_long, char *, int); -//void mbpr (u_long, u_long, u_long, u_long); -void mbpr (u_long); +void mbpr (void); void hostpr (u_long, u_long); void impstats (u_long, u_long); -void intpr (int, u_long, void (*)(char *)); +void intpr (void (*)(char *)); void pr_rthdr (int); void pr_family (int); -void rt_stats (u_long, u_long); +void rt_stats (void); char *ipx_pnet (struct sockaddr *); char *ipx_phost (struct sockaddr *); char *ns_phost (struct sockaddr *); @@ -172,6 +174,6 @@ void tp_protopr (u_long, char *, int); void tp_inproto (u_long); void tp_stats (caddr_t, caddr_t); -void mroutepr (u_long, u_long); -void mrt_stats (u_long); +void mroutepr (void); +void mrt_stats (void); diff --git a/netstat.tproj/route.c b/netstat.tproj/route.c index 493437b..e94d0d6 100644 --- a/netstat.tproj/route.c +++ b/netstat.tproj/route.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -60,11 +59,10 @@ static char sccsid[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95"; #endif static const char rcsid[] = - "$Id: route.c,v 1.4 2003/07/08 23:03:54 lindak Exp $"; + "$Id: route.c,v 1.7 2004/10/14 22:24:09 lindak Exp $"; #endif /* not lint */ #include -#include #include #include @@ -73,6 +71,7 @@ static const char rcsid[] = #include #include #include +#include #include #ifndef __APPLE__ @@ -100,8 +99,9 @@ static const char rcsid[] = #include #include "netstat.h" +#if 0 #define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d))) - +#endif /* alignment constraint for routing socket */ #define ROUNDUP(a) \ @@ -142,7 +142,9 @@ typedef union { u_short u_data[128]; } sa_u; +#if 0 static sa_u pt_u; +#endif int do_rtent = 0; struct rtentry rtentry; @@ -150,16 +152,16 @@ struct radix_node rnode; struct radix_mask rmask; struct radix_node_head *rt_tables[AF_MAX+1]; -int NewTree = 0; - +#if 0 static struct sockaddr *kgetsa __P((struct sockaddr *)); static void p_tree __P((struct radix_node *)); static void p_rtnode __P((void)); +static void p_rtentry __P((struct rtentry *)); +#endif static void ntreestuff __P((void)); -static void np_rtentry __P((struct rt_msghdr *)); +static void np_rtentry __P((struct rt_msghdr2 *)); static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int)); static void p_flags __P((int, char *)); -static void p_rtentry __P((struct rtentry *)); static u_long forgemask __P((u_long)); static void domask __P((char *, u_long, u_long)); @@ -169,19 +171,21 @@ static void domask __P((char *, u_long, u_long)); void routepr(u_long rtree) { +#if 0 struct radix_node_head *rnh, head; int i; +#endif printf("Routing tables\n"); - if (Aflag == 0 && NewTree) + if (dflag == 0) ntreestuff(); else { if (rtree == 0) { printf("rt_tables: symbol not in namelist\n"); return; } - +#if 0 kget(rtree, rt_tables); for (i = 0; i <= AF_MAX; i++) { if ((rnh = rt_tables[i]) == 0) @@ -199,6 +203,7 @@ routepr(u_long rtree) p_tree(head.rnh_treetop); } } +#endif } } @@ -258,9 +263,9 @@ pr_family(int af) #define WID_IF(af) 6 /* width of netif column */ #else #define WID_DST(af) \ - ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 33: 18)) : 18) + ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 39: 18)) : 18) #define WID_GW(af) \ - ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 29 : 18)) : 18) + ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 31 : 18)) : 18) #define WID_IF(af) ((af) == AF_INET6 ? 8 : 6) #endif /*INET6*/ @@ -293,6 +298,7 @@ pr_rthdr(int af) "Flags", "Netif", "Expire"); } +#if 0 static struct sockaddr * kgetsa(struct sockaddr *dst) { @@ -377,6 +383,7 @@ p_rtnode(void) } putchar('\n'); } +#endif static void ntreestuff(void) @@ -384,13 +391,13 @@ ntreestuff(void) size_t needed; int mib[6]; char *buf, *next, *lim; - register struct rt_msghdr *rtm; + register struct rt_msghdr2 *rtm; mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = 0; - mib[4] = NET_RT_DUMP; + mib[4] = NET_RT_DUMP2; mib[5] = 0; if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { err(1, "sysctl: net.route.0.0.dump estimate"); @@ -404,47 +411,90 @@ ntreestuff(void) } lim = buf + needed; for (next = buf; next < lim; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; + rtm = (struct rt_msghdr2 *)next; np_rtentry(rtm); } } static void -np_rtentry(struct rt_msghdr *rtm) +get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info) { - register struct sockaddr *sa = (struct sockaddr *)(rtm + 1); -#ifdef notdef - static int masks_done, banner_printed; -#endif - static int old_af; - int af = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST; - -#ifdef notdef - /* for the moment, netmasks are skipped over */ - if (!banner_printed) { - printf("Netmasks:\n"); - banner_printed = 1; + int i; + + for (i = 0; i < RTAX_MAX; i++) { + if (addrs & (1 << i)) { + rti_info[i] = sa; + sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa); + } + else + rti_info[i] = NULL; + } +} + +static void +np_rtentry(struct rt_msghdr2 *rtm) +{ + struct sockaddr *sa = (struct sockaddr *)(rtm + 1); + struct sockaddr *rti_info[RTAX_MAX]; + static int old_fam; + int fam = 0; + u_short lastindex = 0xffff; + static char ifname[IFNAMSIZ + 1]; + sa_u addr, mask; + + /* + * Don't print protocol-cloned routes unless -a. + */ + if ((rtm->rtm_flags & RTF_WASCLONED) && (rtm->rtm_parentflags & RTF_PRCLONING) && !aflag) { + return; + } + + fam = sa->sa_family; + if (af != AF_UNSPEC && af != fam) + return; + if (fam != old_fam) { + pr_family(fam); + pr_rthdr(fam); + old_fam = fam; } - if (masks_done == 0) { - if (rtm->rtm_addrs != RTA_DST ) { - masks_done = 1; - af = sa->sa_family; + get_rtaddrs(rtm->rtm_addrs, sa, rti_info); + bzero(&addr, sizeof(addr)); + if ((rtm->rtm_addrs & RTA_DST)) + bcopy(rti_info[RTAX_DST], &addr, rti_info[RTAX_DST]->sa_len); + bzero(&mask, sizeof(mask)); + if ((rtm->rtm_addrs & RTA_NETMASK)) + bcopy(rti_info[RTAX_NETMASK], &mask, rti_info[RTAX_NETMASK]->sa_len); + p_sockaddr(&addr.u_sa, &mask.u_sa, rtm->rtm_flags, + WID_DST(addr.u_sa.sa_family)); + + p_sockaddr(rti_info[RTAX_GATEWAY], NULL, RTF_HOST, + WID_GW(addr.u_sa.sa_family)); + + p_flags(rtm->rtm_flags, "%-6.6s "); + + if (addr.u_sa.sa_family == AF_INET || lflag) { + printf("%6u %8d ", rtm->rtm_refcnt, rtm->rtm_use); + if (lflag) { + if (rtm->rtm_rmx.rmx_mtu != 0) + printf("%6lu ", rtm->rtm_rmx.rmx_mtu); + else + printf("%6s ", ""); } - } else -#endif - af = sa->sa_family; - if (af != old_af) { - pr_family(af); - old_af = af; } - if (rtm->rtm_addrs == RTA_DST) - p_sockaddr(sa, NULL, 0, 36); - else { - p_sockaddr(sa, NULL, rtm->rtm_flags, 16); - sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa); - p_sockaddr(sa, NULL, 0, 18); + if (rtm->rtm_index != lastindex) { + if_indextoname(rtm->rtm_index, ifname); + lastindex = rtm->rtm_index; + } + printf("%*.*s", WID_IF(addr.u_sa.sa_family), + WID_IF(addr.u_sa.sa_family), ifname); + + if (rtm->rtm_rmx.rmx_expire) { + time_t expire_time; + + if ((expire_time = + rtm->rtm_rmx.rmx_expire - time((time_t *)0)) > 0) + printf(" %6d", (int)expire_time); } - p_flags(rtm->rtm_flags & interesting, "%-6.6s "); putchar('\n'); } @@ -461,8 +511,8 @@ p_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags, int width) if ((sin->sin_addr.s_addr == INADDR_ANY) && mask && - ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) - ==0L) + (ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) == 0L || + mask->sa_len == 0)) cp = "default" ; else if (flags & RTF_HOST) cp = routename(sin->sin_addr.s_addr); @@ -495,8 +545,7 @@ p_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags, int width) if (flags & RTF_HOST) cp = routename6(sa6); else if (mask) - cp = netname6(sa6, - &((struct sockaddr_in6 *)mask)->sin6_addr); + cp = netname6(sa6, mask); else { cp = netname6(sa6, NULL); } @@ -603,6 +652,7 @@ p_flags(int f, char *format) printf(format, name); } +#if 0 static void p_rtentry(struct rtentry *rt) { @@ -634,7 +684,7 @@ p_rtentry(struct rtentry *rt) WID_GW(addr.u_sa.sa_family)); p_flags(rt->rt_flags, "%-6.6s "); if (addr.u_sa.sa_family == AF_INET || lflag) { - printf("%6ld %8ld ", rt->rt_refcnt, rt->rt_use); + printf("%6u %8ld ", rt->rt_refcnt, rt->rt_use); if (lflag) { if (rt->rt_rmx.rmx_mtu != 0) printf("%6lu ", rt->rt_rmx.rmx_mtu); @@ -664,6 +714,7 @@ p_rtentry(struct rtentry *rt) } putchar('\n'); } +#endif char * routename(u_long in) @@ -796,14 +847,17 @@ netname(u_long in, u_long mask) #ifdef INET6 char * -netname6(struct sockaddr_in6 *sa6, struct in6_addr *mask) +netname6(struct sockaddr_in6 *sa6, struct sockaddr *sam) { static char line[MAXHOSTNAMELEN]; - u_char *p = (u_char *)mask; u_char *lim; int masklen, illegal = 0, flag = NI_WITHSCOPEID; + struct in6_addr *mask = sam ? &((struct sockaddr_in6 *)sam)->sin6_addr : 0; - if (mask) { + if (sam && sam->sa_len == 0) { + masklen = 0; + } else if (mask) { + u_char *p = (u_char *)mask; for (masklen = 0, lim = p + 16; p < lim; p++) { switch (*p) { case 0xff: @@ -882,21 +936,33 @@ routename6(struct sockaddr_in6 *sa6) * Print routing statistics */ void -rt_stats(u_long rtsaddr, u_long rttaddr) +rt_stats(void) { struct rtstat rtstat; int rttrash; + int mib[6]; + size_t len; - if (rtsaddr == 0) { - printf("rtstat: symbol not in namelist\n"); + mib[0] = CTL_NET; + mib[1] = AF_ROUTE; + mib[2] = 0; + mib[3] = 0; + mib[4] = NET_RT_STAT; + mib[5] = 0; + len = sizeof(struct rtstat); + if (sysctl(mib, 6, &rtstat, &len, 0, 0) == -1) return; - } - if (rttaddr == 0) { - printf("rttrash: symbol not in namelist\n"); + + mib[0] = CTL_NET; + mib[1] = AF_ROUTE; + mib[2] = 0; + mib[3] = 0; + mib[4] = NET_RT_TRASH; + mib[5] = 0; + len = sizeof(rttrash); + if (sysctl(mib, 6, &rttrash, &len, 0, 0) == -1) return; - } - kread(rtsaddr, (char *)&rtstat, sizeof (rtstat)); - kread(rttaddr, (char *)&rttrash, sizeof (rttrash)); + printf("routing:\n"); #define p(f, m) if (rtstat.f || sflag <= 1) \ diff --git a/netstat.tproj/unix.c b/netstat.tproj/unix.c index 2711e01..3cf131b 100644 --- a/netstat.tproj/unix.c +++ b/netstat.tproj/unix.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -60,7 +59,7 @@ static char sccsid[] = "@(#)unix.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$Id: unix.c,v 1.2 2001/07/31 05:54:11 wsanchez Exp $"; + "$Id: unix.c,v 1.3 2004/08/26 23:55:22 lindak Exp $"; #endif /* not lint */ /* @@ -68,7 +67,6 @@ static const char rcsid[] = */ #include #include -#include #include #include #include diff --git a/nfsd.tproj/Makefile b/nfsd.tproj/Makefile index a765f04..27cd3d6 100644 --- a/nfsd.tproj/Makefile +++ b/nfsd.tproj/Makefile @@ -14,7 +14,7 @@ PROJECT_TYPE = Tool CFILES = nfsd.c -OTHERSRCS = Makefile.preamble Makefile Makefile.dist nfsd.8 +OTHERSRCS = Makefile.preamble Makefile Makefile.dist nfsd.8 Makefile.postamble MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/nfsd.tproj/Makefile.postamble b/nfsd.tproj/Makefile.postamble new file mode 100644 index 0000000..401f3a7 --- /dev/null +++ b/nfsd.tproj/Makefile.postamble @@ -0,0 +1,3 @@ +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 nfsd.8 $(DSTROOT)/usr/share/man/man8/nfsd.8 diff --git a/nfsd.tproj/nfsd.c b/nfsd.tproj/nfsd.c index 84eed6b..a40ac6a 100644 --- a/nfsd.tproj/nfsd.c +++ b/nfsd.tproj/nfsd.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/nfsiod.tproj/Makefile b/nfsiod.tproj/Makefile index fa0ae2f..7e502a3 100644 --- a/nfsiod.tproj/Makefile +++ b/nfsiod.tproj/Makefile @@ -14,7 +14,7 @@ PROJECT_TYPE = Tool CFILES = nfsiod.c -OTHERSRCS = Makefile.preamble Makefile Makefile.dist nfsiod.8 +OTHERSRCS = Makefile.preamble Makefile Makefile.dist nfsiod.8 Makefile.postamble MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/nfsiod.tproj/Makefile.postamble b/nfsiod.tproj/Makefile.postamble new file mode 100644 index 0000000..a3b5f8e --- /dev/null +++ b/nfsiod.tproj/Makefile.postamble @@ -0,0 +1,3 @@ +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 nfsiod.8 $(DSTROOT)/usr/share/man/man8/nfsiod.8 diff --git a/nfsiod.tproj/nfsiod.c b/nfsiod.tproj/nfsiod.c index dfc48d0..92acb86 100644 --- a/nfsiod.tproj/nfsiod.c +++ b/nfsiod.tproj/nfsiod.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/nfsstat.tproj/Makefile.postamble b/nfsstat.tproj/Makefile.postamble index b5bfe61..459f48c 100644 --- a/nfsstat.tproj/Makefile.postamble +++ b/nfsstat.tproj/Makefile.postamble @@ -1,2 +1,6 @@ INSTALL_AS_GROUP = kmem INSTALL_PERMISSIONS =2555 + +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man1 + install -c -m 444 nfsstat.1 $(DSTROOT)/usr/share/man/man1/nfsstat.1 diff --git a/nfsstat.tproj/nfsstat.c b/nfsstat.tproj/nfsstat.c index b91f089..5cf77d2 100644 --- a/nfsstat.tproj/nfsstat.c +++ b/nfsstat.tproj/nfsstat.c @@ -1,24 +1,23 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999-2004 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -242,18 +241,14 @@ intpr(nfsstataddr, display) nfsstats.rpccnt[NFSPROC_READDIR], nfsstats.rpccnt[NFSPROC_READDIRPLUS], nfsstats.rpccnt[NFSPROC_ACCESS]); - printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", - "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit", - "GLease", "Vacate", "Evict"); - printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", + printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n", + "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit"); + printf("%9d %9d %9d %9d %9d\n", nfsstats.rpccnt[NFSPROC_MKNOD], nfsstats.rpccnt[NFSPROC_FSSTAT], nfsstats.rpccnt[NFSPROC_FSINFO], nfsstats.rpccnt[NFSPROC_PATHCONF], - nfsstats.rpccnt[NFSPROC_COMMIT], - nfsstats.rpccnt[NQNFSPROC_GETLEASE], - nfsstats.rpccnt[NQNFSPROC_VACATED], - nfsstats.rpccnt[NQNFSPROC_EVICTED]); + nfsstats.rpccnt[NFSPROC_COMMIT]); printf("Rpc Info:\n"); printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n", "TimedOut", "Invalid", "X Replies", "Retries", "Requests"); @@ -313,18 +308,14 @@ intpr(nfsstataddr, display) nfsstats.srvrpccnt[NFSPROC_READDIR], nfsstats.srvrpccnt[NFSPROC_READDIRPLUS], nfsstats.srvrpccnt[NFSPROC_ACCESS]); - printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", - "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit", - "GLease", "Vacate", "Evict"); - printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", + printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n", + "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit"); + printf("%9d %9d %9d %9d %9d\n", nfsstats.srvrpccnt[NFSPROC_MKNOD], nfsstats.srvrpccnt[NFSPROC_FSSTAT], nfsstats.srvrpccnt[NFSPROC_FSINFO], nfsstats.srvrpccnt[NFSPROC_PATHCONF], - nfsstats.srvrpccnt[NFSPROC_COMMIT], - nfsstats.srvrpccnt[NQNFSPROC_GETLEASE], - nfsstats.srvrpccnt[NQNFSPROC_VACATED], - nfsstats.srvrpccnt[NQNFSPROC_EVICTED]); + nfsstats.srvrpccnt[NFSPROC_COMMIT]); printf("Server Ret-Failed\n"); printf("%17d\n", nfsstats.srvrpc_errs); printf("Server Faults\n"); @@ -337,13 +328,6 @@ intpr(nfsstataddr, display) nfsstats.srvcache_idemdonehits, nfsstats.srvcache_nonidemdonehits, nfsstats.srvcache_misses); - printf("Server Lease Stats:\n"); - printf("%9.9s %9.9s %9.9s\n", - "Leases", "PeakL", "GLeases"); - printf("%9d %9d %9d\n", - nfsstats.srvnqnfs_leases, - nfsstats.srvnqnfs_maxleases, - nfsstats.srvnqnfs_getleases); printf("Server Write Gathering:\n"); printf("%9.9s %9.9s %9.9s\n", "WriteOps", "WriteRPC", "Opsaved"); diff --git a/ping.tproj/ping.8 b/ping.tproj/ping.8 index 2382365..4c0fca4 100644 --- a/ping.tproj/ping.8 +++ b/ping.tproj/ping.8 @@ -1,328 +1,519 @@ -.\" Copyright (c) 1985, 1991, 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. -.\" -.\" @(#)ping.8 8.3 (Berkeley) 4/28/95 -.\" -.Dd April 28, 1995 -.Dt PING 8 -.Os BSD 4.3 -.Sh NAME -.Nm ping -.Nd send -.Tn ICMP ECHO_REQUEST -packets to network hosts -.Sh SYNOPSIS -.Nm ping -.Op Fl Rdfnqrv -.Op Fl c Ar count -.Op Fl i Ar wait -.Op Fl l Ar preload -.Op Fl p Ar pattern -.Op Fl s Ar packetsize -.Ar host -.Sh DESCRIPTION -.Nm Ping -uses the -.Tn ICMP -protocol's mandatory -.Tn ECHO_REQUEST -datagram to elicit an -.Tn ICMP ECHO_RESPONSE -from a host or gateway. -.Tn ECHO_REQUEST -datagrams (``pings'') have an IP and -.Tn ICMP -header, -followed by a -.Dq struct timeval -and then an arbitrary number of ``pad'' bytes used to fill out the -packet. -The options are as follows: -.Bl -tag -width Ds -.It Fl c Ar count -Stop after sending (and receiving) -.Ar count -.Tn ECHO_RESPONSE -packets. -.It Fl d -Set the -.Dv SO_DEBUG -option on the socket being used. -.It Fl f -Flood ping. -Outputs packets as fast as they come back or one hundred times per second, -whichever is more. -For every -.Tn ECHO_REQUEST -sent a period ``.'' is printed, while for every -.Tn ECHO_REPLY -received a backspace is printed. -This provides a rapid display of how many packets are being dropped. -Only the super-user may use this option. -.Bf -emphasis -This can be very hard on a network and should be used with caution. -.Ef -.It Fl i Ar wait -Wait -.Ar wait -seconds -.Em between sending each packet . -The default is to wait for one second between each packet. -This option is incompatible with the -.Fl f -option. -.It Fl l Ar preload -If -.Ar preload -is specified, -.Nm ping -sends that many packets as fast as possible before falling into its normal -mode of behavior. -.It Fl n -Numeric output only. -No attempt will be made to lookup symbolic names for host addresses. -.It Fl p Ar pattern -You may specify up to 16 ``pad'' bytes to fill out the packet you send. -This is useful for diagnosing data-dependent problems in a network. -For example, -.Dq Li \-p ff -will cause the sent packet to be filled with all -ones. -.It Fl q -Quiet output. -Nothing is displayed except the summary lines at startup time and -when finished. -.It Fl R -Record route. -Includes the -.Tn RECORD_ROUTE -option in the -.Tn ECHO_REQUEST -packet and displays -the route buffer on returned packets. -Note that the IP header is only large enough for nine such routes. -Many hosts ignore or discard this option. -.It Fl r -Bypass the normal routing tables and send directly to a host on an attached -network. -If the host is not on a directly-attached network, an error is returned. -This option can be used to ping a local host through an interface -that has no route through it (e.g., after the interface was dropped by -.Xr routed 8 ) . -.It Fl s Ar packetsize -Specifies the number of data bytes to be sent. -The default is 56, which translates into 64 -.Tn ICMP -data bytes when combined -with the 8 bytes of -.Tn ICMP -header data. -.It Fl v -Verbose output. -.Tn ICMP -packets other than -.Tn ECHO_RESPONSE -that are received are listed. -.El -.Pp -When using -.Nm ping -for fault isolation, it should first be run on the local host, to verify -that the local network interface is up and running. -Then, hosts and gateways further and further away should be ``pinged''. -Round-trip times and packet loss statistics are computed. -If duplicate packets are received, they are not included in the packet -loss calculation, although the round trip time of these packets is used -in calculating the minimum/average/maximum round-trip time numbers. -When the specified number of packets have been sent (and received) or -if the program is terminated with a -.Dv SIGINT , -a brief summary is displayed. -.Pp -This program is intended for use in network testing, measurement and -management. -Because of the load it can impose on the network, it is unwise to use -.Nm ping -during normal operations or from automated scripts. -.Sh ICMP PACKET DETAILS -An IP header without options is 20 bytes. -An -.Tn ICMP -.Tn ECHO_REQUEST -packet contains an additional 8 bytes worth -of -.Tn ICMP -header followed by an arbitrary amount of data. -When a -.Ar packetsize -is given, this indicated the size of this extra piece of data (the -default is 56). -Thus the amount of data received inside of an IP packet of type -.Tn ICMP -.Tn ECHO_REPLY -will always be 8 bytes more than the requested data space -(the -.Tn ICMP -header). -.Pp -If the data space is at least eight bytes large, -.Nm ping -uses the first eight bytes of this space to include a timestamp which -it uses in the computation of round trip times. -If less than eight bytes of pad are specified, no round trip times are -given. -.Sh DUPLICATE AND DAMAGED PACKETS -.Nm Ping -will report duplicate and damaged packets. -Duplicate packets should never occur, and seem to be caused by -inappropriate link-level retransmissions. -Duplicates may occur in many situations and are rarely (if ever) a -good sign, although the presence of low levels of duplicates may not -always be cause for alarm. -.Pp -Damaged packets are obviously serious cause for alarm and often -indicate broken hardware somewhere in the -.Nm ping -packet's path (in the network or in the hosts). -.Sh TRYING DIFFERENT DATA PATTERNS -The (inter)network layer should never treat packets differently depending -on the data contained in the data portion. -Unfortunately, data-dependent problems have been known to sneak into -networks and remain undetected for long periods of time. -In many cases the particular pattern that will have problems is something -that doesn't have sufficient ``transitions'', such as all ones or all -zeros, or a pattern right at the edge, such as almost all zeros. -It isn't necessarily enough to specify a data pattern of all zeros (for -example) on the command line because the pattern that is of interest is -at the data link level, and the relationship between what you type and -what the controllers transmit can be complicated. -.Pp -This means that if you have a data-dependent problem you will probably -have to do a lot of testing to find it. -If you are lucky, you may manage to find a file that either can't be sent -across your network or that takes much longer to transfer than other -similar length files. -You can then examine this file for repeated patterns that you can test -using the -.Fl p -option of -.Nm ping . -.Sh TTL DETAILS -The -.Tn TTL -value of an IP packet represents the maximum number of IP routers -that the packet can go through before being thrown away. -In current practice you can expect each router in the Internet to decrement -the -.Tn TTL -field by exactly one. -.Pp -The -.Tn TCP/IP -specification states that the -.Tn TTL -field for -.Tn TCP -packets should -be set to 60, but many systems use smaller values (4.3 -.Tn BSD -uses 30, 4.2 used -15). -.Pp -The maximum possible value of this field is 255, and most Unix systems set -the -.Tn TTL -field of -.Tn ICMP ECHO_REQUEST -packets to 255. -This is why you will find you can ``ping'' some hosts, but not reach them -with -.Xr telnet 1 -or -.Xr ftp 1 . -.Pp -In normal operation ping prints the ttl value from the packet it receives. -When a remote system receives a ping packet, it can do one of three things -with the -.Tn TTL -field in its response: -.Bl -bullet -.It -Not change it; this is what Berkeley Unix systems did before the -.Bx 4.3 tahoe -release. -In this case the -.Tn TTL -value in the received packet will be 255 minus the -number of routers in the round-trip path. -.It -Set it to 255; this is what current Berkeley Unix systems do. -In this case the -.Tn TTL -value in the received packet will be 255 minus the -number of routers in the path -.Xr from -the remote system -.Em to -the -.Nm ping Ns Em ing -host. -.It -Set it to some other value. -Some machines use the same value for -.Tn ICMP -packets that they use for -.Tn TCP -packets, for example either 30 or 60. -Others may use completely wild values. -.El -.Sh BUGS -Many Hosts and Gateways ignore the -.Tn RECORD_ROUTE -option. -.Pp -The maximum IP header length is too small for options like -.Tn RECORD_ROUTE -to -be completely useful. -There's not much that that can be done about this, however. -.Pp -Flood pinging is not recommended in general, and flood pinging the -broadcast address should only be done under very controlled conditions. -.Sh SEE ALSO -.Xr netstat 1 , -.Xr ifconfig 8 , -.Xr routed 8 -.Sh HISTORY -The -.Nm -command appeared in -.Bx 4.3 . +.\" Copyright (c) 1985, 1991, 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. +.\" 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. +.\" +.\" @(#)ping.8 8.2 (Berkeley) 12/11/93 +.\" $FreeBSD: /repoman/r/ncvs/src/sbin/ping/ping.8,v 1.51 2004/04/09 19:58:34 markm Exp $ +.\" +.Dd October 2, 2002 +.Dt PING 8 +.Os +.Sh NAME +.Nm ping +.Nd send +.Tn ICMP ECHO_REQUEST +packets to network hosts +.Sh SYNOPSIS +.Nm +.Op Fl AaDdfnoQqRrv +.Op Fl c Ar count +.Op Fl i Ar wait +.Op Fl l Ar preload +.Op Fl M Cm mask | time +.Op Fl m Ar ttl +.Op Fl P Ar policy +.Op Fl p Ar pattern +.Op Fl S Ar src_addr +.Op Fl s Ar packetsize +.Op Fl t Ar timeout +.Op Fl z Ar tos +.Ar host +.Nm +.Op Fl AaDdfLnoQqRrv +.Op Fl c Ar count +.Op Fl I Ar iface +.Op Fl i Ar wait +.Op Fl l Ar preload +.Op Fl M Cm mask | time +.Op Fl m Ar ttl +.Op Fl P Ar policy +.Op Fl p Ar pattern +.Op Fl S Ar src_addr +.Op Fl s Ar packetsize +.Op Fl T Ar ttl +.Op Fl t Ar timeout +.Op Fl z Ar tos +.Ar mcast-group +.Sh DESCRIPTION +The +.Nm +utility uses the +.Tn ICMP +.No protocol Ap s mandatory +.Tn ECHO_REQUEST +datagram to elicit an +.Tn ICMP ECHO_RESPONSE +from a host or gateway. +.Tn ECHO_REQUEST +datagrams +.Pq Dq pings +have an IP and +.Tn ICMP +header, followed by a +.Dq struct timeval +and then an arbitrary number of +.Dq pad +bytes used to fill out the packet. +The options are as follows: +.Bl -tag -width indent +.It Fl A +Audible. +Output a bell +.Tn ( ASCII +0x07) +character when no packet is received before the next packet +is transmitted. +To cater for round-trip times that are longer than the interval +between transmissions, further missing packets cause a bell only +if the maximum number of unreceived packets has increased. +.It Fl a +Audible. +Include a bell +.Tn ( ASCII +0x07) +character in the output when any packet is received. +This option is ignored +if other format options are present. +.It Fl c Ar count +Stop after sending +(and receiving) +.Ar count +.Tn ECHO_RESPONSE +packets. +If this option is not specified, +.Nm +will operate until interrupted. +.It Fl D +Set the Don't Fragment bit. +.It Fl d +Set the +.Dv SO_DEBUG +option on the socket being used. +.It Fl f +Flood ping. +Outputs packets as fast as they come back or one hundred times per second, +whichever is more. +For every +.Tn ECHO_REQUEST +sent a period +.Dq .\& +is printed, while for every +.Tn ECHO_REPLY +received a backspace is printed. +This provides a rapid display of how many packets are being dropped. +Only the super-user may use this option. +.Bf -emphasis +This can be very hard on a network and should be used with caution. +.Ef +.It Fl I Ar iface +Source multicast packets with the given interface address. +This flag only applies if the ping destination is a multicast address. +.It Fl i Ar wait +Wait +.Ar wait +seconds +.Em between sending each packet . +The default is to wait for one second between each packet. +The wait time may be fractional, but only the super-user may specify +values less than 1 second. +This option is incompatible with the +.Fl f +option. +.It Fl L +Suppress loopback of multicast packets. +This flag only applies if the ping destination is a multicast address. +.It Fl l Ar preload +If +.Ar preload +is specified, +.Nm +sends that many packets as fast as possible before falling into its normal +mode of behavior. +Only the super-user may use this option. +.It Fl M Cm mask | time +Use +.Dv ICMP_MASKREQ +or +.Dv ICMP_TSTAMP +instead of +.Dv ICMP_ECHO . +For +.Cm mask , +print the netmask of the remote machine. +Set the +.Va net.inet.icmp.maskrepl +MIB variable to enable +.Dv ICMP_MASKREPLY . +For +.Cm time , +print the origination, reception and transmission timestamps. +.It Fl m Ar ttl +Set the IP Time To Live for outgoing packets. +If not specified, the kernel uses the value of the +.Va net.inet.ip.ttl +MIB variable. +.It Fl n +Numeric output only. +No attempt will be made to lookup symbolic names for host addresses. +.It Fl o +Exit successfully after receiving one reply packet. +.It Fl P Ar policy +.Ar policy +specifies IPsec policy for the ping session. +For details please refer to +.Xr ipsec 4 +and +.Xr ipsec_set_policy 3 . +.It Fl p Ar pattern +You may specify up to 16 +.Dq pad +bytes to fill out the packet you send. +This is useful for diagnosing data-dependent problems in a network. +For example, +.Dq Li \-p ff +will cause the sent packet to be filled with all +ones. +.It Fl Q +Somewhat quiet output. +.No Don Ap t +display ICMP error messages that are in response to our query messages. +Originally, the +.Fl v +flag was required to display such errors, but +.Fl v +displays all ICMP error messages. +On a busy machine, this output can be overbearing. +Without the +.Fl Q +flag, +.Nm +prints out any ICMP error messages caused by its own ECHO_REQUEST +messages. +.It Fl q +Quiet output. +Nothing is displayed except the summary lines at startup time and +when finished. +.It Fl R +Record route. +Includes the +.Tn RECORD_ROUTE +option in the +.Tn ECHO_REQUEST +packet and displays +the route buffer on returned packets. +Note that the IP header is only large enough for nine such routes; +the +.Xr traceroute 8 +command is usually better at determining the route packets take to a +particular destination. +If more routes come back than should, such as due to an illegal spoofed +packet, ping will print the route list and then truncate it at the correct +spot. +Many hosts ignore or discard the +.Tn RECORD_ROUTE +option. +.It Fl r +Bypass the normal routing tables and send directly to a host on an attached +network. +If the host is not on a directly-attached network, an error is returned. +This option can be used to ping a local host through an interface +that has no route through it +(e.g., after the interface was dropped by +.Xr routed 8 ) . +.It Fl S Ar src_addr +Use the following IP address as the source address in outgoing packets. +On hosts with more than one IP address, this option can be used to +force the source address to be something other than the IP address +of the interface the probe packet is sent on. +If the IP address +is not one of this machine's interface addresses, an error is +returned and nothing is sent. +.It Fl s Ar packetsize +Specify the number of data bytes to be sent. +The default is 56, which translates into 64 +.Tn ICMP +data bytes when combined +with the 8 bytes of +.Tn ICMP +header data. +.It Fl T Ar ttl +Set the IP Time To Live for multicasted packets. +This flag only applies if the ping destination is a multicast address. +.It Fl t Ar timeout +Specify a timeout, in seconds, before ping exits regardless of how +many packets have been received. +.It Fl v +Verbose output. +.Tn ICMP +packets other than +.Tn ECHO_RESPONSE +that are received are listed. +.It Fl z Ar tos +Use the specified type of service. +.El +.Pp +When using +.Nm +for fault isolation, it should first be run on the local host, to verify +that the local network interface is up and running. +Then, hosts and gateways further and further away should be +.Dq pinged . +Round-trip times and packet loss statistics are computed. +If duplicate packets are received, they are not included in the packet +loss calculation, although the round trip time of these packets is used +in calculating the round-trip time statistics. +When the specified number of packets have been sent +(and received) +or if the program is terminated with a +.Dv SIGINT , +a brief summary is displayed, showing the number of packets sent and +received, and the minimum, mean, maximum, and standard deviation of +the round-trip times. +.Pp +If +.Nm +receives a +.Dv SIGINFO +(see the +.Cm status +argument for +.Xr stty 1 ) +signal, the current number of packets sent and received, and the +minimum, mean, and maximum of the round-trip times will be written to +the standard error output. +.Pp +This program is intended for use in network testing, measurement and +management. +Because of the load it can impose on the network, it is unwise to use +.Nm +during normal operations or from automated scripts. +.Sh ICMP PACKET DETAILS +An IP header without options is 20 bytes. +An +.Tn ICMP +.Tn ECHO_REQUEST +packet contains an additional 8 bytes worth of +.Tn ICMP +header followed by an arbitrary amount of data. +When a +.Ar packetsize +is given, this indicated the size of this extra piece of data +(the default is 56). +Thus the amount of data received inside of an IP packet of type +.Tn ICMP +.Tn ECHO_REPLY +will always be 8 bytes more than the requested data space +(the +.Tn ICMP +header). +.Pp +If the data space is at least eight bytes large, +.Nm +uses the first eight bytes of this space to include a timestamp which +it uses in the computation of round trip times. +If less than eight bytes of pad are specified, no round trip times are +given. +.Sh DUPLICATE AND DAMAGED PACKETS +The +.Nm +utility will report duplicate and damaged packets. +Duplicate packets should never occur when pinging a unicast address, +and seem to be caused by +inappropriate link-level retransmissions. +Duplicates may occur in many situations and are rarely +(if ever) +a good sign, although the presence of low levels of duplicates may not +always be cause for alarm. +Duplicates are expected when pinging a broadcast or multicast address, +since they are not really duplicates but replies from different hosts +to the same request. +.Pp +Damaged packets are obviously serious cause for alarm and often +indicate broken hardware somewhere in the +.Nm +packet's path (in the network or in the hosts). +.Sh TRYING DIFFERENT DATA PATTERNS +The +(inter)network +layer should never treat packets differently depending on the data +contained in the data portion. +Unfortunately, data-dependent problems have been known to sneak into +networks and remain undetected for long periods of time. +In many cases the particular pattern that will have problems is something +that does not have sufficient +.Dq transitions , +such as all ones or all zeros, or a pattern right at the edge, such as +almost all zeros. +It is not +necessarily enough to specify a data pattern of all zeros (for example) +on the command line because the pattern that is of interest is +at the data link level, and the relationship between what you type and +what the controllers transmit can be complicated. +.Pp +This means that if you have a data-dependent problem you will probably +have to do a lot of testing to find it. +If you are lucky, you may manage to find a file that either +cannot +be sent across your network or that takes much longer to transfer than +other similar length files. +You can then examine this file for repeated patterns that you can test +using the +.Fl p +option of +.Nm . +.Sh TTL DETAILS +The +.Tn TTL +value of an IP packet represents the maximum number of IP routers +that the packet can go through before being thrown away. +In current practice you can expect each router in the Internet to decrement +the +.Tn TTL +field by exactly one. +.Pp +The +.Tn TCP/IP +specification recommends setting the +.Tn TTL +field for +.Tn IP +packets to 64, but many systems use smaller values +.No ( Bx 4.3 +uses 30, +.Bx 4.2 +used 15). +.Pp +The maximum possible value of this field is 255, and most +.Ux +systems set +the +.Tn TTL +field of +.Tn ICMP ECHO_REQUEST +packets to 255. +This is why you will find you can +.Dq ping +some hosts, but not reach them with +.Xr telnet 1 +or +.Xr ftp 1 . +.Pp +In normal operation +.Nm +prints the ttl value from the packet it receives. +When a remote system receives a ping packet, it can do one of three things +with the +.Tn TTL +field in its response: +.Bl -bullet +.It +Not change it; this is what +.Bx +systems did before the +.Bx 4.3 tahoe +release. +In this case the +.Tn TTL +value in the received packet will be 255 minus the +number of routers in the round-trip path. +.It +Set it to 255; this is what current +.Bx +systems do. +In this case the +.Tn TTL +value in the received packet will be 255 minus the +number of routers in the path +.Em from +the remote system +.Em to +the +.Nm Ns Em ing +host. +.It +Set it to some other value. +Some machines use the same value for +.Tn ICMP +packets that they use for +.Tn TCP +packets, for example either 30 or 60. +Others may use completely wild values. +.El +.Sh RETURN VALUES +The +.Nm +utility returns an exit status of zero if at least one response was +heard from the specified +.Ar host ; +a status of two if the transmission was successful but no responses +were received; or another value +(from +.In sysexits.h ) +if an error occurred. +.Sh SEE ALSO +.Xr netstat 1 , +.Xr ifconfig 8 , +.Xr routed 8 , +.Xr traceroute 8 +.Sh HISTORY +The +.Nm +utility appeared in +.Bx 4.3 . +.Sh AUTHORS +The original +.Nm +utility was written by +.An Mike Muuss +while at the US Army Ballistics +Research Laboratory. +.Sh BUGS +Many Hosts and Gateways ignore the +.Tn RECORD_ROUTE +option. +.Pp +The maximum IP header length is too small for options like +.Tn RECORD_ROUTE +to be completely useful. +.No There Ap s +not much that can be done about this, however. +.Pp +Flood pinging is not recommended in general, and flood pinging the +broadcast address should only be done under very controlled conditions. +.Pp +The +.Fl v +option is not worth much on busy hosts. diff --git a/ping.tproj/ping.c b/ping.tproj/ping.c index c152f09..3b1b89c 100644 --- a/ping.tproj/ping.c +++ b/ping.tproj/ping.c @@ -1,27 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -37,10 +13,6 @@ * 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. @@ -58,11 +30,26 @@ * SUCH DAMAGE. */ +#if 0 +#ifndef lint +static const char copyright[] = +"@(#) Copyright (c) 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; +#endif /* not lint */ +#endif +#include +#ifndef __APPLE__ +__FBSDID("$FreeBSD: /repoman/r/ncvs/src/sbin/ping/ping.c,v 1.105 2004/08/14 17:46:10 stefanf Exp $"); +#endif /* * P I N G . C * - * Using the InterNet Control Message Protocol (ICMP) "ECHO" facility, + * Using the Internet Control Message Protocol (ICMP) "ECHO" facility, * measure round-trip-delays and packet loss across network paths. * * Author - @@ -77,30 +64,47 @@ * This program has to run SUID to ROOT to access the ICMP socket. */ -#include +#include /* NB: we rely on this for */ #include -#include +#include #include -#include +#include -#include #include +#include #include #include #include -#include -#include -#include +#include + +#ifdef IPSEC +#include +#endif /*IPSEC*/ + #include +#include #include +#include +#include +#include +#include +#include #include +#include +#include -#define DEFDATALEN (64 - 8) /* default data length */ -#define MAXIPLEN 60 -#define MAXICMPLEN 76 -#define MAXPACKET (65536 - 60 - 8)/* max packet size */ +#define INADDR_LEN ((int)sizeof(in_addr_t)) +#define TIMEVAL_LEN ((int)sizeof(struct timeval)) +#define MASK_LEN (ICMP_MASKLEN - ICMP_MINLEN) +#define TS_LEN (ICMP_TSLEN - ICMP_MINLEN) +#define DEFDATALEN 56 /* default data length */ +#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */ + /* runs out of buffer space */ +#define MAXIPLEN (sizeof(struct ip) + MAX_IPOPTLEN) +#define MAXICMPLEN (ICMP_ADVLENMIN + MAX_IPOPTLEN) #define MAXWAIT 10 /* max seconds to wait for response */ -#define NROUTES 9 /* number of record route slots */ +#define MAXALARM (60 * 60) /* max seconds for alarm timeout */ +#define MAXTOS 255 #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ #define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */ @@ -110,15 +114,31 @@ /* various options */ int options; -#define F_FLOOD 0x001 -#define F_INTERVAL 0x002 -#define F_NUMERIC 0x004 -#define F_PINGFILLED 0x008 -#define F_QUIET 0x010 -#define F_RROUTE 0x020 -#define F_SO_DEBUG 0x040 -#define F_SO_DONTROUTE 0x080 -#define F_VERBOSE 0x100 +#define F_FLOOD 0x0001 +#define F_INTERVAL 0x0002 +#define F_NUMERIC 0x0004 +#define F_PINGFILLED 0x0008 +#define F_QUIET 0x0010 +#define F_RROUTE 0x0020 +#define F_SO_DEBUG 0x0040 +#define F_SO_DONTROUTE 0x0080 +#define F_VERBOSE 0x0100 +#define F_QUIET2 0x0200 +#define F_NOLOOP 0x0400 +#define F_MTTL 0x0800 +#define F_MIF 0x1000 +#define F_AUDIBLE 0x2000 +#ifdef IPSEC +#ifdef IPSEC_POLICY_IPSEC +#define F_POLICY 0x4000 +#endif /*IPSEC_POLICY_IPSEC*/ +#endif /*IPSEC*/ +#define F_TTL 0x8000 +#define F_MISSED 0x10000 +#define F_ONCE 0x20000 +#define F_HDRINCL 0x40000 +#define F_MASK 0x80000 +#define F_TIME 0x100000 /* * MAX_DUP_CHK is the number of bits in received table, i.e. the maximum @@ -129,102 +149,228 @@ int options; int mx_dup_ck = MAX_DUP_CHK; char rcvd_tbl[MAX_DUP_CHK / 8]; -struct sockaddr whereto; /* who to ping */ +struct sockaddr_in whereto; /* who to ping */ int datalen = DEFDATALEN; +int maxpayload; int s; /* socket file descriptor */ -u_char outpack[MAXPACKET]; +u_char outpackhdr[IP_MAXPACKET], *outpack; +char BBELL = '\a'; /* characters written for MISSED and AUDIBLE */ char BSPACE = '\b'; /* characters written for flood */ char DOT = '.'; char *hostname; +char *shostname; int ident; /* process id to identify our packets */ +int uid; /* cached uid for micro-optimization */ +u_char icmp_type = ICMP_ECHO; +u_char icmp_type_rsp = ICMP_ECHOREPLY; +int phdr_len = 0; +int send_len; /* counters */ +long nmissedmax; /* max value of ntransmitted - nreceived - 1 */ long npackets; /* max packets to transmit */ long nreceived; /* # of packets we got back */ long nrepeats; /* number of duplicates */ long ntransmitted; /* sequence # for outbound packets = #sent */ -int interval = 1; /* interval between packets */ +int interval = 1000; /* interval between packets, ms */ /* timing */ int timing; /* flag to do timing */ double tmin = 999999999.0; /* minimum round trip time */ double tmax = 0.0; /* maximum round trip time */ double tsum = 0.0; /* sum of all times, for doing average */ - -char *pr_addr(); -void catcher(), finish(); - +double tsumsq = 0.0; /* sum of all times squared, for std. dev. */ + +volatile sig_atomic_t finish_up; /* nonzero if we've been told to finish up */ +volatile sig_atomic_t siginfo_p; + +static void fill(char *, char *); +static u_short in_cksum(u_short *, int); +static void check_status(void); +static void finish(void) __dead2; +static void pinger(void); +static char *pr_addr(struct in_addr); +static char *pr_ntime(n_time); +static void pr_icmph(struct icmp *); +static void pr_iph(struct ip *); +static void pr_pack(char *, int, struct sockaddr_in *, struct timeval *); +static void pr_retip(struct ip *); +static void status(int); +static void stopit(int); +static void tvsub(struct timeval *, struct timeval *); +static void usage(void) __dead2; + +int main(argc, argv) int argc; - char **argv; + char *const *argv; { - extern int errno, optind; - extern char *optarg; - struct timeval timeout; + struct sockaddr_in from, sock_in; + struct in_addr ifaddr; + struct timeval last, intvl; + struct iovec iov; + struct ip *ip; + struct msghdr msg; + struct sigaction si_sa; + size_t sz; + u_char *datap, packet[IP_MAXPACKET]; + char *ep, *source, *target, *payload; struct hostent *hp; +#ifdef IPSEC_POLICY_IPSEC + char *policy_in, *policy_out; +#endif struct sockaddr_in *to; - struct protoent *proto; - register int i; - int ch, fdmask, hold, packlen, preload; - u_char *datap, *packet; - char *target, hnamebuf[MAXHOSTNAMELEN], *malloc(); + double t; + u_long alarmtimeout, ultmp; + int almost_done, ch, df, hold, i, icmp_len, mib[4], preload, sockerrno, + tos, ttl; + char ctrl[CMSG_SPACE(sizeof(struct timeval))]; + char hnamebuf[MAXHOSTNAMELEN], snamebuf[MAXHOSTNAMELEN]; #ifdef IP_OPTIONS - char rspace[3 + 4 * NROUTES + 1]; /* record route space */ + char rspace[MAX_IPOPTLEN]; /* record route space */ +#endif + unsigned char loop, mttl; + + payload = source = NULL; +#ifdef IPSEC_POLICY_IPSEC + policy_in = policy_out = NULL; #endif - preload = 0; - datap = &outpack[8 + sizeof(struct timeval)]; - while ((ch = getopt(argc, argv, "Rc:dfh:i:l:np:qrs:v")) != EOF) + /* + * Do the stuff that we need root priv's for *first*, and + * then drop our setuid bit. Save error reporting for + * after arg parsing. + */ + s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); + sockerrno = errno; + + setuid(getuid()); + uid = getuid(); + + alarmtimeout = df = preload = tos = 0; + + outpack = outpackhdr + sizeof(struct ip); + while ((ch = getopt(argc, argv, + "Aac:DdfI:i:Ll:M:m:nop:QqRrS:s:T:t:vz:" +#ifdef IPSEC +#ifdef IPSEC_POLICY_IPSEC + "P:" +#endif /*IPSEC_POLICY_IPSEC*/ +#endif /*IPSEC*/ + )) != -1) + { switch(ch) { + case 'A': + options |= F_MISSED; + break; + case 'a': + options |= F_AUDIBLE; + break; case 'c': - npackets = atoi(optarg); - if (npackets <= 0) { - (void)fprintf(stderr, - "ping: bad number of packets to transmit.\n"); - exit(1); - } + ultmp = strtoul(optarg, &ep, 0); + if (*ep || ep == optarg || ultmp > LONG_MAX || !ultmp) + errx(EX_USAGE, + "invalid count of packets to transmit: `%s'", + optarg); + npackets = ultmp; + break; + case 'D': + options |= F_HDRINCL; + df = 1; break; case 'd': options |= F_SO_DEBUG; break; case 'f': - if (getuid()) { - (void)fprintf(stderr, - "ping: %s\n", strerror(EPERM)); - exit(1); + if (uid) { + errno = EPERM; + err(EX_NOPERM, "-f flag"); } options |= F_FLOOD; setbuf(stdout, (char *)NULL); break; + case 'I': /* multicast interface */ + if (inet_aton(optarg, &ifaddr) == 0) + errx(EX_USAGE, + "invalid multicast interface: `%s'", + optarg); + options |= F_MIF; + break; case 'i': /* wait between sending packets */ - interval = atoi(optarg); - if (interval <= 0) { - (void)fprintf(stderr, - "ping: bad timing interval.\n"); - exit(1); - } + t = strtod(optarg, &ep) * 1000.0; + if (*ep || ep == optarg || t > (double)INT_MAX) + errx(EX_USAGE, "invalid timing interval: `%s'", + optarg); options |= F_INTERVAL; + interval = (int)t; + if (uid && interval < 1000) { + errno = EPERM; + err(EX_NOPERM, "-i interval too short"); + } + break; + case 'L': + options |= F_NOLOOP; + loop = 0; break; case 'l': - if (getuid()) { - (void)fprintf(stderr, - "ping: %s\n", strerror(EPERM)); - exit(1); + ultmp = strtoul(optarg, &ep, 0); + if (*ep || ep == optarg || ultmp > INT_MAX) + errx(EX_USAGE, + "invalid preload value: `%s'", optarg); + if (uid) { + errno = EPERM; + err(EX_NOPERM, "-l flag"); } - preload = atoi(optarg); - if (preload < 0) { - (void)fprintf(stderr, - "ping: bad preload value.\n"); - exit(1); + preload = ultmp; + break; + case 'M': + switch(optarg[0]) { + case 'M': + case 'm': + options |= F_MASK; + break; + case 'T': + case 't': + options |= F_TIME; + break; + default: + errx(EX_USAGE, "invalid message: `%c'", optarg[0]); + break; } break; + case 'm': /* TTL */ + ultmp = strtoul(optarg, &ep, 0); + if (*ep || ep == optarg || ultmp > MAXTTL) + errx(EX_USAGE, "invalid TTL: `%s'", optarg); + ttl = ultmp; + options |= F_TTL; + break; case 'n': options |= F_NUMERIC; break; + case 'o': + options |= F_ONCE; + break; +#ifdef IPSEC +#ifdef IPSEC_POLICY_IPSEC + case 'P': + options |= F_POLICY; + if (!strncmp("in", optarg, 2)) + policy_in = strdup(optarg); + else if (!strncmp("out", optarg, 3)) + policy_out = strdup(optarg); + else + errx(1, "invalid security policy"); + break; +#endif /*IPSEC_POLICY_IPSEC*/ +#endif /*IPSEC*/ case 'p': /* fill buffer with user pattern */ options |= F_PINGFILLED; - fill((char *)datap, optarg); - break; + payload = optarg; + break; + case 'Q': + options |= F_QUIET2; + break; case 'q': options |= F_QUIET; break; @@ -234,77 +380,162 @@ main(argc, argv) case 'r': options |= F_SO_DONTROUTE; break; + case 'S': + source = optarg; + break; case 's': /* size of packet to send */ - datalen = atoi(optarg); - if (datalen > MAXPACKET) { - (void)fprintf(stderr, - "ping: packet size too large.\n"); - exit(1); - } - if (datalen <= 0) { - (void)fprintf(stderr, - "ping: illegal packet size.\n"); - exit(1); + ultmp = strtoul(optarg, &ep, 0); + if (*ep || ep == optarg) + errx(EX_USAGE, "invalid packet size: `%s'", + optarg); +#ifndef __APPLE__ + if (uid != 0 && ultmp > DEFDATALEN) { + errno = EPERM; + err(EX_NOPERM, + "packet size too large: %lu > %u", + ultmp, DEFDATALEN); } +#endif + datalen = ultmp; + break; + case 'T': /* multicast TTL */ + ultmp = strtoul(optarg, &ep, 0); + if (*ep || ep == optarg || ultmp > MAXTTL) + errx(EX_USAGE, "invalid multicast TTL: `%s'", + optarg); + mttl = ultmp; + options |= F_MTTL; + break; + case 't': + alarmtimeout = strtoul(optarg, &ep, 0); + if ((alarmtimeout < 1) || (alarmtimeout == ULONG_MAX)) + errx(EX_USAGE, "invalid timeout: `%s'", + optarg); + if (alarmtimeout > MAXALARM) + errx(EX_USAGE, "invalid timeout: `%s' > %d", + optarg, MAXALARM); + alarm((int)alarmtimeout); break; case 'v': options |= F_VERBOSE; break; + case 'z': + options |= F_HDRINCL; + ultmp = strtoul(optarg, &ep, 0); + if (*ep || ep == optarg || ultmp > MAXTOS) + errx(EX_USAGE, "invalid TOS: `%s'", optarg); + tos = ultmp; + break; default: usage(); } - argc -= optind; - argv += optind; + } - if (argc != 1) + if (argc - optind != 1) usage(); - target = *argv; + target = argv[optind]; + + switch (options & (F_MASK|F_TIME)) { + case 0: break; + case F_MASK: + icmp_type = ICMP_MASKREQ; + icmp_type_rsp = ICMP_MASKREPLY; + phdr_len = MASK_LEN; + if (!(options & F_QUIET)) + (void)printf("ICMP_MASKREQ\n"); + break; + case F_TIME: + icmp_type = ICMP_TSTAMP; + icmp_type_rsp = ICMP_TSTAMPREPLY; + phdr_len = TS_LEN; + if (!(options & F_QUIET)) + (void)printf("ICMP_TSTAMP\n"); + break; + default: + errx(EX_USAGE, "ICMP_TSTAMP and ICMP_MASKREQ are exclusive."); + break; + } + icmp_len = sizeof(struct ip) + ICMP_MINLEN + phdr_len; + if (options & F_RROUTE) + icmp_len += MAX_IPOPTLEN; + maxpayload = IP_MAXPACKET - icmp_len; + if (datalen > maxpayload) + errx(EX_USAGE, "packet size too large: %d > %d", datalen, + maxpayload); + send_len = icmp_len + datalen; + datap = &outpack[ICMP_MINLEN + phdr_len + TIMEVAL_LEN]; + if (options & F_PINGFILLED) { + fill((char *)datap, payload); + } + if (source) { + bzero((char *)&sock_in, sizeof(sock_in)); + sock_in.sin_family = AF_INET; + if (inet_aton(source, &sock_in.sin_addr) != 0) { + shostname = source; + } else { + hp = gethostbyname2(source, AF_INET); + if (!hp) + errx(EX_NOHOST, "cannot resolve %s: %s", + source, hstrerror(h_errno)); + + sock_in.sin_len = sizeof sock_in; + if ((unsigned)hp->h_length > sizeof(sock_in.sin_addr) || + hp->h_length < 0) + errx(1, "gethostbyname2: illegal address"); + memcpy(&sock_in.sin_addr, hp->h_addr_list[0], + sizeof(sock_in.sin_addr)); + (void)strncpy(snamebuf, hp->h_name, + sizeof(snamebuf) - 1); + snamebuf[sizeof(snamebuf) - 1] = '\0'; + shostname = snamebuf; + } + if (bind(s, (struct sockaddr *)&sock_in, sizeof sock_in) == -1) + err(1, "bind"); + } - memset(&whereto, 0, sizeof(struct sockaddr)); - to = (struct sockaddr_in *)&whereto; + bzero(&whereto, sizeof(whereto)); + to = &whereto; to->sin_family = AF_INET; - to->sin_addr.s_addr = inet_addr(target); - if (to->sin_addr.s_addr != (u_int)-1) + to->sin_len = sizeof *to; + if (inet_aton(target, &to->sin_addr) != 0) { hostname = target; - else { - hp = gethostbyname(target); - if (!hp) { - (void)fprintf(stderr, - "ping: unknown host %s\n", target); - exit(1); - } - to->sin_family = hp->h_addrtype; - memmove(&to->sin_addr, hp->h_addr, hp->h_length); + } else { + hp = gethostbyname2(target, AF_INET); + if (!hp) + errx(EX_NOHOST, "cannot resolve %s: %s", + target, hstrerror(h_errno)); + + if ((unsigned)hp->h_length > sizeof(to->sin_addr)) + errx(1, "gethostbyname2 returned an illegal address"); + memcpy(&to->sin_addr, hp->h_addr_list[0], sizeof to->sin_addr); (void)strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1); + hnamebuf[sizeof(hnamebuf) - 1] = '\0'; hostname = hnamebuf; } - if (options & F_FLOOD && options & F_INTERVAL) { - (void)fprintf(stderr, - "ping: -f and -i incompatible options.\n"); - exit(1); - } + if (options & F_FLOOD && options & F_INTERVAL) + errx(EX_USAGE, "-f and -i: incompatible options"); - if (datalen >= sizeof(struct timeval)) /* can we time transfer */ + if (options & F_FLOOD && IN_MULTICAST(ntohl(to->sin_addr.s_addr))) + errx(EX_USAGE, + "-f flag cannot be used with multicast destination"); + if (options & (F_MIF | F_NOLOOP | F_MTTL) + && !IN_MULTICAST(ntohl(to->sin_addr.s_addr))) + errx(EX_USAGE, + "-I, -L, -T flags cannot be used with unicast destination"); + + if (datalen >= TIMEVAL_LEN) /* can we time transfer */ timing = 1; - packlen = datalen + MAXIPLEN + MAXICMPLEN; - if (!(packet = (u_char *)malloc((u_int)packlen))) { - (void)fprintf(stderr, "ping: out of memory.\n"); - exit(1); - } + if (!(options & F_PINGFILLED)) - for (i = 8; i < datalen; ++i) + for (i = TIMEVAL_LEN; i < datalen; ++i) *datap++ = i; ident = getpid() & 0xFFFF; - if (!(proto = getprotobyname("icmp"))) { - (void)fprintf(stderr, "ping: unknown protocol icmp.\n"); - exit(1); - } - if ((s = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) { - perror("ping: socket"); - exit(1); + if (s < 0) { + errno = sockerrno; + err(EX_OSERR, "socket"); } hold = 1; if (options & F_SO_DEBUG) @@ -313,156 +544,359 @@ main(argc, argv) if (options & F_SO_DONTROUTE) (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&hold, sizeof(hold)); +#ifdef IPSEC +#ifdef IPSEC_POLICY_IPSEC + if (options & F_POLICY) { + char *buf; + if (policy_in != NULL) { + buf = ipsec_set_policy(policy_in, strlen(policy_in)); + if (buf == NULL) + errx(EX_CONFIG, "%s", ipsec_strerror()); + if (setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY, + buf, ipsec_get_policylen(buf)) < 0) + err(EX_CONFIG, + "ipsec policy cannot be configured"); + free(buf); + } + if (policy_out != NULL) { + buf = ipsec_set_policy(policy_out, strlen(policy_out)); + if (buf == NULL) + errx(EX_CONFIG, "%s", ipsec_strerror()); + if (setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY, + buf, ipsec_get_policylen(buf)) < 0) + err(EX_CONFIG, + "ipsec policy cannot be configured"); + free(buf); + } + } +#endif /*IPSEC_POLICY_IPSEC*/ +#endif /*IPSEC*/ + + if (options & F_HDRINCL) { + ip = (struct ip*)outpackhdr; + if (!(options & (F_TTL | F_MTTL))) { + mib[0] = CTL_NET; + mib[1] = PF_INET; + mib[2] = IPPROTO_IP; + mib[3] = IPCTL_DEFTTL; + sz = sizeof(ttl); + if (sysctl(mib, 4, &ttl, &sz, NULL, 0) == -1) + err(1, "sysctl(net.inet.ip.ttl)"); + } + setsockopt(s, IPPROTO_IP, IP_HDRINCL, &hold, sizeof(hold)); + ip->ip_v = IPVERSION; + ip->ip_hl = sizeof(struct ip) >> 2; + ip->ip_tos = tos; + ip->ip_id = 0; + ip->ip_off = df ? IP_DF : 0; + ip->ip_ttl = ttl; + ip->ip_p = IPPROTO_ICMP; + ip->ip_src.s_addr = source ? sock_in.sin_addr.s_addr : INADDR_ANY; + ip->ip_dst = to->sin_addr; + } /* record route option */ if (options & F_RROUTE) { #ifdef IP_OPTIONS + bzero(rspace, sizeof(rspace)); rspace[IPOPT_OPTVAL] = IPOPT_RR; - rspace[IPOPT_OLEN] = sizeof(rspace)-1; + rspace[IPOPT_OLEN] = sizeof(rspace) - 1; rspace[IPOPT_OFFSET] = IPOPT_MINOFF; + rspace[sizeof(rspace) - 1] = IPOPT_EOL; if (setsockopt(s, IPPROTO_IP, IP_OPTIONS, rspace, - sizeof(rspace)) < 0) { - perror("ping: record route"); - exit(1); - } + sizeof(rspace)) < 0) + err(EX_OSERR, "setsockopt IP_OPTIONS"); #else - (void)fprintf(stderr, - "ping: record route not available in this implementation.\n"); - exit(1); + errx(EX_UNAVAILABLE, + "record route not available in this implementation"); #endif /* IP_OPTIONS */ } + if (options & F_TTL) { + if (setsockopt(s, IPPROTO_IP, IP_TTL, &ttl, + sizeof(ttl)) < 0) { + err(EX_OSERR, "setsockopt IP_TTL"); + } + } + if (options & F_NOLOOP) { + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, + sizeof(loop)) < 0) { + err(EX_OSERR, "setsockopt IP_MULTICAST_LOOP"); + } + } + if (options & F_MTTL) { + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &mttl, + sizeof(mttl)) < 0) { + err(EX_OSERR, "setsockopt IP_MULTICAST_TTL"); + } + } + if (options & F_MIF) { + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &ifaddr, + sizeof(ifaddr)) < 0) { + err(EX_OSERR, "setsockopt IP_MULTICAST_IF"); + } + } +#ifdef SO_TIMESTAMP + { int on = 1; + if (setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on)) < 0) + err(EX_OSERR, "setsockopt SO_TIMESTAMP"); + } +#endif + /* * When pinging the broadcast address, you can get a lot of answers. * Doing something so evil is useful if you are trying to stress the * ethernet, or just want to fill the arp cache to get some stuff for - * /etc/ethers. + * /etc/ethers. But beware: RFC 1122 allows hosts to ignore broadcast + * or multicast pings if they wish. */ - (void)setsockopt(s, SOL_SOCKET, SO_RCVBUF, &packlen, sizeof(packlen)); - if (to->sin_family == AF_INET) - (void)printf("PING %s (%s): %d data bytes\n", hostname, - inet_ntoa(*(struct in_addr *)&to->sin_addr.s_addr), - datalen); - else + /* + * XXX receive buffer needs undetermined space for mbuf overhead + * as well. + */ + hold = IP_MAXPACKET + 128; + (void)setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&hold, + sizeof(hold)); + if (uid == 0) + (void)setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&hold, + sizeof(hold)); + + if (to->sin_family == AF_INET) { + (void)printf("PING %s (%s)", hostname, + inet_ntoa(to->sin_addr)); + if (source) + (void)printf(" from %s", shostname); + (void)printf(": %d data bytes\n", datalen); + } else (void)printf("PING %s: %d data bytes\n", hostname, datalen); - (void)signal(SIGINT, finish); - (void)signal(SIGALRM, catcher); + /* + * Use sigaction() instead of signal() to get unambiguous semantics, + * in particular with SA_RESTART not set. + */ + + sigemptyset(&si_sa.sa_mask); + si_sa.sa_flags = 0; - while (preload--) /* fire off them quickies */ - pinger(); + si_sa.sa_handler = stopit; + if (sigaction(SIGINT, &si_sa, 0) == -1) { + err(EX_OSERR, "sigaction SIGINT"); + } - if ((options & F_FLOOD) == 0) - catcher(); /* start things going */ + si_sa.sa_handler = status; + if (sigaction(SIGINFO, &si_sa, 0) == -1) { + err(EX_OSERR, "sigaction"); + } - for (;;) { - struct sockaddr_in from; - register int cc; - int fromlen; - sigset_t omask, nmask; + if (alarmtimeout > 0) { + si_sa.sa_handler = stopit; + if (sigaction(SIGALRM, &si_sa, 0) == -1) + err(EX_OSERR, "sigaction SIGALRM"); + } + + bzero(&msg, sizeof(msg)); + msg.msg_name = (caddr_t)&from; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; +#ifdef SO_TIMESTAMP + msg.msg_control = (caddr_t)ctrl; +#endif + iov.iov_base = packet; + iov.iov_len = IP_MAXPACKET; - if (options & F_FLOOD) { + if (preload == 0) + pinger(); /* send the first ping */ + else { + if (npackets != 0 && preload > npackets) + preload = npackets; + while (preload--) /* fire off them quickies */ pinger(); - timeout.tv_sec = 0; - timeout.tv_usec = 10000; - fdmask = 1 << s; - if (select(s + 1, (fd_set *)&fdmask, (fd_set *)NULL, - (fd_set *)NULL, &timeout) < 1) - continue; + } + (void)gettimeofday(&last, NULL); + + if (options & F_FLOOD) { + intvl.tv_sec = 0; + intvl.tv_usec = 10000; + } else { + intvl.tv_sec = interval / 1000; + intvl.tv_usec = interval % 1000 * 1000; + } + + almost_done = 0; + while (!finish_up) { + struct timeval now, timeout; + fd_set rfds; + int cc, n; + + check_status(); + if ((unsigned)s >= FD_SETSIZE) + errx(EX_OSERR, "descriptor too large"); + FD_ZERO(&rfds); + FD_SET(s, &rfds); + (void)gettimeofday(&now, NULL); + timeout.tv_sec = last.tv_sec + intvl.tv_sec - now.tv_sec; + timeout.tv_usec = last.tv_usec + intvl.tv_usec - now.tv_usec; + while (timeout.tv_usec < 0) { + timeout.tv_usec += 1000000; + timeout.tv_sec--; } - fromlen = sizeof(from); - if ((cc = recvfrom(s, (char *)packet, packlen, 0, - (struct sockaddr *)&from, &fromlen)) < 0) { - if (errno == EINTR) + while (timeout.tv_usec >= 1000000) { + timeout.tv_usec -= 1000000; + timeout.tv_sec++; + } + if (timeout.tv_sec < 0) + timeout.tv_sec = timeout.tv_usec = 0; + n = select(s + 1, &rfds, NULL, NULL, &timeout); + if (n < 0) + continue; /* Must be EINTR. */ + if (n == 1) { + struct timeval *tv = NULL; +#ifdef SO_TIMESTAMP + struct cmsghdr *cmsg = (struct cmsghdr *)&ctrl; + + msg.msg_controllen = sizeof(ctrl); +#endif + msg.msg_namelen = sizeof(from); + if ((cc = recvmsg(s, &msg, 0)) < 0) { + if (errno == EINTR) + continue; + warn("recvmsg"); continue; - perror("ping: recvfrom"); - continue; + } +#ifdef SO_TIMESTAMP + if (cmsg->cmsg_level == SOL_SOCKET && + cmsg->cmsg_type == SCM_TIMESTAMP && + cmsg->cmsg_len == CMSG_LEN(sizeof *tv)) { + /* Copy to avoid alignment problems: */ + memcpy(&now, CMSG_DATA(cmsg), sizeof(now)); + tv = &now; + } +#endif + if (tv == NULL) { + (void)gettimeofday(&now, NULL); + tv = &now; + } + pr_pack((char *)packet, cc, &from, tv); + if ((options & F_ONCE && nreceived) || + (npackets && nreceived >= npackets)) + break; + } + if (n == 0 || options & F_FLOOD) { + if (!npackets || ntransmitted < npackets) + pinger(); + else { + if (almost_done) + break; + almost_done = 1; + intvl.tv_usec = 0; + if (nreceived) { + intvl.tv_sec = 2 * tmax / 1000; + if (!intvl.tv_sec) + intvl.tv_sec = 1; + } else + intvl.tv_sec = MAXWAIT; + } + (void)gettimeofday(&last, NULL); + if (ntransmitted - nreceived - 1 > nmissedmax) { + nmissedmax = ntransmitted - nreceived - 1; + if (options & F_MISSED) + (void)write(STDOUT_FILENO, &BBELL, 1); + } } - sigemptyset(&nmask); - sigaddset(&nmask, SIGALRM); - sigprocmask(SIG_BLOCK, &nmask, &omask); - pr_pack((char *)packet, cc, &from); - sigprocmask(SIG_SETMASK, &omask, NULL); - if (npackets && nreceived >= npackets) - break; } finish(); /* NOTREACHED */ + exit(0); /* Make the compiler happy */ } /* - * catcher -- - * This routine causes another PING to be transmitted, and then - * schedules another SIGALRM for 1 second from now. - * - * bug -- - * Our sense of time will slowly skew (i.e., packets will not be - * launched exactly at 1-second intervals). This does not affect the - * quality of the delay and loss statistics. + * stopit -- + * Set the global bit that causes the main loop to quit. + * Do NOT call finish() from here, since finish() does far too much + * to be called from a signal handler. */ void -catcher() +stopit(sig) + int sig __unused; { - int waittime; - pinger(); - (void)signal(SIGALRM, catcher); - if (!npackets || ntransmitted < npackets) - alarm((u_int)interval); - else { - if (nreceived) { - waittime = 2 * tmax / 1000; - if (!waittime) - waittime = 1; - } else - waittime = MAXWAIT; - (void)signal(SIGALRM, finish); - (void)alarm((u_int)waittime); - } + /* + * When doing reverse DNS lookups, the finish_up flag might not + * be noticed for a while. Just exit if we get a second SIGINT. + */ + if (!(options & F_NUMERIC) && finish_up) + _exit(nreceived ? 0 : 2); + finish_up = 1; } /* * pinger -- * Compose and transmit an ICMP ECHO REQUEST packet. The IP packet * will be added on by the kernel. The ID field is our UNIX process ID, - * and the sequence number is an ascending integer. The first 8 bytes - * of the data portion are used to hold a UNIX "timeval" struct in VAX - * byte-order, to compute the round-trip time. + * and the sequence number is an ascending integer. The first TIMEVAL_LEN + * bytes of the data portion are used to hold a UNIX "timeval" struct in + * host byte-order, to compute the round-trip time. */ -pinger() +static void +pinger(void) { - register struct icmp *icp; - register int cc; - int i; + struct timeval now; + struct ip *ip; + struct icmp *icp; + int cc, i; + u_char *packet; + packet = outpack; icp = (struct icmp *)outpack; - icp->icmp_type = ICMP_ECHO; + icp->icmp_type = icmp_type; icp->icmp_code = 0; icp->icmp_cksum = 0; - icp->icmp_seq = ntransmitted++; + icp->icmp_seq = htons(ntransmitted); icp->icmp_id = ident; /* ID */ - CLR(icp->icmp_seq % mx_dup_ck); + CLR(ntransmitted % mx_dup_ck); - if (timing) - (void)gettimeofday((struct timeval *)&outpack[8], - (struct timezone *)NULL); + if ((options & F_TIME) || timing) { + (void)gettimeofday(&now, NULL); - cc = datalen + 8; /* skips ICMP portion */ + if (options & F_TIME) + icp->icmp_otime = htonl((now.tv_sec % (24*60*60)) + * 1000 + now.tv_usec / 1000); + if (timing) + bcopy((void *)&now, + (void *)&outpack[ICMP_MINLEN + phdr_len], + sizeof(struct timeval)); + } + + cc = ICMP_MINLEN + phdr_len + datalen; /* compute ICMP checksum here */ icp->icmp_cksum = in_cksum((u_short *)icp, cc); - i = sendto(s, (char *)outpack, cc, 0, &whereto, - sizeof(struct sockaddr)); + if (options & F_HDRINCL) { + cc += sizeof(struct ip); + ip = (struct ip *)outpackhdr; + ip->ip_len = cc; + ip->ip_sum = in_cksum((u_short *)outpackhdr, cc); + packet = outpackhdr; + } + i = sendto(s, (char *)packet, cc, 0, (struct sockaddr *)&whereto, + sizeof(whereto)); if (i < 0 || i != cc) { - if (i < 0) - perror("ping: sendto"); - (void)printf("ping: wrote %s %d chars, ret=%d\n", - hostname, cc, i); + if (i < 0) { + if (options & F_FLOOD && errno == ENOBUFS) { + usleep(FLOOD_BACKOFF); + return; + } + warn("sendto"); + } else { + warn("%s: partial write: %d of %d bytes", + hostname, i, cc); + } } + ntransmitted++; if (!(options & F_QUIET) && options & F_FLOOD) (void)write(STDOUT_FILENO, &DOT, 1); } @@ -474,64 +908,75 @@ pinger() * which arrive ('tis only fair). This permits multiple copies of this * program to be run without having intermingled output (or statistics!). */ -pr_pack(buf, cc, from) +static void +pr_pack(buf, cc, from, tv) char *buf; int cc; struct sockaddr_in *from; + struct timeval *tv; { - register struct icmp *icp; - register u_long l; - register u_int i, j; - register u_char *cp,*dp; - static int old_rrlen; - static char old_rr[MAX_IPOPTLEN]; + struct in_addr ina; + u_char *cp, *dp; + struct icmp *icp; struct ip *ip; - struct timeval tv, *tp; + const void *tp; double triptime; - int hlen, dupflag; - - (void)gettimeofday(&tv, (struct timezone *)NULL); + int dupflag, hlen, i, j, recv_len, seq; + static int old_rrlen; + static char old_rr[MAX_IPOPTLEN]; /* Check the IP header */ ip = (struct ip *)buf; hlen = ip->ip_hl << 2; + recv_len = cc; if (cc < hlen + ICMP_MINLEN) { if (options & F_VERBOSE) - (void)fprintf(stderr, - "ping: packet too short (%d bytes) from %s\n", cc, - inet_ntoa(*(struct in_addr *)&from->sin_addr.s_addr)); + warn("packet too short (%d bytes) from %s", cc, + inet_ntoa(from->sin_addr)); return; } /* Now the ICMP part */ cc -= hlen; icp = (struct icmp *)(buf + hlen); - if (icp->icmp_type == ICMP_ECHOREPLY) { + if (icp->icmp_type == icmp_type_rsp) { if (icp->icmp_id != ident) return; /* 'Twas not our ECHO */ ++nreceived; + triptime = 0.0; if (timing) { + struct timeval tv1; #ifndef icmp_data - tp = (struct timeval *)&icp->icmp_ip; + tp = &icp->icmp_ip; #else - tp = (struct timeval *)icp->icmp_data; + tp = icp->icmp_data; #endif - tvsub(&tv, tp); - triptime = ((double)tv.tv_sec) * 1000.0 + - ((double)tv.tv_usec) / 1000.0; - tsum += triptime; - if (triptime < tmin) - tmin = triptime; - if (triptime > tmax) - tmax = triptime; + tp = (const char *)tp + phdr_len; + + if (cc - ICMP_MINLEN - phdr_len >= sizeof(tv1)) { + /* Copy to avoid alignment problems: */ + memcpy(&tv1, tp, sizeof(tv1)); + tvsub(tv, &tv1); + triptime = ((double)tv->tv_sec) * 1000.0 + + ((double)tv->tv_usec) / 1000.0; + tsum += triptime; + tsumsq += triptime * triptime; + if (triptime < tmin) + tmin = triptime; + if (triptime > tmax) + tmax = triptime; + } else + timing = 0; } - if (TST(icp->icmp_seq % mx_dup_ck)) { + seq = ntohs(icp->icmp_seq); + + if (TST(seq % mx_dup_ck)) { ++nrepeats; --nreceived; dupflag = 1; } else { - SET(icp->icmp_seq % mx_dup_ck); + SET(seq % mx_dup_ck); dupflag = 0; } @@ -543,36 +988,91 @@ pr_pack(buf, cc, from) else { (void)printf("%d bytes from %s: icmp_seq=%u", cc, inet_ntoa(*(struct in_addr *)&from->sin_addr.s_addr), - icp->icmp_seq); + seq); (void)printf(" ttl=%d", ip->ip_ttl); if (timing) - (void)printf(" time=%g ms", triptime); + (void)printf(" time=%.3f ms", triptime); if (dupflag) (void)printf(" (DUP!)"); + if (options & F_AUDIBLE) + (void)write(STDOUT_FILENO, &BBELL, 1); + if (options & F_MASK) { + /* Just prentend this cast isn't ugly */ + (void)printf(" mask=%s", + pr_addr(*(struct in_addr *)&(icp->icmp_mask))); + } + if (options & F_TIME) { + (void)printf(" tso=%s", pr_ntime(icp->icmp_otime)); + (void)printf(" tsr=%s", pr_ntime(icp->icmp_rtime)); + (void)printf(" tst=%s", pr_ntime(icp->icmp_ttime)); + } + if (recv_len != send_len) { + (void)printf( + "\nwrong total length %d instead of %d", + recv_len, send_len); + } /* check the data */ - cp = (u_char*)&icp->icmp_data[8]; - dp = &outpack[8 + sizeof(struct timeval)]; - for (i = 8; i < datalen; ++i, ++cp, ++dp) { + cp = (u_char*)&icp->icmp_data[phdr_len]; + dp = &outpack[ICMP_MINLEN + phdr_len]; + cc -= ICMP_MINLEN + phdr_len; + i = 0; + if (timing) { /* don't check variable timestamp */ + cp += TIMEVAL_LEN; + dp += TIMEVAL_LEN; + cc -= TIMEVAL_LEN; + i += TIMEVAL_LEN; + } + for (; i < datalen && cc > 0; ++i, ++cp, ++dp, --cc) { if (*cp != *dp) { (void)printf("\nwrong data byte #%d should be 0x%x but was 0x%x", i, *dp, *cp); + (void)printf("\ncp:"); cp = (u_char*)&icp->icmp_data[0]; - for (i = 8; i < datalen; ++i, ++cp) { - if ((i % 32) == 8) + for (i = 0; i < datalen; ++i, ++cp) { + if ((i % 16) == 8) + (void)printf("\n\t"); + (void)printf("%2x ", *cp); + } + (void)printf("\ndp:"); + cp = &outpack[ICMP_MINLEN]; + for (i = 0; i < datalen; ++i, ++cp) { + if ((i % 16) == 8) (void)printf("\n\t"); - (void)printf("%x ", *cp); + (void)printf("%2x ", *cp); } break; } } } } else { - /* We've got something other than an ECHOREPLY */ - if (!(options & F_VERBOSE)) - return; - (void)printf("%d bytes from %s: ", cc, - pr_addr(from->sin_addr.s_addr)); - pr_icmph(icp); + /* + * We've got something other than an ECHOREPLY. + * See if it's a reply to something that we sent. + * We can compare IP destination, protocol, + * and ICMP type and ID. + * + * Only print all the error messages if we are running + * as root to avoid leaking information not normally + * available to those not running as root. + */ +#ifndef icmp_data + struct ip *oip = &icp->icmp_ip; +#else + struct ip *oip = (struct ip *)icp->icmp_data; +#endif + struct icmp *oicmp = (struct icmp *)(oip + 1); + + if (((options & F_VERBOSE) && uid == 0) || + (!(options & F_QUIET2) && + (oip->ip_dst.s_addr == whereto.sin_addr.s_addr) && + (oip->ip_p == IPPROTO_ICMP) && + (oicmp->icmp_type == ICMP_ECHO) && + (oicmp->icmp_id == ident))) { + (void)printf("%d bytes from %s: ", cc, + pr_addr(from->sin_addr)); + pr_icmph(icp); + } else + return; } /* Display any IP options */ @@ -584,74 +1084,72 @@ pr_pack(buf, cc, from) hlen = 0; break; case IPOPT_LSRR: - (void)printf("\nLSRR: "); + case IPOPT_SSRR: + (void)printf(*cp == IPOPT_LSRR ? + "\nLSRR: " : "\nSSRR: "); + j = cp[IPOPT_OLEN] - IPOPT_MINOFF + 1; hlen -= 2; - j = *++cp; - ++cp; - if (j > IPOPT_MINOFF) + cp += 2; + if (j >= INADDR_LEN && + j <= hlen - (int)sizeof(struct ip)) { for (;;) { - l = *++cp; - l = (l<<8) + *++cp; - l = (l<<8) + *++cp; - l = (l<<8) + *++cp; - if (l == 0) + bcopy(++cp, &ina.s_addr, INADDR_LEN); + if (ina.s_addr == 0) (void)printf("\t0.0.0.0"); - else - (void)printf("\t%s", pr_addr(ntohl(l))); - hlen -= 4; - j -= 4; - if (j <= IPOPT_MINOFF) - break; - (void)putchar('\n'); - } + else + (void)printf("\t%s", + pr_addr(ina)); + hlen -= INADDR_LEN; + cp += INADDR_LEN - 1; + j -= INADDR_LEN; + if (j < INADDR_LEN) + break; + (void)putchar('\n'); + } + } else + (void)printf("\t(truncated route)\n"); break; case IPOPT_RR: - j = *++cp; /* get length */ - i = *++cp; /* and pointer */ + j = cp[IPOPT_OLEN]; /* get length */ + i = cp[IPOPT_OFFSET]; /* and pointer */ hlen -= 2; + cp += 2; if (i > j) i = j; - i -= IPOPT_MINOFF; - if (i <= 0) + i = i - IPOPT_MINOFF + 1; + if (i < 0 || i > (hlen - (int)sizeof(struct ip))) { + old_rrlen = 0; continue; + } if (i == old_rrlen - && cp == (u_char *)buf + sizeof(struct ip) + 2 - && !memcmp(cp, old_rr, i) + && !bcmp((char *)cp, old_rr, i) && !(options & F_FLOOD)) { (void)printf("\t(same route)"); - i = ((i + 3) / 4) * 4; hlen -= i; cp += i; break; } - if (i < MAX_IPOPTLEN) { - old_rrlen = i; - memcpy(old_rr, cp, i); - } else - old_rrlen = 0; - + old_rrlen = i; + bcopy((char *)cp, old_rr, i); (void)printf("\nRR: "); - j = 0; - for (;;) { - l = *++cp; - l = (l<<8) + *++cp; - l = (l<<8) + *++cp; - l = (l<<8) + *++cp; - if (l == 0) - (void)printf("\t0.0.0.0"); - else - (void)printf("\t%s", pr_addr(ntohl(l))); - hlen -= 4; - i -= 4; - j += 4; - if (i <= 0) - break; - if (j >= MAX_IPOPTLEN) { - (void)printf("\t(truncated route)"); - break; + if (i >= INADDR_LEN && + i <= hlen - (int)sizeof(struct ip)) { + for (;;) { + bcopy(++cp, &ina.s_addr, INADDR_LEN); + if (ina.s_addr == 0) + (void)printf("\t0.0.0.0"); + else + (void)printf("\t%s", + pr_addr(ina)); + hlen -= INADDR_LEN; + cp += INADDR_LEN - 1; + i -= INADDR_LEN; + if (i < INADDR_LEN) + break; + (void)putchar('\n'); } - (void)putchar('\n'); - } + } else + (void)printf("\t(truncated route)"); break; case IPOPT_NOP: (void)printf("\nNOP"); @@ -670,14 +1168,22 @@ pr_pack(buf, cc, from) * in_cksum -- * Checksum routine for Internet Protocol family headers (C Version) */ +u_short in_cksum(addr, len) u_short *addr; int len; { - register int nleft = len; - register u_short *w = addr; - register int sum = 0; - u_short answer = 0; + int nleft, sum; + u_short *w; + union { + u_short us; + u_char uc[2]; + } last; + u_short answer; + + nleft = len; + sum = 0; + w = addr; /* * Our algorithm is simple, using a 32 bit accumulator (sum), we add @@ -691,8 +1197,9 @@ in_cksum(addr, len) /* mop up an odd byte, if necessary */ if (nleft == 1) { - *(u_char *)(&answer) = *(u_char *)w ; - sum += answer; + last.uc[0] = *(u_char *)w; + last.uc[1] = 0; + sum += last.us; } /* add back carry outs from top 16 bits to low 16 bits */ @@ -707,9 +1214,11 @@ in_cksum(addr, len) * Subtract 2 timeval structs: out = out - in. Out is assumed to * be >= in. */ +static void tvsub(out, in) - register struct timeval *out, *in; + struct timeval *out, *in; { + if ((out->tv_usec -= in->tv_usec) < 0) { --out->tv_sec; out->tv_usec += 1000000; @@ -717,16 +1226,45 @@ tvsub(out, in) out->tv_sec -= in->tv_sec; } +/* + * status -- + * Print out statistics when SIGINFO is received. + */ + +static void +status(sig) + int sig __unused; +{ + + siginfo_p = 1; +} + +static void +check_status() +{ + + if (siginfo_p) { + siginfo_p = 0; + (void)fprintf(stderr, "\r%ld/%ld packets received (%.0f%%)", + nreceived, ntransmitted, + ntransmitted ? nreceived * 100.0 / ntransmitted : 0.0); + if (nreceived && timing) + (void)fprintf(stderr, " %.3f min / %.3f avg / %.3f max", + tmin, tsum / (nreceived + nrepeats), tmax); + (void)fprintf(stderr, "\n"); + } +} + /* * finish -- * Print out statistics, and give up. */ -void +static void finish() { - register int i; (void)signal(SIGINT, SIG_IGN); + (void)signal(SIGALRM, SIG_IGN); (void)putchar('\n'); (void)fflush(stdout); (void)printf("--- %s ping statistics ---\n", hostname); @@ -734,21 +1272,28 @@ finish() (void)printf("%ld packets received, ", nreceived); if (nrepeats) (void)printf("+%ld duplicates, ", nrepeats); - if (ntransmitted) + if (ntransmitted) { if (nreceived > ntransmitted) (void)printf("-- somebody's printing up packets!"); else (void)printf("%d%% packet loss", - (int) (((ntransmitted - nreceived) * 100) / + (int)(((ntransmitted - nreceived) * 100) / ntransmitted)); + } (void)putchar('\n'); if (nreceived && timing) { - /* Only display average to microseconds */ - i = 1000.0 * tsum / (nreceived + nrepeats); - (void)printf("round-trip min/avg/max = %g/%g/%g ms\n", - tmin, ((double)i) / 1000.0, tmax); + double n = nreceived + nrepeats; + double avg = tsum / n; + double vari = tsumsq / n - avg * avg; + (void)printf( + "round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f ms\n", + tmin, avg, tmax, sqrt(vari)); } - exit(0); + + if (nreceived) + exit(0); + else + exit(2); } #ifdef notdef @@ -771,9 +1316,11 @@ static char *ttab[] = { * pr_icmph -- * Print a descriptive string about an ICMP header. */ +static void pr_icmph(icp) struct icmp *icp; { + switch(icp->icmp_type) { case ICMP_ECHOREPLY: (void)printf("Echo Reply\n"); @@ -794,11 +1341,15 @@ pr_icmph(icp) (void)printf("Destination Port Unreachable\n"); break; case ICMP_UNREACH_NEEDFRAG: - (void)printf("frag needed and DF set\n"); + (void)printf("frag needed and DF set (MTU %d)\n", + ntohs(icp->icmp_nextmtu)); break; case ICMP_UNREACH_SRCFAIL: (void)printf("Source Route Failed\n"); break; + case ICMP_UNREACH_FILTER_PROHIB: + (void)printf("Communication prohibited by filter\n"); + break; default: (void)printf("Dest Unreachable, Bad Code: %d\n", icp->icmp_code); @@ -837,7 +1388,7 @@ pr_icmph(icp) (void)printf("Redirect, Bad Code: %d", icp->icmp_code); break; } - (void)printf("(New addr: 0x%08lx)\n", icp->icmp_gwaddr.s_addr); + (void)printf("(New addr: %s)\n", inet_ntoa(icp->icmp_gwaddr)); #ifndef icmp_data pr_retip(&icp->icmp_ip); #else @@ -892,16 +1443,18 @@ pr_icmph(icp) (void)printf("Information Reply\n"); /* XXX ID + Seq */ break; -#ifdef ICMP_MASKREQ case ICMP_MASKREQ: (void)printf("Address Mask Request\n"); break; -#endif -#ifdef ICMP_MASKREPLY case ICMP_MASKREPLY: (void)printf("Address Mask Reply\n"); break; -#endif + case ICMP_ROUTERADVERT: + (void)printf("Router Advertisement\n"); + break; + case ICMP_ROUTERSOLICIT: + (void)printf("Router Solicitation\n"); + break; default: (void)printf("Bad ICMP type: %d\n", icp->icmp_type); } @@ -911,24 +1464,28 @@ pr_icmph(icp) * pr_iph -- * Print an IP header with options. */ +static void pr_iph(ip) struct ip *ip; { - int hlen; u_char *cp; + int hlen; hlen = ip->ip_hl << 2; cp = (u_char *)ip + 20; /* point to options */ - (void)printf("Vr HL TOS Len ID Flg off TTL Pro cks Src Dst Data\n"); + (void)printf("Vr HL TOS Len ID Flg off TTL Pro cks Src Dst\n"); (void)printf(" %1x %1x %02x %04x %04x", - ip->ip_v, ip->ip_hl, ip->ip_tos, ip->ip_len, ip->ip_id); - (void)printf(" %1x %04x", ((ip->ip_off) & 0xe000) >> 13, - (ip->ip_off) & 0x1fff); - (void)printf(" %02x %02x %04x", ip->ip_ttl, ip->ip_p, ip->ip_sum); + ip->ip_v, ip->ip_hl, ip->ip_tos, ntohs(ip->ip_len), + ntohs(ip->ip_id)); + (void)printf(" %1lx %04lx", + (u_long) (ntohl(ip->ip_off) & 0xe000) >> 13, + (u_long) ntohl(ip->ip_off) & 0x1fff); + (void)printf(" %02x %02x %04x", ip->ip_ttl, ip->ip_p, + ntohs(ip->ip_sum)); (void)printf(" %s ", inet_ntoa(*(struct in_addr *)&ip->ip_src.s_addr)); (void)printf(" %s ", inet_ntoa(*(struct in_addr *)&ip->ip_dst.s_addr)); - /* dump and option bytes */ + /* dump any option bytes */ while (hlen-- > 20) { (void)printf("%02x", *cp++); } @@ -940,19 +1497,19 @@ pr_iph(ip) * Return an ascii host address as a dotted quad and optionally with * a hostname. */ -char * -pr_addr(l) - u_long l; +static char * +pr_addr(ina) + struct in_addr ina; { struct hostent *hp; - static char buf[80]; + static char buf[16 + 3 + MAXHOSTNAMELEN]; if ((options & F_NUMERIC) || - !(hp = gethostbyaddr((char *)&l, 4, AF_INET))) - (void)sprintf(buf, "%s", inet_ntoa(*(struct in_addr *)&l)); + !(hp = gethostbyaddr((char *)&ina, 4, AF_INET))) + return inet_ntoa(ina); else - (void)sprintf(buf, "%s (%s)", hp->h_name, - inet_ntoa(*(struct in_addr *)&l)); + (void)snprintf(buf, sizeof(buf), "%s (%s)", hp->h_name, + inet_ntoa(ina)); return(buf); } @@ -960,11 +1517,12 @@ pr_addr(l) * pr_retip -- * Dump some info on a returned (via ICMP) IP packet. */ +static void pr_retip(ip) struct ip *ip; { - int hlen; u_char *cp; + int hlen; pr_iph(ip); hlen = ip->ip_hl << 2; @@ -978,19 +1536,36 @@ pr_retip(ip) (*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3))); } +static char * +pr_ntime (n_time timestamp) +{ + static char buf[10]; + int hour, min, sec; + + sec = ntohl(timestamp) / 1000; + hour = sec / 60 / 60; + min = (sec % (60 * 60)) / 60; + sec = (sec % (60 * 60)) % 60; + + (void)snprintf(buf, sizeof(buf), "%02d:%02d:%02d", hour, min, sec); + + return (buf); +} + +static void fill(bp, patp) char *bp, *patp; { - register int ii, jj, kk; - int pat[16]; char *cp; + int pat[16]; + u_int ii, jj, kk; - for (cp = patp; *cp; cp++) - if (!isxdigit(*cp)) { - (void)fprintf(stderr, - "ping: patterns must be specified as hex digits.\n"); - exit(1); - } + for (cp = patp; *cp; cp++) { + if (!isxdigit(*cp)) + errx(EX_USAGE, + "patterns must be specified as hex digits"); + + } ii = sscanf(patp, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", &pat[0], &pat[1], &pat[2], &pat[3], &pat[4], &pat[5], &pat[6], @@ -998,9 +1573,7 @@ fill(bp, patp) &pat[13], &pat[14], &pat[15]); if (ii > 0) - for (kk = 0; - kk <= MAXPACKET - (8 + sizeof(struct timeval) + ii); - kk += ii) + for (kk = 0; kk <= maxpayload - (TIMEVAL_LEN + ii); kk += ii) for (jj = 0; jj < ii; ++jj) bp[jj + kk] = pat[jj]; if (!(options & F_QUIET)) { @@ -1011,9 +1584,21 @@ fill(bp, patp) } } +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) +#define SECOPT " [-P policy]" +#else +#define SECOPT "" +#endif +static void usage() { - (void)fprintf(stderr, - "usage: ping [-Rdfnqrv] [-c count] [-i wait] [-l preload]\n\t[-p pattern] [-s packetsize] host\n"); - exit(1); + + (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", +"usage: ping [-AaDdfnoQqRrv] [-c count] [-i wait] [-l preload] [-M mask | time]", +" [-m ttl]" SECOPT " [-p pattern] [-S src_addr] [-s packetsize]", +" [-t timeout] [-z tos] host", +" ping [-AaDdfLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]", +" [-M mask | time] [-m ttl]" SECOPT " [-p pattern] [-S src_addr]", +" [-s packetsize] [-T ttl] [-t timeout] [-z tos] mcast-group"); + exit(EX_USAGE); } diff --git a/racoon.tproj/Makefile b/racoon.tproj/Makefile index 7836daf..1e6a158 100644 --- a/racoon.tproj/Makefile +++ b/racoon.tproj/Makefile @@ -21,7 +21,8 @@ HFILES = admin.h algorithm.h arc4random.h backupsa.h crypto_openssl.h dnssec.h\ schedule.h session.h sha2.h sockmisc.h str2val.h strnames.h\ vendorid.h vmbuf.h admin_var.h cftoken.h debug.h dhgroup.h\ gcmalloc.h isakmp_var.h libpfkey.h netdb_dnssec.h\ - rijndael_local.h rijndael.h var.h isakmp_natd.h + rijndael_local.h rijndael.h var.h isakmp_natd.h crypto_cssm.h\ + open_dir.h OTHERLINKED = cfparse.y cftoken.l @@ -33,7 +34,8 @@ CFILES = admin.c algorithm.c backupsa.c crypto_openssl.c dnssec.c\ pfkey2.c pfkey_dump.c plog.c policy.c proposal.c\ remoteconf.c rijndael-alg-fst.c rijndael-api-fst.c safefile.c\ sainfo.c schedule.c session.c sha2.c sockmisc.c str2val.c\ - strnames.c vendorid.c vmbuf.c isakmp_natd.c + strnames.c vendorid.c vmbuf.c isakmp_natd.c crypto_cssm.c\ + open_dir.c OTHERSRCS = Makefile.preamble Makefile Makefile.postamble boxes-fst.dat\ psk.txt racoon.8 racoon.conf anonymous.conf racoon.conf.5 @@ -50,7 +52,9 @@ LIBS = -lcrypto -lipsec -lssl DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) -FRAMEWORKS = -framework CoreFoundation -framework Security +HEADER_PATHS =\ + -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/ +FRAMEWORKS = -framework CoreFoundation -framework Security -framework DirectoryService NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc diff --git a/racoon.tproj/PB.project b/racoon.tproj/PB.project index 6bb393f..488b851 100644 --- a/racoon.tproj/PB.project +++ b/racoon.tproj/PB.project @@ -51,7 +51,9 @@ "rijndael_local.h", "rijndael.h", "var.h", - "isakmp_natd.h" + "isakmp_natd.h", + "crypto_cssm.h", + "open_dir.h" ); "OTHER_LIBS" = (crypto, ipsec, ssl); "OTHER_LINKED" = ( @@ -99,7 +101,9 @@ "strnames.c", "vendorid.c", "vmbuf.c", - "isakmp_natd.c" + "isakmp_natd.c", + "crypto_cssm.c", + "open_dir.c" ); "OTHER_SOURCES" = ( "Makefile.preamble", diff --git a/racoon.tproj/admin.h b/racoon.tproj/admin.h index ef0b3ef..bf2d68d 100644 --- a/racoon.tproj/admin.h +++ b/racoon.tproj/admin.h @@ -29,6 +29,10 @@ * SUCH DAMAGE. */ +#ifndef __ADMIN_H__ +#define __ADMIN_H__ + + /* command for administration. */ /* NOTE: host byte order. */ struct admin_com { @@ -75,3 +79,7 @@ struct admin_com_indexes { }; extern int admin2pfkey_proto __P((u_int)); + + +#endif /* __ADMIN_H__ */ + diff --git a/racoon.tproj/admin_var.h b/racoon.tproj/admin_var.h index 60d88ac..724f15c 100644 --- a/racoon.tproj/admin_var.h +++ b/racoon.tproj/admin_var.h @@ -29,8 +29,16 @@ * SUCH DAMAGE. */ +#ifndef __ADMIN_VAR_H__ +#define __ADMIN_VAR_H__ + + #define PORT_ADMIN "/tmp/.racoon" extern int admin_handler __P((void)); extern int admin_init __P((void)); extern int admin_close __P((void)); + + +#endif /*__ADMIN_VAR_H__ */ + diff --git a/racoon.tproj/algorithm.h b/racoon.tproj/algorithm.h index 0e7bd2b..057c53f 100644 --- a/racoon.tproj/algorithm.h +++ b/racoon.tproj/algorithm.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __ALGORITHM_H__ +#define __ALGORITHM_H__ + /* algorithm class */ enum { algclass_ipsec_enc, @@ -189,3 +192,7 @@ extern int default_keylen __P((int, int)); extern int check_keylen __P((int, int, int)); extern int algtype2doi __P((int, int)); extern int algclass2doi __P((int)); + + +#endif /* __ALGORITHM_H__ */ + diff --git a/racoon.tproj/arc4random.h b/racoon.tproj/arc4random.h index f89e924..1957945 100644 --- a/racoon.tproj/arc4random.h +++ b/racoon.tproj/arc4random.h @@ -29,4 +29,11 @@ * SUCH DAMAGE. */ +#ifndef __ARC4RANDOM_H__ +#define __ARC4RANDOM_H__ + extern u_int32_t arc4random __P((void)); + + +#endif /* __ARC4RANDOM_H__ */ + diff --git a/racoon.tproj/backupsa.h b/racoon.tproj/backupsa.h index c3b2533..771c51b 100644 --- a/racoon.tproj/backupsa.h +++ b/racoon.tproj/backupsa.h @@ -29,9 +29,17 @@ * SUCH DAMAGE. */ +#ifndef __BACKUPSA_H__ +#define __BACKUPSA_H__ + + extern int backupsa_to_file __P((u_int, u_int, struct sockaddr *, struct sockaddr *, u_int32_t, u_int32_t, u_int, caddr_t, u_int, u_int, u_int, u_int, u_int, u_int32_t, u_int64_t, u_int64_t, u_int64_t, u_int32_t)); extern int backupsa_from_file __P((void)); extern int backupsa_clean __P((void)); + + +#endif /* __BACKUPSA_H__ */ + diff --git a/racoon.tproj/cfparse.y b/racoon.tproj/cfparse.y index 13376a7..9c655fa 100644 --- a/racoon.tproj/cfparse.y +++ b/racoon.tproj/cfparse.y @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #if !defined(HAVE_GETADDRINFO) || !defined(HAVE_GETNAMEINFO) @@ -47,6 +48,7 @@ #include "gssapi.h" #endif #include "vendorid.h" +#include struct proposalspec { time_t lifetime; /* for isakmp/ipsec */ @@ -103,6 +105,8 @@ static int set_isakmp_proposal static void clean_tmpalgtype __P((void)); static int expand_isakmpspec __P((int, int, int *, int, int, time_t, int, int, int, char *, struct remoteconf *)); + +static int base64toCFData(vchar_t *, CFDataRef*); #if 0 static int fix_lifebyte __P((u_long)); @@ -142,6 +146,8 @@ static int fix_lifebyte __P((u_long)); %token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE VERIFY_CERT SEND_CERT SEND_CR %token IDENTIFIERTYPE MY_IDENTIFIER PEERS_IDENTIFIER VERIFY_IDENTIFIER %token SHARED_SECRET SECRETTYPE +%token OPEN_DIR_AUTH_GROUP IN_KEYCHAIN +%token CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION %token DNSSEC CERT_X509 %token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT %token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL @@ -169,6 +175,7 @@ static int fix_lifebyte __P((u_long)); %type ul_proto UL_PROTO %type EXCHANGETYPE DOITYPE SITUATIONTYPE %type CERTTYPE CERT_X509 PROPOSAL_CHECK_LEVEL +%type VERIFICATION_MODULE VERIFICATION_OPTION %type unittype_time unittype_byte %type QUOTEDSTRING HEXSTRING ADDRSTRING sainfo_id %type identifierstring @@ -322,7 +329,9 @@ listen_stmt delmyaddr(p); return -1; } - + p->sock = -1; + p->nattsock = -1; + p->addrcount = 1; insmyaddr(p, &lcconf->myaddrs); lcconf->autograbaddr = 0; @@ -648,7 +657,7 @@ remote_statement { struct remoteconf *new; struct proposalspec *prspec; - + new = newrmconf(); if (new == NULL) { yyerror("failed to get new remoteconf."); @@ -673,11 +682,19 @@ remote_statement } if (cur_rmconf->idvtype == IDTYPE_ASN1DN - && cur_rmconf->mycertfile == NULL) { + && cur_rmconf->mycertfile == NULL + && cur_rmconf->identity_in_keychain == 0) { yyerror("id type mismatched due to " "no CERT defined.\n"); return -1; } + + if (cur_rmconf->cert_verification_option == VERIFICATION_OPTION_PEERS_IDENTIFIER + && cur_rmconf->idv_p == NULL) { + yyerror("peers_identifier required for specified certificate " + "verification option.\n"); + return -1; + } if (set_isakmp_proposal(cur_rmconf, prhead) != 0) return -1; @@ -771,6 +788,14 @@ remote_spec | VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS | SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS | SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS + | CERTIFICATE_VERIFICATION VERIFICATION_MODULE { cur_rmconf->cert_verification = $2; } EOS + | CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION + { + cur_rmconf->cert_verification = $2; + cur_rmconf->cert_verification_option = $3; + } + EOS + | OPEN_DIR_AUTH_GROUP QUOTEDSTRING { cur_rmconf->open_dir_auth_group = $2; } EOS | IDENTIFIER IDENTIFIERTYPE { /*XXX to be deleted */ @@ -781,6 +806,7 @@ remote_spec { if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) { yyerror("failed to set identifer.\n"); + vfree($3); return -1; } vfree($3); @@ -791,6 +817,7 @@ remote_spec { if (set_identifier(&cur_rmconf->idv_p, $2, $3) != 0) { yyerror("failed to set identifer.\n"); + vfree($3); return -1; } vfree($3); @@ -881,7 +908,28 @@ cert_spec #endif } EOS + | CERT_X509 IN_KEYCHAIN + { + cur_rmconf->certtype = $1; + cur_rmconf->identity_in_keychain = 1; + cur_rmconf->keychainCertRef = 0; + } + EOS + ; + | CERT_X509 IN_KEYCHAIN QUOTEDSTRING + { + int result; + + cur_rmconf->certtype = $1; + cur_rmconf->identity_in_keychain = 1; + result = base64toCFData($3, &cur_rmconf->keychainCertRef); + vfree($3); + if (result) + return -1; + } + EOS ; + dh_group_num : ALGORITHMTYPE { @@ -1380,3 +1428,79 @@ cfreparse() return(cfparse()); } + +/* ----------------------------------------------------------------------------- +The base-64 encoding packs three 8-bit bytes into four 7-bit ASCII +characters. If the number of bytes in the original data isn't divisable +by three, "=" characters are used to pad the encoded data. The complete +set of characters used in base-64 are: + 'A'..'Z' => 00..25 + 'a'..'z' => 26..51 + '0'..'9' => 52..61 + '+' => 62 + '/' => 63 + '=' => pad + +----------------------------------------------------------------------------- */ +static const signed char base64_DecodeTable[128] = { + /* 000 */ -1, -1, -1, -1, -1, -1, -1, -1, + /* 010 */ -1, -1, -1, -1, -1, -1, -1, -1, + /* 020 */ -1, -1, -1, -1, -1, -1, -1, -1, + /* 030 */ -1, -1, -1, -1, -1, -1, -1, -1, + /* ' ' */ -1, -1, -1, -1, -1, -1, -1, -1, + /* '(' */ -1, -1, -1, 62, -1, -1, -1, 63, + /* '0' */ 52, 53, 54, 55, 56, 57, 58, 59, + /* '8' */ 60, 61, -1, -1, -1, 0, -1, -1, + /* '@' */ -1, 0, 1, 2, 3, 4, 5, 6, + /* 'H' */ 7, 8, 9, 10, 11, 12, 13, 14, + /* 'P' */ 15, 16, 17, 18, 19, 20, 21, 22, + /* 'X' */ 23, 24, 25, -1, -1, -1, -1, -1, + /* '`' */ -1, 26, 27, 28, 29, 30, 31, 32, + /* 'h' */ 33, 34, 35, 36, 37, 38, 39, 40, + /* 'p' */ 41, 42, 43, 44, 45, 46, 47, 48, + /* 'x' */ 49, 50, 51, -1, -1, -1, -1, -1 +}; + +static int base64toCFData(vchar_t *textin, CFDataRef *dataRef) +{ + uint8_t *tmpbuf; + uint8_t c; + int tmpbufpos = 0; + int numeq = 0; + int acc = 0; + int cntr = 0; + uint8_t *textcur = textin->v; + int len = textin->l; + int i; + + tmpbuf = malloc(len); // len of result will be less than encoded len + if (tmpbuf == NULL) { + yyerror("memory error - could not allocate buffer for certificate reference conversion from base-64."); + return -1; + } + + for (i = 0; i < len; i++) { + c = *(textcur++); + if (c == '=') + numeq++; + else if (!isspace(c)) + numeq = 0; + if (base64_DecodeTable[c] < 0) + continue; + cntr++; + acc <<= 6; + acc += base64_DecodeTable[c]; + if (0 == (cntr & 0x3)) { + tmpbuf[tmpbufpos++] = (acc >> 16) & 0xff; + if (numeq < 2) + tmpbuf[tmpbufpos++] = (acc >> 8) & 0xff; + if (numeq < 1) + tmpbuf[tmpbufpos++] = acc & 0xff; + } + } + *dataRef = CFDataCreate(NULL, tmpbuf, tmpbufpos); + free(tmpbuf); + return 0; + +} + diff --git a/racoon.tproj/cftoken.h b/racoon.tproj/cftoken.h index b70fce4..1c0b43b 100644 --- a/racoon.tproj/cftoken.h +++ b/racoon.tproj/cftoken.h @@ -29,6 +29,10 @@ * SUCH DAMAGE. */ +#ifndef __CFTOKEN_H__ +#define __CFTOKEN_H__ + + extern int yyerrorcount; extern int yylex __P((void)); @@ -39,3 +43,7 @@ extern int yycf_switch_buffer __P((char *)); extern int yycf_set_buffer __P((char *)); extern void yycf_init_buffer __P((void)); extern void yycf_clean_buffer __P((void)); + + +#endif /* __CFTOKEN_H__ */ + diff --git a/racoon.tproj/cftoken.l b/racoon.tproj/cftoken.l index 1695072..2a465c7 100644 --- a/racoon.tproj/cftoken.l +++ b/racoon.tproj/cftoken.l @@ -71,7 +71,7 @@ static int incstackp = 0; static int yy_first_time = 1; %} -/* common seciton */ +/* common section */ nl \n ws [ \t]+ digit [0-9] @@ -211,9 +211,12 @@ hexstring 0x{hexdigit}+ my_identifier { YYD; return(MY_IDENTIFIER); } peers_identifier { YYD; return(PEERS_IDENTIFIER); } verify_identifier { YYD; return(VERIFY_IDENTIFIER); } +open_dir_auth_group { YYD; return(OPEN_DIR_AUTH_GROUP); } certificate_type { YYD; return(CERTIFICATE_TYPE); } shared_secret { YYD; return(SHARED_SECRET); } x509 { YYD; yylval.num = ISAKMP_CERT_X509SIGN; return(CERT_X509); } +in_keychain { YYD; return(IN_KEYCHAIN); } +certificate_verification { YYD; return(CERTIFICATE_VERIFICATION); } peers_certfile { YYD; return(PEERS_CERTFILE); } dnssec { YYD; return(DNSSEC); } verify_cert { YYD; return(VERIFY_CERT); } @@ -342,6 +345,12 @@ use { YYD; yylval.num = SECRETTYPE_USE; return(SECRETTYPE); } key { YYD; yylval.num = SECRETTYPE_KEY; return(SECRETTYPE); } keychain { YYD; yylval.num = SECRETTYPE_KEYCHAIN; return(SECRETTYPE); } + /* certificate verification */ +openssl { YYD; yylval.num = VERIFICATION_MODULE_OPENSSL; return(VERIFICATION_MODULE); } +sec_framework { YYD; yylval.num = VERIFICATION_MODULE_SEC_FRAMEWORK; return(VERIFICATION_MODULE); } +use_open_dir { YYD; yylval.num = VERIFICATION_OPTION_OPEN_DIR; return(VERIFICATION_OPTION); } +use_peers_identifier { YYD; yylval.num = VERIFICATION_OPTION_PEERS_IDENTIFIER; return(VERIFICATION_OPTION); } + /* units */ B|byte|bytes { YYD; return(UNITTYPE_BYTE); } KB { YYD; return(UNITTYPE_KBYTES); } diff --git a/racoon.tproj/crypto_cssm.c b/racoon.tproj/crypto_cssm.c new file mode 100644 index 0000000..aa6f83b --- /dev/null +++ b/racoon.tproj/crypto_cssm.c @@ -0,0 +1,534 @@ + +/* + * Copyright (c) 2001-2004 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + + +/* + * Racoon module for verifying and signing certificates through Security + * Framework and CSSM + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "plog.h" +#include "debug.h" +#include "misc.h" + +#include "crypto_cssm.h" + + + +static OSStatus FindPolicy(const CSSM_OID *policyOID, SecPolicyRef *policyRef); +static OSStatus EvaluateCert(SecCertificateRef cert, CFTypeRef policyRef); +static OSStatus CopySystemKeychain(SecKeychainRef *keychainRef); +static const char *GetSecurityErrorString(OSStatus err); + + +/* + * Verify cert using security framework + */ +int crypto_cssm_check_x509cert(vchar_t *cert) +{ + OSStatus status; + SecCertificateRef certRef = 0; + CSSM_DATA certData; + CSSM_OID ourPolicyOID = CSSMOID_APPLE_TP_IP_SEC; + SecPolicyRef policyRef = 0; + + // create cert ref + certData.Length = cert->l; + certData.Data = cert->v; + status = SecCertificateCreateFromData(&certData, CSSM_CERT_X_509v3, CSSM_CERT_ENCODING_DER, + &certRef); + if (status != noErr) + goto end; + + // get our policy object + status = FindPolicy(&ourPolicyOID, &policyRef); + if (status != noErr) + goto end; + + // setup policy options ??? + // no options used at present - verification of subjectAltName fields, etc. + // are done elsewhere in racoon in oakley_check_certid() + + // evaluate cert + status = EvaluateCert(certRef, policyRef); + + +end: + + if (certRef) + CFRelease(certRef); + if (policyRef) + CFRelease(policyRef); + + if (status != noErr && status != -1) { + plog(LLV_ERROR, LOCATION, NULL, + "error %d %s.\n", status, GetSecurityErrorString(status)); + status = -1; + } + return status; + +} + +/* + * Encrypt a hash via CSSM using the private key in the keychain + * from an identity. + */ +vchar_t* crypto_cssm_getsign(CFDataRef persistentCertRef, vchar_t* hash) +{ + + OSStatus status; + SecCertificateRef certificateRef = NULL; + SecIdentityRef identityRef = NULL; + SecIdentitySearchRef idSearchRef = NULL; + SecKeychainRef keychainRef = NULL; + SecKeyRef privateKeyRef = NULL; + const CSSM_KEY *cssmKey = NULL; + CSSM_CSP_HANDLE cspHandle = nil; + CSSM_CC_HANDLE cssmContextHandle = nil; + const CSSM_ACCESS_CREDENTIALS *credentials = NULL; + uint32 bytesEncrypted = 0; + CSSM_DATA clearData; + CSSM_DATA cipherData; + CSSM_DATA remData; + CSSM_CONTEXT_ATTRIBUTE newAttr; + vchar_t *sig = NULL; + + remData.Length = 0; + remData.Data = 0; + + if (persistentCertRef) { + // get cert from keychain + status = SecKeychainItemCopyFromPersistentReference(persistentCertRef, (SecKeychainItemRef*)&certificateRef); + if (status != noErr) + goto end; + + // get keychain ref where cert is contained + status = SecKeychainItemCopyKeychain((SecKeychainItemRef)certificateRef, &keychainRef); + if (status != noErr) + goto end; + + // get identity from the certificate + status = SecIdentityCreateWithCertificate(keychainRef, certificateRef, &identityRef); + if (status != noErr) + goto end; + + } else { + // copy system keychain + status = CopySystemKeychain(&keychainRef); + if (status != noErr) + goto end; + + // serach for first identity in system keychain + status = SecIdentitySearchCreate(keychainRef, CSSM_KEYUSE_SIGN, &idSearchRef); + if (status != noErr) + goto end; + + status = SecIdentitySearchCopyNext(idSearchRef, &identityRef); + if (status != noErr) + goto end; + + // get certificate from identity + status = SecIdentityCopyCertificate(identityRef, &certificateRef); + if (status != noErr) + goto end; + } + + + // get private key from identity + status = SecIdentityCopyPrivateKey(identityRef, &privateKeyRef); + if (status != noErr) + goto end; + + // get CSSM_KEY pointer from key ref + status = SecKeyGetCSSMKey(privateKeyRef, &cssmKey); + if (status != noErr) + goto end; + + // get CSSM CSP handle + status = SecKeychainGetCSPHandle(keychainRef, &cspHandle); + if (status != noErr) + goto end; + + // create CSSM credentials to unlock private key for encryption - no UI to be used + status = SecKeyGetCredentials(privateKeyRef, CSSM_ACL_AUTHORIZATION_ENCRYPT, + kSecCredentialTypeNoUI, &credentials); + if (status != noErr) + goto end; + + // create asymmetric context for encryption + status = CSSM_CSP_CreateAsymmetricContext(cspHandle, CSSM_ALGID_RSA, credentials, cssmKey, + CSSM_PADDING_PKCS1, &cssmContextHandle); + if (status != noErr) + goto end; + + // add mode attribute to use private key for encryption + newAttr.AttributeType = CSSM_ATTRIBUTE_MODE; + newAttr.AttributeLength = sizeof(uint32); + newAttr.Attribute.Data = (CSSM_DATA_PTR)CSSM_ALGMODE_PRIVATE_KEY; + status = CSSM_UpdateContextAttributes(cssmContextHandle, 1, &newAttr); + if(status != noErr) + goto end; + + // and finally - encrypt data + clearData.Length = hash->l; + clearData.Data = hash->v; + cipherData.Length = 0; + cipherData.Data = NULL; + status = CSSM_EncryptData(cssmContextHandle, &clearData, 1, &cipherData, 1, &bytesEncrypted, + &remData); + if (status != noErr) + goto end; + + if (remData.Length != 0) { // something didn't go right - should be zero + status = -1; + plog(LLV_ERROR, LOCATION, NULL, + "unencrypted data remaining after encrypting hash.\n"); + goto end; + } + + // alloc buffer for result + sig = vmalloc(cipherData.Length); + if (sig == NULL) + goto end; + + sig->v = cipherData.Data; + +end: + if (certificateRef) + CFRelease(certificateRef); + if (keychainRef) + CFRelease(keychainRef); + if (identityRef) + CFRelease(identityRef); + if (privateKeyRef) + CFRelease(privateKeyRef); + if (idSearchRef) + CFRelease(idSearchRef); + if (cssmContextHandle) + CSSM_DeleteContext(cssmContextHandle); + if (status != noErr) { + if (sig) { + vfree(sig); + sig = NULL; + } + } + + if (status != noErr && status != -1) { + plog(LLV_ERROR, LOCATION, NULL, + "error %d %s.\n", status, GetSecurityErrorString(status)); + status = -1; + } + return sig; + +} + + +/* + * Retrieve a cert from the keychain + */ +vchar_t* crypto_cssm_get_x509cert(CFDataRef persistentCertRef) +{ + + OSStatus status; + CSSM_DATA cssmData; + vchar_t *cert = NULL; + SecIdentityRef identityRef = NULL; + SecIdentitySearchRef idSearchRef = NULL; + SecKeychainRef keychainRef = NULL; + SecCertificateRef certificateRef = NULL; + + + // get cert ref + if (persistentCertRef) { + status = SecKeychainItemCopyFromPersistentReference(persistentCertRef, (SecKeychainItemRef*)&certificateRef); + if (status != noErr) + goto end; + } else { + // copy system keychain + status = CopySystemKeychain(&keychainRef); + if (status != noErr) + goto end; + + // find first identity in system keychain + status = SecIdentitySearchCreate(keychainRef, CSSM_KEYUSE_SIGN, &idSearchRef); + if (status != noErr) + goto end; + + status = SecIdentitySearchCopyNext(idSearchRef, &identityRef); + if (status != noErr) + goto end; + + // get certificate from identity + status = SecIdentityCopyCertificate(identityRef, &certificateRef); + if (status != noErr) + goto end; + + } + + // get certificate data + cssmData.Length = 0; + cssmData.Data = NULL; + status = SecCertificateGetData(certificateRef, &cssmData); + if (status != noErr) + goto end; + + if (cssmData.Length == 0) + goto end; + + cert = vmalloc(cssmData.Length); + if (cert == NULL) + goto end; + + // cssmData struct just points to the data + // data must be copied to be returned + memcpy(cert->v, cssmData.Data, cssmData.Length); + +end: + if (certificateRef) + CFRelease(certificateRef); + if (identityRef) + CFRelease(identityRef); + if (idSearchRef) + CFRelease(idSearchRef); + if (keychainRef) + CFRelease(keychainRef); + + if (status != noErr && status != -1) { + plog(LLV_ERROR, LOCATION, NULL, + "error %d %s.\n", status, GetSecurityErrorString(status)); + status = -1; + } + return cert; + +} + + +/* + * Find a policy ref by OID + */ +static OSStatus FindPolicy(const CSSM_OID *policyOID, SecPolicyRef *policyRef) +{ + + OSStatus status; + SecPolicySearchRef searchRef = nil; + + status = SecPolicySearchCreate(CSSM_CERT_X_509v3, policyOID, NULL, &searchRef); + if (status != noErr) + goto end; + + status = SecPolicySearchCopyNext(searchRef, policyRef); + +end: + if (searchRef) + CFRelease(searchRef); + + if (status != noErr) { + plog(LLV_ERROR, LOCATION, NULL, + "error %d %s.\n", status, GetSecurityErrorString(status)); + status = -1; + } + return status; +} + + +/* + * Evaluate the trust of a cert using the policy provided + */ +static OSStatus EvaluateCert(SecCertificateRef cert, CFTypeRef policyRef) +{ + OSStatus status; + SecTrustRef trustRef = 0; + SecTrustResultType evalResult; + + SecCertificateRef evalCertArray[1] = { cert }; + + CFArrayRef cfCertRef = CFArrayCreate((CFAllocatorRef) NULL, (void*)evalCertArray, 1, + &kCFTypeArrayCallBacks); + + if (!cfCertRef) { + plog(LLV_ERROR, LOCATION, NULL, + "unable to create CFArray.\n"); + return -1; + } + + status = SecTrustCreateWithCertificates(cfCertRef, policyRef, &trustRef); + if (status != noErr) + goto end; + + status = SecTrustEvaluate(trustRef, &evalResult); + if (status != noErr) + goto end; + + if (evalResult != kSecTrustResultProceed && evalResult != kSecTrustResultUnspecified) { + plog(LLV_ERROR, LOCATION, NULL, + "error evaluating certificate.\n"); + status = -1; + } + + +end: + if (cfCertRef) + CFRelease(cfCertRef); + if (trustRef) + CFRelease(trustRef); + + if (status != noErr && status != -1) { + plog(LLV_ERROR, LOCATION, NULL, + "error %d %s.\n", status, GetSecurityErrorString(status)); + status = -1; + } + return status; +} + + +/* + * Copy the system keychain + */ +static OSStatus CopySystemKeychain(SecKeychainRef *keychainRef) +{ + + OSStatus status; + + status = SecKeychainSetPreferenceDomain(kSecPreferencesDomainSystem); + if (status != noErr) + goto end; + + status = SecKeychainCopyDomainDefault(kSecPreferencesDomainSystem, keychainRef); + +end: + + if (status != noErr) { + plog(LLV_ERROR, LOCATION, NULL, + "error %d %s.\n", status, GetSecurityErrorString(status)); + status = -1; + } + return status; + +} + + +/* + * Return string representation of Security-related OSStatus. + */ +const char * +GetSecurityErrorString(OSStatus err) +{ + switch(err) { + case noErr: + return "noErr"; + case memFullErr: + return "memFullErr"; + case paramErr: + return "paramErr"; + case unimpErr: + return "unimpErr"; + + /* SecBase.h: */ + case errSecNotAvailable: + return "errSecNotAvailable"; + case errSecReadOnly: + return "errSecReadOnly"; + case errSecAuthFailed: + return "errSecAuthFailed"; + case errSecNoSuchKeychain: + return "errSecNoSuchKeychain"; + case errSecInvalidKeychain: + return "errSecInvalidKeychain"; + case errSecDuplicateKeychain: + return "errSecDuplicateKeychain"; + case errSecDuplicateCallback: + return "errSecDuplicateCallback"; + case errSecInvalidCallback: + return "errSecInvalidCallback"; + case errSecDuplicateItem: + return "errSecDuplicateItem"; + case errSecItemNotFound: + return "errSecItemNotFound"; + case errSecBufferTooSmall: + return "errSecBufferTooSmall"; + case errSecDataTooLarge: + return "errSecDataTooLarge"; + case errSecNoSuchAttr: + return "errSecNoSuchAttr"; + case errSecInvalidItemRef: + return "errSecInvalidItemRef"; + case errSecInvalidSearchRef: + return "errSecInvalidSearchRef"; + case errSecNoSuchClass: + return "errSecNoSuchClass"; + case errSecNoDefaultKeychain: + return "errSecNoDefaultKeychain"; + case errSecInteractionNotAllowed: + return "errSecInteractionNotAllowed"; + case errSecReadOnlyAttr: + return "errSecReadOnlyAttr"; + case errSecWrongSecVersion: + return "errSecWrongSecVersion"; + case errSecKeySizeNotAllowed: + return "errSecKeySizeNotAllowed"; + case errSecNoStorageModule: + return "errSecNoStorageModule"; + case errSecNoCertificateModule: + return "errSecNoCertificateModule"; + case errSecNoPolicyModule: + return "errSecNoPolicyModule"; + case errSecInteractionRequired: + return "errSecInteractionRequired"; + case errSecDataNotAvailable: + return "errSecDataNotAvailable"; + case errSecDataNotModifiable: + return "errSecDataNotModifiable"; + case errSecCreateChainFailed: + return "errSecCreateChainFailed"; + case errSecACLNotSimple: + return "errSecACLNotSimple"; + case errSecPolicyNotFound: + return "errSecPolicyNotFound"; + case errSecInvalidTrustSetting: + return "errSecInvalidTrustSetting"; + case errSecNoAccessForItem: + return "errSecNoAccessForItem"; + case errSecInvalidOwnerEdit: + return "errSecInvalidOwnerEdit"; + default: + return ""; + } +} + diff --git a/racoon.tproj/crypto_cssm.h b/racoon.tproj/crypto_cssm.h new file mode 100644 index 0000000..6152770 --- /dev/null +++ b/racoon.tproj/crypto_cssm.h @@ -0,0 +1,41 @@ + +/* + * Copyright (c) 2001-2004 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#ifndef __CRYPTO_CSSM_H__ +#define __CRYPTO_CSSM_H__ + +/* + * Racoon module for verifying and signing certificates through Security + * Framework and CSSM + */ + +#include "vmbuf.h" + + +extern int crypto_cssm_check_x509cert(vchar_t *cert); +extern vchar_t* crypto_cssm_getsign(CFDataRef persistentCertRef, vchar_t* hash); +extern vchar_t* crypto_cssm_get_x509cert(CFDataRef persistentCertRef); + + +#endif /* __CRYPTO_CSSM_H__ */ + diff --git a/racoon.tproj/crypto_openssl.c b/racoon.tproj/crypto_openssl.c index cb4da65..37bd183 100644 --- a/racoon.tproj/crypto_openssl.c +++ b/racoon.tproj/crypto_openssl.c @@ -56,6 +56,7 @@ #endif #ifdef HAVE_OPENSSL_X509_H #include +#include #include #endif #include @@ -99,8 +100,8 @@ */ #ifdef HAVE_SIGNING_C -static int cb_check_cert __P((int, X509_STORE_CTX *)); -static void eay_setgentype __P((char *, int *)); +static int cb_check_cert_local __P((int, X509_STORE_CTX *)); +static int cb_check_cert_remote __P((int, X509_STORE_CTX *)); static X509 *mem2x509 __P((vchar_t *)); #endif @@ -209,7 +210,7 @@ eay_cmp_asn1dn(n1, n2) i = X509_NAME_cmp(a, b); - end: + end: if (a) X509_NAME_free(a); if (b) @@ -221,9 +222,10 @@ eay_cmp_asn1dn(n1, n2) * this functions is derived from apps/verify.c in OpenSSL0.9.5 */ int -eay_check_x509cert(cert, CApath) +eay_check_x509cert(cert, CApath, local) vchar_t *cert; char *CApath; + int local; { X509_STORE *cert_ctx = NULL; X509_LOOKUP *lookup = NULL; @@ -245,7 +247,11 @@ eay_check_x509cert(cert, CApath) cert_ctx = X509_STORE_new(); if (cert_ctx == NULL) goto end; - X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert); + + if (local) + X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert_local); + else + X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert_remote); lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file()); if (lookup == NULL) @@ -272,6 +278,12 @@ eay_check_x509cert(cert, CApath) if (csc == NULL) goto end; X509_STORE_CTX_init(csc, cert_ctx, x509, NULL); + +#if OPENSSL_VERSION_NUMBER >= 0x00907000L + X509_STORE_CTX_set_flags(csc, X509_V_FLAG_CRL_CHECK); + X509_STORE_CTX_set_flags(csc, X509_V_FLAG_CRL_CHECK_ALL); +#endif + error = X509_verify_cert(csc); X509_STORE_CTX_cleanup(csc); #else @@ -286,7 +298,7 @@ eay_check_x509cert(cert, CApath) */ error = error ? 0 : -1; -end: + end: if (error) printf("%s\n", eay_strerror()); if (cert_ctx != NULL) @@ -299,10 +311,13 @@ end: /* * callback function for verifing certificate. - * this function is derived from cb() in openssl/apps/s_server.c + * Derived from cb() in openssl/apps/s_server.c + * + * This one is called for certificates obtained from + * 'peers_certfile' directive. */ static int -cb_check_cert(ok, ctx) +cb_check_cert_local(ok, ctx) int ok; X509_STORE_CTX *ctx; { @@ -311,42 +326,90 @@ cb_check_cert(ok, ctx) if (!ok) { X509_NAME_oneline( - X509_get_subject_name(ctx->current_cert), + X509_get_subject_name(ctx->current_cert), buf, 256); - /* - * since we are just checking the certificates, it is - * ok if they are self signed. But we should still warn - * the user. - */ - switch (ctx->error) { - case X509_V_ERR_CERT_HAS_EXPIRED: - case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: + /* + * since we are just checking the certificates, it is + * ok if they are self signed. But we should still warn + * the user. + */ + switch (ctx->error) { + case X509_V_ERR_CERT_HAS_EXPIRED: + case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: #if OPENSSL_VERSION_NUMBER >= 0x00905100L - case X509_V_ERR_INVALID_CA: - case X509_V_ERR_PATH_LENGTH_EXCEEDED: - case X509_V_ERR_INVALID_PURPOSE: + case X509_V_ERR_INVALID_PURPOSE: + case X509_V_ERR_UNABLE_TO_GET_CRL: #endif - ok = 1; - log_tag = LLV_WARNING; - break; - default: - log_tag = LLV_ERROR; - } + ok = 1; + log_tag = LLV_WARNING; + break; + + default: + log_tag = LLV_ERROR; + } + + +#ifndef EAYDEBUG + plog(log_tag, LOCATION, NULL, + "%s(%d) at depth:%d SubjectName:%s\n", + X509_verify_cert_error_string(ctx->error), + ctx->error, + ctx->error_depth, + buf); +#else + printf("%d: %s(%d) at depth:%d SubjectName:%s\n", + log_tag, + X509_verify_cert_error_string(ctx->error), + ctx->error, + ctx->error_depth, + buf); +#endif + } + ERR_clear_error(); + + return ok; +} + +/* + * Similar to cb_check_cert_local() but this one is called + * for certificates obtained from the IKE payload. + */ +static int +cb_check_cert_remote(ok, ctx) + int ok; + X509_STORE_CTX *ctx; +{ + char buf[256]; + int log_tag; + + if (!ok) { + X509_NAME_oneline( + X509_get_subject_name(ctx->current_cert), + buf, + 256); + switch (ctx->error) { + case X509_V_ERR_UNABLE_TO_GET_CRL: + ok = 1; + log_tag = LLV_WARNING; + break; + default: + log_tag = LLV_ERROR; + } #ifndef EAYDEBUG - plog(log_tag, LOCATION, NULL, - "%s(%d) at depth:%d SubjectName:%s\n", - X509_verify_cert_error_string(ctx->error), - ctx->error, - ctx->error_depth, - buf); + plog(log_tag, LOCATION, NULL, + "%s(%d) at depth:%d SubjectName:%s\n", + X509_verify_cert_error_string(ctx->error), + ctx->error, + ctx->error_depth, + buf); #else - printf("%d: %s(%d) at depth:%d SubjectName:%s\n", - log_tag, - X509_verify_cert_error_string(ctx->error), - ctx->error, - ctx->error_depth, - buf); + printf("%d: %s(%d) at depth:%d SubjectName:%s\n", + log_tag, + X509_verify_cert_error_string(ctx->error), + ctx->error, + ctx->error_depth, + buf); #endif } ERR_clear_error(); @@ -381,7 +444,7 @@ eay_get_x509asn1subjectname(cert) /* get the name */ bp = name->v; len = i2d_X509_NAME(x509->cert_info->subject, &bp); - + error = 0; end: @@ -402,75 +465,99 @@ eay_get_x509asn1subjectname(cert) return name; } +/* + * Get the common name from a cert + */ +#define EAY_MAX_CN_LEN 256 +vchar_t * +eay_get_x509_common_name(cert) + vchar_t *cert; +{ + X509 *x509 = NULL; + X509_NAME *name; + vchar_t *commonName = NULL; + + commonName = vmalloc(EAY_MAX_CN_LEN); + if (commonName == NULL) { + plog(LLV_ERROR, LOCATION, NULL, "no memory\n"); + return NULL; + } + + x509 = mem2x509(cert); + if (x509 == NULL) { + vfree(commonName); + return NULL; + } + + name = X509_get_subject_name(x509); + X509_NAME_get_text_by_NID(name, NID_commonName, commonName->v, EAY_MAX_CN_LEN); + + commonName->l = strlen(commonName->v); + + if (x509) + X509_free(x509); + return commonName; +} + /* * get the subjectAltName from X509 certificate. - * the name is terminated by '\0'. + * the name must be terminated by '\0'. */ -#include int -eay_get_x509subjectaltname(cert, altname, type, pos) +eay_get_x509subjectaltname(cert, altname, type, pos, len) vchar_t *cert; char **altname; int *type; int pos; + int *len; { X509 *x509 = NULL; - X509_EXTENSION *ext; - X509V3_EXT_METHOD *method = NULL; - STACK_OF(GENERAL_NAME) *name; - CONF_VALUE *cval = NULL; - STACK_OF(CONF_VALUE) *nval = NULL; - u_char *bp; - int i, len; + int i; + GENERAL_NAMES *gens; + GENERAL_NAME *gen; int error = -1; *altname = NULL; *type = GENT_OTHERNAME; - bp = cert->v; - x509 = mem2x509(cert); if (x509 == NULL) goto end; - i = X509_get_ext_by_NID(x509, NID_subject_alt_name, -1); - if (i < 0) - goto end; - ext = X509_get_ext(x509, i); - method = X509V3_EXT_get(ext); - if(!method) - goto end; - - bp = ext->value->data; - name = method->d2i(NULL, &bp, ext->value->length); - if(!name) - goto end; - - nval = method->i2v(method, name, NULL); - method->ext_free(name); - name = NULL; - if(!nval) + gens = X509_get_ext_d2i(x509, NID_subject_alt_name, NULL, NULL); + if (gens == NULL) goto end; - for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { - /* skip the name */ + for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) { if (i + 1 != pos) continue; - cval = sk_CONF_VALUE_value(nval, i); - len = strlen(cval->value) + 1; /* '\0' included */ - *altname = racoon_malloc(len); - if (!*altname) { - sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); - goto end; - } - strlcpy(*altname, cval->value, len); - - /* set type of the name */ - eay_setgentype(cval->name, type); + break; + } + + /* there is no data at "pos" */ + if (i == sk_GENERAL_NAME_num(gens)) + goto end; + + gen = sk_GENERAL_NAME_value(gens, i); + + /* make sure the data is terminated by '\0'. */ + if (gen->d.ia5->data[gen->d.ia5->length] != '\0') { +#ifndef EAYDEBUG + plog(LLV_ERROR, LOCATION, NULL, + "data is not terminated by '\0'."); +#endif + hexdump(gen->d.ia5->data, gen->d.ia5->length + 1); + goto end; } - sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); - + *len = gen->d.ia5->length + 1; + *altname = racoon_malloc(*len); + if (!*altname) + goto end; + + strlcpy(*altname, gen->d.ia5->data, *len); + *type = gen->type; + error = 0; end: @@ -491,26 +578,6 @@ eay_get_x509subjectaltname(cert, altname, type, pos) return error; } -static void -eay_setgentype(name, type) - char *name; - int *type; -{ - /* XXX It's needed effective code */ - if(!memcmp(name, "email", strlen("email"))) { - *type = GENT_EMAIL; - } else if(!memcmp(name, "URI", strlen("URI"))) { - *type = GENT_URI; - } else if(!memcmp(name, "DNS", strlen("DNS"))) { - *type = GENT_DNS; - } else if(!memcmp(name, "RID", strlen("RID"))) { - *type = GENT_RID; - } else if(!memcmp(name, "IP", strlen("IP"))) { - *type = GENT_IPADD; - } else { - *type = GENT_OTHERNAME; - } -} /* * decode a X509 certificate and make a readable text terminated '\n'. @@ -700,7 +767,9 @@ eay_check_x509sign(source, sig, cert) evp = X509_get_pubkey(x509); if (!evp) { +#ifndef EAYDEBUG plog(LLV_ERROR, LOCATION, NULL, "X509_get_pubkey: %s\n", eay_strerror()); +#endif return -1; } diff --git a/racoon.tproj/crypto_openssl.h b/racoon.tproj/crypto_openssl.h index 7e2e20a..3efb418 100644 --- a/racoon.tproj/crypto_openssl.h +++ b/racoon.tproj/crypto_openssl.h @@ -28,6 +28,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + +#ifndef __CRYPTO_OPENSSL_H__ +#define __CRYPTO_OPENSSL_H__ #ifdef HAVE_OPENSSL_EVP_H #include @@ -35,21 +38,25 @@ #ifdef HAVE_SIGNING_C /* X509 Certificate */ -#define GENT_OTHERNAME 0 -#define GENT_EMAIL 1 -#define GENT_DNS 2 -#define GENT_X400 3 -#define GENT_DIRNAME 4 -#define GENT_EDIPARTY 5 -#define GENT_URI 6 -#define GENT_IPADD 7 -#define GENT_RID 8 +#include + +#define GENT_OTHERNAME GEN_OTHERNAME +#define GENT_EMAIL GEN_EMAIL +#define GENT_DNS GEN_DNS +#define GENT_X400 GEN_X400 +#define GENT_DIRNAME GEN_DIRNAME +#define GENT_EDIPARTY GEN_EDIPARTY +#define GENT_URI GEN_URI +#define GENT_IPADD GEN_IPADD +#define GENT_RID GEN_RID + extern vchar_t *eay_str2asn1dn __P((char *, int)); extern int eay_cmp_asn1dn __P((vchar_t *, vchar_t *)); -extern int eay_check_x509cert __P((vchar_t *, char *)); +extern int eay_check_x509cert __P((vchar_t *, char *, int)); extern vchar_t *eay_get_x509asn1subjectname __P((vchar_t *)); -extern int eay_get_x509subjectaltname __P((vchar_t *, char **, int *, int)); +extern vchar_t *eay_get_x509_common_name __P((vchar_t *)); +extern int eay_get_x509subjectaltname __P((vchar_t *, char **, int *, int, int *)); extern char *eay_get_x509text __P((vchar_t *)); extern vchar_t *eay_get_x509cert __P((char *)); extern vchar_t *eay_get_x509sign __P((vchar_t *, vchar_t *, vchar_t *)); @@ -192,3 +199,7 @@ extern const char *eay_version __P((void)); #define CBC_BLOCKLEN 8 #define IPSEC_ENCRYPTKEYLEN 8 + + +#endif /* __CRYPTO_OPENSSL_H__ */ + diff --git a/racoon.tproj/debug.h b/racoon.tproj/debug.h index e98118d..eb08f9b 100644 --- a/racoon.tproj/debug.h +++ b/racoon.tproj/debug.h @@ -29,6 +29,14 @@ * SUCH DAMAGE. */ +#ifndef __DEBUG_H__ +#define __DEBUG_H__ + + /* define by main.c */ extern int f_local; extern int vflag; + + +#endif /* __DEBUG_H__ */ + diff --git a/racoon.tproj/dhgroup.h b/racoon.tproj/dhgroup.h index 4824079..ac63144 100644 --- a/racoon.tproj/dhgroup.h +++ b/racoon.tproj/dhgroup.h @@ -29,6 +29,10 @@ * SUCH DAMAGE. */ +#ifndef __DHGROUP_H__ +#define __DHGROUP_H__ + + #define OAKLEY_PRIME_MODP768 \ "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" \ "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" \ @@ -196,3 +200,7 @@ extern struct dhgroup dh_modp3072; extern struct dhgroup dh_modp4096; extern struct dhgroup dh_modp6144; extern struct dhgroup dh_modp8192; + + +#endif /* __DHGROUP_H__ */ + diff --git a/racoon.tproj/dnssec.h b/racoon.tproj/dnssec.h index f2e25bb..9c6b2d1 100644 --- a/racoon.tproj/dnssec.h +++ b/racoon.tproj/dnssec.h @@ -29,4 +29,10 @@ * SUCH DAMAGE. */ +#ifndef __DNSSEC_H__ +#define __DNSSEC_H__ + extern cert_t *dnssec_getcert __P((vchar_t *)); + +#endif /* __DNSSEC_H__ */ + diff --git a/racoon.tproj/gcmalloc.h b/racoon.tproj/gcmalloc.h index ca08528..b4343ec 100644 --- a/racoon.tproj/gcmalloc.h +++ b/racoon.tproj/gcmalloc.h @@ -33,8 +33,8 @@ * Debugging malloc glue for Racoon. */ -#ifndef _GCMALLOC_H_DEFINED -#define _GCMALLOC_H_DEFINED +#ifndef __GCMALLOC_H__ +#define __GCMALLOC_H__ /* ElectricFence needs no special handling. */ @@ -111,4 +111,5 @@ free(void *ptr) #endif #endif /* DEBUG_RECORD_MALLOCATION */ -#endif /* _GCMALLOC_H_DEFINED */ +#endif /* __GCMALLOC_H__ */ + diff --git a/racoon.tproj/grabmyaddr.h b/racoon.tproj/grabmyaddr.h index b467b56..f9eab2d 100644 --- a/racoon.tproj/grabmyaddr.h +++ b/racoon.tproj/grabmyaddr.h @@ -29,6 +29,10 @@ * SUCH DAMAGE. */ +#ifndef __GRABMYADDR_H__ +#define __GRABMYADDR_H__ + + struct myaddrs { struct myaddrs *next; struct sockaddr *addr; @@ -50,3 +54,7 @@ extern void insmyaddr __P((struct myaddrs *, struct myaddrs **)); extern void delmyaddr __P((struct myaddrs *)); extern int initmyaddr __P((void)); extern int getsockmyaddr __P((struct sockaddr *)); + + +#endif /* __GRABMYADDR_H__ */ + diff --git a/racoon.tproj/gssapi.h b/racoon.tproj/gssapi.h index 4a487e1..e5a6eb2 100644 --- a/racoon.tproj/gssapi.h +++ b/racoon.tproj/gssapi.h @@ -36,6 +36,10 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifndef __GSSAPI_H__ +#define __GSSAPI_H__ + + #include #define GSSAPI_DEF_NAME "ike" @@ -86,3 +90,7 @@ void gssapi_set_id_rcvd __P((struct ph1handle *)); int gssapi_id_rcvd __P((struct ph1handle *)); void gssapi_free_state __P((struct ph1handle *)); vchar_t *gssapi_get_default_id __P((struct ph1handle *)); + + +#endif /* __GSSAPI_H__ */ + diff --git a/racoon.tproj/handler.h b/racoon.tproj/handler.h index 1e11fb1..5b951a2 100644 --- a/racoon.tproj/handler.h +++ b/racoon.tproj/handler.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __HANDLER_H__ +#define __HANDLER_H__ + /* Phase 1 handler */ /* * main mode: @@ -433,3 +436,6 @@ extern int check_recvdpkt __P((struct sockaddr *, extern int add_recvdpkt __P((struct sockaddr *, struct sockaddr *, vchar_t *, vchar_t *)); extern void init_recvdpkt __P((void)); + +#endif /* __HANDLER_H__ */ + diff --git a/racoon.tproj/ipsec_doi.c b/racoon.tproj/ipsec_doi.c index c046103..293b0e1 100644 --- a/racoon.tproj/ipsec_doi.c +++ b/racoon.tproj/ipsec_doi.c @@ -2970,6 +2970,8 @@ ipsecdoi_checkid1(iph1) struct ph1handle *iph1; { struct ipsecdoi_id_b *id_b; + struct sockaddr *sa; + caddr_t sa1, sa2; if (iph1->id_p == NULL) { plog(LLV_ERROR, LOCATION, NULL, @@ -3074,19 +3076,43 @@ ipsecdoi_checkid1(iph1) case IDTYPE_ASN1DN: ident.v = (caddr_t)(id_b + 1); ident.l = ident0->l; - if (eay_cmp_asn1dn(ident0, &ident)) { - plog(LLV_WARNING, LOCATION, NULL, - "ID value mismatched.\n"); - if (iph1->rmconf->verify_identifier) - return ISAKMP_NTYPE_INVALID_ID_INFORMATION; + if (eay_cmp_asn1dn(ident0, &ident)) + goto err; + break; + case IDTYPE_ADDRESS: + sa = (struct sockaddr *)ident0->v; + sa2 = (caddr_t)(id_b + 1); + switch (sa->sa_family) { + case AF_INET: + if (iph1->id_p->l - sizeof(*id_b) != sizeof(struct in_addr)) + goto err; + + sa1 = (caddr_t)&((struct sockaddr_in *)sa)->sin_addr; + if (memcmp(sa1, sa2, sizeof(struct in_addr)) != 0) + goto err; + break; +#ifdef INET6 + case AF_INET6: + if (iph1->id_p->l - sizeof(*id_b) != sizeof(struct in6_addr)) + goto err; + sa1 = (caddr_t)&((struct sockaddr_in6 *)sa)->sin6_addr; + if (memcmp(sa1, sa2, sizeof(struct in6_addr)) != 0) + goto err; + break; +#endif + default: + goto err; } break; default: if (memcmp(ident0->v, id_b + 1, ident0->l)) { +err: plog(LLV_WARNING, LOCATION, NULL, "ID value mismatched.\n"); - if (iph1->rmconf->verify_identifier) + if (iph1->rmconf->verify_identifier) { + vfree(ident0); return ISAKMP_NTYPE_INVALID_ID_INFORMATION; + } } break; } diff --git a/racoon.tproj/ipsec_doi.h b/racoon.tproj/ipsec_doi.h index 6e5a5aa..b4af2b3 100644 --- a/racoon.tproj/ipsec_doi.h +++ b/racoon.tproj/ipsec_doi.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __IPSEC_DOI_H__ +#define __IPSEC_DOI_H__ + /* refered to RFC2407 */ #define IPSEC_DOI 1 @@ -164,7 +167,7 @@ struct ipsecdoi_pl_id { #define IPSECDOI_ID_KEY_ID 11 /* compressing doi type, it's internal use. */ -#define IDTYPE_FQDN 0 +#define IDTYPE_FQDN 0 #define IDTYPE_USERFQDN 1 #define IDTYPE_KEYID 2 #define IDTYPE_ADDRESS 3 @@ -175,6 +178,15 @@ struct ipsecdoi_pl_id { #define SECRETTYPE_KEY 1 #define SECRETTYPE_KEYCHAIN 2 +/* verification modules */ +#define VERIFICATION_MODULE_OPENSSL 0 +#define VERIFICATION_MODULE_SEC_FRAMEWORK 1 + +/* verification options */ +#define VERIFICATION_OPTION_NONE 0 +#define VERIFICATION_OPTION_PEERS_IDENTIFIER 1 +#define VERIFICATION_OPTION_OPEN_DIR 2 + /* The use for checking proposal payload. This is not exchange type. */ #define IPSECDOI_TYPE_PH1 0 #define IPSECDOI_TYPE_PH2 1 @@ -217,3 +229,6 @@ extern int ipsecdoi_authalg2trnsid __P((int)); extern int idtype2doi __P((int)); extern int doi2idtype __P((int)); + +#endif /* __IPSEC_DOI_H__ */ + diff --git a/racoon.tproj/isakmp.c b/racoon.tproj/isakmp.c index 6d9ef9a..2734907 100644 --- a/racoon.tproj/isakmp.c +++ b/racoon.tproj/isakmp.c @@ -147,6 +147,8 @@ static int isakmp_ph2begin_i __P((struct ph1handle *, struct ph2handle *)); static int isakmp_ph2begin_r __P((struct ph1handle *, vchar_t *)); static int etypesw1 __P((int)); static int etypesw2 __P((int)); +static void isakmp_free_addrs __P((void)); + /* * isakmp packet handler @@ -201,6 +203,8 @@ isakmp_handler(so_isakmp) goto end; } + remote_len = sizeof(remote); + /* read real message */ if ((buf = vmalloc(ntohl(isakmp.len))) == NULL) { plog(LLV_ERROR, LOCATION, NULL, @@ -220,7 +224,8 @@ isakmp_handler(so_isakmp) if (errno == EINTR) continue; plog(LLV_ERROR, LOCATION, NULL, - "failed to receive isakmp packet\n"); + "failed to read isakmp packet from socket %d, len=%d\n", so_isakmp, buf->l); + error = -2; /* serious problem with socket */ goto end; } @@ -341,6 +346,8 @@ isakmp_natt_handler(so_isakmp) goto end; } + remote_len = sizeof(remote); + /* read real message */ if ((buf = vmalloc(ntohl(isakmp->len) + 4)) == NULL) { plog(LLV_ERROR, LOCATION, NULL, @@ -360,7 +367,8 @@ isakmp_natt_handler(so_isakmp) if (errno == EINTR) continue; plog(LLV_ERROR, LOCATION, NULL, - "failed to receive isakmp packet\n"); + "failed to read isakmp packet from socket %d, len=%d\n", so_isakmp, buf->l); + error = -2; /* serious problem with socket */ goto end; } @@ -923,10 +931,6 @@ quick_main(iph2, msg) return -1; } - /* when using commit bit, status will be reached here. */ - if (iph2->status == PHASE2ST_ADDSA) - return 0; - /* free resend buffer */ if (iph2->sendbuf == NULL) { plog(LLV_ERROR, LOCATION, NULL, @@ -939,6 +943,10 @@ quick_main(iph2, msg) /* turn off schedule */ if (iph2->scr) SCHED_KILL(iph2->scr); + + /* when using commit bit, status will be reached here. */ + if (iph2->status == PHASE2ST_ADDSA) + return 0; /* send */ plog(LLV_DEBUG, LOCATION, NULL, "===\n"); @@ -1627,26 +1635,54 @@ isakmp_open() void isakmp_close() { - struct myaddrs *p, *next; + isakmp_close_sockets(); + isakmp_free_addrs(); +} - for (p = lcconf->myaddrs; p; p = next) { - next = p->next; +void +isakmp_close_sockets() +{ + struct myaddrs *p; - if (!p->addr) { - racoon_free(p); + for (p = lcconf->myaddrs; p; p = p->next) { + + if (!p->addr) continue; + + if (p->sock >= 0) { + close(p->sock); + p->sock = -1; } - close(p->sock); + #ifdef IKE_NAT_T - if (p->nattsock >= 0) close(p->nattsock); + if (p->nattsock >= 0) { + close(p->nattsock); + p->nattsock = -1; + } #endif - racoon_free(p->addr); + + } + +} + +void +isakmp_free_addrs() +{ + struct myaddrs *p, *next; + + for (p = lcconf->myaddrs; p; p = next) { + next = p->next; + + if (p->addr) + racoon_free(p->addr); racoon_free(p); } lcconf->myaddrs = NULL; + } + // close sockets for addresses that have gone away void isakmp_close_unused() @@ -1780,6 +1816,15 @@ isakmp_ph2resend(iph2) return -1; } + if (iph2->ph1 == 0) { + plog(LLV_ERROR, LOCATION, NULL, + "internal error - attempt to re-send phase2 with no phase1 bound.\n"); + iph2->retry_counter = -1; + remph2(iph2); + delph2(iph2); + return -1; + } + if (isakmp_send(iph2->ph1, iph2->sendbuf) < 0) return -1; diff --git a/racoon.tproj/isakmp.h b/racoon.tproj/isakmp.h index d0c097a..cbc8c99 100644 --- a/racoon.tproj/isakmp.h +++ b/racoon.tproj/isakmp.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __ISAKMP_H__ +#define __ISAKMP_H__ + /* refer to RFC 2408 */ /* must include first. */ @@ -347,3 +350,6 @@ struct isakmp_pl_d { /* SPI(es) */ } __attribute__((__packed__)); + +#endif /* __ISAKMP_H__ */ + diff --git a/racoon.tproj/isakmp_agg.h b/racoon.tproj/isakmp_agg.h index 0609be7..65c193f 100644 --- a/racoon.tproj/isakmp_agg.h +++ b/racoon.tproj/isakmp_agg.h @@ -29,6 +29,10 @@ * SUCH DAMAGE. */ +#ifndef __ISAKMP_AGG_H__ +#define __ISAKMP_AGG_H__ + + extern int agg_i1send __P((struct ph1handle *, vchar_t *)); extern int agg_i2recv __P((struct ph1handle *, vchar_t *)); extern int agg_i2send __P((struct ph1handle *, vchar_t *)); @@ -37,3 +41,6 @@ extern int agg_r1recv __P((struct ph1handle *, vchar_t *)); extern int agg_r1send __P((struct ph1handle *, vchar_t *)); extern int agg_r2recv __P((struct ph1handle *, vchar_t *)); extern int agg_r2send __P((struct ph1handle *, vchar_t *)); + +#endif /* __ISAKMP_AGG_H__ */ + diff --git a/racoon.tproj/isakmp_base.h b/racoon.tproj/isakmp_base.h index 5e71818..38c080d 100644 --- a/racoon.tproj/isakmp_base.h +++ b/racoon.tproj/isakmp_base.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __ISAKMP_BASE_H__ +#define __ISAKMP_BASE_H__ + extern int base_i1send __P((struct ph1handle *, vchar_t *)); extern int base_i2recv __P((struct ph1handle *, vchar_t *)); extern int base_i2send __P((struct ph1handle *, vchar_t *)); @@ -39,3 +42,7 @@ extern int base_r1recv __P((struct ph1handle *, vchar_t *)); extern int base_r1send __P((struct ph1handle *, vchar_t *)); extern int base_r2recv __P((struct ph1handle *, vchar_t *)); extern int base_r2send __P((struct ph1handle *, vchar_t *)); + + +#endif /* __ISAKMP_BASE_H__ */ + diff --git a/racoon.tproj/isakmp_ident.h b/racoon.tproj/isakmp_ident.h index 85937cc..b1f3c35 100644 --- a/racoon.tproj/isakmp_ident.h +++ b/racoon.tproj/isakmp_ident.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __ISAKMP_IDENT_H__ +#define __ISAKMP_IDENT_H__ + extern int ident_i1send __P((struct ph1handle *, vchar_t *)); extern int ident_i2recv __P((struct ph1handle *, vchar_t *)); extern int ident_i2send __P((struct ph1handle *, vchar_t *)); @@ -43,3 +46,7 @@ extern int ident_r2recv __P((struct ph1handle *, vchar_t *)); extern int ident_r2send __P((struct ph1handle *, vchar_t *)); extern int ident_r3recv __P((struct ph1handle *, vchar_t *)); extern int ident_r3send __P((struct ph1handle *, vchar_t *)); + + +#endif /* __ISAKMP_IDENT_H__ */ + diff --git a/racoon.tproj/isakmp_inf.c b/racoon.tproj/isakmp_inf.c index 36bb435..4174255 100644 --- a/racoon.tproj/isakmp_inf.c +++ b/racoon.tproj/isakmp_inf.c @@ -34,7 +34,6 @@ #include #include -#include #include #include #ifdef IPV6_INRIA_VERSION diff --git a/racoon.tproj/isakmp_inf.h b/racoon.tproj/isakmp_inf.h index 26ad55a..880c800 100644 --- a/racoon.tproj/isakmp_inf.h +++ b/racoon.tproj/isakmp_inf.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __ISAKMP_INF_H__ +#define __ISAKMP_INF_H__ + struct saproto; extern int isakmp_info_recv __P((struct ph1handle *, vchar_t *)); extern int isakmp_info_send_d1 __P((struct ph1handle *)); @@ -44,3 +47,6 @@ extern vchar_t * isakmp_add_pl_n __P((vchar_t *, u_int8_t **, int, struct saproto *, vchar_t *)); extern void isakmp_check_notify __P((struct isakmp_gen *, struct ph1handle *)); + +#endif /* __ISAKMP_INF_H__ */ + diff --git a/racoon.tproj/isakmp_natd.h b/racoon.tproj/isakmp_natd.h index 84cc4f1..b3d043b 100644 --- a/racoon.tproj/isakmp_natd.h +++ b/racoon.tproj/isakmp_natd.h @@ -3,6 +3,10 @@ // if natd_record matches source, returns 1. // if natd_record matches desination, returns 2. // if natd_record doesn't match any entries, returns 0. + +#ifndef __ISAKMP_NATD_H__ +#define __ISAKMP_NATD_H__ + typedef enum { natd_match_none = 0, @@ -12,4 +16,8 @@ typedef enum natd_match_t natd_matches(struct ph1handle* iph1, struct isakmp_gen *natd_record); int natd_create(struct ph1handle* iph1); -int natd_hasnat(const struct ph1handle* iph1); \ No newline at end of file +int natd_hasnat(const struct ph1handle* iph1); + + +#endif /* __ISAKMP_NATD_H__ */ + diff --git a/racoon.tproj/isakmp_newg.h b/racoon.tproj/isakmp_newg.h index 6d1a17f..59db2f6 100644 --- a/racoon.tproj/isakmp_newg.h +++ b/racoon.tproj/isakmp_newg.h @@ -29,4 +29,11 @@ * SUCH DAMAGE. */ +#ifndef __ISAKMP_NEWG_H__ +#define __ISAKMP_NEWG_H__ + + extern int isakmp_newgroup_r __P((struct ph1handle *, vchar_t *)); + +#endif /* __ISAKMP_NEWG_H__ */ + diff --git a/racoon.tproj/isakmp_quick.h b/racoon.tproj/isakmp_quick.h index d87f78f..a6f7d15 100644 --- a/racoon.tproj/isakmp_quick.h +++ b/racoon.tproj/isakmp_quick.h @@ -29,6 +29,10 @@ * SUCH DAMAGE. */ +#ifndef __ISAKMP_QUICK_H__ +#define __ISAKMP_QUICK_H__ + + extern int quick_i1prep __P((struct ph2handle *, vchar_t *)); extern int quick_i1send __P((struct ph2handle *, vchar_t *)); extern int quick_i2recv __P((struct ph2handle *, vchar_t *)); @@ -41,3 +45,6 @@ extern int quick_r2send __P((struct ph2handle *, vchar_t *)); extern int quick_r3recv __P((struct ph2handle *, vchar_t *)); extern int quick_r3send __P((struct ph2handle *, vchar_t *)); extern int quick_r3prep __P((struct ph2handle *, vchar_t *)); + +#endif /* __ISAKMP_QUICK_H__ */ + diff --git a/racoon.tproj/isakmp_var.h b/racoon.tproj/isakmp_var.h index 54945ae..3c7936b 100644 --- a/racoon.tproj/isakmp_var.h +++ b/racoon.tproj/isakmp_var.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __ISAKMP_VAR_H__ +#define __ISAKMP_VAR_H__ + #define PORT_ISAKMP 500 #define PORT_ISAKMP_NATT 4500 @@ -65,6 +68,7 @@ extern int isakmp_init __P((void)); extern const char *isakmp_pindex __P((const isakmp_index *, const u_int32_t)); extern int isakmp_open __P((void)); extern void isakmp_close __P((void)); +extern void isakmp_close_sockets __P((void)); extern void isakmp_close_unused __P((void)); extern int isakmp_send __P((struct ph1handle *, vchar_t *)); @@ -108,3 +112,7 @@ extern void isakmp_printpacket __P((vchar_t *, struct sockaddr *, extern int copy_ph1addresses __P(( struct ph1handle *, struct remoteconf *, struct sockaddr *, struct sockaddr *)); extern void log_ph1established __P((const struct ph1handle *)); + + +#endif /* __ISAKMP_VAR_H__ */ + diff --git a/racoon.tproj/key_debug.c b/racoon.tproj/key_debug.c index 7ace6be..ebd1f57 100644 --- a/racoon.tproj/key_debug.c +++ b/racoon.tproj/key_debug.c @@ -48,7 +48,6 @@ #include #include -#include #include #include diff --git a/racoon.tproj/libpfkey.h b/racoon.tproj/libpfkey.h index 99428f5..541700f 100644 --- a/racoon.tproj/libpfkey.h +++ b/racoon.tproj/libpfkey.h @@ -30,6 +30,9 @@ * SUCH DAMAGE. */ +#ifndef __LIBPFKEY_H__ +#define __LIBPFKEY_H__ + struct sadb_msg; extern void pfkey_sadump __P((struct sadb_msg *)); extern void pfkey_spdump __P((struct sadb_msg *)); @@ -88,3 +91,7 @@ struct sadb_msg *pfkey_recv __P((int)); int pfkey_send __P((int, struct sadb_msg *, int)); int pfkey_align __P((struct sadb_msg *, caddr_t *)); int pfkey_check __P((caddr_t *)); + + +#endif /* __LIBPFKEY_H__ */ + diff --git a/racoon.tproj/localconf.h b/racoon.tproj/localconf.h index 8f7219f..b5ca916 100644 --- a/racoon.tproj/localconf.h +++ b/racoon.tproj/localconf.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __LOCALCONF_H__ +#define __LOCALCONF_H__ + /* local configuration */ #define LC_DEFAULT_CF SYSCONFDIR "/racoon.conf" @@ -111,3 +114,7 @@ extern vchar_t *getpskfromkeychain __P((const char *)); extern void getpathname __P((char *, int, int, const char *)); extern int sittype2doi __P((int)); extern int doitype2doi __P((int)); + + +#endif /* __LOCALCONF_H__ */ + diff --git a/racoon.tproj/logger.h b/racoon.tproj/logger.h index eb5c556..ebd9f6b 100644 --- a/racoon.tproj/logger.h +++ b/racoon.tproj/logger.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __LOGGER_H__ +#define __LOGGER_H__ + struct log { int head; int siz; @@ -44,3 +47,6 @@ extern int log_vprint __P((struct log *, const char *, ...)); extern int log_vaprint __P((struct log *, const char *, va_list)); extern int log_close __P((struct log *)); extern void log_free __P((struct log *)); + +#endif /* __LOGGER_H__ */ + diff --git a/racoon.tproj/misc.h b/racoon.tproj/misc.h index 989e583..0d4fb1a 100644 --- a/racoon.tproj/misc.h +++ b/racoon.tproj/misc.h @@ -29,6 +29,10 @@ * SUCH DAMAGE. */ +#ifndef __MISC_H__ +#define __MISC_H__ + + #define BIT2STR(b) bit2str(b, sizeof(b)<<3) #ifdef HAVE_FUNCTION_MACRO @@ -44,3 +48,7 @@ extern const char *debug_location __P((const char *, int, const char *)); extern int getfsize __P((char *)); struct timeval; extern double timedelta __P((struct timeval *, struct timeval *)); + + +#endif /* __MISC_H__ */ + diff --git a/racoon.tproj/netdb_dnssec.h b/racoon.tproj/netdb_dnssec.h index 94c933f..f7e2c18 100644 --- a/racoon.tproj/netdb_dnssec.h +++ b/racoon.tproj/netdb_dnssec.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __NETDB_DNSSEC_H__ +#define __NETDB_DNSSEC_H__ + #ifndef T_CERT #define T_CERT 37 /* defined by RFC2538 section 2 */ #endif @@ -65,3 +68,7 @@ struct certinfo { extern void freecertinfo __P((struct certinfo *)); extern int getcertsbyname __P((char *, struct certinfo **)); + + +#endif /* __NETDB_DNSSEC_H__ */ + diff --git a/racoon.tproj/oakley.c b/racoon.tproj/oakley.c index d7e47da..5017f66 100644 --- a/racoon.tproj/oakley.c +++ b/racoon.tproj/oakley.c @@ -33,6 +33,7 @@ #include #include /* XXX for subjectaltname */ #include /* XXX for subjectaltname */ +#include #include #include @@ -70,6 +71,8 @@ #include "sainfo.h" #include "proposal.h" #include "crypto_openssl.h" +#include "crypto_cssm.h" +#include "open_dir.h" #include "dnssec.h" #include "sockmisc.h" #include "strnames.h" @@ -109,7 +112,7 @@ struct dhgroup dh_modp8192; static int oakley_compute_keymat_x __P((struct ph2handle *, int, int)); #ifdef HAVE_SIGNING_C static int get_cert_fromlocal __P((struct ph1handle *, int)); -static int oakley_check_certid __P((struct ph1handle *iph1)); +static int oakley_check_certid(u_int8_t idtype, int idlen, void* id, cert_t* cert_p); static int check_typeofcertname __P((int, int)); static cert_t *save_certbuf __P((struct isakmp_gen *)); #endif @@ -1269,18 +1272,34 @@ oakley_validate_auth(iph1) return ISAKMP_INTERNAL_ERROR; } - /* compare ID payload and certificate name */ - if (iph1->rmconf->verify_cert && - (error = oakley_check_certid(iph1)) != 0) - return error; + /* check cert ID */ + if (iph1->rmconf->verify_cert) { + + struct ipsecdoi_id_b *id_b; + int idlen; + + if (iph1->id_p == NULL || iph1->cert_p == NULL) { + plog(LLV_ERROR, LOCATION, NULL, "no ID or CERT found.\n"); + return ISAKMP_NTYPE_INVALID_ID_INFORMATION; + } + + id_b = (struct ipsecdoi_id_b *)iph1->id_p->v; + idlen = iph1->id_p->l - sizeof(*id_b); + + if ((error = oakley_check_certid(id_b->type, idlen, id_b + 1, iph1->cert_p)) != 0) + return error; + } /* verify certificate */ if (iph1->rmconf->verify_cert && iph1->rmconf->getcert_method == ISAKMP_GETCERT_PAYLOAD) { switch (iph1->rmconf->certtype) { case ISAKMP_CERT_X509SIGN: - error = eay_check_x509cert(&iph1->cert_p->cert, - lcconf->pathinfo[LC_PATHTYPE_CERT]); + if (iph1->rmconf->cert_verification == VERIFICATION_MODULE_SEC_FRAMEWORK) + error = crypto_cssm_check_x509cert(&iph1->cert_p->cert); + else + error = eay_check_x509cert(&iph1->cert_p->cert, + lcconf->pathinfo[LC_PATHTYPE_CERT], 0); break; default: plog(LLV_ERROR, LOCATION, NULL, @@ -1293,9 +1312,66 @@ oakley_validate_auth(iph1) "the peer's certificate is not verified.\n"); return ISAKMP_NTYPE_INVALID_CERT_AUTHORITY; } + } + + /* check configured peers identifier against cert IDs */ + /* allows checking of specified ID against multiple ids in the cert */ + /* such as multiple domain names */ + if (iph1->rmconf->cert_verification_option == VERIFICATION_OPTION_PEERS_IDENTIFIER) { + u_int8_t doi_type = 255; + void *peers_id = NULL; + int peers_id_len = 0; + + if (iph1->rmconf->idvtype_p == IDTYPE_ADDRESS) { + switch (((struct sockaddr *)(iph1->rmconf->idv_p->v))->sa_family) { + case AF_INET: + doi_type = IPSECDOI_ID_IPV4_ADDR; + peers_id_len = sizeof(struct in_addr); + peers_id = &(((struct sockaddr_in *)(iph1->rmconf->idv_p->v))->sin_addr.s_addr); + break; +#ifdef INET6 + case AF_INET6: + doi_type = IPSECDOI_ID_IPV6_ADDR; + peers_id_len = sizeof(struct in6_addr); + peers_id = &(((struct sockaddr_in6 *)(iph1->rmconf->idv_p->v))->sin6_addr.s6_addr); + break; +#endif + default: + plog(LLV_ERROR, LOCATION, NULL, + "unknown address type for peers identifier.\n"); + return ISAKMP_NTYPE_AUTHENTICATION_FAILED; + break; + } + + } else { + doi_type = idtype2doi(iph1->rmconf->idvtype_p); + peers_id = iph1->rmconf->idv_p->v; + peers_id_len = iph1->rmconf->idv_p->l; + } + if ((error = oakley_check_certid(doi_type, peers_id_len, + peers_id, iph1->cert_p)) != 0) + return error; + } + + if (iph1->rmconf->cert_verification_option == VERIFICATION_OPTION_OPEN_DIR) { + + vchar_t *user_id = NULL; + + user_id = eay_get_x509_common_name(&iph1->cert_p->cert); + + // the following functions will check if user_id == 0 + if (open_dir_authorize_id(user_id, iph1->rmconf->open_dir_auth_group) == 0) { + plog(LLV_ERROR, LOCATION, NULL, + "the peer is not authorized for access.\n"); + return ISAKMP_NTYPE_AUTHENTICATION_FAILED; + } + vfree(user_id); + } + plog(LLV_DEBUG, LOCATION, NULL, "CERT validated\n"); + /* compute hash */ switch (iph1->etype) { @@ -1445,33 +1521,36 @@ get_cert_fromlocal(iph1, my) certfile = iph1->rmconf->peerscertfile; certpl = &iph1->cert_p; } - if (!certfile) { + if (!certfile && iph1->rmconf->identity_in_keychain == 0) { plog(LLV_ERROR, LOCATION, NULL, "no CERT defined.\n"); return 0; } switch (iph1->rmconf->certtype) { - case ISAKMP_CERT_X509SIGN: - case ISAKMP_CERT_DNS: - /* make public file name */ - getpathname(path, sizeof(path), LC_PATHTYPE_CERT, certfile); - cert = eay_get_x509cert(path); - if (cert) { - char *p = NULL; - p = eay_get_x509text(cert); - plog(LLV_DEBUG, LOCATION, NULL, "%s", p ? p : "\n"); - racoon_free(p); - }; - break; - - default: - plog(LLV_ERROR, LOCATION, NULL, - "not supported certtype %d\n", - iph1->rmconf->certtype); - goto end; + case ISAKMP_CERT_X509SIGN: + if (iph1->rmconf->identity_in_keychain) { + cert = crypto_cssm_get_x509cert(iph1->rmconf->keychainCertRef); + break; + } // else fall thru + case ISAKMP_CERT_DNS: + /* make public file name */ + getpathname(path, sizeof(path), LC_PATHTYPE_CERT, certfile); + cert = eay_get_x509cert(path); + break; + + default: + plog(LLV_ERROR, LOCATION, NULL, + "not supported certtype %d\n", + iph1->rmconf->certtype); + goto end; } - - if (!cert) { + + if (cert) { + char *p = NULL; + p = eay_get_x509text(cert); + plog(LLV_DEBUG, LOCATION, NULL, "%s", p ? p : "\n"); + racoon_free(p); + } else { plog(LLV_ERROR, LOCATION, NULL, "failed to get %s CERT.\n", my ? "my" : "peers"); @@ -1521,6 +1600,11 @@ oakley_getsign(iph1) switch (iph1->rmconf->certtype) { case ISAKMP_CERT_X509SIGN: + // cert in keychain - use cssm to sign + if (iph1->rmconf->identity_in_keychain) { + iph1->sig = crypto_cssm_getsign(iph1->rmconf->keychainCertRef, iph1->hash); + break; + } // else fall thru case ISAKMP_CERT_DNS: if (iph1->rmconf->myprivfile == NULL) { plog(LLV_ERROR, LOCATION, NULL, "no cert defined.\n"); @@ -1542,6 +1626,7 @@ oakley_getsign(iph1) iph1->sig = eay_get_x509sign(iph1->hash, privkey, &iph1->cert->cert); + break; default: goto end; @@ -1568,26 +1653,16 @@ end: * compare certificate name and ID value. */ static int -oakley_check_certid(iph1) - struct ph1handle *iph1; +oakley_check_certid(u_int8_t idtype, int idlen, void* id, cert_t* cert_p) { - struct ipsecdoi_id_b *id_b; vchar_t *name = NULL; char *altname = NULL; - int idlen, type; + int type, len; int error; - if (iph1->id_p == NULL || iph1->cert_p == NULL) { - plog(LLV_ERROR, LOCATION, NULL, "no ID nor CERT found.\n"); - return ISAKMP_NTYPE_INVALID_ID_INFORMATION; - } - - id_b = (struct ipsecdoi_id_b *)iph1->id_p->v; - idlen = iph1->id_p->l - sizeof(*id_b); - - switch (id_b->type) { + switch (idtype) { case IPSECDOI_ID_DER_ASN1_DN: - name = eay_get_x509asn1subjectname(&iph1->cert_p->cert); + name = eay_get_x509asn1subjectname(&cert_p->cert); if (!name) { plog(LLV_ERROR, LOCATION, NULL, "failed to get subjectName\n"); @@ -1599,7 +1674,7 @@ oakley_check_certid(iph1) vfree(name); return ISAKMP_NTYPE_INVALID_ID_INFORMATION; } - error = memcmp(id_b + 1, name->v, idlen); + error = memcmp(id, name->v, idlen); vfree(name); if (error != 0) { plog(LLV_ERROR, LOCATION, NULL, @@ -1607,21 +1682,28 @@ oakley_check_certid(iph1) return ISAKMP_NTYPE_INVALID_ID_INFORMATION; } return 0; - case IPSECDOI_ID_IPV4_ADDR: + case IPSECDOI_ID_IPV4_ADDR: case IPSECDOI_ID_IPV6_ADDR: { - /* - * converting to binary from string because openssl return - * a string even if object is a binary. - * XXX fix it ! access by ASN.1 directly without. - */ - struct addrinfo hints, *res; - caddr_t a = NULL; + + /* + * Openssl returns the IPAddress as an ASN1 octet string (binary format) + * followed by a trailing NULL. 5 bytes for IPv4 and 17 bytes for IPv6 + */ + #define SUBJ_ALT_NAME_IPV4_ADDRESS_LEN 5 + #define SUBJ_ALT_NAME_IPV6_ADDRESS_LEN 17 + int pos; + + if (idtype == IPSECDOI_ID_IPV4_ADDR && idlen != sizeof(struct in_addr) + || idtype == IPSECDOI_ID_IPV6_ADDR && idlen != sizeof(struct in6_addr)) { + plog(LLV_ERROR, LOCATION, NULL, + "invalid address length passed.\n"); + return ISAKMP_NTYPE_INVALID_ID_INFORMATION; + } for (pos = 1; ; pos++) { - if (eay_get_x509subjectaltname(&iph1->cert_p->cert, - &altname, &type, pos) !=0) { + if (eay_get_x509subjectaltname(&cert_p->cert, &altname, &type, pos, &len) !=0) { plog(LLV_ERROR, LOCATION, NULL, "failed to get subjectAltName\n"); return ISAKMP_NTYPE_INVALID_CERTIFICATE; @@ -1629,54 +1711,53 @@ oakley_check_certid(iph1) /* it's the end condition of the loop. */ if (!altname) { - plog(LLV_ERROR, LOCATION, NULL, - "no proper subjectAltName.\n"); - return ISAKMP_NTYPE_INVALID_CERTIFICATE; + return ISAKMP_NTYPE_INVALID_ID_INFORMATION; } - if (check_typeofcertname(id_b->type, type) == 0) - break; - - /* next name */ - racoon_free(altname); - altname = NULL; - } - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_RAW; - hints.ai_flags = AI_NUMERICHOST; - error = getaddrinfo(altname, NULL, &hints, &res); - if (error != 0) { - plog(LLV_ERROR, LOCATION, NULL, - "no proper subjectAltName.\n"); - racoon_free(altname); - return ISAKMP_NTYPE_INVALID_CERTIFICATE; - } - switch (res->ai_family) { - case AF_INET: - a = (caddr_t)&((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr; - break; + if (check_typeofcertname(idtype, type) != 0) { + /* wrong type - skip this one */ + racoon_free(altname); + altname = NULL; + continue; + } + + if (len == SUBJ_ALT_NAME_IPV4_ADDRESS_LEN) { /* IPv4 */ + if (idtype != IPSECDOI_ID_IPV4_ADDR) { + /* wrong IP address type - skip this one */ + racoon_free(altname); + altname = NULL; + continue; + } + } #ifdef INET6 - case AF_INET6: - a = (caddr_t)&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr.s6_addr; - break; + else if (len == SUBJ_ALT_NAME_IPV6_ADDRESS_LEN) { /* IPv6 */ + if (idtype != IPSECDOI_ID_IPV6_ADDR) { + /* wrong IP address type - skip this one */ + racoon_free(altname); + altname = NULL; + continue; + } + } #endif - default: - plog(LLV_ERROR, LOCATION, NULL, - "family not supported: %d.\n", res->ai_family); + else { + /* invalid IP address length in certificate - bad or bogus certificate */ + plog(LLV_ERROR, LOCATION, NULL, + "invalid IP address in certificate.\n"); + racoon_free(altname); + altname = NULL; + return ISAKMP_NTYPE_INVALID_CERTIFICATE; + } + + /* compare the addresses */ + error = memcmp(id, altname, idlen); racoon_free(altname); - freeaddrinfo(res); - return ISAKMP_NTYPE_INVALID_CERTIFICATE; - } - error = memcmp(id_b + 1, a, idlen); - freeaddrinfo(res); - vfree(name); - if (error != 0) { - plog(LLV_ERROR, LOCATION, NULL, - "ID mismatched with subjectAltName.\n"); - return ISAKMP_NTYPE_INVALID_ID_INFORMATION; + if (error != 0) { + plog(LLV_ERROR, LOCATION, NULL, + "ID mismatched with subjectAltName.\n"); + return ISAKMP_NTYPE_INVALID_ID_INFORMATION; + } + return 0; } - return 0; } case IPSECDOI_ID_FQDN: case IPSECDOI_ID_USER_FQDN: @@ -1684,8 +1765,7 @@ oakley_check_certid(iph1) int pos; for (pos = 1; ; pos++) { - if (eay_get_x509subjectaltname(&iph1->cert_p->cert, - &altname, &type, pos) != 0){ + if (eay_get_x509subjectaltname(&cert_p->cert, &altname, &type, pos, &len) != 0) { plog(LLV_ERROR, LOCATION, NULL, "failed to get subjectAltName\n"); return ISAKMP_NTYPE_INVALID_CERTIFICATE; @@ -1693,47 +1773,37 @@ oakley_check_certid(iph1) /* it's the end condition of the loop. */ if (!altname) { - plog(LLV_ERROR, LOCATION, NULL, - "no proper subjectAltName.\n"); - return ISAKMP_NTYPE_INVALID_CERTIFICATE; + return ISAKMP_NTYPE_INVALID_ID_INFORMATION; } - if (check_typeofcertname(id_b->type, type) == 0) - break; + if (check_typeofcertname(idtype, type) != 0) { + /* wrong general type - skip this one */ + racoon_free(altname); + altname = NULL; + continue; + } - /* next name */ - racoon_free(altname); - altname = NULL; - } - if (idlen != strlen(altname)) { - plog(LLV_ERROR, LOCATION, NULL, - "Invalid ID length in phase 1.\n"); - racoon_free(altname); - return ISAKMP_NTYPE_INVALID_ID_INFORMATION; - } - if (check_typeofcertname(id_b->type, type) != 0) { - plog(LLV_ERROR, LOCATION, NULL, - "ID type mismatched. ID: %s CERT: %s.\n", - s_ipsecdoi_ident(id_b->type), - s_ipsecdoi_ident(type)); - racoon_free(altname); - return ISAKMP_NTYPE_INVALID_ID_INFORMATION; - } - error = memcmp(id_b + 1, altname, idlen); - if (error) { - plog(LLV_ERROR, LOCATION, NULL, "ID mismatched.\n"); + if (idlen != strlen(altname)) { + /* wrong length - skip this one */ + racoon_free(altname); + altname = NULL; + continue; + } + error = memcmp(id, altname, idlen); racoon_free(altname); - return ISAKMP_NTYPE_INVALID_ID_INFORMATION; + if (error) { + plog(LLV_ERROR, LOCATION, NULL, "ID mismatched.\n"); + return ISAKMP_NTYPE_INVALID_ID_INFORMATION; + } + return 0; } - racoon_free(altname); - return 0; } default: plog(LLV_ERROR, LOCATION, NULL, "Inpropper ID type passed: %s.\n", - s_ipsecdoi_ident(id_b->type)); + s_ipsecdoi_ident(idtype)); return ISAKMP_NTYPE_INVALID_ID_INFORMATION; - } + } /*NOTREACHED*/ } diff --git a/racoon.tproj/oakley.h b/racoon.tproj/oakley.h index 488f430..3b1bc29 100644 --- a/racoon.tproj/oakley.h +++ b/racoon.tproj/oakley.h @@ -29,6 +29,10 @@ * SUCH DAMAGE. */ +#ifndef __OAKLEY_H__ +#define __OAKLEY_H__ + + /* refer to RFC 2409 */ /* Attribute Classes */ @@ -189,3 +193,6 @@ extern vchar_t *oakley_do_decrypt __P((struct ph1handle *, vchar_t *, vchar_t *, vchar_t *)); extern vchar_t *oakley_do_encrypt __P((struct ph1handle *, vchar_t *, vchar_t *, vchar_t *)); + +#endif /* __OAKLEY_H__ */ + diff --git a/racoon.tproj/open_dir.c b/racoon.tproj/open_dir.c new file mode 100644 index 0000000..952d0ce --- /dev/null +++ b/racoon.tproj/open_dir.c @@ -0,0 +1,426 @@ +/* + * Copyright (c) 2001-2004 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + + +#include + +#include +#include +#include +#include +#include + +#include "vmbuf.h" +#include "remoteconf.h" +#include "plog.h" +#include "misc.h" +#include "gcmalloc.h" +#include "open_dir.h" + +#define BUF_LEN 1024 + + +static tDirStatus open_dir_get_search_node_ref(tDirReference dirRef, unsigned long index, + tDirNodeReference *searchNodeRef, unsigned long *count); +static tDirStatus open_dir_get_user_attr(tDirReference dirRef, tDirNodeReference searchNodeRef, char *user_name, + char *attr, tAttributeValueEntryPtr *attr_value); +static tDirStatus open_dir_check_group_membership(tDirReference dirRef, tDirNodeReference searchNodeRef, + char *group_name, char *user_name, char *userGID, int *authorized); + + +//---------------------------------------------------------------------- +// open_dir_authorize_id +//---------------------------------------------------------------------- +int open_dir_authorize_id(vchar_t *id, vchar_t *group) +{ + + tDirReference dirRef; + tDirStatus dsResult = eDSNoErr; + int authorized = 0; + tDirNodeReference searchNodeRef; + tAttributeValueEntryPtr groupID = NULL; + tAttributeValueEntryPtr recordName = NULL; + unsigned long searchNodeCount; + char* user_name = NULL; + char* group_name = NULL; + + if (id == 0 || id->l < 1) { + plog(LLV_ERROR, LOCATION, NULL, "invalid user name.\n"); + goto end; + } + user_name = racoon_malloc(id->l + 1); + if (user_name == NULL) { + plog(LLV_ERROR, LOCATION, NULL, "out of memory - unable to allocate space for user name.\n"); + goto end; + } + bcopy(id->v, user_name, id->l); + *(user_name + id->l) = 0; + + if (group && group->l > 0) { + group_name = racoon_malloc(group->l + 1); + if (group_name == NULL) { + plog(LLV_NOTIFY, LOCATION, NULL, "out of memeory - unable to allocate space for group name.\n"); + goto end; + } + bcopy(group->v, group_name, group->l); + *(group_name + group->l) = 0; + } + + if ((dsResult = dsOpenDirService(&dirRef)) == eDSNoErr) { + // get the search node ref + if ((dsResult = open_dir_get_search_node_ref(dirRef, 1, &searchNodeRef, &searchNodeCount)) == eDSNoErr) { + // get the user's primary group ID + if (dsResult = open_dir_get_user_attr(dirRef, searchNodeRef, user_name, kDSNAttrRecordName, &recordName) == eDSNoErr) { + if (recordName != 0) { + if (group_name != 0) { + if ((dsResult = open_dir_get_user_attr(dirRef, searchNodeRef, user_name, kDS1AttrPrimaryGroupID, &groupID)) == eDSNoErr) { + // check if user is member of the group + dsResult = open_dir_check_group_membership(dirRef, searchNodeRef, group_name, + recordName->fAttributeValueData.fBufferData, groupID->fAttributeValueData.fBufferData, &authorized); + } + } else + authorized = 1; // no group required - user record found + } + } + if (groupID) + dsDeallocAttributeValueEntry(dirRef, groupID); + if (recordName) + dsDeallocAttributeValueEntry(dirRef, recordName); + dsCloseDirNode(searchNodeRef); // close the search node + } + dsCloseDirService(dirRef); + } + +end: + if (authorized) + plog(LLV_NOTIFY, LOCATION, NULL, "User '%s' authorized for access\n", user_name); + else + plog(LLV_NOTIFY, LOCATION, NULL, "User '%s' not authorized for access\n", user_name); + if (user_name) + free(user_name); + if (group_name) + free(group_name); + return authorized; +} + + +//---------------------------------------------------------------------- +// open_dir_get_search_node_ref +//---------------------------------------------------------------------- +static tDirStatus open_dir_get_search_node_ref(tDirReference dirRef, unsigned long index, + tDirNodeReference *searchNodeRef, unsigned long *count) +{ + tDirStatus dsResult = -1; + tDataBufferPtr searchNodeDataBufferPtr = 0; + tDataListPtr searchNodeNameDataListPtr = 0; + + unsigned long outNodeCount; + tContextData continueData = 0; + + *searchNodeRef = 0; + *count = 0; + + // allocate required buffers and data lists + if ((searchNodeDataBufferPtr = dsDataBufferAllocate(dirRef, BUF_LEN)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataBuffer\n"); + goto cleanup; + } + if ((searchNodeNameDataListPtr = dsDataListAllocate(dirRef)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n"); + goto cleanup; + } + + // find authentication search node(s) + if ((dsResult = dsFindDirNodes(dirRef, searchNodeDataBufferPtr, 0, eDSAuthenticationSearchNodeName, + &outNodeCount, &continueData)) == eDSNoErr) { + if (outNodeCount != 0) { + + // get the seach node name and open the node + if ((dsResult = dsGetDirNodeName(dirRef, searchNodeDataBufferPtr, index, + &searchNodeNameDataListPtr)) == eDSNoErr) { + if ((dsResult = dsOpenDirNode(dirRef, searchNodeNameDataListPtr, searchNodeRef)) == eDSNoErr) { + *count = outNodeCount; + } + } + } + if (continueData) + dsReleaseContinueData(dirRef, continueData); + } + +cleanup: + if (searchNodeDataBufferPtr) + dsDataBufferDeAllocate(dirRef, searchNodeDataBufferPtr); + if (searchNodeNameDataListPtr) + dsDataListDeallocate(dirRef, searchNodeNameDataListPtr); + + return dsResult; +} + +//---------------------------------------------------------------------- +// open_dir_get_user_attr +//---------------------------------------------------------------------- +static tDirStatus open_dir_get_user_attr(tDirReference dirRef, tDirNodeReference searchNodeRef, char *user_name, + char *attr, tAttributeValueEntryPtr *attr_value) +{ + + tDirStatus dsResult = -1; + + tDataBufferPtr userRcdDataBufferPtr = 0; + tDataListPtr recordNameDataListPtr = 0; + tDataListPtr recordTypeDataListPtr = 0; + tDataListPtr attrTypeDataListPtr = 0; + tContextData continueData = 0; + + unsigned long outRecordCount; + int userRcdFound = 0; + u_int32_t userRecordIndex, attrIndex; + + *attr_value = 0; + + if ((userRcdDataBufferPtr = dsDataBufferAllocate(dirRef, BUF_LEN)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataBuffer\n"); + goto cleanup; + } + if ((recordNameDataListPtr = dsBuildListFromStrings(dirRef, user_name, 0)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n"); + goto cleanup; + } + if ((recordTypeDataListPtr = dsBuildListFromStrings(dirRef, kDSStdRecordTypeUsers, 0)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n"); + goto cleanup; + } + if ((attrTypeDataListPtr = dsBuildListFromStrings(dirRef, kDSNAttrRecordName, kDS1AttrDistinguishedName, attr, 0)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n"); + goto cleanup; + } + + // find the user record(s), extracting the user name and requested attribute + do { + dsResult = dsGetRecordList(searchNodeRef, userRcdDataBufferPtr, recordNameDataListPtr, eDSExact, + recordTypeDataListPtr, attrTypeDataListPtr, 0, &outRecordCount, &continueData); + + // if buffer too small - allocate a larger one + if (dsResult == eDSBufferTooSmall) { + u_int32_t size = userRcdDataBufferPtr->fBufferSize * 2; + + dsDataBufferDeAllocate(dirRef, userRcdDataBufferPtr); + if ((userRcdDataBufferPtr = dsDataBufferAllocate(dirRef, size)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataBuffer\n"); + dsResult = -1; + goto cleanup; + } + } + } while (dsResult == eDSBufferTooSmall); + + if (dsResult == eDSNoErr) { + // for each user record + for (userRecordIndex = 1; (userRecordIndex <= outRecordCount) && (dsResult == eDSNoErr) + && (userRcdFound == 0); userRecordIndex++) { + + tAttributeListRef attrListRef; + tRecordEntryPtr userRcdEntryPtr; + + // get the user record entry from the data buffer + if ((dsResult = dsGetRecordEntry(searchNodeRef, userRcdDataBufferPtr, userRecordIndex, + &attrListRef, &userRcdEntryPtr)) == eDSNoErr) { + // for each attribute + for (attrIndex = 1; (attrIndex <= userRcdEntryPtr->fRecordAttributeCount) + && (dsResult == eDSNoErr); attrIndex++) { + + tAttributeValueListRef attrValueListRef; + tAttributeEntryPtr attrInfoPtr; + tAttributeValueEntryPtr attrValuePtr; + + if ((dsResult = dsGetAttributeEntry(searchNodeRef, userRcdDataBufferPtr, + attrListRef, attrIndex, &attrValueListRef, &attrInfoPtr)) == eDSNoErr) { + if ((dsResult = dsGetAttributeValue(searchNodeRef, userRcdDataBufferPtr, 1, + attrValueListRef, &attrValuePtr)) == eDSNoErr) { + + // check for user record name or attribute searching for + if (!strcmp(attrInfoPtr->fAttributeSignature.fBufferData, kDSNAttrRecordName)) { + if (!strcmp(attrValuePtr->fAttributeValueData.fBufferData, user_name)) + userRcdFound = 1; + } + if (!strcmp(attrInfoPtr->fAttributeSignature.fBufferData, kDS1AttrDistinguishedName)) { + if (!strcmp(attrValuePtr->fAttributeValueData.fBufferData, user_name)) + userRcdFound = 1; + } + if (!strcmp(attrInfoPtr->fAttributeSignature.fBufferData, attr)) { + *attr_value = attrValuePtr; // return the attribute value + attrValuePtr = 0; // set to zero so we don't deallocate it + } + if (attrValuePtr) + dsDeallocAttributeValueEntry(dirRef, attrValuePtr); + } + dsCloseAttributeValueList(attrValueListRef); + dsDeallocAttributeEntry(dirRef, attrInfoPtr); + } + } + // make sure we've processed both attributes and we have a match on user name + if(userRcdFound == 0 || *attr_value == 0) { + userRcdFound = 0; + if (*attr_value) + dsDeallocAttributeValueEntry(dirRef, *attr_value); + *attr_value = 0; + } + dsCloseAttributeList(attrListRef); + dsDeallocRecordEntry(dirRef, userRcdEntryPtr); + } + } + } + +cleanup: + if (continueData) + dsReleaseContinueData(searchNodeRef, continueData); + if (userRcdDataBufferPtr) + dsDataBufferDeAllocate(dirRef, userRcdDataBufferPtr); + if (recordNameDataListPtr) + dsDataListDeallocate(dirRef, recordNameDataListPtr); + if (recordTypeDataListPtr) + dsDataListDeallocate(dirRef, recordTypeDataListPtr); + if (attrTypeDataListPtr) + dsDataListDeallocate(dirRef, attrTypeDataListPtr); + + return dsResult; + +} + + +//---------------------------------------------------------------------- +// open_dir_check_group_membership +//---------------------------------------------------------------------- +static tDirStatus open_dir_check_group_membership(tDirReference dirRef, tDirNodeReference searchNodeRef, + char *group_name, char *user_name, char *userGID, int *authorized) +{ + tDirStatus dsResult = -1; + + tDataBufferPtr groupRcdDataBufferPtr = 0; + tDataListPtr recordNameDataListPtr = 0; + tDataListPtr recordTypeDataListPtr = 0; + tDataListPtr attrTypeDataListPtr = 0; + tContextData continueData = 0; + + unsigned long outRecordCount; + u_int32_t attrIndex, valueIndex; + + *authorized = 0; + + if ((groupRcdDataBufferPtr = dsDataBufferAllocate(dirRef, BUF_LEN)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataBuffer\n"); + goto cleanup; + } + if ((recordNameDataListPtr = dsBuildListFromStrings(dirRef, group_name, 0)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n"); + goto cleanup; + } + if ((recordTypeDataListPtr = dsBuildListFromStrings(dirRef, kDSStdRecordTypeGroups, 0)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n"); + goto cleanup; + } + if ((attrTypeDataListPtr = dsBuildListFromStrings(dirRef, kDS1AttrPrimaryGroupID, kDSNAttrGroupMembership, 0)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n"); + goto cleanup; + } + + // find the group record, extracting the group ID and group membership attribute + do { + dsResult = dsGetRecordList(searchNodeRef, groupRcdDataBufferPtr, recordNameDataListPtr, eDSExact, + recordTypeDataListPtr, attrTypeDataListPtr, 0, &outRecordCount, &continueData); + // if buffer too small - allocate a larger one + if (dsResult == eDSBufferTooSmall) { + u_int32_t size = groupRcdDataBufferPtr->fBufferSize * 2; + + dsDataBufferDeAllocate(dirRef, groupRcdDataBufferPtr); + if ((groupRcdDataBufferPtr = dsDataBufferAllocate(dirRef, size)) == 0) { + plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataBuffer\n"); + dsResult = -1; + goto cleanup; + } + } + } while (dsResult == eDSBufferTooSmall); + + if (dsResult == eDSNoErr) { + + tAttributeListRef attrListRef; + tRecordEntryPtr groupRcdEntryPtr; + + // get the group record entry + if ((dsResult = dsGetRecordEntry(searchNodeRef, groupRcdDataBufferPtr, 1, &attrListRef, &groupRcdEntryPtr)) == eDSNoErr) { + + // for each attribute + for (attrIndex = 1; (attrIndex <= groupRcdEntryPtr->fRecordAttributeCount) && (dsResult == eDSNoErr) + && (*authorized == 0); attrIndex++) { + + tAttributeValueListRef attrValueListRef; + tAttributeEntryPtr attrInfoPtr; + tAttributeValueEntryPtr attrValuePtr; + + if ((dsResult = dsGetAttributeEntry(searchNodeRef, groupRcdDataBufferPtr, attrListRef, + attrIndex, &attrValueListRef, &attrInfoPtr)) == eDSNoErr) { + + // group ID attribute ? + if (!strcmp(attrInfoPtr->fAttributeSignature.fBufferData, kDS1AttrPrimaryGroupID)) { + if ((dsResult = dsGetAttributeValue(searchNodeRef, groupRcdDataBufferPtr, 1, + attrValueListRef, &attrValuePtr)) == eDSNoErr) { + + // check for match on primary group ID + if (!strcmp(attrValuePtr->fAttributeValueData.fBufferData, userGID)) + *authorized = 1; + dsDeallocAttributeValueEntry(dirRef, attrValuePtr); + } + } else if (!strcmp(attrInfoPtr->fAttributeSignature.fBufferData, kDSNAttrGroupMembership)) { + // for each value check for user's name in the group + for (valueIndex = 1; (valueIndex <= attrInfoPtr->fAttributeValueCount) + && (dsResult == eDSNoErr) && (*authorized == 0); valueIndex++) { + + if ((dsResult = dsGetAttributeValue(searchNodeRef, groupRcdDataBufferPtr, + valueIndex, attrValueListRef, &attrValuePtr)) == eDSNoErr) { + if (!strcmp(attrValuePtr->fAttributeValueData.fBufferData, user_name)) + *authorized = 1; + dsDeallocAttributeValueEntry(dirRef, attrValuePtr); + } + } + } + dsCloseAttributeValueList(attrValueListRef); + dsDeallocAttributeEntry(dirRef, attrInfoPtr); + } + } + dsCloseAttributeList(attrListRef); + dsDeallocRecordEntry(dirRef, groupRcdEntryPtr); + } + } + +cleanup: + if (continueData) + dsReleaseContinueData(searchNodeRef, continueData); + if (groupRcdDataBufferPtr) + dsDataBufferDeAllocate(dirRef, groupRcdDataBufferPtr); + if (recordNameDataListPtr) + dsDataListDeallocate(dirRef, recordNameDataListPtr); + if (recordTypeDataListPtr) + dsDataListDeallocate(dirRef, recordTypeDataListPtr); + if (attrTypeDataListPtr) + dsDataListDeallocate(dirRef, attrTypeDataListPtr); + + return dsResult; +} + diff --git a/racoon.tproj/open_dir.h b/racoon.tproj/open_dir.h new file mode 100644 index 0000000..89f1f2c --- /dev/null +++ b/racoon.tproj/open_dir.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2001-2004 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#ifndef __OPEN_DIR_H__ +#define __OPEN_DIR_H__ + +extern int open_dir_authorize_id(vchar_t *id, vchar_t *group); + + +#endif /* __OPEN_DIR_H__ */ + diff --git a/racoon.tproj/pfkey.c b/racoon.tproj/pfkey.c index 4da945a..de54f2e 100644 --- a/racoon.tproj/pfkey.c +++ b/racoon.tproj/pfkey.c @@ -38,7 +38,6 @@ #include #include -#include #include #ifdef IPV6_INRIA_VERSION @@ -976,7 +975,7 @@ pk_sendupdate(iph2) iph2->ph1->remote->sa_family == AF_INET) { flags |= SADB_X_EXT_NATT; - port = ((struct sockaddr_in*)iph2->ph1->remote)->sin_port; + port = ntohs(((struct sockaddr_in*)iph2->ph1->remote)->sin_port); } #endif @@ -1228,7 +1227,7 @@ pk_sendadd(iph2) iph2->ph1->remote->sa_family == AF_INET) { flags |= SADB_X_EXT_NATT; - port = ((struct sockaddr_in*)iph2->ph1->remote)->sin_port; + port = ntohs(((struct sockaddr_in*)iph2->ph1->remote)->sin_port); /* If we're the side behind the NAT, send keepalives */ if ((iph2->ph1->natt_flags & natt_no_local_nat) == 0) @@ -1691,7 +1690,7 @@ pk_recvdelete(mhp) || mhp[SADB_EXT_ADDRESS_SRC] == NULL || mhp[SADB_EXT_ADDRESS_DST] == NULL) { plog(LLV_ERROR, LOCATION, NULL, - "inappropriate sadb acquire message passed.\n"); + "inappropriate sadb delete message passed.\n"); return -1; } msg = (struct sadb_msg *)mhp[0]; @@ -1753,7 +1752,7 @@ pk_recvflush(mhp) /* sanity check */ if (mhp[0] == NULL) { plog(LLV_ERROR, LOCATION, NULL, - "inappropriate sadb acquire message passed.\n"); + "inappropriate sadb flush message passed.\n"); return -1; } diff --git a/racoon.tproj/pfkey.h b/racoon.tproj/pfkey.h index 0813dde..306ac88 100644 --- a/racoon.tproj/pfkey.h +++ b/racoon.tproj/pfkey.h @@ -29,6 +29,10 @@ * SUCH DAMAGE. */ +#ifndef __PFKEY_H__ +#define __PFKEY_H__ + + struct pfkey_satype { u_int8_t ps_satype; const char *ps_name; @@ -68,3 +72,7 @@ extern int pfkey_convertfromipsecdoi __P(( u_int, u_int, u_int, extern u_int32_t pk_getseq __P((void)); extern const char *sadbsecas2str __P((struct sockaddr *, struct sockaddr *, int, u_int32_t, int)); + + +#endif /* __PFKEY_H__ */ + diff --git a/racoon.tproj/pfkey_dump.c b/racoon.tproj/pfkey_dump.c index 507a0dd..7f73140 100644 --- a/racoon.tproj/pfkey_dump.c +++ b/racoon.tproj/pfkey_dump.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include diff --git a/racoon.tproj/plog.h b/racoon.tproj/plog.h index 1302bd4..d8dd456 100644 --- a/racoon.tproj/plog.h +++ b/racoon.tproj/plog.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __PLOG_H__ +#define __PLOG_H__ + #define LC_DEFAULT_LOGF "/var/log/racoon.log" #ifdef HAVE_STDARG_H @@ -66,3 +69,6 @@ extern void plogv __P((int, const char *, struct sockaddr *, extern void plogdump __P((int, void *, size_t)); extern void ploginit __P((void)); extern void plogset __P((char *)); + +#endif /* __PLOG_H__ */ + diff --git a/racoon.tproj/policy.h b/racoon.tproj/policy.h index e43ded0..27ba3fd 100644 --- a/racoon.tproj/policy.h +++ b/racoon.tproj/policy.h @@ -28,6 +28,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ +#ifndef __POLICY_H__ +#define __POLICY_H__ + #include @@ -113,3 +116,7 @@ extern void initsp __P((void)); extern struct ipsecrequest *newipsecreq __P((void)); extern const char *spidx2str __P((const struct policyindex *)); + + +#endif /* __POLICY_H__ */ + diff --git a/racoon.tproj/proposal.h b/racoon.tproj/proposal.h index d38291e..68036c1 100644 --- a/racoon.tproj/proposal.h +++ b/racoon.tproj/proposal.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __PROPOSAL_H__ +#define __PROPOSAL_H__ + #include /* @@ -201,3 +204,6 @@ extern void print_proppair __P((int, struct prop_pair *)); extern int set_proposal_from_policy __P((struct ph2handle *, struct secpolicy *, struct secpolicy *)); extern int set_proposal_from_proposal __P((struct ph2handle *)); + +#endif /* __PROPOSAL_H__ */ + diff --git a/racoon.tproj/remoteconf.c b/racoon.tproj/remoteconf.c index 9e569b1..8e12a8d 100644 --- a/racoon.tproj/remoteconf.c +++ b/racoon.tproj/remoteconf.c @@ -174,6 +174,7 @@ void delrmconf(rmconf) struct remoteconf *rmconf; { + if (rmconf->etypes) deletypes(rmconf->etypes); if (rmconf->dhgrp) @@ -188,7 +189,11 @@ delrmconf(rmconf) racoon_free(rmconf->remote); if (rmconf->shared_secret) vfree(rmconf->shared_secret); - + if (rmconf->keychainCertRef) + CFRelease(rmconf->keychainCertRef); + if (rmconf->open_dir_auth_group) + vfree(rmconf->open_dir_auth_group); + racoon_free(rmconf); } diff --git a/racoon.tproj/remoteconf.h b/racoon.tproj/remoteconf.h index fd3c898..86ede32 100644 --- a/racoon.tproj/remoteconf.h +++ b/racoon.tproj/remoteconf.h @@ -29,9 +29,14 @@ * SUCH DAMAGE. */ +#ifndef __REMOTECONF_H__ +#define __REMOTECONF_H__ + /* remote configuration */ #include +#include + struct etypes { int type; @@ -43,45 +48,51 @@ struct remoteconf { /* if family is AF_UNSPEC, that is * for anonymous configuration. */ - struct etypes *etypes; /* exchange type list. the head - * is a type to be sent first. */ + struct etypes *etypes; /* exchange type list. the head + * is a type to be sent first. */ int doitype; /* doi type */ int sittype; /* situation type */ int idvtype; /* my identifier type */ - vchar_t *idv; /* my identifier */ + vchar_t *idv; /* my identifier */ int idvtype_p; /* peer's identifier type */ vchar_t *idv_p; /* peer's identifier */ int secrettype; /* type of secret [use, key, keychain] */ - vchar_t *shared_secret; /* shared secret */ - + vchar_t *shared_secret; /* shared secret */ + vchar_t *open_dir_auth_group; /* group to be used to authorize user */ + int certtype; /* certificate type if need */ + int identity_in_keychain; /* cert and private key is in the keychain */ + CFDataRef keychainCertRef; /* peristant keychain ref for cert */ char *mycertfile; /* file name of my certificate */ char *myprivfile; /* file name of my private key file */ - char *peerscertfile; /* file name of peer's certifcate */ + char *peerscertfile; /* file name of peer's certifcate */ + int getcert_method; /* the way to get peer's certificate */ int send_cert; /* send to CERT or not */ int send_cr; /* send to CR or not */ int verify_cert; /* verify a CERT strictly */ - int verify_identifier; /* vefify the peer's identifier */ + int cert_verification; /* openssl or security framework */ + int cert_verification_option; /* nothing, peers identifier, or open_dir */ + int verify_identifier; /* vefify the peer's identifier */ int nonce_size; /* the number of bytes of nonce */ int keepalive; /* XXX may not use */ int passive; /* never initiate */ int support_mip6; /* support mip6 */ int gen_policy; /* generate policy if no policy found */ int ini_contact; /* initial contact */ - int pcheck_level; /* level of propocl checking */ + int pcheck_level; /* level of protocol checking */ int dh_group; /* use it when only aggressive mode */ - struct dhgroup *dhgrp; /* use it when only aggressive mode */ - /* avobe two cann't be defined by user*/ + struct dhgroup *dhgrp; /* use it when only aggressive mode */ + /* above two can't be defined by user*/ int retry_counter; /* times to retry. */ int retry_interval; /* interval each retry. */ - /* above 2 values are copied from localconf. */ + /* above 2 values are copied from localconf. */ - struct isakmpsa *proposal; /* proposal list */ + struct isakmpsa *proposal; /* proposal list */ LIST_ENTRY(remoteconf) chain; /* next remote conf */ }; @@ -123,3 +134,6 @@ extern struct etypes *check_etypeok extern struct isakmpsa *newisakmpsa __P((void)); extern void insisakmpsa __P((struct isakmpsa *, struct remoteconf *)); extern const char *rm2str __P((const struct remoteconf *)); + +#endif /* __REMOTECONF_H__ */ + diff --git a/racoon.tproj/rijndael-alg-fst.h b/racoon.tproj/rijndael-alg-fst.h index 4f02543..7a725ae 100644 --- a/racoon.tproj/rijndael-alg-fst.h +++ b/racoon.tproj/rijndael-alg-fst.h @@ -8,8 +8,8 @@ * #define INTERMEDIATE_VALUE_KAT to generate the Intermediate Value Known Answer Test. */ -#ifndef __RIJNDAEL_ALG_FST_H -#define __RIJNDAEL_ALG_FST_H +#ifndef __RIJNDAEL_ALG_FST_H__ +#define __RIJNDAEL_ALG_FST_H__ #define RIJNDAEL_MAXKC (256/32) #define RIJNDAEL_MAXROUNDS 14 @@ -30,4 +30,5 @@ int rijndaelDecrypt(u_int8_t a[16], u_int8_t b[16], u_int8_t rk[RIJNDAEL_MAXROUN int rijndaelDecryptRound(u_int8_t a[4][4], u_int8_t rk[RIJNDAEL_MAXROUNDS+1][4][4], int ROUNDS, int rounds); #endif /* INTERMEDIATE_VALUE_KAT */ -#endif /* __RIJNDAEL_ALG_FST_H */ +#endif /* __RIJNDAEL_ALG_FST_H__ */ + diff --git a/racoon.tproj/rijndael-api-fst.h b/racoon.tproj/rijndael-api-fst.h index 75b99c3..9e0ed3a 100644 --- a/racoon.tproj/rijndael-api-fst.h +++ b/racoon.tproj/rijndael-api-fst.h @@ -8,8 +8,8 @@ * #define INTERMEDIATE_VALUE_KAT to generate the Intermediate Value Known Answer Test. */ -#ifndef __RIJNDAEL_API_FST_H -#define __RIJNDAEL_API_FST_H +#ifndef __RIJNDAEL_API_FST_H__ +#define __RIJNDAEL_API_FST_H__ #include @@ -100,4 +100,5 @@ int rijndael_cipherUpdateRounds(cipherInstance *cipher, keyInstance *key, u_int8_t *input, int inputLen, u_int8_t *outBuffer, int Rounds); #endif /* INTERMEDIATE_VALUE_KAT */ -#endif /* __RIJNDAEL_API_FST_H */ +#endif /* __RIJNDAEL_API_FST_H__ */ + diff --git a/racoon.tproj/rijndael.h b/racoon.tproj/rijndael.h index 26a5c54..6af4aa0 100644 --- a/racoon.tproj/rijndael.h +++ b/racoon.tproj/rijndael.h @@ -1,3 +1,10 @@ /* $KAME: rijndael.h,v 1.2 2000/10/02 17:14:27 itojun Exp $ */ +#ifndef __RIJNDAEL_H__ +#define __RIJNDAEL_H__ + #include + + +#endif /* __RIJNDAEL_H__ */ + diff --git a/racoon.tproj/rijndael_local.h b/racoon.tproj/rijndael_local.h index 240e3ff..652b328 100644 --- a/racoon.tproj/rijndael_local.h +++ b/racoon.tproj/rijndael_local.h @@ -1,5 +1,8 @@ /* $KAME: rijndael_local.h,v 1.3 2000/10/02 17:14:27 itojun Exp $ */ +#ifndef __RIJNDAEL_LOCAL_H__ +#define __RIJNDAEL_LOCAL_H__ + /* the file should not be used from outside */ typedef u_int8_t BYTE; typedef u_int8_t word8; @@ -8,3 +11,7 @@ typedef u_int32_t word32; #define MAXKC RIJNDAEL_MAXKC #define MAXROUNDS RIJNDAEL_MAXROUNDS + + +#endif /* __RIJNDAEL_LOCAL_H__ */ + diff --git a/racoon.tproj/safefile.h b/racoon.tproj/safefile.h index aa61ecb..bbb67ce 100644 --- a/racoon.tproj/safefile.h +++ b/racoon.tproj/safefile.h @@ -31,4 +31,10 @@ * SUCH DAMAGE. */ +#ifndef __SAFEFILE_H__ +#define __SAFEFILE_H__ + extern int safefile __P((const char *, int)); + +#endif /* __SAFEFILE_H__ */ + diff --git a/racoon.tproj/sainfo.h b/racoon.tproj/sainfo.h index 5a3a841..1712a63 100644 --- a/racoon.tproj/sainfo.h +++ b/racoon.tproj/sainfo.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __SAINFO_H__ +#define __SAINFO_H__ + #include /* SA info */ @@ -69,3 +72,6 @@ extern struct sainfoalg *newsainfoalg __P((void)); extern void delsainfoalg __P((struct sainfoalg *)); extern void inssainfoalg __P((struct sainfoalg **, struct sainfoalg *)); extern const char * sainfo2str __P((const struct sainfo *)); + +#endif /* __SAINFO_H__ */ + diff --git a/racoon.tproj/schedule.h b/racoon.tproj/schedule.h index b793bb6..a604e05 100644 --- a/racoon.tproj/schedule.h +++ b/racoon.tproj/schedule.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __SCHEDULE_H__ +#define __SCHEDULE_H__ + #include /* scheduling table */ @@ -73,3 +76,6 @@ void sched_kill __P((struct sched *)); int sched_dump __P((caddr_t *, int *)); void sched_init __P((void)); void sched_scrub_param __P((void *)); + +#endif /* __SCHEDULE_H__ */ + diff --git a/racoon.tproj/session.c b/racoon.tproj/session.c index ac63be3..bdd2975 100644 --- a/racoon.tproj/session.c +++ b/racoon.tproj/session.c @@ -155,12 +155,29 @@ session(void) continue; if (FD_ISSET(p->sock, &rfds)) - isakmp_handler(p->sock); + if ((error = isakmp_handler(p->sock)) == -2) + break; + + #ifdef IKE_NAT_T if (p->nattsock >= 0 && FD_ISSET(p->nattsock, &rfds)) - isakmp_natt_handler(p->nattsock); + if ((error = isakmp_natt_handler(p->nattsock)) == -2) + break; #endif } + if (error == -2) { + if (lcconf->autograbaddr) { + /* serious socket problem - close all listening sockets and re-open */ + isakmp_close(); + initfds(); + sched_new(5, check_rtsock, NULL); + continue; + } else { + isakmp_close_sockets(); + isakmp_open(); + } + + } if (FD_ISSET(lcconf->sock_pfkey, &rfds)) pfkey_handler(); diff --git a/racoon.tproj/session.h b/racoon.tproj/session.h index 78704d7..d993bbd 100644 --- a/racoon.tproj/session.h +++ b/racoon.tproj/session.h @@ -29,5 +29,12 @@ * SUCH DAMAGE. */ +#ifndef __SESSION_H__ +#define __SESSION_H__ + extern int session __P((void)); extern RETSIGTYPE signal_handler __P((int)); + + +#endif /* __SESSION_H__ */ + diff --git a/racoon.tproj/sockmisc.h b/racoon.tproj/sockmisc.h index 5b786df..b323ca5 100644 --- a/racoon.tproj/sockmisc.h +++ b/racoon.tproj/sockmisc.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __SOCKMISC_H__ +#define __SOCKMISC_H__ + extern const int niflags; extern int cmpsaddrwop __P((struct sockaddr *, struct sockaddr *)); @@ -51,3 +54,6 @@ extern char *saddrwop2str __P((struct sockaddr *)); extern struct sockaddr *str2saddr __P((char *, char *)); extern void mask_sockaddr __P((struct sockaddr *, const struct sockaddr *, size_t)); + +#endif /* __SOCKMISC_H__ */ + diff --git a/racoon.tproj/str2val.h b/racoon.tproj/str2val.h index a100da8..296e0a9 100644 --- a/racoon.tproj/str2val.h +++ b/racoon.tproj/str2val.h @@ -29,5 +29,12 @@ * SUCH DAMAGE. */ +#ifndef __STR2VAL_H__ +#define __STR2VAL_H__ + extern caddr_t val2str __P((const char *, size_t)); extern char *str2val __P((const char *, int, size_t *)); + + +#endif /* __STR2VAL_H__ */ + diff --git a/racoon.tproj/strnames.h b/racoon.tproj/strnames.h index 587ada3..db0bec8 100644 --- a/racoon.tproj/strnames.h +++ b/racoon.tproj/strnames.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __STRNAMES_H__ +#define __STRNAMES_H__ + extern char * s_isakmp_state __P((int, int, int)); extern char *s_isakmp_certtype __P((int)); extern char *s_isakmp_etype __P((int)); @@ -61,3 +64,6 @@ extern char *s_pfkey_type __P((int)); extern char *s_pfkey_satype __P((int)); extern char *s_direction __P((int)); extern char *s_proto __P((int)); + +#endif /* __STRNAMES_H__ */ + diff --git a/racoon.tproj/var.h b/racoon.tproj/var.h index a4d3891..a036022 100644 --- a/racoon.tproj/var.h +++ b/racoon.tproj/var.h @@ -29,8 +29,8 @@ * SUCH DAMAGE. */ -#if !defined(_VAR_H_) -#define _VAR_H_ +#ifndef __VAR_H__ +#define __VAR_H__ #define MAX3(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c)) @@ -90,4 +90,5 @@ do { \ #include "gcmalloc.h" -#endif /*!defined(_VAR_H_)*/ +#endif /* __VAR_H__ */ + diff --git a/racoon.tproj/vendorid.h b/racoon.tproj/vendorid.h index cf4785d..1342697 100644 --- a/racoon.tproj/vendorid.h +++ b/racoon.tproj/vendorid.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __VENDORID_H__ +#define __VENDORID_H__ + /* The unknown vendor ID. */ #define VENDORID_UNKNOWN -1 @@ -62,3 +65,7 @@ extern const char *vendorid_strings[]; vchar_t *set_vendorid __P((int)); int check_vendorid __P((struct isakmp_gen *)); + + +#endif /* __VENDORID_H__ */ + diff --git a/racoon.tproj/vmbuf.h b/racoon.tproj/vmbuf.h index 829c0f2..b8884c3 100644 --- a/racoon.tproj/vmbuf.h +++ b/racoon.tproj/vmbuf.h @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifndef __VMBUF_H__ +#define __VMBUF_H__ + /* * bp v * v v @@ -61,3 +64,7 @@ extern vchar_t *vmalloc __P((size_t)); extern vchar_t *vrealloc __P((vchar_t *, size_t)); extern void vfree __P((vchar_t *)); extern vchar_t *vdup __P((vchar_t *)); + + +#endif /* __VMBUF_H__ */ + diff --git a/rarpd.tproj/Makefile b/rarpd.tproj/Makefile index 34700cd..2199fe3 100644 --- a/rarpd.tproj/Makefile +++ b/rarpd.tproj/Makefile @@ -14,7 +14,7 @@ PROJECT_TYPE = Tool CFILES = rarpd.c -OTHERSRCS = Makefile.dist Makefile.preamble rarpd.8 +OTHERSRCS = Makefile.dist Makefile.preamble rarpd.8 Makefile.postamble MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/rarpd.tproj/Makefile.postamble b/rarpd.tproj/Makefile.postamble new file mode 100644 index 0000000..775a702 --- /dev/null +++ b/rarpd.tproj/Makefile.postamble @@ -0,0 +1,3 @@ +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 rarpd.8 $(DSTROOT)/usr/share/man/man8/rarpd.8 diff --git a/rarpd.tproj/rarpd.c b/rarpd.tproj/rarpd.c index cb3f2dd..890be78 100644 --- a/rarpd.tproj/rarpd.c +++ b/rarpd.tproj/rarpd.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rcp.tproj/Makefile.postamble b/rcp.tproj/Makefile.postamble index 54c0935..76748f7 100644 --- a/rcp.tproj/Makefile.postamble +++ b/rcp.tproj/Makefile.postamble @@ -3,3 +3,5 @@ INSTALL_PERMISSIONS = 4555 # If set, 'install' chmod's executable to this after_install:: $(CHFLAGS) schg $(DSTROOT)$(INSTALLDIR)/$(NAME) + mkdir -p $(DSTROOT)/usr/share/man/man1 + install -c -m 444 rcp.1 $(DSTROOT)/usr/share/man/man1/rcp.1 diff --git a/rcp.tproj/extern.h b/rcp.tproj/extern.h index 3c20d43..706251f 100644 --- a/rcp.tproj/extern.h +++ b/rcp.tproj/extern.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rcp.tproj/pathnames.h b/rcp.tproj/pathnames.h index 9d207d9..a93c4e6 100644 --- a/rcp.tproj/pathnames.h +++ b/rcp.tproj/pathnames.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rcp.tproj/rcp.c b/rcp.tproj/rcp.c index d9cf956..579f328 100644 --- a/rcp.tproj/rcp.c +++ b/rcp.tproj/rcp.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rcp.tproj/util.c b/rcp.tproj/util.c index a83035c..7ee6866 100644 --- a/rcp.tproj/util.c +++ b/rcp.tproj/util.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/revnetgroup.tproj/hash.c b/revnetgroup.tproj/hash.c index f54a48f..9aee4bd 100644 --- a/revnetgroup.tproj/hash.c +++ b/revnetgroup.tproj/hash.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/revnetgroup.tproj/hash.h b/revnetgroup.tproj/hash.h index b8308f9..822c9e0 100644 --- a/revnetgroup.tproj/hash.h +++ b/revnetgroup.tproj/hash.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/revnetgroup.tproj/parse_netgroup.c b/revnetgroup.tproj/parse_netgroup.c index c9dab0f..0d1e07a 100644 --- a/revnetgroup.tproj/parse_netgroup.c +++ b/revnetgroup.tproj/parse_netgroup.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/revnetgroup.tproj/revnetgroup.c b/revnetgroup.tproj/revnetgroup.c index bc24bd7..a45db99 100644 --- a/revnetgroup.tproj/revnetgroup.c +++ b/revnetgroup.tproj/revnetgroup.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rexecd.tproj/Makefile b/rexecd.tproj/Makefile index 2b445ca..cc14895 100644 --- a/rexecd.tproj/Makefile +++ b/rexecd.tproj/Makefile @@ -14,7 +14,7 @@ PROJECT_TYPE = Tool CFILES = rexecd.c -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rexecd.8 +OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rexecd.8 exec.plist MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/rexecd.tproj/Makefile.postamble b/rexecd.tproj/Makefile.postamble index 7ede358..034b0ce 100644 --- a/rexecd.tproj/Makefile.postamble +++ b/rexecd.tproj/Makefile.postamble @@ -109,3 +109,8 @@ STRIPFLAGS = # owned by the top-level Makefile API and no context has been set up for where # derived files should go. +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 rexecd.8 $(DSTROOT)/usr/share/man/man8/rexecd.8 + mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons" + cp exec.plist "$(DSTROOT)/System/Library/LaunchDaemons/" diff --git a/rexecd.tproj/exec.plist b/rexecd.tproj/exec.plist new file mode 100644 index 0000000..4d2849e --- /dev/null +++ b/rexecd.tproj/exec.plist @@ -0,0 +1,27 @@ + + + + + Disabled + + Label + com.apple.rexecd + ProgramArguments + + /usr/libexec/rexecd + + inetdCompatibility + + Wait + + + Sockets + + Listeners + + SockServiceName + exec + + + + diff --git a/rexecd.tproj/rexecd.c b/rexecd.tproj/rexecd.c index e54cde6..ec9e009 100644 --- a/rexecd.tproj/rexecd.c +++ b/rexecd.tproj/rexecd.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rlogin.tproj/Makefile.postamble b/rlogin.tproj/Makefile.postamble index acddb30..f68db0c 100644 --- a/rlogin.tproj/Makefile.postamble +++ b/rlogin.tproj/Makefile.postamble @@ -1 +1,5 @@ INSTALL_PERMISSIONS = 4755 # If set, 'install' chmod's executable to this + +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man1 + install -c -m 444 rlogin.1 $(DSTROOT)/usr/share/man/man1/rlogin.1 diff --git a/rlogin.tproj/des_rw.c b/rlogin.tproj/des_rw.c index cd1729e..4e056cf 100644 --- a/rlogin.tproj/des_rw.c +++ b/rlogin.tproj/des_rw.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rlogin.tproj/kcmd.c b/rlogin.tproj/kcmd.c index 0f8e6e3..1482dda 100644 --- a/rlogin.tproj/kcmd.c +++ b/rlogin.tproj/kcmd.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rlogin.tproj/krb.h b/rlogin.tproj/krb.h index 5337052..10b6dca 100644 --- a/rlogin.tproj/krb.h +++ b/rlogin.tproj/krb.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rlogin.tproj/krcmd.c b/rlogin.tproj/krcmd.c index d5cab34..8f7710e 100644 --- a/rlogin.tproj/krcmd.c +++ b/rlogin.tproj/krcmd.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rlogin.tproj/rlogin.c b/rlogin.tproj/rlogin.c index c03229f..b819699 100644 --- a/rlogin.tproj/rlogin.c +++ b/rlogin.tproj/rlogin.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rlogind.tproj/Makefile b/rlogind.tproj/Makefile index 753d291..cfc5a28 100644 --- a/rlogind.tproj/Makefile +++ b/rlogind.tproj/Makefile @@ -16,7 +16,7 @@ HFILES = pathnames.h CFILES = rlogind.c -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rlogind.8 +OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rlogind.8 login.plist MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/rlogind.tproj/Makefile.postamble b/rlogind.tproj/Makefile.postamble index 046da0d..fc25871 100644 --- a/rlogind.tproj/Makefile.postamble +++ b/rlogind.tproj/Makefile.postamble @@ -1,2 +1,7 @@ VPATH += :../rlogin.tproj +after_install: + install -d $(DSTROOT)/usr/share/man/man8 + install -c -m 444 rlogind.8 $(DSTROOT)/usr/share/man/man8/rlogind.8 + mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons" + cp login.plist "$(DSTROOT)/System/Library/LaunchDaemons/" diff --git a/rlogind.tproj/login.plist b/rlogind.tproj/login.plist new file mode 100644 index 0000000..0362a21 --- /dev/null +++ b/rlogind.tproj/login.plist @@ -0,0 +1,27 @@ + + + + + Disabled + + Label + com.apple.rlogind + ProgramArguments + + /usr/libexec/rlogind + + inetdCompatibility + + Wait + + + Sockets + + Listeners + + SockServiceName + login + + + + diff --git a/rlogind.tproj/pathnames.h b/rlogind.tproj/pathnames.h index 23b2f3f..b9a57fa 100644 --- a/rlogind.tproj/pathnames.h +++ b/rlogind.tproj/pathnames.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rlogind.tproj/rlogind.c b/rlogind.tproj/rlogind.c index 8f1a346..5bd88f8 100644 --- a/rlogind.tproj/rlogind.c +++ b/rlogind.tproj/rlogind.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -599,11 +598,19 @@ do_rlogin(dest) getstr(term+ENVSIZE, sizeof(term)-ENVSIZE, "Terminal type too long"); pwd = getpwnam(lusername); - if (pwd == NULL) + if (pwd == NULL) { + syslog(LOG_ERR, + "rlogin denied for user %s: getpwnam() failed\n", + lusername); return (-1); - if (pwd->pw_uid == 0) + } + if (pwd->pw_uid == 0 && strcmp("root", lusername)) + { + syslog(LOG_ALERT, + "rlogin denied for non-root user %s with uid 0\n", + lusername); return (-1); - /* XXX why don't we syslog() failure? */ + } return (iruserok(dest->sin_addr.s_addr, 0, rusername, lusername)); } diff --git a/route.tproj/Makefile b/route.tproj/Makefile index caea41c..efffa2f 100644 --- a/route.tproj/Makefile +++ b/route.tproj/Makefile @@ -31,6 +31,8 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) +HEADER_PATHS =\ + -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/ NEXTSTEP_BUILD_OUTPUT_DIR = /$(USER)/BUILD diff --git a/route.tproj/keywords.h b/route.tproj/keywords.h index 0cc369f..84e5531 100644 --- a/route.tproj/keywords.h +++ b/route.tproj/keywords.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/route.tproj/route.c b/route.tproj/route.c index 259c50f..42d4c45 100644 --- a/route.tproj/route.c +++ b/route.tproj/route.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/Makefile b/routed.tproj/Makefile index 00a172a..acfd6a6 100644 --- a/routed.tproj/Makefile +++ b/routed.tproj/Makefile @@ -31,6 +31,8 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) +HEADER_PATHS =\ + -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/ NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc diff --git a/routed.tproj/af.c b/routed.tproj/af.c index ae8aaeb..a879b6c 100644 --- a/routed.tproj/af.c +++ b/routed.tproj/af.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/af.h b/routed.tproj/af.h index ed74f54..02f48b0 100644 --- a/routed.tproj/af.h +++ b/routed.tproj/af.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/defs.c b/routed.tproj/defs.c index 3cf5dd2..5b176bc 100644 --- a/routed.tproj/defs.c +++ b/routed.tproj/defs.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/defs.h b/routed.tproj/defs.h index d05e349..fad0ae1 100644 --- a/routed.tproj/defs.h +++ b/routed.tproj/defs.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/if.c b/routed.tproj/if.c index 7bb035f..5235d58 100644 --- a/routed.tproj/if.c +++ b/routed.tproj/if.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/inet.c b/routed.tproj/inet.c index abdb24e..ef194a8 100644 --- a/routed.tproj/inet.c +++ b/routed.tproj/inet.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/input.c b/routed.tproj/input.c index 443a495..d39615f 100644 --- a/routed.tproj/input.c +++ b/routed.tproj/input.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/interface.h b/routed.tproj/interface.h index 0f9baa1..8e2df84 100644 --- a/routed.tproj/interface.h +++ b/routed.tproj/interface.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/main.c b/routed.tproj/main.c index d1d6fac..43597a5 100644 --- a/routed.tproj/main.c +++ b/routed.tproj/main.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/output.c b/routed.tproj/output.c index 152aba4..168c320 100644 --- a/routed.tproj/output.c +++ b/routed.tproj/output.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/pathnames.h b/routed.tproj/pathnames.h index 4e87b53..12482f7 100644 --- a/routed.tproj/pathnames.h +++ b/routed.tproj/pathnames.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/startup.c b/routed.tproj/startup.c index 9b76857..c183ac6 100644 --- a/routed.tproj/startup.c +++ b/routed.tproj/startup.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/table.h b/routed.tproj/table.h index f21ca78..3e0246d 100644 --- a/routed.tproj/table.h +++ b/routed.tproj/table.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/tables.c b/routed.tproj/tables.c index 8719d31..f9ade65 100644 --- a/routed.tproj/tables.c +++ b/routed.tproj/tables.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/timer.c b/routed.tproj/timer.c index dfa9436..cf8e3ba 100644 --- a/routed.tproj/timer.c +++ b/routed.tproj/timer.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/routed.tproj/trace.c b/routed.tproj/trace.c index ef31d21..ade2817 100644 --- a/routed.tproj/trace.c +++ b/routed.tproj/trace.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -77,10 +76,11 @@ int traceactions = 0; static struct timeval lastlog; static char *savetracename; +static int iftraceinit(); + traceinit(ifp) register struct interface *ifp; { - static int iftraceinit(); if (iftraceinit(ifp, &ifp->int_input) && iftraceinit(ifp, &ifp->int_output)) @@ -89,7 +89,7 @@ traceinit(ifp) fprintf(stderr, "traceinit: can't init %s\n", ifp->int_name); } -static + iftraceinit(ifp, ifd) struct interface *ifp; register struct ifdebug *ifd; diff --git a/routed.tproj/trace.h b/routed.tproj/trace.h index 832ad62..aa7f753 100644 --- a/routed.tproj/trace.h +++ b/routed.tproj/trace.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rpc_lockd.tproj/kern.c b/rpc_lockd.tproj/kern.c index eb29905..37974e5 100644 --- a/rpc_lockd.tproj/kern.c +++ b/rpc_lockd.tproj/kern.c @@ -123,14 +123,7 @@ pid_t client_request(void) { LOCKD_MSG msg; -/* - * select on FIFOs can currently hang, so we'll use - * the nfslockdwait syscall instead for now. - */ -#define USE_NFSLOCKDWAIT_INSTEAD_OF_SELECT 1 -#ifndef USE_NFSLOCKDWAIT_INSTEAD_OF_SELECT fd_set rdset; -#endif int fd, nr, ret; pid_t child; mode_t old_umask; @@ -177,7 +170,6 @@ client_request(void) } for (;;) { -#ifndef USE_NFSLOCKDWAIT_INSTEAD_OF_SELECT /* Wait for contact... fifo's return EAGAIN when read with * no data */ @@ -185,7 +177,6 @@ client_request(void) FD_ZERO(&rdset); FD_SET(fd, &rdset); (void)select(fd + 1, &rdset, NULL, NULL, NULL); -#endif /* Read the fixed length message. */ if ((nr = read(fd, &msg, sizeof(msg))) == sizeof(msg)) { @@ -235,18 +226,10 @@ client_request(void) syslog(LOG_ERR, "read: %s: %m", _PATH_LCKFIFO); goto err; } -#ifdef USE_NFSLOCKDWAIT_INSTEAD_OF_SELECT - else - nfsclnt(NFSCLNT_LOCKDWAIT, NULL); -#endif } else if (nr != 0) { syslog(LOG_ERR, "%s: discard %d bytes", _PATH_LCKFIFO, nr); } -#ifdef USE_NFSLOCKDWAIT_INSTEAD_OF_SELECT - else - nfsclnt(NFSCLNT_LOCKDWAIT, NULL); -#endif } /* Reached only on error. */ @@ -710,16 +693,11 @@ void show(LOCKD_MSG *mp) { static char hex[] = "0123456789abcdef"; - struct fid *fidp; - fsid_t *fsidp; size_t len; u_int8_t *p, *t, buf[NFS_SMALLFH*3+1]; syslog(LOG_DEBUG, "process ID: %lu\n", (long)mp->lm_fl.l_pid); - fsidp = (fsid_t *)&mp->lm_fh; - fidp = (struct fid *)((u_int8_t *)&mp->lm_fh + sizeof(fsid_t)); - for (t = buf, p = (u_int8_t *)mp->lm_fh, len = mp->lm_fh_len; len > 0; ++p, --len) { diff --git a/rpc_lockd.tproj/lockd.c b/rpc_lockd.tproj/lockd.c index 7bb5833..07a1c90 100644 --- a/rpc_lockd.tproj/lockd.c +++ b/rpc_lockd.tproj/lockd.c @@ -60,6 +60,7 @@ __RCSID("$NetBSD: lockd.c,v 1.7 2000/08/12 18:08:44 thorpej Exp $"); #include #include #include +#include #include #include @@ -105,6 +106,10 @@ main(argc, argv) struct sigaction sigalarm; int grace_period = 30; struct rlimit rlp; + int mib[6]; + int oldstate; + int oldsize; + int newstate; while ((ch = getopt(argc, argv, "d:g:wx:")) != (-1)) { switch (ch) { @@ -154,8 +159,21 @@ main(argc, argv) signal(SIGHUP, handle_sig_cleanup); signal(SIGQUIT, handle_sig_cleanup); + + openlog("rpc.lockd", debug_level == 99 ? LOG_PERROR : 0, LOG_DAEMON); + mib[0] = CTL_KERN; + mib[1] = KERN_PROCDELAYTERM; + + oldstate = 0; + oldsize = 4; + newstate = 1; + + if (sysctl(mib, 2, &oldstate, &oldsize, &newstate, 4) < 0) { + syslog(LOG_INFO, "cannot mark pid for delayed termination"); + } + if (claim_pid_file("/var/run/lockd.pid", 0) < 0) { syslog(LOG_ERR, "cannot claim pid file"); exit(1); diff --git a/rpc_lockd.tproj/lockd_lock.c b/rpc_lockd.tproj/lockd_lock.c index 9784236..1ee60d1 100644 --- a/rpc_lockd.tproj/lockd_lock.c +++ b/rpc_lockd.tproj/lockd_lock.c @@ -168,7 +168,8 @@ enum hwlock_status { HW_GRANTED = 0, HW_GRANTED_DUPLICATE, enum partialfilelock_status { PFL_GRANTED=0, PFL_GRANTED_DUPLICATE, PFL_DENIED, PFL_NFSDENIED, PFL_NFSBLOCKED, PFL_NFSDENIED_NOLOCK, PFL_NFSRESERR, - PFL_HWDENIED, PFL_HWBLOCKED, PFL_HWDENIED_NOLOCK, PFL_HWRESERR}; + PFL_HWDENIED, PFL_HWBLOCKED, PFL_HWDENIED_NOLOCK, PFL_HWRESERR, + PFL_HWDENIED_STALEFH, PFL_HWDENIED_READONLY }; enum LFLAGS {LEDGE_LEFT, LEDGE_LBOUNDARY, LEDGE_INSIDE, LEDGE_RBOUNDARY, LEDGE_RIGHT}; enum RFLAGS {REDGE_LEFT, REDGE_LBOUNDARY, REDGE_INSIDE, REDGE_RBOUNDARY, REDGE_RIGHT}; @@ -232,10 +233,9 @@ enum partialfilelock_status unlock_partialfilelock( void clear_partialfilelock(const char *hostname); enum partialfilelock_status test_partialfilelock( const struct file_lock *fl, struct file_lock **conflicting_fl); -enum nlm_stats do_test(struct file_lock *fl, - struct file_lock **conflicting_fl); -enum nlm_stats do_unlock(struct file_lock *fl); -enum nlm_stats do_lock(struct file_lock *fl); +enum nlm4_stats do_test(struct file_lock *fl, struct file_lock **conflicting_fl); +enum nlm4_stats do_unlock(struct file_lock *fl); +enum nlm4_stats do_lock(struct file_lock *fl); void do_clear(const char *hostname); @@ -1080,6 +1080,7 @@ lock_hwlock(struct file_lock *fl) { struct monfile *imf,*nmf; int lflags, flerror; + fhandle_t fh; /* Scan to see if filehandle already present */ LIST_FOREACH(imf, &monfilelist_head, monfilelist) { @@ -1114,8 +1115,18 @@ lock_hwlock(struct file_lock *fl) return (HW_RESERR); } + if (fl->filehandle.n_len > NFS_MAX_FH_SIZE) { + debuglog("hwlock: bad fh length %d (from %16s): %32s\n", + fl->filehandle.n_len, fl->client_name, strerror(errno)); + free(nmf->filehandle.n_bytes); + free(nmf); + return (HW_STALEFH); + } + fh.fh_len = fl->filehandle.n_len; + bcopy(fl->filehandle.n_bytes, fh.fh_data, fh.fh_len); + /* XXX: Is O_RDWR always the correct mode? */ - nmf->fd = fhopen((fhandle_t *)fl->filehandle.n_bytes, O_RDWR); + nmf->fd = fhopen(&fh, O_RDWR); if (nmf->fd < 0) { debuglog("fhopen failed (from %16s): %32s\n", fl->client_name, strerror(errno)); @@ -1384,6 +1395,32 @@ retry_blockingfilelocklist(netobj *fh) do_unlock(ifl); /* ifl is NO LONGER VALID AT THIS POINT */ } + } else if (pflstatus == PFL_HWDENIED_STALEFH) { + /* + * Uh oh... + * It would be nice if we could inform the client of + * this error. Unfortunately, there's no way to do + * that in the NLM protocol (can't send "granted" + * message with an error and there's no "never going + * to be granted" message). + * + * Since there's no chance of this blocked request ever + * succeeding, we drop the lock request rather than + * needlessly keeping it around just to rot forever in + * the blocked lock list. + * + * Hopefully, if the client is still waiting for the lock, + * they will resend the request (and get an error then). + * + * XXX Note: PFL_HWDENIED_READONLY could potentially + * be handled this way as well, although that would + * only be an issue if a file system changed from + * read-write to read-only out from under a blocked + * lock request, and that's far less likely than a + * file disappearing out from under such a request. + */ + deallocate_file_lock(ifl); + /* ifl is NO LONGER VALID AT THIS POINT */ } else { /* Reinsert lock back into same place in blocked list */ debuglog("Replacing blocked lock\n"); @@ -1394,9 +1431,10 @@ retry_blockingfilelocklist(netobj *fh) LIST_INSERT_HEAD(&blockedlocklist_head, ifl, nfslocklist); } - if (pflstatus == PFL_GRANTED || pflstatus == PFL_GRANTED_DUPLICATE) { - /* If ifl was permanently removed from the list, (e.g the */ - /* lock was granted), pfl should remain where it's at. */ + if (pflstatus == PFL_GRANTED || pflstatus == PFL_GRANTED_DUPLICATE || + pflstatus == PFL_HWDENIED_STALEFH) { + /* If ifl was permanently removed from the list, (e.g it */ + /* was granted or dropped), pfl should remain where it's at. */ } else { /* If ifl was left in the list, (e.g it was reinserted back */ /* in place), pfl should simply be moved forward to be ifl */ @@ -1493,6 +1531,18 @@ lock_partialfilelock(struct file_lock *fl) debuglog("HW DENIED\n"); retval = PFL_HWDENIED; break; + case HW_DENIED_NOLOCK: + debuglog("HW DENIED NOLOCK\n"); + retval = PFL_HWDENIED_NOLOCK; + break; + case HW_STALEFH: + debuglog("HW STALE FH\n"); + retval = PFL_HWDENIED_STALEFH; + break; + case HW_READONLY: + debuglog("HW READONLY\n"); + retval = PFL_HWDENIED_READONLY; + break; default: debuglog("Unmatched hwstatus %d\n",hwstatus); break; @@ -1724,6 +1774,7 @@ void clear_partialfilelock(const char *hostname) { struct file_lock *ifl, *nfl; + enum partialfilelock_status pfsret; /* Clear blocking file lock list */ clear_blockingfilelock(hostname); @@ -1737,7 +1788,7 @@ clear_partialfilelock(const char *hostname) * would mess up the iteration. Thus, a next element * must be used explicitly */ - +restart: ifl = LIST_FIRST(&nfslocklist_head); while (ifl != NULL) { @@ -1745,8 +1796,21 @@ clear_partialfilelock(const char *hostname) if (strncmp(hostname, ifl->client_name, SM_MAXSTRLEN) == 0) { /* Unlock destroys ifl out from underneath */ - unlock_partialfilelock(ifl); + pfsret = unlock_partialfilelock(ifl); + if (pfsret != PFL_GRANTED) { + /* Uh oh... there was some sort of problem. */ + /* If we restart the loop, we may get */ + /* stuck here forever getting errors. */ + /* So, let's just abort the whole scan. */ + syslog(LOG_WARNING, "lock clearing for %s failed: %d", + hostname, pfsret); + break; + } /* ifl is NO LONGER VALID AT THIS POINT */ + /* Note: the unlock may deallocate several existing locks. */ + /* Therefore, we need to restart the scanning of the list, */ + /* because nfl could be pointing to a freed lock. */ + goto restart; } ifl = nfl; } @@ -1800,11 +1864,11 @@ test_partialfilelock(const struct file_lock *fl, * the few return codes which the nlm subsystems wishes to trasmit */ -enum nlm_stats +enum nlm4_stats do_test(struct file_lock *fl, struct file_lock **conflicting_fl) { enum partialfilelock_status pfsret; - enum nlm_stats retval; + enum nlm4_stats retval; debuglog("Entering do_test...\n"); @@ -1859,11 +1923,11 @@ do_test(struct file_lock *fl, struct file_lock **conflicting_fl) * convinced that this should be abstracted out and bounced up a level */ -enum nlm_stats +enum nlm4_stats do_lock(struct file_lock *fl) { enum partialfilelock_status pfsret; - enum nlm_stats retval; + enum nlm4_stats retval; debuglog("Entering do_lock...\n"); @@ -1894,10 +1958,22 @@ do_lock(struct file_lock *fl) break; case PFL_NFSRESERR: case PFL_HWRESERR: + case PFL_NFSDENIED_NOLOCK: + case PFL_HWDENIED_NOLOCK: debuglog("PFL lock resource alocation fail\n"); dump_filelock(fl); retval = (fl->flags & LOCK_V4) ? nlm4_denied_nolocks : nlm_denied_nolocks; break; + case PFL_HWDENIED_STALEFH: + debuglog("PFL_NFS lock denied STALEFH"); + dump_filelock(fl); + retval = (fl->flags & LOCK_V4) ? nlm4_stale_fh : nlm_denied; + break; + case PFL_HWDENIED_READONLY: + debuglog("PFL_NFS lock denied READONLY"); + dump_filelock(fl); + retval = (fl->flags & LOCK_V4) ? nlm4_rofs : nlm_denied; + break; default: debuglog("PFL lock *FAILED*"); dump_filelock(fl); @@ -1910,11 +1986,11 @@ do_lock(struct file_lock *fl) return retval; } -enum nlm_stats +enum nlm4_stats do_unlock(struct file_lock *fl) { enum partialfilelock_status pfsret; - enum nlm_stats retval; + enum nlm4_stats retval; debuglog("Entering do_unlock...\n"); pfsret = unlock_partialfilelock(fl); @@ -1986,9 +2062,9 @@ testlock(struct nlm4_lock *lock, bool_t exclusive, int flags __unused) { struct file_lock test_fl, *conflicting_fl; - if (lock->fh.n_len != sizeof(fhandle_t)) { - debuglog("received fhandle size %d, local size %d", - lock->fh.n_len, (int)sizeof(fhandle_t)); + if (lock->fh.n_len > NFS_MAX_FH_SIZE) { + debuglog("received fhandle size %d, max size %d", + lock->fh.n_len, NFS_MAX_FH_SIZE); return NULL; } @@ -2021,11 +2097,11 @@ testlock(struct nlm4_lock *lock, bool_t exclusive, int flags __unused) * will do the blocking lock. */ -enum nlm_stats +enum nlm4_stats getlock(nlm4_lockargs *lckarg, struct svc_req *rqstp, const int flags) { struct file_lock *newfl; - enum nlm_stats retval; + enum nlm4_stats retval; debuglog("Entering getlock...\n"); @@ -2033,9 +2109,9 @@ getlock(nlm4_lockargs *lckarg, struct svc_req *rqstp, const int flags) return (flags & LOCK_V4) ? nlm4_denied_grace_period : nlm_denied_grace_period; - if (lckarg->alock.fh.n_len != sizeof(fhandle_t)) { - debuglog("received fhandle size %d, local size %d", - lckarg->alock.fh.n_len, (int)sizeof(fhandle_t)); + if (lckarg->alock.fh.n_len > NFS_MAX_FH_SIZE) { + debuglog("received fhandle size %d, max size %d", + lckarg->alock.fh.n_len, NFS_MAX_FH_SIZE); return (flags & LOCK_V4) ? nlm4_failed : nlm_denied; } @@ -2090,17 +2166,17 @@ getlock(nlm4_lockargs *lckarg, struct svc_req *rqstp, const int flags) /* unlock a filehandle */ -enum nlm_stats +enum nlm4_stats unlock(nlm4_lock *lock, const int flags) { struct file_lock fl; - enum nlm_stats err; + enum nlm4_stats err; debuglog("Entering unlock...\n"); - if (lock->fh.n_len != sizeof(fhandle_t)) { - debuglog("received fhandle size %d, local size %d", - lock->fh.n_len, (int)sizeof(fhandle_t)); + if (lock->fh.n_len > NFS_MAX_FH_SIZE) { + debuglog("received fhandle size %d, max size %d", + lock->fh.n_len, NFS_MAX_FH_SIZE); return (flags & LOCK_V4) ? nlm4_failed : nlm_denied; } @@ -2122,23 +2198,23 @@ unlock(nlm4_lock *lock, const int flags) } /* cancel a blocked lock request */ -enum nlm_stats +enum nlm4_stats cancellock(nlm4_cancargs *args, const int flags) { struct file_lock *ifl, *nfl; - enum nlm_stats err; + enum nlm4_stats err; debuglog("Entering cancellock...\n"); - if (args->alock.fh.n_len != sizeof(fhandle_t)) { - debuglog("received fhandle size %d, local size %d", - args->alock.fh.n_len, (int)sizeof(fhandle_t)); + if (args->alock.fh.n_len > NFS_MAX_FH_SIZE) { + debuglog("received fhandle size %d, max size %d", + args->alock.fh.n_len, NFS_MAX_FH_SIZE); return (flags & LOCK_V4) ? nlm4_failed : nlm_denied; } siglock(); - err = nlm_denied; + err = (flags & LOCK_V4) ? nlm4_denied : nlm_denied; /* * scan blocked lock list for matching request and remove/destroy @@ -2182,7 +2258,7 @@ cancellock(nlm4_cancargs *args, const int flags) /* got it */ remove_blockingfilelock(ifl); deallocate_file_lock(ifl); - err = nlm_granted; + err = (flags & LOCK_V4) ? nlm4_granted : nlm_granted; break; } @@ -2618,7 +2694,7 @@ granted_failed(nlm4_res *arg) /* * getshare: try to acquire a share reservation */ -enum nlm_stats +enum nlm4_stats getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) { struct sharefile *shrfile; @@ -2634,9 +2710,9 @@ getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) nlm_denied_grace_period; } - if (shrarg->share.fh.n_len != sizeof(fhandle_t)) { - debuglog("received fhandle size %d, local size %d", - shrarg->share.fh.n_len, (int)sizeof(fhandle_t)); + if (shrarg->share.fh.n_len > NFS_MAX_FH_SIZE) { + debuglog("received fhandle size %d, max size %d", + shrarg->share.fh.n_len, NFS_MAX_FH_SIZE); return (flags & LOCK_V4) ? nlm4_failed : nlm_denied; } @@ -2652,8 +2728,11 @@ getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) /* if share file not found, create a new share file */ if (!shrfile) { + fhandle_t fh; int fd; - fd = fhopen((fhandle_t *)shrarg->share.fh.n_bytes, O_RDONLY); + fh.fh_len = shrarg->share.fh.n_len; + bcopy(shrarg->share.fh.n_bytes, fh.fh_data, fh.fh_len); + fd = fhopen(&fh, O_RDONLY); if (fd < 0) { debuglog("fhopen failed (from %16s): %32s\n", shrarg->share.caller_name, strerror(errno)); @@ -2670,7 +2749,7 @@ getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) if (!shrfile) { debuglog("getshare failed: can't allocate sharefile\n"); close(fd); - return (flags & LOCK_V4) ? nlm4_failed : nlm_denied; + return (flags & LOCK_V4) ? nlm4_denied_nolocks : nlm_denied_nolocks; } shrfile->filehandle.n_len = shrarg->share.fh.n_len; shrfile->filehandle.n_bytes = malloc(shrarg->share.fh.n_len); @@ -2678,7 +2757,7 @@ getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) debuglog("getshare failed: can't allocate sharefile filehandle\n"); free(shrfile); close(fd); - return (flags & LOCK_V4) ? nlm4_failed : nlm_denied; + return (flags & LOCK_V4) ? nlm4_denied_nolocks : nlm_denied_nolocks; } bcopy(shrarg->share.fh.n_bytes, shrfile->filehandle.n_bytes, shrarg->share.fh.n_len); @@ -2697,13 +2776,13 @@ getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) sh->mode = shrarg->share.mode; sh->access = shrarg->share.access; debuglog("getshare: updated existing share\n"); - return nlm_granted; + return (flags & LOCK_V4) ? nlm4_granted : nlm_granted; } if (((shrarg->share.mode & sh->access) != 0) || ((shrarg->share.access & sh->mode) != 0)) { /* share request conflicts with existing share */ debuglog("getshare: conflicts with existing share\n"); - return nlm_denied; + return (flags & LOCK_V4) ? nlm4_denied : nlm_denied; } } @@ -2723,7 +2802,7 @@ getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) free(shrfile->filehandle.n_bytes); free(shrfile); } - return (flags & LOCK_V4) ? nlm4_failed : nlm_denied; + return (flags & LOCK_V4) ? nlm4_denied_nolocks : nlm_denied_nolocks; } bzero(sh, sizeof(*sh) - sizeof(sh->client_name)); sh->oh.n_len = shrarg->share.oh.n_len; @@ -2737,7 +2816,7 @@ getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) free(shrfile->filehandle.n_bytes); free(shrfile); } - return (flags & LOCK_V4) ? nlm4_failed : nlm_denied; + return (flags & LOCK_V4) ? nlm4_denied_nolocks : nlm_denied_nolocks; } memcpy(sh->client_name, shrarg->share.caller_name, n); sh->client_name[n] = 0; @@ -2750,12 +2829,12 @@ getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) debuglog("Exiting getshare...\n"); - return nlm_granted; + return (flags & LOCK_V4) ? nlm4_granted : nlm_granted; } /* remove a share reservation */ -enum nlm_stats +enum nlm4_stats unshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) { struct sharefile *shrfile; @@ -2763,9 +2842,9 @@ unshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) debuglog("Entering unshare...\n"); - if (shrarg->share.fh.n_len != sizeof(fhandle_t)) { - debuglog("received fhandle size %d, local size %d", - shrarg->share.fh.n_len, (int)sizeof(fhandle_t)); + if (shrarg->share.fh.n_len > NFS_MAX_FH_SIZE) { + debuglog("received fhandle size %d, max size %d", + shrarg->share.fh.n_len, NFS_MAX_FH_SIZE); return (flags & LOCK_V4) ? nlm4_failed : nlm_denied; } @@ -2782,7 +2861,7 @@ unshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) /* if share file not found, return success (per spec) */ if (!shrfile) { debuglog("unshare: no such share file\n"); - return nlm_granted; + return (flags & LOCK_V4) ? nlm4_granted : nlm_granted; } /* find share */ @@ -2796,7 +2875,7 @@ unshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) /* if share not found, return success (per spec) */ if (!sh) { debuglog("unshare: no such share\n"); - return nlm_granted; + return (flags & LOCK_V4) ? nlm4_granted : nlm_granted; } /* remove share from file and deallocate */ @@ -2816,7 +2895,7 @@ unshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags) debuglog("Exiting unshare...\n"); - return nlm_granted; + return (flags & LOCK_V4) ? nlm4_granted : nlm_granted; } /* @@ -2831,6 +2910,7 @@ do_free_all(const char *hostname) struct file_lock *ifl, *nfl; struct sharefile *shrfile, *nshrfile; struct file_share *ifs, *nfs; + enum partialfilelock_status pfsret; /* clear non-monitored blocking file locks */ ifl = LIST_FIRST(&blockedlocklist_head); @@ -2847,6 +2927,7 @@ do_free_all(const char *hostname) } /* clear non-monitored file locks */ +restart: ifl = LIST_FIRST(&nfslocklist_head); while (ifl != NULL) { nfl = LIST_NEXT(ifl, nfslocklist); @@ -2854,8 +2935,21 @@ do_free_all(const char *hostname) if (((ifl->flags & LOCK_MON) == 0) && (strncmp(hostname, ifl->client_name, SM_MAXSTRLEN) == 0)) { /* Unlock destroys ifl out from underneath */ - unlock_partialfilelock(ifl); + pfsret = unlock_partialfilelock(ifl); + if (pfsret != PFL_GRANTED) { + /* Uh oh... there was some sort of problem. */ + /* If we restart the loop, we may get */ + /* stuck here forever getting errors. */ + /* So, let's just abort the whole scan. */ + syslog(LOG_WARNING, "unmonitored lock clearing for %s failed: %d", + hostname, pfsret); + break; + } /* ifl is NO LONGER VALID AT THIS POINT */ + /* Note: the unlock may deallocate several existing locks. */ + /* Therefore, we need to restart the scanning of the list, */ + /* because nfl could be pointing to a freed lock. */ + goto restart; } ifl = nfl; diff --git a/rpc_lockd.tproj/lockd_lock.h b/rpc_lockd.tproj/lockd_lock.h index d3dd12b..5c71e26 100644 --- a/rpc_lockd.tproj/lockd_lock.h +++ b/rpc_lockd.tproj/lockd_lock.h @@ -6,12 +6,12 @@ #ifndef LOCKD_LOCK_H #define LOCKD_LOCK_H struct nlm4_holder * testlock(struct nlm4_lock *lock, bool_t exclusive, int flags); -enum nlm_stats getlock(nlm4_lockargs *lckarg, struct svc_req *rqstp, const int flags); -enum nlm_stats unlock(nlm4_lock *lock, const int flags); -enum nlm_stats cancellock(nlm4_cancargs *args, const int flags); +enum nlm4_stats getlock(nlm4_lockargs *lckarg, struct svc_req *rqstp, const int flags); +enum nlm4_stats unlock(nlm4_lock *lock, const int flags); +enum nlm4_stats cancellock(nlm4_cancargs *args, const int flags); int lock_answer(int version, netobj *netcookie, nlm4_lock *lock, int flags, int result); -enum nlm_stats getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags); -enum nlm_stats unshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags); +enum nlm4_stats getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags); +enum nlm4_stats unshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags); void do_free_all(const char *hostname); void granted_failed(nlm4_res *arg); diff --git a/rpc_statd.tproj/procs.c b/rpc_statd.tproj/procs.c index de0906d..c564094 100644 --- a/rpc_statd.tproj/procs.c +++ b/rpc_statd.tproj/procs.c @@ -381,9 +381,33 @@ void *sm_notify_1_svc(stat_chge *arg, struct svc_req *req __unused) hp = find_host(arg->mon_name, FALSE); if (!hp) { - /* Never heard of this host - why is it notifying us? */ - syslog(LOG_DEBUG, "Unsolicited notification from host %s", arg->mon_name); - return (&dummy); + /* + * Hmmm... We've never heard of this host. + * It's possible the host just didn't give us the right hostname. + * Let's try the IP address the request came from and any hostnames it has. + */ + struct sockaddr_in *claddr; + if ((claddr = svc_getcaller(req->rq_xprt))) { + struct hostent *he; + he = gethostbyaddr((char*)&claddr->sin_addr, sizeof(claddr->sin_addr), AF_INET); + if (he) { + char **np = he->h_aliases; + hp = find_host(he->h_name, FALSE); + while (!hp && *np) { + hp = find_host(*np, FALSE); + if (!hp) + np++; + } + } + if (hp) + syslog(LOG_DEBUG, "Notification from host %s found as %s", + arg->mon_name, hp->hostname); + } + if (!hp) { + /* Never heard of this host - why is it notifying us? */ + syslog(LOG_DEBUG, "Unsolicited notification from host %s", arg->mon_name); + return (&dummy); + } } lp = hp->monList; if (!lp) return (&dummy); /* We know this host, but have no */ @@ -398,7 +422,7 @@ void *sm_notify_1_svc(stat_chge *arg, struct svc_req *req __unused) while (lp) { - tx_arg.mon_name = arg->mon_name; + tx_arg.mon_name = hp->hostname; tx_arg.state = arg->state; memcpy(tx_arg.priv, lp->notifyData, sizeof(tx_arg.priv)); cli = clnt_create(lp->notifyHost, lp->notifyProg, lp->notifyVers, "udp"); diff --git a/rpc_statd.tproj/statd.c b/rpc_statd.tproj/statd.c index a0d2478..4527568 100644 --- a/rpc_statd.tproj/statd.c +++ b/rpc_statd.tproj/statd.c @@ -53,6 +53,7 @@ static const char rcsid[] = #include #include #include +#include #include "statd.h" int debug = 0; /* Controls syslog() calls for debug messages */ @@ -71,7 +72,11 @@ main(int argc, char **argv) SVCXPRT *transp; struct sigaction sa; int c; - struct timespec ts; + int mib[6]; + int oldstate; + int oldsize; + int newstate; + while ((c = getopt(argc, argv, "dn")) != EOF) switch (c) { @@ -104,17 +109,21 @@ main(int argc, char **argv) /* protocol assumes that it will run immediately at boot time. */ daemon(0, 0); + mib[0] = CTL_KERN; + mib[1] = KERN_PROCDELAYTERM; + + oldstate = 0; + oldsize = 4; + newstate = 1; + + if (sysctl(mib, 2, &oldstate, &oldsize, &newstate, 4) < 0) { + syslog(LOG_INFO, "cannot mark pid for delayed termination"); + } + + if (claim_pid_file("/var/run/statd.pid", 0) < 0) errx(1, "rpc.statd already running"); - /* start portmapper, in case it hasn't been started yet */ - system("portmap"); - /* sleep a little to give portmap a chance to start */ - /* (better to sleep 50ms now than to timeout on portmap calls) */ - ts.tv_sec = 0; - ts.tv_nsec = 50*1000*1000; - nanosleep(&ts, NULL); - (void)pmap_unset(SM_PROG, SM_VERS); transp = svcudp_create(RPC_ANYSOCK); diff --git a/rpc_yppasswdd.tproj/passwd.c b/rpc_yppasswdd.tproj/passwd.c index 81bf739..a5d9982 100644 --- a/rpc_yppasswdd.tproj/passwd.c +++ b/rpc_yppasswdd.tproj/passwd.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rpc_yppasswdd.tproj/rpc.yppasswdd.c b/rpc_yppasswdd.tproj/rpc.yppasswdd.c index ef2fc87..1a88517 100644 --- a/rpc_yppasswdd.tproj/rpc.yppasswdd.c +++ b/rpc_yppasswdd.tproj/rpc.yppasswdd.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rpc_yppasswdd.tproj/yppasswd.h b/rpc_yppasswdd.tproj/yppasswd.h index 618d876..5592e87 100644 --- a/rpc_yppasswdd.tproj/yppasswd.h +++ b/rpc_yppasswdd.tproj/yppasswd.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rpc_yppasswdd.tproj/yppasswdd_mkpw.c b/rpc_yppasswdd.tproj/yppasswdd_mkpw.c index c835f8d..6904c44 100644 --- a/rpc_yppasswdd.tproj/yppasswdd_mkpw.c +++ b/rpc_yppasswdd.tproj/yppasswdd_mkpw.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rpc_yppasswdd.tproj/yppasswdd_proc.c b/rpc_yppasswdd.tproj/yppasswdd_proc.c index 710e839..2053263 100644 --- a/rpc_yppasswdd.tproj/yppasswdd_proc.c +++ b/rpc_yppasswdd.tproj/yppasswdd_proc.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rpcinfo.tproj/rpcinfo.c b/rpcinfo.tproj/rpcinfo.c index 5c0af78..3315bda 100644 --- a/rpcinfo.tproj/rpcinfo.c +++ b/rpcinfo.tproj/rpcinfo.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rsh.tproj/Makefile.postamble b/rsh.tproj/Makefile.postamble index 625a231..8e11482 100644 --- a/rsh.tproj/Makefile.postamble +++ b/rsh.tproj/Makefile.postamble @@ -3,3 +3,5 @@ INSTALL_PERMISSIONS = 4555 after_install:: $(CHFLAGS) schg $(DSTROOT)$(INSTALLDIR)/$(NAME) + install -d $(DSTROOT)/usr/share/man/man1 + install -c -m 444 rsh.1 $(DSTROOT)/usr/share/man/man1/rsh.1 diff --git a/rshd.tproj/Makefile b/rshd.tproj/Makefile index 3ebcdb8..8b293c0 100644 --- a/rshd.tproj/Makefile +++ b/rshd.tproj/Makefile @@ -14,7 +14,7 @@ PROJECT_TYPE = Tool CFILES = rshd.c -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rshd.8 +OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rshd.8 shell.plist MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/rshd.tproj/Makefile.postamble b/rshd.tproj/Makefile.postamble index fd0e632..b1f0957 100644 --- a/rshd.tproj/Makefile.postamble +++ b/rshd.tproj/Makefile.postamble @@ -111,3 +111,8 @@ STRIPFLAGS = VPATH += :../rlogin.tproj +after_install: + install -d $(DSTROOT)/usr/share/man/man8 + install -c -m 444 rshd.8 $(DSTROOT)/usr/share/man/man8/rshd.8 + mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons" + cp shell.plist "$(DSTROOT)/System/Library/LaunchDaemons/" diff --git a/rshd.tproj/rshd.c b/rshd.tproj/rshd.c index 2f9085c..7e8d10c 100644 --- a/rshd.tproj/rshd.c +++ b/rshd.tproj/rshd.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rshd.tproj/shell.plist b/rshd.tproj/shell.plist new file mode 100644 index 0000000..0417b13 --- /dev/null +++ b/rshd.tproj/shell.plist @@ -0,0 +1,27 @@ + + + + + Disabled + + Label + com.apple.rshd + ProgramArguments + + /usr/libexec/rshd + + inetdCompatibility + + Wait + + + Sockets + + Listeners + + SockServiceName + shell + + + + diff --git a/rtadvd.tproj/Makefile b/rtadvd.tproj/Makefile index 9a18eb3..453faf5 100644 --- a/rtadvd.tproj/Makefile +++ b/rtadvd.tproj/Makefile @@ -29,6 +29,8 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) +HEADER_PATHS =\ + -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/ NEXTSTEP_BUILD_OUTPUT_DIR = /$(USER)/BUILD diff --git a/rtsol.tproj/Makefile b/rtsol.tproj/Makefile index f1a8386..482efb6 100644 --- a/rtsol.tproj/Makefile +++ b/rtsol.tproj/Makefile @@ -30,6 +30,8 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) +HEADER_PATHS =\ + -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/ NEXTSTEP_BUILD_OUTPUT_DIR = /$(USER)/BUILD diff --git a/ruptime.tproj/Makefile.postamble b/ruptime.tproj/Makefile.postamble index 7823726..8b2ef6a 100644 --- a/ruptime.tproj/Makefile.postamble +++ b/ruptime.tproj/Makefile.postamble @@ -121,3 +121,7 @@ STRIPFLAGS = # # Note: on MS Windows, executables, have an extension, so rules and dependencies # for generated tools should use $(EXECUTABLE_EXT) on the end. + +after_install: + install -d $(DSTROOT)/usr/share/man/man1 + install -c -m 444 ruptime.1 $(DSTROOT)/usr/share/man/man1/ruptime.1 diff --git a/ruptime.tproj/ruptime.c b/ruptime.tproj/ruptime.c index 3a7714c..e6cb457 100644 --- a/ruptime.tproj/ruptime.c +++ b/ruptime.tproj/ruptime.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rwho.tproj/Makefile.postamble b/rwho.tproj/Makefile.postamble index 7823726..80bc0aa 100644 --- a/rwho.tproj/Makefile.postamble +++ b/rwho.tproj/Makefile.postamble @@ -121,3 +121,7 @@ STRIPFLAGS = # # Note: on MS Windows, executables, have an extension, so rules and dependencies # for generated tools should use $(EXECUTABLE_EXT) on the end. + +after_install: + install -d $(DSTROOT)/usr/share/man/man1 + install -c -m 444 rwho.1 $(DSTROOT)/usr/share/man/man1/rwho.1 diff --git a/rwho.tproj/rwho.c b/rwho.tproj/rwho.c index adc1ec0..815f13a 100644 --- a/rwho.tproj/rwho.c +++ b/rwho.tproj/rwho.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/rwhod.tproj/Makefile.postamble b/rwhod.tproj/Makefile.postamble index f5c79e2..f5bd05c 100644 --- a/rwhod.tproj/Makefile.postamble +++ b/rwhod.tproj/Makefile.postamble @@ -108,3 +108,7 @@ STRIPFLAGS = # Makefile API), which are rules that get invoked before and after the install # target runs. Such rules should be specified with the '::' syntax rather than # a single colon. + +after_install: + install -d $(DSTROOT)/usr/share/man/man8 + install -c -m 444 rwhod.8 $(DSTROOT)/usr/share/man/man8/rwhod.8 diff --git a/rwhod.tproj/rwhod.c b/rwhod.tproj/rwhod.c index d6411ee..cbff644 100644 --- a/rwhod.tproj/rwhod.c +++ b/rwhod.tproj/rwhod.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/setkey.tproj/Makefile b/setkey.tproj/Makefile index fc8fbf0..fbb7ae5 100644 --- a/setkey.tproj/Makefile +++ b/setkey.tproj/Makefile @@ -32,6 +32,8 @@ LIBS = -lipsec DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) +HEADER_PATHS =\ + -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/ NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc diff --git a/slattach.tproj/Makefile b/slattach.tproj/Makefile index 1f2fd2d..c4a4f06 100644 --- a/slattach.tproj/Makefile +++ b/slattach.tproj/Makefile @@ -14,7 +14,7 @@ PROJECT_TYPE = Tool CFILES = slattach.c -OTHERSRCS = Makefile.preamble Makefile Makefile.dist slattach.8 +OTHERSRCS = Makefile.preamble Makefile Makefile.dist slattach.8 Makefile.postamble MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/slattach.tproj/Makefile.postamble b/slattach.tproj/Makefile.postamble new file mode 100644 index 0000000..5002221 --- /dev/null +++ b/slattach.tproj/Makefile.postamble @@ -0,0 +1,3 @@ +after_install: + install -d $(DSTROOT)/usr/share/man/man8 + install -c -m 444 slattach.8 $(DSTROOT)/usr/share/man/man8 diff --git a/slattach.tproj/slattach.c b/slattach.tproj/slattach.c index 028efc7..580da18 100644 --- a/slattach.tproj/slattach.c +++ b/slattach.tproj/slattach.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/spray.tproj/spray.c b/spray.tproj/spray.c index 847ac34..72d9c3e 100644 --- a/spray.tproj/spray.c +++ b/spray.tproj/spray.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/spray.tproj/spray.x b/spray.tproj/spray.x index a9ff8df..5d2f883 100644 --- a/spray.tproj/spray.x +++ b/spray.tproj/spray.x @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/stdethers.tproj/stdethers.c b/stdethers.tproj/stdethers.c index 4fb93da..7a50f99 100644 --- a/stdethers.tproj/stdethers.c +++ b/stdethers.tproj/stdethers.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -70,8 +69,6 @@ static char rcsid[] = "$OpenBSD: stdethers.c,v 1.3 1997/09/11 19:47:33 deraadt E char *ProgramName = "stdethers"; -extern int ether_line(char *, struct ether_addr *, char *); - #ifndef NTOA_FIX #define NTOA(x) (char *)ether_ntoa(x) #else diff --git a/stdhosts.tproj/stdhosts.c b/stdhosts.tproj/stdhosts.c index bccf8f3..3406558 100644 --- a/stdhosts.tproj/stdhosts.c +++ b/stdhosts.tproj/stdhosts.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/syslogd.tproj/Makefile b/syslogd.tproj/Makefile deleted file mode 100644 index eb7c9ec..0000000 --- a/syslogd.tproj/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = syslogd - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Tool - -HFILES = pathnames.h ttymsg.h - -CFILES = ttymsg.c syslogd.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble syslogd.8\ - syslog.conf.5 - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = tool.make -NEXTSTEP_INSTALLDIR = /usr/sbin -WINDOWS_INSTALLDIR = /usr/sbin -PDO_UNIX_INSTALLDIR = /usr/sbin -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/syslogd.tproj/Makefile.postamble b/syslogd.tproj/Makefile.postamble deleted file mode 100644 index 22e0890..0000000 --- a/syslogd.tproj/Makefile.postamble +++ /dev/null @@ -1,118 +0,0 @@ -############################################################################### -# NeXT Makefile.postamble Template -# Copyright 1993, NeXT Computer, Inc. -# -# This Makefile is used for configuring the standard app makefiles associated -# with ProjectBuilder. -# -# Use this template to set attributes for a project, sub-project, bundle, or -# palette. Each node in the project's tree of sub-projects and bundles -# should have it's own Makefile.preamble and Makefile.postamble. Additional -# rules (e.g., after_install) that are defined by the developer should be -# defined in this file. -# -############################################################################### -# -# Here are the variables exported by the common "app" makefiles that can be -# used in any customizations you make to the template below: -# -# PRODUCT_ROOT - Name of top-level app-wrapper (e.g., Webster.app) -# OFILE_DIR - Directory into which .o object files are generated. -# (Note that this name is calculated based on the target -# architectures specified in Project Builder). -# DERIVED_SRC_DIR - Directory used for all other derived files -# ALL_CFLAGS - All the flags passed to the cc(1) driver for compilations -# -# NAME - name of application, bundle, subproject, palette, etc. -# LANGUAGE - langage in which the project is written (default "English") -# ENGLISH - boolean flag set iff $(LANGUAGE) = "English" -# JAPANESE - boolean flag set iff $(LANGUAGE) = "Japanese" -# LOCAL_RESOURCES - localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES - non-localized resources of project -# PROJECTVERSION - version of ProjectBuilder that output Makefile -# APPICON - application icon file -# DOCICONS - dock icon files -# ICONSECTIONS - Specifies icon sections when linking executable -# -# CLASSES - Class implementation files in project. -# HFILES - Header files in project. -# MFILES - Other Objective-C source files in project. -# CFILES - Other C source files in project. -# PSWFILES - .psw files in the project -# PSWMFILES - .pswm files in the project -# SUBPROJECTS - Subprojects of this project -# BUNDLES - Bundle subprojects of this project -# OTHERSRCS - Other miscellaneous sources of this project -# OTHERLINKED - Source files not matching a standard source extention -# -# LIBS - Libraries to link with when making app target -# DEBUG_LIBS - Libraries to link with when making debug target -# PROF_LIBS - Libraries to link with when making profile target -# OTHERLINKEDOFILES - Other relocatable files to (always) link in. -# -# APP_MAKEFILE_DIR - Directory in which to find generic set of Makefiles -# MAKEFILEDIR - Directory in which to find $(MAKEFILE) -# MAKEFILE - Top level mechanism Makefile (e.g., app.make, bundle.make) -# INSTALLDIR - Directory app will be installed into by 'install' target - - -# Change defaults assumed by the standard app makefiles here. Edit the -# following default values as appropriate. (Note that if no Makefile.postamble -# exists, these values will have defaults set in common.make). - -# Add Makefile.preamble, Makefile.postamble, and Makefile.dependencies here if -# you would like changes to them to invalidate previous builds. The project -# depends on $(MAKEFILES) so that changes to Makefiles will trigger a re-build. -#MAKEFILES = Makefile - -# Optimization flag passed to compiler: -#OPTIMIZATION_CFLAG = -O - -# Flags always passed to compiler: -#COMMON_CFLAGS = $(PROJECT_SPECIFIC_CFLAGS) -g -Wall - -# Flags passed to compiler in normal 'app' compiles: -#NORMAL_CFLAGS = $(COMMON_CFLAGS) $(OPTIMIZATION_CFLAG) - -# Flags passed to compiler in 'debug' compiles: -#DEBUG_CFLAGS = $(COMMON_CFLAGS) -DDEBUG - -# Flags passed to compiler in 'profile' compiles -#PROFILE_CFLAGS = $(COMMON_CFLAGS) -pg $(OPTIMIZATION_CFLAG) -DPROFILE - -# Flags passed to yacc -#YFLAGS = -d - -# Ownership and permissions of files installed by 'install' target -#INSTALL_AS_USER = root # User to chown app to -#INSTALL_AS_GROUP = wheel # Group to chgrp app to -#INSTALL_PERMISSIONS = # If set, 'install' chmod's executable to this - -# Options to strip for bundles, apps with bundles, and apps without bundles, -# respectively. -#RELOCATABLE_STRIP_OPTS = -x -u -#DYLD_APP_STRIP_OPTS = -A -n -#APP_STRIP_OPTS = -#TOOL_STRIP_OPTS = -#LIBRARY_STRIP_OPTS = -x -S # Note: -S strips debugging symbols -# (Note: APP_STRIP_OPTS and TOOL_STRIP_OPTS default to empty, but -# developers doing their own dynamic loading should set this to -# $(DYLD_APP_STRIP_OPTS)). -STRIPFLAGS = - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Typical -# user-defined rules are before_install and after_install (please don't -# redefine things like install or app, as they are owned by the top-level -# Makefile API), which are rules that get invoked before and after the install -# target runs. Such rules should be specified with the '::' syntax rather than -# a single colon. -VPATH += :../wall.tproj - -# a rule with which to install the man page -install-man-page: - install -d $(DSTROOT)/usr/share/man/man5 - install -d $(DSTROOT)/usr/share/man/man8 - install -c -m 444 syslog.conf.5 $(DSTROOT)/usr/share/man/man5/syslog.conf.5 - install -c -m 444 syslogd.8 $(DSTROOT)/usr/share/man/man8/syslogd.8 diff --git a/syslogd.tproj/Makefile.preamble b/syslogd.tproj/Makefile.preamble deleted file mode 100644 index 3e33b22..0000000 --- a/syslogd.tproj/Makefile.preamble +++ /dev/null @@ -1,118 +0,0 @@ -############################################################################### -# NeXT Makefile.preamble Template -# Copyright 1993, NeXT Computer, Inc. -# -# This Makefile is used for configuring the standard app makefiles associated -# with ProjectBuilder. -# -# Use this template to set attributes for a project, sub-project, bundle, or -# palette. Each node in the project's tree of sub-projects and bundles -# should have it's own Makefile.preamble and Makefile.postamble. -# -############################################################################### -## Configure the flags passed to $(CC) here. These flags will also be -## inherited by all nested sub-projects and bundles. Put your -I, -D, -U, and -## -L flags here. To change the default flags that get passed to ${CC} -## (e.g. change -O to -O2), see Makefile.postamble. - -# Flags passed to compiler (in addition to -g, -O, etc) -OTHER_CFLAGS = -DINET6 -Dsocklen_t=int -# Flags passed to ld (in addition to -ObjC, etc.) -OTHER_LDFLAGS = - -BUNDLELDFLAGS = # use iff project is a bundle -PALETTELDFLAGS = # use iff project is a palette - -## Specify which headers in this project should be published to the outside -## world in a flat header directory given in PUBLIC_HEADER_DIR (which will be -## prepended by DSTROOT, below. Any subset of these public headers can be -## precompiled automatically after installation, with extra user-defined flags. -PUBLIC_HEADER_DIR = -PUBLIC_HEADERS = -PUBLIC_PRECOMPILED_HEADERS = -PUBLIC_PRECOMPILED_HEADERS_CFLAGS = - -## Configure what is linked in at each level here. Libraries are only used in -## the final 'app' linking step. Final 'app' linking is only done via the -## 'app', 'debug', and 'profile' targets when they are invoked for -## the top-level app. - -# Additional libs to link apps against ('app' target) -#OTHER_LIBS = -# Additional libs to link apps against ('debug' target) -OTHER_DEBUG_LIBS = -# Additional libs to link apps against ('profile' target) -OTHER_PROF_LIBS = - -# More 'app' libraries when $(JAPANESE) = "YES" -OTHER_JAPANESE_LIBS = -# More 'debug' libraries when $(JAPANESE) = "YES" -OTHER_JAPANESE_DEBUG_LIBS = -# More 'profile' libs when $(JAPANESE) = "YES" -OTHER_JAPANESE_PROF_LIBS = - -# If this is a bundle, and you *know* the enclosing application will not -# be linking with a library which you require in your bundle code, then -# mention it here so that it gets linked into the bundle. Note that this -# is wasteful but sometimes necessary. -BUNDLE_LIBS = - -## Configure how things get built here. Additional dependencies, sourcefiles, -## derived files, and build order should be specified here. - -# Other dependencies of this project -OTHER_PRODUCT_DEPENDS = -# Built *before* building subprojects/bundles -OTHER_INITIAL_TARGETS = -# Other source files maintained by .pre/postamble -OTHER_SOURCEFILES = -# Additional files to be removed by `make clean' -OTHER_GARBAGE = -# Precompiled headers to be built before any compilation occurs (e.g., draw.p) -PRECOMPS = - -# Targets to be built before installation -OTHER_INSTALL_DEPENDS = - -# A virtual root directory (other than /) to be prepended to the $(INSTALLDIR) -# passed from ProjectBuilder. -DSTROOT = - -# Set the following to "YES" if you want the old behavior of recursively -# cleaning all nested subprojects during 'make clean'. -CLEAN_ALL_SUBPROJECTS = - -## Add more obscure source files here to cause them to be automatically -## processed by the appropriate tool. Note that these files should also be -## added to "Supporting Files" in ProjectBuilder. The desired .o files that -## result from these files should also be added to OTHER_OFILES above so they -## will be linked in. - -# .msg files that should have msgwrap run on them -MSGFILES = -# .defs files that should have mig run on them -DEFSFILES = -# .mig files (no .defs files) that should have mig run on them -MIGFILES = - -## Add additional Help directories here (add them to the project as "Other -## Resources" in Project Builder) so that they will be compressed into .store -## files and copied into the app wrapper. If the help directories themselves -## need to also be in the app wrapper, then a cp command will need to be added -## in an after_install target. -OTHER_HELP_DIRS = - -# Don't add more rules here unless you want the first one to be the default -# target for make! Put all your targets in Makefile.postamble. - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. - -OTHER_GENERATED_OFILES = $(VERS_OFILE) - -#OTHER_OFILES = ttymsg.o - -# to allow installing man page after main install -AFTER_INSTALL += install-man-page - --include ../Makefile.include diff --git a/syslogd.tproj/PB.project b/syslogd.tproj/PB.project deleted file mode 100644 index 45a56f3..0000000 --- a/syslogd.tproj/PB.project +++ /dev/null @@ -1,41 +0,0 @@ -{ - DOCICONFILES = (); - FILESTABLE = { - C_FILES = (); - H_FILES = (pathnames.h); - OTHER_LIBS = (); - OTHER_LINKED = (syslogd.c); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, syslogd.8, syslog.conf.5); - PRECOMPILED_HEADERS = (); - PROJECT_HEADERS = (); - PUBLIC_HEADERS = (); - SUBPROJECTS = (); - }; - GENERATEMAIN = YES; - LANGUAGE = English; - LOCALIZABLE_FILES = {}; - NEXTSTEP_BUILDDIR = ""; - NEXTSTEP_BUILDTOOL = /bin/make; - NEXTSTEP_COMPILEROPTIONS = ""; - NEXTSTEP_INSTALLDIR = /usr/sbin; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_LINKEROPTIONS = ""; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDDIR = ""; - PDO_UNIX_BUILDTOOL = /bin/make; - PDO_UNIX_COMPILEROPTIONS = ""; - PDO_UNIX_INSTALLDIR = /usr/sbin; - PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; - PDO_UNIX_LINKEROPTIONS = ""; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = syslogd; - PROJECTTYPE = Tool; - PROJECTVERSION = 2.8; - WINDOWS_BUILDDIR = ""; - WINDOWS_BUILDTOOL = /bin/make; - WINDOWS_COMPILEROPTIONS = ""; - WINDOWS_INSTALLDIR = /usr/sbin; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_LINKEROPTIONS = ""; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/syslogd.tproj/pathnames.h b/syslogd.tproj/pathnames.h deleted file mode 100644 index 2dc61a8..0000000 --- a/syslogd.tproj/pathnames.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 1989, 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. - * - * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 - */ - -#include - -#define _PATH_KLOG "/dev/klog" -#define _PATH_LOGCONF "/etc/syslog.conf" -#define _PATH_LOGPID "/var/run/syslog.pid" diff --git a/syslogd.tproj/syslog.conf.5 b/syslogd.tproj/syslog.conf.5 deleted file mode 100644 index e3b88b9..0000000 --- a/syslogd.tproj/syslog.conf.5 +++ /dev/null @@ -1,232 +0,0 @@ -.\" Copyright (c) 1990, 1991, 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. -.\" -.\" from: @(#)syslog.conf.5 8.1 (Berkeley) 6/9/93 -.\" $NetBSD: syslog.conf.5,v 1.4 1996/01/02 17:41:46 perry Exp $ -.\" -.Dd June 9, 1993 -.Dt SYSLOG.CONF 5 -.Os -.Sh NAME -.Nm syslog.conf -.Nd -.Xr syslogd 8 -configuration file -.Sh DESCRIPTION -The -.Nm syslog.conf -file is the configuration file for the -.Xr syslogd 8 -program. -It consists of lines with two fields: the -.Em selector -field which specifies the types of messages and priorities to which the -line applies, and an -.Em action -field which specifies the action to be taken if a message -.Xr syslogd -receives matches the selection criteria. -The -.Em selector -field is separated from the -.Em action -field by one or more tab characters. -.Pp -The -.Em Selectors -function -are encoded as a -.Em facility , -a period (``.''), and a -.Em level , -with no intervening white-space. -Both the -.Em facility -and the -.Em level -are case insensitive. -.Pp -The -.Em facility -describes the part of the system generating the message, and is one of -the following keywords: auth, authpriv, cron, daemon, kern, lpr, mail, -mark, news, syslog, user, uucp and local0 through local7. -These keywords (with the exception of mark) correspond to the -similar -.Dq Dv LOG_ -values specified to the -.Xr openlog 3 -and -.Xr syslog 3 -library routines. -.Pp -The -.Em level -describes the severity of the message, and is a keyword from the -following ordered list (higher to lower): emerg, alert, crit, err, -warning, notice, info and debug. -These keywords correspond to the -similar -.Pq Dv LOG_ -values specified to the -.Xr syslog -library routine. -.Pp -See -.Xr syslog 3 -for a further descriptions of both the -.Em facility -and -.Em level -keywords and their significance. -.Pp -If a received message matches the specified -.Em facility -and is of the specified -.Em level -.Em (or a higher level) , -the action specified in the -.Em action -field will be taken. -.Pp -Multiple -.Em selectors -may be specified for a single -.Em action -by separating them with semicolon (``;'') characters. -It is important to note, however, that each -.Em selector -can modify the ones preceding it. -.Pp -Multiple -.Em facilities -may be specified for a single -.Em level -by separating them with comma (``,'') characters. -.Pp -An asterisk (``*'') can be used to specify all -.Em facilities -or all -.Em levels . -.Pp -The special -.Em facility -``mark'' receives a message at priority ``info'' every 20 minutes -(see -.Xr syslogd 8 ) . -This is not enabled by a -.Em facility -field containing an asterisk. -.Pp -The special -.Em level -``none'' disables a particular -.Em facility . -.Pp -The -.Em action -field of each line specifies the action to be taken when the -.Em selector -field selects a message. -There are four forms: -.Bl -bullet -.It -A pathname (beginning with a leading slash). -Selected messages are appended to the file. -.It -A hostname (preceded by an at (``@'') sign). -Selected messages are forwarded to the -.Xr syslogd -program on the named host. -.It -A comma separated list of users. -Selected messages are written to those users -if they are logged in. -.It -An asterisk. -Selected messages are written to all logged-in users. -.El -.Pp -Blank lines and lines whose first non-blank character is a hash (``#'') -character are ignored. -.Sh EXAMPLES -.Pp -A configuration file might appear as follows: -.Bd -literal -# Log all kernel messages, authentication messages of -# level notice or higher and anything of level err or -# higher to the console. -# Don't log private authentication messages! -*.err;kern.*;auth.notice;authpriv.none /dev/console - -# Log anything (except mail) of level info or higher. -# Don't log private authentication messages! -*.info;mail.none;authpriv.none /var/log/messages - -# The authpriv file has restricted access. -authpriv.* /var/log/secure - -# Log all the mail messages in one place. -mail.* /var/log/maillog - -# Everybody gets emergency messages, plus log them on another -# machine. -*.emerg * -*.emerg @arpa.berkeley.edu - -# Root and Eric get alert and higher messages. -*.alert root,eric - -# Save mail and news errors of level err and higher in a -# special file. -uucp,news.crit /var/log/spoolerr -.Ed -.Sh FILES -.Bl -tag -width /etc/syslog.conf -compact -.It Pa /etc/syslog.conf -The -.Xr syslogd 8 -configuration file. -.El -.Sh BUGS -The effects of multiple selectors are sometimes not intuitive. -For example ``mail.crit,*.err'' will select ``mail'' facility messages at -the level of ``err'' or higher, not at the level of ``crit'' or higher. -.Sh SEE ALSO -.Xr syslog 3 , -.Xr syslogd 8 -.Sh HISTORY -The -.Nm -file appeared in -.Bx 4.3 , -along with -.Xr syslogd 8 . diff --git a/syslogd.tproj/syslogd.8 b/syslogd.tproj/syslogd.8 deleted file mode 100644 index acd1380..0000000 --- a/syslogd.tproj/syslogd.8 +++ /dev/null @@ -1,331 +0,0 @@ -.\" Copyright (c) 1983, 1986, 1991, 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. -.\" -.\" @(#)syslogd.8 8.1 (Berkeley) 6/6/93 -.\" $FreeBSD: src/usr.sbin/syslogd/syslogd.8,v 1.49 2002/12/12 17:26:04 ru Exp $ -.\" -.Dd November 24, 2001 -.Dt SYSLOGD 8 -.Os -.Sh NAME -.Nm syslogd -.Nd log systems messages -.Sh SYNOPSIS -.Nm -.Op Fl 46Acdknosuv -.Op Fl a Ar allowed_peer -.Op Fl b Ar bind_address -.Op Fl f Ar config_file -.Op Fl l Ar path -.Op Fl m Ar mark_interval -.Op Fl P Ar pid_file -.Op Fl p Ar log_socket -.Sh DESCRIPTION -The -.Nm -utility reads and logs messages to the system console, log files, other -machines and/or users as specified by its configuration file. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl 4 -Force -.Nm -to use IPv4 addresses only. -.It Fl 6 -Force -.Nm -to use IPv6 addresses only. -.It Fl A -Ordinarily, -.Nm -tries to send the message to only one address -even if the host has more than one A or AAAA record. -If this option is specified, -.Nm -tries to send the message to all addresses. -.It Fl a Ar allowed_peer -Allow -.Ar allowed_peer -to log to this -.Nm -using UDP datagrams. Multiple -.Fl a -options may be specified. -.Pp -.Ar Allowed_peer -can be any of the following: -.Bl -tag -width "ipaddr/masklen[:service]XX" -.It Xo -.Sm off -.Ar ipaddr -.No / Ar masklen -.Op : Ar service -.Sm on -.Xc -Accept datagrams from -.Ar ipaddr -(in the usual dotted quad notation) with -.Ar masklen -bits being taken into account when doing the address comparison. -.Ar ipaddr -can be also IPv6 address by enclosing the address with -.Ql \&[ -and -.Ql \&] . -If specified, -.Ar service -is the name or number of an UDP service (see -.Xr services 5 ) -the source packet must belong to. A -.Ar service -of -.Ql \&* -allows packets being sent from any UDP port. The default -.Ar service -is -.Ql syslog . -If -.Ar ipaddr -is IPv4 address, a missing -.Ar masklen -will be substituted by the historic class A or class B netmasks if -.Ar ipaddr -belongs into the address range of class A or B, respectively, or -by 24 otherwise. If -.Ar ipaddr -is IPv6 address, a missing -.Ar masklen -will be substituted by 128. -.It Xo -.Sm off -.Ar domainname Op : Ar service -.Sm on -.Xc -Accept datagrams where the reverse address lookup yields -.Ar domainname -for the sender address. The meaning of -.Ar service -is as explained above. -.It Xo -.Sm off -.No * Ar domainname Op : Ar service -.Sm on -.Xc -Same as before, except that any source host whose name -.Em ends -in -.Ar domainname -will get permission. -.El -.Pp -The -.Fl a -options are ignored if the -.Fl s -option is also specified. -.It Fl b Ar bind_address -Specify one specific IP address or hostname to bind to. -If a hostname is specified, -the IPv4 or IPv6 address which corresponds to it is used. -.It Fl c -Disable the compression of repeated instances of the same line -into a single line of the form -.Dq Li "last message repeated N times" -when the output is a pipe to another program. -If specified twice, disable this compression in all cases. -.It Fl d -Put -.Nm -into debugging mode. This is probably only of use to developers working on -.Nm . -.It Fl f -Specify the pathname of an alternate configuration file; -the default is -.Pa /etc/syslog.conf . -.It Fl k -Disable the translation of -messages received with facility -.Dq kern -to facility -.Dq user . -Usually the -.Dq kern -facility is reserved for messages read directly from -.Pa /dev/klog . -.It Fl m -Select the number of minutes between -.Dq mark -messages; the default is 20 minutes. -.It Fl n -Disable dns query for every request. -.It Fl o -Prefix kernel messages with the full kernel boot file as determined by -.Xr getbootfile 3 . -Without this, the kernel message prefix is always -.Dq Li kernel: . -.It Fl p -Specify the pathname of an alternate log socket to be used instead; -the default is -.Pa /var/run/log . -.It Fl P -Specify an alternative file in which to store the process ID. -The default is -.Pa /var/run/syslog.pid . -.It Fl l -Specify a location where -.Nm -should place an additional log socket. -Up to 19 additional logging sockets can be specified. -The primary use for this is to place additional log sockets in -.Pa /var/run/log -of various chroot filespaces. -.It Fl s -Operate in secure mode. Do not log messages from remote machines. If -specified twice, no network socket will be opened at all, which also -disables logging to remote machines. -.It Fl u -Unique priority logging. Only log messages at the specified priority. -Without this option, messages at the stated priority or higher are logged. -This option changes the default comparison from -.Dq => -to -.Dq = . -.It Fl v -Verbose logging. If specified once, the numeric facility and priority are -logged with each locally-written message. If specified more than once, -the names of the facility and priority are logged with each locally-written -message. -.El -.Pp -The -.Nm -utility reads its configuration file when it starts up and whenever it -receives a hangup signal. -For information on the format of the configuration file, -see -.Xr syslog.conf 5 . -.Pp -The -.Nm -utility reads messages from the -.Ux -domain socket -.Pa /var/run/log , -from an Internet domain socket specified in -.Pa /etc/services , -and from the special device -.Pa /dev/klog -(to read kernel messages). -.Pp -The -.Nm -utility creates its process ID file, -by default -.Pa /var/run/syslog.pid , -and stores its process -ID there. -This can be used to kill or reconfigure -.Nm . -.Pp -The message sent to -.Nm -should consist of a single line. -The message can contain a priority code, which should be a preceding -decimal number in angle braces, for example, -.Sq Aq 5 . -This priority code should map into the priorities defined in the -include file -.Aq Pa sys/syslog.h . -.Pp -For security reasons, -.Nm -will not append to log files that do not exist; -therefore, they must be created manually before running -.Nm . -.Sh FILES -.Bl -tag -width /var/run/syslog.pid -compact -.It Pa /etc/syslog.conf -configuration file -.It Pa /var/run/syslog.pid -default process ID file -.It Pa /var/run/log -name of the -.Ux -domain datagram log socket -.It Pa /dev/klog -kernel log device -.El -.Sh SEE ALSO -.Xr logger 1 , -.Xr syslog 3 , -.Xr services 5 , -.Xr syslog.conf 5 -.Sh HISTORY -The -.Nm -utility appeared in -.Bx 4.3 . -.Pp -The -.Fl a , -.Fl s , -.Fl u , -and -.Fl v -options are -.Fx 2.2 -extensions. -.Sh BUGS -The ability to log messages received in UDP packets is equivalent to -an unauthenticated remote disk-filling service, and should probably be -disabled by default. Some sort of -.No inter- Ns Nm syslogd -authentication mechanism ought to be worked out. To prevent the worst -abuse, use of the -.Fl a -option is therefore highly recommended. -.Pp -The -.Fl a -matching algorithm doesn't pretend to be very efficient; use of numeric -IP addresses is faster than domain name comparison. Since the allowed -peer list is being walked linearly, peer groups where frequent messages -are being anticipated from should be put early into the -.Fl a -list. -.Pp -The log socket was moved from -.Pa /dev -to ease the use of a read-only root file system. -This may confuse -some old binaries so that a symbolic link might be used for a -transitional period. diff --git a/syslogd.tproj/syslogd.c b/syslogd.tproj/syslogd.c deleted file mode 100644 index 9c9c1d6..0000000 --- a/syslogd.tproj/syslogd.c +++ /dev/null @@ -1,2534 +0,0 @@ -/* - * Copyright (c) 1983, 1988, 1993, 1994 - * 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. - */ - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1983, 1988, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94"; -#endif -#endif /* not lint */ - -/* - * syslogd -- log system messages - * - * This program implements a system log. It takes a series of lines. - * Each line may have a priority, signified as "" as - * the first characters of the line. If this is - * not present, a default priority is used. - * - * To kill syslogd, send a signal 15 (terminate). A signal 1 (hup) will - * cause it to reread its configuration file. - * - * Defined Constants: - * - * MAXLINE -- the maximimum line length that can be handled. - * DEFUPRI -- the default priority for user messages - * DEFSPRI -- the default priority for kernel messages - * - * Author: Eric Allman - * extensive changes by Ralph Campbell - * more extensive changes by Eric Allman (again) - * Extension to log by program name as well as facility and priority - * by Peter da Silva. - * -u and -v by Harlan Stenn. - * Priority comparison code by Harlan Stenn. - */ - -#define MAXLINE 1024 /* maximum line length */ -#define MAXSVLINE 120 /* maximum saved line length */ -#define DEFUPRI (LOG_USER|LOG_NOTICE) -#define DEFSPRI (LOG_KERN|LOG_CRIT) -#define TIMERINTVL 30 /* interval for checking flush, mark */ -#define TTYMSGTIME 1 /* timed out passed to ttymsg */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef NETWORK_CHANGE_NOTIFICATION -#define NETWORK_CHANGE_NOTIFICATION "com.apple.system.config.network_change" -#endif - -#include "pathnames.h" -#include "ttymsg.h" - -#define SYSLOG_NAMES -#include - -#ifdef NI_WITHSCOPEID -static const int withscopeid = NI_WITHSCOPEID; -#else -static const int withscopeid; -#endif - -const char *ConfFile = _PATH_LOGCONF; -const char *PidFile = _PATH_LOGPID; -const char ctty[] = _PATH_CONSOLE; - -#define dprintf if (Debug) printf - -#define MAXUNAMES 20 /* maximum number of user names */ - -#define MAXFUNIX 20 - -int nfunix = 1; -const char *funixn[MAXFUNIX] = { _PATH_LOG }; -int funix[MAXFUNIX]; - -/* - * Flags to logmsg(). - */ - -#define IGN_CONS 0x001 /* don't print on console */ -#define SYNC_FILE 0x002 /* do fsync on file after printing */ -#define ADDDATE 0x004 /* add a date to the message */ -#define MARK 0x008 /* this message is a mark */ -#define ISKERNEL 0x010 /* kernel generated message */ - -/* - * This structure represents the files that will have log - * copies printed. - */ - -struct filed { - struct filed *f_next; /* next in linked list */ - short f_type; /* entry type, see below */ - short f_file; /* file descriptor */ - time_t f_time; /* time this was last written */ - char *f_host; /* host from which to recd. */ - u_char f_pmask[LOG_NFACILITIES+1]; /* priority mask */ - u_char f_pcmp[LOG_NFACILITIES+1]; /* compare priority */ -#define PRI_LT 0x1 -#define PRI_EQ 0x2 -#define PRI_GT 0x4 - char *f_program; /* program this applies to */ - union { - char f_uname[MAXUNAMES][UT_NAMESIZE+1]; - struct { - char f_hname[MAXHOSTNAMELEN]; - struct addrinfo *f_addr; - - } f_forw; /* forwarding address */ - char f_fname[MAXPATHLEN]; - struct { - char f_pname[MAXPATHLEN]; - pid_t f_pid; - } f_pipe; - } f_un; - char f_prevline[MAXSVLINE]; /* last message logged */ - char f_lasttime[16]; /* time of last occurrence */ - char f_prevhost[MAXHOSTNAMELEN]; /* host from which recd. */ - int f_prevpri; /* pri of f_prevline */ - int f_prevlen; /* length of f_prevline */ - int f_prevcount; /* repetition cnt of prevline */ - u_int f_repeatcount; /* number of "repeated" msgs */ -}; - -/* - * Queue of about-to-be dead processes we should watch out for. - */ - -TAILQ_HEAD(stailhead, deadq_entry) deadq_head; -struct stailhead *deadq_headp; - -struct deadq_entry { - pid_t dq_pid; - int dq_timeout; - TAILQ_ENTRY(deadq_entry) dq_entries; -}; - -/* - * The timeout to apply to processes waiting on the dead queue. Unit - * of measure is `mark intervals', i.e. 20 minutes by default. - * Processes on the dead queue will be terminated after that time. - */ - -#define DQ_TIMO_INIT 2 - -typedef struct deadq_entry *dq_t; - - -/* - * Struct to hold records of network addresses that are allowed to log - * to us. - */ -struct allowedpeer { - int isnumeric; - u_short port; - union { - struct { - struct sockaddr_storage addr; - struct sockaddr_storage mask; - } numeric; - char *name; - } u; -#define a_addr u.numeric.addr -#define a_mask u.numeric.mask -#define a_name u.name -}; - - -/* - * Intervals at which we flush out "message repeated" messages, - * in seconds after previous message is logged. After each flush, - * we move to the next interval until we reach the largest. - */ -int repeatinterval[] = { 30, 120, 600 }; /* # of secs before flush */ -#define MAXREPEAT ((sizeof(repeatinterval) / sizeof(repeatinterval[0])) - 1) -#define REPEATTIME(f) ((f)->f_time + repeatinterval[(f)->f_repeatcount]) -#define BACKOFF(f) { if (++(f)->f_repeatcount > MAXREPEAT) \ - (f)->f_repeatcount = MAXREPEAT; \ - } - -/* values for f_type */ -#define F_UNUSED 0 /* unused entry */ -#define F_FILE 1 /* regular file */ -#define F_TTY 2 /* terminal */ -#define F_CONSOLE 3 /* console terminal */ -#define F_FORW 4 /* remote machine */ -#define F_USERS 5 /* list of users */ -#define F_WALL 6 /* everyone logged on */ -#define F_PIPE 7 /* pipe to program */ -#define F_CHECKTTY 8 /* think it's a tty, so check */ - -const char *TypeNames[9] = { - "UNUSED", "FILE", "TTY", "CONSOLE", - "FORW", "USERS", "WALL", "PIPE", - "CHECKTTY" -}; - -static struct filed *Files = NULL; /* Log files that we write to */ -static struct filed consfile; /* Console */ - -static int Debug = 0; /* debug flag */ -static int resolve = 1; /* resolve hostname */ -static char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */ -static char *LocalDomain = NULL; /* our local domain name */ -static int *finet = NULL; /* Internet datagram socket */ -static int fklog = -1; /* /dev/klog */ -static int Initialized = 0; /* set when we have initialized ourselves */ -static int MarkInterval = 20 * 60; /* interval between marks in seconds */ -static int MarkSeq = 0; /* mark sequence number */ -#ifdef __APPLE__ -static int RcvSockBufSize = 49152; /* Our default receive socket buffer size 3301629*/ -#endif -static int SecureMode = 0; /* when true, receive only unix domain socks */ -#ifdef INET6 -static int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both) */ -#else -static int family = PF_INET; /* protocol family (IPv4 only) */ -#endif -static int send_to_all = 0; /* send message to all IPv4/IPv6 addresses */ -static int use_bootfile = 0; /* log entire bootfile for every kern msg */ -static int no_compress = 0; /* don't compress messages (1=pipes, 2=all) */ - -static char bootfile[MAXLINE+1]; /* booted kernel file */ - -struct allowedpeer *AllowedPeers = NULL; /* List of allowed peers */ -static int NumAllowed = 0; /* Number of entries in AllowedPeers */ - -static int UniquePriority = 0; /* Only log specified priority? */ -static int LogFacPri = 0; /* Put facility and priority in log message: */ - /* 0=no, 1=numeric, 2=names */ -static int KeepKernFac = 0; /* Keep remotely logged kernel facility */ -static int create_files = 0; - -volatile sig_atomic_t MarkSet = 0, WantDie = 0; - -static int allowaddr(char *); -static void cfline(const char *, struct filed *, - const char *, const char *); -static const char *cvthname(struct sockaddr *); -static void deadq_enter(pid_t, const char *); -static int deadq_remove(pid_t); -static int decode(const char *, CODE *); -static void die(int); -static void dodie(int); -static void domark(int); -static void fprintlog(struct filed *, int, const char *); -static int *socksetup(int, const char *); -static void init(int); -static void logerror(const char *); -static void logmsg(int, const char *, const char *, int); -static void log_deadchild(pid_t, int, const char *); -static void markit(void); -static int skip_message(const char *, const char *); -static void printline(const char *, char *); -static void printsys(char *); -static int p_open(const char *, pid_t *); -static void readklog(void); -static void reapchild(int); -static void usage(void); -static int validate(struct sockaddr *, const char *); -static void unmapped(struct sockaddr *); -static void wallmsg(struct filed *, struct iovec *); -static int waitdaemon(int, int, int); -static void timedout(int); - -int -main(int argc, char *argv[]) -{ - int ch, i, fdsrmax = 0, l; - struct sockaddr_un sunx, fromunix; - struct sockaddr_storage frominet; - fd_set *fdsr = NULL; - FILE *fp; - char line[MAXLINE + 1]; - const char *bindhostname, *hname; - struct timeval tv, *tvp; - struct sigaction sact; - sigset_t mask; - pid_t ppid = 1; - socklen_t len; - int nctoken = -1; - - bindhostname = NULL; - while ((ch = getopt(argc, argv, "46ACa:b:cdf:kl:m:nop:P:suv")) != -1) - switch (ch) { - case '4': - family = PF_INET; - break; -#ifdef INET6 - case '6': - family = PF_INET6; - break; -#endif - case 'A': - send_to_all++; - break; - case 'C': - create_files++; - break; - case 'a': /* allow specific network addresses only */ - if (allowaddr(optarg) == -1) - usage(); - break; - case 'b': - bindhostname = optarg; - break; - case 'c': - no_compress++; - break; - case 'd': /* debug */ - Debug++; - break; - case 'f': /* configuration file */ - ConfFile = optarg; - break; - case 'k': /* keep remote kern fac */ - KeepKernFac = 1; - break; - case 'l': - if (nfunix < MAXFUNIX) - funixn[nfunix++] = optarg; - else - warnx("out of descriptors, ignoring %s", - optarg); - break; - case 'm': /* mark interval */ - MarkInterval = atoi(optarg) * 60; - break; - case 'n': - resolve = 0; - break; - case 'o': - use_bootfile = 1; - break; - case 'p': /* path */ - funixn[0] = optarg; - break; - case 'P': /* path for alt. PID */ - PidFile = optarg; - break; - case 's': /* no network mode */ - SecureMode++; - break; - case 'u': /* only log specified priority */ - UniquePriority++; - break; - case 'v': /* log facility and priority */ - LogFacPri++; - break; - case '?': - default: - usage(); - } - if ((argc -= optind) != 0) - usage(); - - if (!Debug) { - ppid = waitdaemon(0, 0, 30); - if (ppid < 0) - err(1, "could not become daemon"); - } else { - setlinebuf(stdout); - } - - if (NumAllowed) - endservent(); - - consfile.f_type = F_CONSOLE; - (void)strlcpy(consfile.f_un.f_fname, ctty + sizeof _PATH_DEV - 1, - sizeof(consfile.f_un.f_fname)); -#ifdef __APPLE__ - /* We lack getbootfile() 3187949 and 3187947 */ - (void)strlcpy(bootfile, "/mach_kernel", sizeof("/mach_kernel")); -#else - (void)strlcpy(bootfile, getbootfile(), sizeof(bootfile)); -#endif - (void)signal(SIGTERM, dodie); - (void)signal(SIGINT, Debug ? dodie : SIG_IGN); - (void)signal(SIGQUIT, Debug ? dodie : SIG_IGN); - /* - * We don't want the SIGCHLD and SIGHUP handlers to interfere - * with each other; they are likely candidates for being called - * simultaneously (SIGHUP closes pipe descriptor, process dies, - * SIGCHLD happens). - */ - sigemptyset(&mask); - sigaddset(&mask, SIGHUP); - sact.sa_handler = reapchild; - sact.sa_mask = mask; - sact.sa_flags = SA_RESTART; - (void)sigaction(SIGCHLD, &sact, NULL); - (void)signal(SIGALRM, domark); - (void)signal(SIGPIPE, SIG_IGN); /* We'll catch EPIPE instead. */ - notify_register_signal(NETWORK_CHANGE_NOTIFICATION, SIGHUP, &nctoken); - (void)alarm(TIMERINTVL); - - TAILQ_INIT(&deadq_head); - -#ifndef SUN_LEN -#define SUN_LEN(unp) (strlen((unp)->sun_path) + 2) -#endif - for (i = 0; i < nfunix; i++) { - (void)unlink(funixn[i]); - memset(&sunx, 0, sizeof(sunx)); - sunx.sun_family = AF_UNIX; - (void)strlcpy(sunx.sun_path, funixn[i], sizeof(sunx.sun_path)); - funix[i] = socket(AF_UNIX, SOCK_DGRAM, 0); - if (funix[i] < 0 || - bind(funix[i], (struct sockaddr *)&sunx, - SUN_LEN(&sunx)) < 0 || - chmod(funixn[i], 0666) < 0) { - (void)snprintf(line, sizeof line, - "cannot create %s", funixn[i]); - logerror(line); - dprintf("cannot create %s (%d)\n", funixn[i], errno); - if (i == 0) - die(0); - } -#ifdef __APPLE__ - if (setsockopt(funix[i], SOL_SOCKET, SO_RCVBUF, &RcvSockBufSize, sizeof(int)) < 0) - logerror("setsockopt funix"); -#endif - } - if (SecureMode <= 1) - finet = socksetup(family, bindhostname); - - if (finet) { - if (SecureMode) { - for (i = 0; i < *finet; i++) { - if (shutdown(finet[i+1], SHUT_RD) < 0) { - logerror("shutdown"); - if (!Debug) - die(0); - } - } - } else { - dprintf("listening on inet and/or inet6 socket\n"); - } - dprintf("sending on inet and/or inet6 socket\n"); - } - - if ((fklog = open(_PATH_KLOG, O_RDONLY, 0)) >= 0) - if (fcntl(fklog, F_SETFL, O_NONBLOCK) < 0) - fklog = -1; - if (fklog < 0) - dprintf("can't open %s (%d)\n", _PATH_KLOG, errno); - - /* tuck my process id away */ - fp = fopen(PidFile, "w"); - if (fp != NULL) { - fprintf(fp, "%d\n", getpid()); - (void)fclose(fp); - } - - dprintf("off & running....\n"); - - init(0); - /* prevent SIGHUP and SIGCHLD handlers from running in parallel */ - sigemptyset(&mask); - sigaddset(&mask, SIGCHLD); - sact.sa_handler = init; - sact.sa_mask = mask; - sact.sa_flags = SA_RESTART; - (void)sigaction(SIGHUP, &sact, NULL); - - tvp = &tv; - tv.tv_sec = tv.tv_usec = 0; - - if (fklog != -1 && fklog > fdsrmax) - fdsrmax = fklog; - if (finet && !SecureMode) { - for (i = 0; i < *finet; i++) { - if (finet[i+1] != -1 && finet[i+1] > fdsrmax) - fdsrmax = finet[i+1]; - } - } - for (i = 0; i < nfunix; i++) { - if (funix[i] != -1 && funix[i] > fdsrmax) - fdsrmax = funix[i]; - } - - fdsr = (fd_set *)calloc(howmany(fdsrmax+1, NFDBITS), - sizeof(fd_mask)); - if (fdsr == NULL) - errx(1, "calloc fd_set"); - - for (;;) { - if (MarkSet) - markit(); - if (WantDie) - die(WantDie); - - bzero(fdsr, howmany(fdsrmax+1, NFDBITS) * - sizeof(fd_mask)); - - if (fklog != -1) - FD_SET(fklog, fdsr); - if (finet && !SecureMode) { - for (i = 0; i < *finet; i++) { - if (finet[i+1] != -1) - FD_SET(finet[i+1], fdsr); - } - } - for (i = 0; i < nfunix; i++) { - if (funix[i] != -1) - FD_SET(funix[i], fdsr); - } - - i = select(fdsrmax+1, fdsr, NULL, NULL, tvp); - switch (i) { - case 0: - if (tvp) { - tvp = NULL; - if (ppid != 1) - kill(ppid, SIGALRM); - } - continue; - case -1: - if (errno != EINTR) - logerror("select"); - continue; - } - if (fklog != -1 && FD_ISSET(fklog, fdsr)) - readklog(); - if (finet && !SecureMode) { - for (i = 0; i < *finet; i++) { - if (FD_ISSET(finet[i+1], fdsr)) { - len = sizeof(frominet); - l = recvfrom(finet[i+1], line, MAXLINE, - 0, (struct sockaddr *)&frominet, - &len); - if (l > 0) { - line[l] = '\0'; - hname = cvthname((struct sockaddr *)&frominet); - unmapped((struct sockaddr *)&frominet); - if (validate((struct sockaddr *)&frominet, hname)) - printline(hname, line); - } else if (l < 0 && errno != EINTR) - logerror("recvfrom inet"); - } - } - } - for (i = 0; i < nfunix; i++) { - if (funix[i] != -1 && FD_ISSET(funix[i], fdsr)) { - len = sizeof(fromunix); - l = recvfrom(funix[i], line, MAXLINE, 0, - (struct sockaddr *)&fromunix, &len); - if (l > 0) { - line[l] = '\0'; - printline(LocalHostName, line); - } else if (l < 0 && errno != EINTR) - logerror("recvfrom unix"); - } - } - } - if (fdsr) - free(fdsr); -} - -static void -unmapped(struct sockaddr *sa) -{ - struct sockaddr_in6 *sin6; - struct sockaddr_in sin4; - - if (sa->sa_family != AF_INET6) - return; - if (sa->sa_len != sizeof(struct sockaddr_in6) || - sizeof(sin4) > sa->sa_len) - return; - sin6 = (struct sockaddr_in6 *)sa; - if (!IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) - return; - - memset(&sin4, 0, sizeof(sin4)); - sin4.sin_family = AF_INET; - sin4.sin_len = sizeof(struct sockaddr_in); - memcpy(&sin4.sin_addr, &sin6->sin6_addr.s6_addr[12], - sizeof(sin4.sin_addr)); - sin4.sin_port = sin6->sin6_port; - - memcpy(sa, &sin4, sin4.sin_len); -} - -static void -usage(void) -{ - - fprintf(stderr, "%s\n%s\n%s\n%s\n", - "usage: syslogd [-46Acdknosuv] [-a allowed_peer]", - " [-b bind address] [-f config_file]", - " [-l log_socket] [-m mark_interval]", - " [-P pid_file] [-p log_socket]"); - exit(1); -} - -/* - * Take a raw input line, decode the message, and print the message - * on the appropriate log files. - */ -static void -printline(const char *hname, char *msg) -{ - int c, pri; - char *p, *q, line[MAXLINE + 1]; - - /* test for special codes */ - pri = DEFUPRI; - p = msg; - if (*p == '<') { - pri = 0; - while (isdigit(*++p)) - pri = 10 * pri + (*p - '0'); - if (*p == '>') - ++p; - } - if (pri &~ (LOG_FACMASK|LOG_PRIMASK)) - pri = DEFUPRI; - - /* don't allow users to log kernel messages */ - if (LOG_FAC(pri) == LOG_KERN && !KeepKernFac) - pri = LOG_MAKEPRI(LOG_USER, LOG_PRI(pri)); - - q = line; - - while ((c = (unsigned char)*p++) != '\0' && - q < &line[sizeof(line) - 4]) { -#ifdef __APPLE__ - /* Gross installer hack to be removed 3314128 */ - if (LOG_FACMASK&pri != LOG_INSTALL) { - if ((c & 0x80) && c < 0xA0) { - c &= 0x7F; - *q++ = 'M'; - *q++ = '-'; - } - } -#endif - if (isascii(c) && iscntrl(c)) { - if (c == '\n') { - *q++ = ' '; - } else if (c == '\t') { - *q++ = '\t'; - } else { - *q++ = '^'; - *q++ = c ^ 0100; - } - } else { - *q++ = c; - } - } - *q = '\0'; - - logmsg(pri, line, hname, 0); -} - -/* - * Read /dev/klog while data are available, split into lines. - */ -static void -readklog(void) -{ - char *p, *q, line[MAXLINE + 1]; - int len, i; - - len = 0; - for (;;) { - i = read(fklog, line + len, MAXLINE - 1 - len); - if (i > 0) { - line[i + len] = '\0'; - } else { - if (i < 0 && errno != EINTR && errno != EAGAIN) { - logerror("klog"); - fklog = -1; - } - break; - } - - for (p = line; (q = strchr(p, '\n')) != NULL; p = q + 1) { - *q = '\0'; - printsys(p); - } - len = strlen(p); - if (len >= MAXLINE - 1) { - printsys(p); - len = 0; - } - if (len > 0) - memmove(line, p, len + 1); - } - if (len > 0) - printsys(line); -} - -/* - * Take a raw input line from /dev/klog, format similar to syslog(). - */ -static void -printsys(char *p) -{ - int pri, flags; - - flags = ISKERNEL | SYNC_FILE | ADDDATE; /* fsync after write */ - pri = DEFSPRI; - if (*p == '<') { - pri = 0; - while (isdigit(*++p)) - pri = 10 * pri + (*p - '0'); - if (*p == '>') - ++p; -#ifndef __APPLE__ - if ((pri & LOG_FACMASK) == LOG_CONSOLE) - flags |= IGN_CONS; -#endif - } else { - /* kernel printf's come out on console */ - flags |= IGN_CONS; - } - if (pri &~ (LOG_FACMASK|LOG_PRIMASK)) - pri = DEFSPRI; - logmsg(pri, p, LocalHostName, flags); -} - -static time_t now; - -/* - * Match a program or host name against a specification. - * Return a non-0 value if the message must be ignored - * based on the specification. - */ -static int -skip_message(const char *name, const char *spec) { - const char *s; - char prev, next; - int exclude = 0; - /* Behaviour on explicit match */ - - if (spec == NULL) - return 0; - switch (*spec) { - case '-': - exclude = 1; - /*FALLTHROUGH*/ - case '+': - spec++; - break; - default: - break; - } - s = strstr (spec, name); - - if (s != NULL) { - prev = (s == spec ? ',' : *(s - 1)); - next = *(s + strlen (name)); - - if (prev == ',' && (next == '\0' || next == ',')) - /* Explicit match: skip iff the spec is an - exclusive one. */ - return exclude; - } - - /* No explicit match for this name: skip the message iff - the spec is an inclusive one. */ - return !exclude; -} - -/* - * Log a message to the appropriate log files, users, etc. based on - * the priority. - */ -static void -logmsg(int pri, const char *msg, const char *from, int flags) -{ - struct filed *f; - int i, fac, msglen, omask, prilev; - const char *timestamp; - char prog[NAME_MAX+1]; - char buf[MAXLINE+1]; - - dprintf("logmsg: pri %o, flags %x, from %s, msg %s\n", - pri, flags, from, msg); - - omask = sigblock(sigmask(SIGHUP)|sigmask(SIGALRM)); - - /* - * Check to see if msg looks non-standard. - */ - msglen = strlen(msg); - if (msglen < 16 || msg[3] != ' ' || msg[6] != ' ' || - msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') - flags |= ADDDATE; - - (void)time(&now); - if (flags & ADDDATE) { - timestamp = ctime(&now) + 4; - } else { - timestamp = msg; - msg += 16; - msglen -= 16; - } - - /* skip leading blanks */ - while (isspace(*msg)) { - msg++; - msglen--; - } - - /* extract facility and priority level */ - if (flags & MARK) - fac = LOG_NFACILITIES; - else - fac = LOG_FAC(pri); - prilev = LOG_PRI(pri); - - /* extract program name */ - for (i = 0; i < NAME_MAX; i++) { - if (!isprint(msg[i]) || msg[i] == ':' || msg[i] == '[') - break; - prog[i] = msg[i]; - } - prog[i] = 0; - - /* add kernel prefix for kernel messages */ - if (flags & ISKERNEL) { - snprintf(buf, sizeof(buf), "%s: %s", - use_bootfile ? bootfile : "kernel", msg); - msg = buf; - msglen = strlen(buf); - } - - /* log the message to the particular outputs */ - if (!Initialized) { - f = &consfile; - f->f_file = open(ctty, O_WRONLY, 0); - - if (f->f_file >= 0) { - fprintlog(f, flags, msg); - (void)close(f->f_file); - } - (void)sigsetmask(omask); - return; - } - for (f = Files; f; f = f->f_next) { - /* skip messages that are incorrect priority */ - if (!(((f->f_pcmp[fac] & PRI_EQ) && (f->f_pmask[fac] == prilev)) - ||((f->f_pcmp[fac] & PRI_LT) && (f->f_pmask[fac] < prilev)) - ||((f->f_pcmp[fac] & PRI_GT) && (f->f_pmask[fac] > prilev)) - ) - || f->f_pmask[fac] == INTERNAL_NOPRI) - continue; - - /* skip messages with the incorrect hostname */ - if (skip_message(from, f->f_host)) - continue; - - /* skip messages with the incorrect program name */ - if (skip_message(prog, f->f_program)) - continue; - - /* skip message to console if it has already been printed */ - if (f->f_type == F_CONSOLE && (flags & IGN_CONS)) - continue; - - /* don't output marks to recently written files */ - if ((flags & MARK) && (now - f->f_time) < MarkInterval / 2) - continue; - - /* - * suppress duplicate lines to this file - */ - if (no_compress - (f->f_type != F_PIPE) < 1 && - (flags & MARK) == 0 && msglen == f->f_prevlen && - !strcmp(msg, f->f_prevline) && - !strcasecmp(from, f->f_prevhost)) { - (void)strlcpy(f->f_lasttime, timestamp, 16); - f->f_prevcount++; - dprintf("msg repeated %d times, %ld sec of %d\n", - f->f_prevcount, (long)(now - f->f_time), - repeatinterval[f->f_repeatcount]); - /* - * If domark would have logged this by now, - * flush it now (so we don't hold isolated messages), - * but back off so we'll flush less often - * in the future. - */ - if (now > REPEATTIME(f)) { - fprintlog(f, flags, (char *)NULL); - BACKOFF(f); - } - } else { - /* new line, save it */ - if (f->f_prevcount) - fprintlog(f, 0, (char *)NULL); - f->f_repeatcount = 0; - f->f_prevpri = pri; - (void)strlcpy(f->f_lasttime, timestamp, 16); - (void)strlcpy(f->f_prevhost, from, - sizeof(f->f_prevhost)); - if (msglen < MAXSVLINE) { - f->f_prevlen = msglen; - (void)strlcpy(f->f_prevline, msg, sizeof(f->f_prevline)); - fprintlog(f, flags, (char *)NULL); - } else { - f->f_prevline[0] = 0; - f->f_prevlen = 0; - fprintlog(f, flags, msg); - } - } - } - (void)sigsetmask(omask); -} - -static void -fprintlog(struct filed *f, int flags, const char *msg) -{ - struct iovec iov[7]; - struct iovec *v; - struct addrinfo *r; - int i, l, lsent = 0; - char line[MAXLINE + 1], repbuf[80], greetings[200], *wmsg = NULL; - const char *msgret; - - v = iov; - if (f->f_type == F_WALL) { - v->iov_base = greetings; - v->iov_len = snprintf(greetings, sizeof greetings, - "\r\n\7Message from syslogd@%s at %.24s ...\r\n", - f->f_prevhost, ctime(&now)); - if (v->iov_len > 0) - v++; - v->iov_base = ""; - v->iov_len = 0; - v++; - } else { - v->iov_base = f->f_lasttime; - v->iov_len = 15; - v++; - v->iov_base = " "; - v->iov_len = 1; - v++; - } - - if (LogFacPri) { - static char fp_buf[30]; /* Hollow laugh */ - int fac = f->f_prevpri & LOG_FACMASK; - int pri = LOG_PRI(f->f_prevpri); - const char *f_s = NULL; - char f_n[5]; /* Hollow laugh */ - const char *p_s = NULL; - char p_n[5]; /* Hollow laugh */ - - if (LogFacPri > 1) { - CODE *c; - - for (c = facilitynames; c->c_name; c++) { - if (c->c_val == fac) { - f_s = c->c_name; - break; - } - } - for (c = prioritynames; c->c_name; c++) { - if (c->c_val == pri) { - p_s = c->c_name; - break; - } - } - } - if (!f_s) { - snprintf(f_n, sizeof f_n, "%d", LOG_FAC(fac)); - f_s = f_n; - } - if (!p_s) { - snprintf(p_n, sizeof p_n, "%d", pri); - p_s = p_n; - } - snprintf(fp_buf, sizeof fp_buf, "<%s.%s> ", f_s, p_s); - v->iov_base = fp_buf; - v->iov_len = strlen(fp_buf); - } else { - v->iov_base=""; - v->iov_len = 0; - } - v++; - - v->iov_base = f->f_prevhost; - v->iov_len = strlen(v->iov_base); - v++; - v->iov_base = " "; - v->iov_len = 1; - v++; - - if (msg) { - wmsg = strdup(msg); /* XXX iov_base needs a `const' sibling. */ - if (wmsg == NULL) { - logerror("strdup"); - exit(1); - } - v->iov_base = wmsg; - v->iov_len = strlen(msg); - } else if (f->f_prevcount > 1) { - v->iov_base = repbuf; - v->iov_len = snprintf(repbuf, sizeof repbuf, - "last message repeated %d times", f->f_prevcount); - } else { - v->iov_base = f->f_prevline; - v->iov_len = f->f_prevlen; - } - v++; - - if (f->f_file == -1) { - int oflags = O_WRONLY|O_APPEND; - struct group *gr; - struct stat sb; - int mode = 0640; - int exists = 0; - - if( stat(f->f_un.f_fname, &sb) == 0 ) { - mode = 0; - exists++; - } - if (create_files && !exists) - oflags |= O_CREAT; - if ((f->f_file = open(f->f_un.f_fname, oflags, mode)) < 0) { - f->f_type = F_UNUSED; - /* We can no longer log this error, since calling - * logerror() could bring us back here again. - * Instead, call dprintf(), which will aid in - * debugging, but not cause the looping. - */ - dprintf("Error openning %s", f->f_un.f_fname); - if (msg) free(wmsg); - return; - } - /* Only chown the file if we created it. If it already - * existed, leave whatever was there. - */ - if( !exists ) { - gr = getgrnam("admin"); - if( gr ) - fchown(f->f_file, 0, gr->gr_gid); - } - if (f->f_type == F_CHECKTTY) { - if (isatty(f->f_file)) { - if (strcmp(f->f_un.f_fname, ctty) == 0) - f->f_type = F_CONSOLE; - else - f->f_type = F_TTY; - } - } - } - - dprintf("Logging to %s", TypeNames[f->f_type]); - f->f_time = now; - - switch (f->f_type) { - case F_UNUSED: - dprintf("\n"); - break; - - case F_FORW: - dprintf(" %s\n", f->f_un.f_forw.f_hname); - /* check for local vs remote messages */ - if (strcasecmp(f->f_prevhost, LocalHostName)) - l = snprintf(line, sizeof line - 1, - "<%d>%.15s Forwarded from %s: %s", - f->f_prevpri, iov[0].iov_base, f->f_prevhost, - iov[5].iov_base); - else - l = snprintf(line, sizeof line - 1, "<%d>%.15s %s", - f->f_prevpri, iov[0].iov_base, iov[5].iov_base); - if (l < 0) - l = 0; - else if (l > MAXLINE) - l = MAXLINE; - - if (finet) { - for (r = f->f_un.f_forw.f_addr; r; r = r->ai_next) { - for (i = 0; i < *finet; i++) { -#if 0 - /* - * should we check AF first, or just - * trial and error? FWD - */ - if (r->ai_family == - address_family_of(finet[i+1])) -#endif - lsent = sendto(finet[i+1], line, l, 0, - r->ai_addr, r->ai_addrlen); - if (lsent == l) - break; - } - if (lsent == l && !send_to_all) - break; - } - dprintf("lsent/l: %d/%d\n", lsent, l); - if (lsent != l) { - int e = errno; - logerror("sendto"); - errno = e; - switch (errno) { - case EHOSTUNREACH: - case EHOSTDOWN: - break; - /* case EBADF: */ - /* case EACCES: */ - /* case ENOTSOCK: */ - /* case EFAULT: */ - /* case EMSGSIZE: */ - /* case EAGAIN: */ - /* case ENOBUFS: */ - /* case ECONNREFUSED: */ - default: - dprintf("removing entry\n"); - (void)close(f->f_file); - f->f_type = F_UNUSED; - break; - } - } - } - break; - - case F_FILE: - dprintf(" %s\n", f->f_un.f_fname); - v->iov_base = "\n"; - v->iov_len = 1; - if (writev(f->f_file, iov, 7) < 0) { - int e = errno; - (void)close(f->f_file); - f->f_type = F_UNUSED; - errno = e; - logerror(f->f_un.f_fname); - } else if (flags & SYNC_FILE) - (void)fsync(f->f_file); - break; - - case F_PIPE: - dprintf(" %s\n", f->f_un.f_pipe.f_pname); - v->iov_base = "\n"; - v->iov_len = 1; - if (f->f_un.f_pipe.f_pid == 0) { - if ((f->f_file = p_open(f->f_un.f_pipe.f_pname, - &f->f_un.f_pipe.f_pid)) < 0) { - f->f_type = F_UNUSED; - logerror(f->f_un.f_pipe.f_pname); - break; - } - } - if (writev(f->f_file, iov, 7) < 0) { - int e = errno; - (void)close(f->f_file); - if (f->f_un.f_pipe.f_pid > 0) - deadq_enter(f->f_un.f_pipe.f_pid, - f->f_un.f_pipe.f_pname); - f->f_un.f_pipe.f_pid = 0; - errno = e; - logerror(f->f_un.f_pipe.f_pname); - } - break; - - case F_CONSOLE: - if (flags & IGN_CONS) { - dprintf(" (ignored)\n"); - break; - } - /* FALLTHROUGH */ - - case F_TTY: - dprintf(" %s%s\n", _PATH_DEV, f->f_un.f_fname); - v->iov_base = "\r\n"; - v->iov_len = 2; - - errno = 0; /* ttymsg() only sometimes returns an errno */ - if ((msgret = ttymsg(iov, 7, f->f_un.f_fname, 10))) { - f->f_type = F_UNUSED; - logerror(msgret); - } - break; - - case F_USERS: - case F_WALL: - dprintf("\n"); - v->iov_base = "\r\n"; - v->iov_len = 2; - wallmsg(f, iov); - break; - } - f->f_prevcount = 0; - if (msg) - free(wmsg); -} - -/* - * WALLMSG -- Write a message to the world at large - * - * Write the specified message to either the entire - * world, or a list of approved users. - */ -static void -wallmsg(struct filed *f, struct iovec *iov) -{ - static int reenter; /* avoid calling ourselves */ - FILE *uf; - struct utmp ut; - int i; - const char *p; - char line[sizeof(ut.ut_line) + 1]; - - if (reenter++) - return; - if ((uf = fopen(_PATH_UTMP, "r")) == NULL) { - logerror(_PATH_UTMP); - reenter = 0; - return; - } - /* NOSTRICT */ - while (fread((char *)&ut, sizeof(ut), 1, uf) == 1) { - if (ut.ut_name[0] == '\0') - continue; - (void)strlcpy(line, ut.ut_line, sizeof(line)); - if (f->f_type == F_WALL) { - if ((p = ttymsg(iov, 7, line, TTYMSGTIME)) != NULL) { - errno = 0; /* already in msg */ - logerror(p); - } - continue; - } - /* should we send the message to this user? */ - for (i = 0; i < MAXUNAMES; i++) { - if (!f->f_un.f_uname[i][0]) - break; - if (!strncmp(f->f_un.f_uname[i], ut.ut_name, - UT_NAMESIZE)) { - if ((p = ttymsg(iov, 7, line, TTYMSGTIME)) - != NULL) { - errno = 0; /* already in msg */ - logerror(p); - } - break; - } - } - } - (void)fclose(uf); - reenter = 0; -} - -static void -reapchild(int signo ) -{ - int status; - pid_t pid; - struct filed *f; - - while ((pid = wait3(&status, WNOHANG, (struct rusage *)NULL)) > 0) { - if (!Initialized) - /* Don't tell while we are initting. */ - continue; - - /* First, look if it's a process from the dead queue. */ - if (deadq_remove(pid)) - goto oncemore; - - /* Now, look in list of active processes. */ - for (f = Files; f; f = f->f_next) - if (f->f_type == F_PIPE && - f->f_un.f_pipe.f_pid == pid) { - (void)close(f->f_file); - f->f_un.f_pipe.f_pid = 0; - log_deadchild(pid, status, - f->f_un.f_pipe.f_pname); - break; - } - oncemore: - continue; - } -} - -/* - * Return a printable representation of a host address. - */ -static const char * -cvthname(struct sockaddr *f) -{ - int error; - sigset_t omask, nmask; - char *p; - static char hname[NI_MAXHOST], ip[NI_MAXHOST]; - - error = getnameinfo((struct sockaddr *)f, - ((struct sockaddr *)f)->sa_len, - ip, sizeof ip, NULL, 0, - NI_NUMERICHOST | withscopeid); - dprintf("cvthname(%s)\n", ip); - - if (error) { - dprintf("Malformed from address %s\n", gai_strerror(error)); - return ("???"); - } - if (!resolve) - return (ip); - - sigemptyset(&nmask); - sigaddset(&nmask, SIGHUP); - sigprocmask(SIG_BLOCK, &nmask, &omask); - error = getnameinfo((struct sockaddr *)f, - ((struct sockaddr *)f)->sa_len, - hname, sizeof hname, NULL, 0, - NI_NAMEREQD | withscopeid); - sigprocmask(SIG_SETMASK, &omask, NULL); - if (error) { - dprintf("Host name for your address (%s) unknown\n", ip); - return (ip); - } - /* XXX Not quite correct, but close enough for government work. */ - if ((p = strchr(hname, '.')) && strcasecmp(p + 1, LocalDomain) == 0) - *p = '\0'; - return (hname); -} - -static void -dodie(int signo) -{ - - WantDie = signo; -} - -static void -domark(int signo ) -{ - - MarkSet = 1; -} - -/* - * Print syslogd errors some place. - */ -static void -logerror(const char *type) -{ - char buf[512]; - - if (errno) - (void)snprintf(buf, - sizeof buf, "syslogd: %s: %s", type, strerror(errno)); - else - (void)snprintf(buf, sizeof buf, "syslogd: %s", type); - errno = 0; - dprintf("%s\n", buf); - logmsg(LOG_SYSLOG|LOG_ERR, buf, LocalHostName, ADDDATE); -} - -static void -die(int signo) -{ - struct filed *f; - int was_initialized; - char buf[100]; - int i; - - was_initialized = Initialized; - Initialized = 0; /* Don't log SIGCHLDs. */ - for (f = Files; f != NULL; f = f->f_next) { - /* flush any pending output */ - if (f->f_prevcount) - fprintlog(f, 0, (char *)NULL); - if (f->f_type == F_PIPE) - (void)close(f->f_file); - } - Initialized = was_initialized; - if (signo) { - dprintf("syslogd: exiting on signal %d\n", signo); - (void)snprintf(buf, sizeof(buf), "exiting on signal %d", signo); - errno = 0; - logerror(buf); - } - for (i = 0; i < nfunix; i++) - if (funixn[i] && funix[i] != -1) - (void)unlink(funixn[i]); - exit(1); -} - -/* - * INIT -- Initialize syslogd from configuration table - */ -static void -init(int signo) -{ - int i; - FILE *cf; - struct filed *f, *next, **nextp; - char *p; - char cline[LINE_MAX]; - char prog[NAME_MAX+1]; - char host[MAXHOSTNAMELEN]; - char oldLocalHostName[MAXHOSTNAMELEN]; - char hostMsg[2*MAXHOSTNAMELEN+40]; - char bootfileMsg[LINE_MAX]; - - dprintf("init\n"); - - /* - * Load hostname (may have changed). - */ - if (signo != 0) - (void)strlcpy(oldLocalHostName, LocalHostName, - sizeof(oldLocalHostName)); - if (gethostname(LocalHostName, sizeof(LocalHostName))) - err(EX_OSERR, "gethostname() failed"); - if ((p = strchr(LocalHostName, '.')) != NULL) { - *p++ = '\0'; - LocalDomain = p; - } else { - LocalDomain = ""; - } - - /* - * Close all open log files. - */ - Initialized = 0; - for (f = Files; f != NULL; f = next) { - /* flush any pending output */ - if (f->f_prevcount) - fprintlog(f, 0, (char *)NULL); - - switch (f->f_type) { - case F_FILE: - case F_FORW: - case F_CONSOLE: - case F_TTY: - (void)close(f->f_file); - break; - case F_PIPE: - (void)close(f->f_file); - if (f->f_un.f_pipe.f_pid > 0) - deadq_enter(f->f_un.f_pipe.f_pid, - f->f_un.f_pipe.f_pname); - f->f_un.f_pipe.f_pid = 0; - break; - } - next = f->f_next; - if (f->f_program) free(f->f_program); - if (f->f_host) free(f->f_host); - free((char *)f); - } - Files = NULL; - nextp = &Files; - - /* open the configuration file */ - if ((cf = fopen(ConfFile, "r")) == NULL) { - dprintf("cannot open %s\n", ConfFile); - *nextp = (struct filed *)calloc(1, sizeof(*f)); - if (*nextp == NULL) { - logerror("calloc"); - exit(1); - } - cfline("*.ERR\t/dev/console", *nextp, "*", "*"); - (*nextp)->f_next = (struct filed *)calloc(1, sizeof(*f)); - if ((*nextp)->f_next == NULL) { - logerror("calloc"); - exit(1); - } - cfline("*.PANIC\t*", (*nextp)->f_next, "*", "*"); - Initialized = 1; - return; - } - - /* - * Foreach line in the conf table, open that file. - */ - f = NULL; - (void)strlcpy(host, "*", sizeof(host)); - (void)strlcpy(prog, "*", sizeof(prog)); - while (fgets(cline, sizeof(cline), cf) != NULL) { - /* - * check for end-of-section, comments, strip off trailing - * spaces and newline character. #!prog is treated specially: - * following lines apply only to that program. - */ - for (p = cline; isspace(*p); ++p) - continue; - if (*p == 0) - continue; - if (*p == '#') { - p++; - if (*p != '!' && *p != '+' && *p != '-') - continue; - } - if (*p == '+' || *p == '-') { - host[0] = *p++; - while (isspace(*p)) - p++; - if ((!*p) || (*p == '*')) { - (void)strlcpy(host, "*", sizeof(host)); - continue; - } - if (*p == '@') - p = LocalHostName; - for (i = 1; i < MAXHOSTNAMELEN - 1; i++) { - if (!isalnum(*p) && *p != '.' && *p != '-' - && *p != ',') - break; - host[i] = *p++; - } - host[i] = '\0'; - continue; - } - if (*p == '!') { - p++; - while (isspace(*p)) p++; - if ((!*p) || (*p == '*')) { - (void)strlcpy(prog, "*", sizeof(prog)); - continue; - } - for (i = 0; i < NAME_MAX; i++) { - if (!isprint(p[i])) - break; - prog[i] = p[i]; - } - prog[i] = 0; - continue; - } - for (p = strchr(cline, '\0'); isspace(*--p);) - continue; - *++p = '\0'; - f = (struct filed *)calloc(1, sizeof(*f)); - if (f == NULL) { - logerror("calloc"); - exit(1); - } - *nextp = f; - nextp = &f->f_next; - cfline(cline, f, prog, host); - } - - /* close the configuration file */ - (void)fclose(cf); - - Initialized = 1; - - if (Debug) { - for (f = Files; f; f = f->f_next) { - for (i = 0; i <= LOG_NFACILITIES; i++) - if (f->f_pmask[i] == INTERNAL_NOPRI) - printf("X "); - else - printf("%d ", f->f_pmask[i]); - printf("%s: ", TypeNames[f->f_type]); - switch (f->f_type) { - case F_FILE: - printf("%s", f->f_un.f_fname); - break; - - case F_CONSOLE: - case F_TTY: - printf("%s%s", _PATH_DEV, f->f_un.f_fname); - break; - - case F_FORW: - printf("%s", f->f_un.f_forw.f_hname); - break; - - case F_PIPE: - printf("%s", f->f_un.f_pipe.f_pname); - break; - - case F_USERS: - for (i = 0; i < MAXUNAMES && *f->f_un.f_uname[i]; i++) - printf("%s, ", f->f_un.f_uname[i]); - break; - } - if (f->f_program) - printf(" (%s)", f->f_program); - printf("\n"); - } - } - - logmsg(LOG_SYSLOG|LOG_INFO, "syslogd: restart", LocalHostName, ADDDATE); - dprintf("syslogd: restarted\n"); - /* - * Log a change in hostname, but only on a restart. - */ - if (signo != 0 && strcmp(oldLocalHostName, LocalHostName) != 0) { - (void)snprintf(hostMsg, sizeof(hostMsg), - "syslogd: hostname changed, \"%s\" to \"%s\"", - oldLocalHostName, LocalHostName); - logmsg(LOG_SYSLOG|LOG_INFO, hostMsg, LocalHostName, ADDDATE); - dprintf("%s\n", hostMsg); - } - /* - * Log the kernel boot file if we aren't going to use it as - * the prefix, and if this is *not* a restart. - */ - if (signo == 0 && !use_bootfile) { - (void)snprintf(bootfileMsg, sizeof(bootfileMsg), - "syslogd: kernel boot file is %s", bootfile); - logmsg(LOG_KERN|LOG_INFO, bootfileMsg, LocalHostName, ADDDATE); - dprintf("%s\n", bootfileMsg); - } -} - -/* - * Crack a configuration file line - */ -static void -cfline(const char *line, struct filed *f, const char *prog, const char *host) -{ - struct addrinfo hints, *res; - int error, i, pri; - const char *p, *q; - char *bp, *port; - char buf[MAXLINE], ebuf[100]; - - dprintf("cfline(\"%s\", f, \"%s\", \"%s\")\n", line, prog, host); - - errno = 0; /* keep strerror() stuff out of logerror messages */ - - /* clear out file entry */ - memset(f, 0, sizeof(*f)); - for (i = 0; i <= LOG_NFACILITIES; i++) - f->f_pmask[i] = INTERNAL_NOPRI; - - /* save hostname if any */ - if (host && *host == '*') - host = NULL; - if (host) { - int hl, dl; - - f->f_host = strdup(host); - if (f->f_host == NULL) { - logerror("strdup"); - exit(1); - } - hl = strlen(f->f_host); - if (f->f_host[hl-1] == '.') - f->f_host[--hl] = '\0'; - dl = strlen(LocalDomain) + 1; - if (hl > dl && f->f_host[hl-dl] == '.' && - strcasecmp(f->f_host + hl - dl + 1, LocalDomain) == 0) - f->f_host[hl-dl] = '\0'; - } - - /* save program name if any */ - if (prog && *prog == '*') - prog = NULL; - if (prog) { - f->f_program = strdup(prog); - if (f->f_program == NULL) { - logerror("strdup"); - exit(1); - } - } - - /* scan through the list of selectors */ - for (p = line; *p && *p != '\t' && *p != ' ';) { - int pri_done; - int pri_cmp; - int pri_invert; - - /* find the end of this facility name list */ - for (q = p; *q && *q != '\t' && *q != ' ' && *q++ != '.'; ) - continue; - - /* get the priority comparison */ - pri_cmp = 0; - pri_done = 0; - pri_invert = 0; - if (*q == '!') { - pri_invert = 1; - q++; - } - while (!pri_done) { - switch (*q) { - case '<': - pri_cmp |= PRI_LT; - q++; - break; - case '=': - pri_cmp |= PRI_EQ; - q++; - break; - case '>': - pri_cmp |= PRI_GT; - q++; - break; - default: - pri_done++; - break; - } - } - - /* collect priority name */ - for (bp = buf; *q && !strchr("\t,; ", *q); ) - *bp++ = *q++; - *bp = '\0'; - - /* skip cruft */ - while (strchr(",;", *q)) - q++; - - /* decode priority name */ - if (*buf == '*') { - pri = LOG_PRIMASK + 1; - pri_cmp = PRI_LT | PRI_EQ | PRI_GT; - } else { - pri = decode(buf, prioritynames); - if (pri < 0) { - (void)snprintf(ebuf, sizeof ebuf, - "unknown priority name \"%s\"", buf); - logerror(ebuf); - return; - } - } - if (!pri_cmp) - pri_cmp = (UniquePriority) - ? (PRI_EQ) - : (PRI_EQ | PRI_GT) - ; - if (pri_invert) - pri_cmp ^= PRI_LT | PRI_EQ | PRI_GT; - - /* scan facilities */ - while (*p && !strchr("\t.; ", *p)) { - for (bp = buf; *p && !strchr("\t,;. ", *p); ) - *bp++ = *p++; - *bp = '\0'; - - if (*buf == '*') { - for (i = 0; i < LOG_NFACILITIES; i++) { - f->f_pmask[i] = pri; - f->f_pcmp[i] = pri_cmp; - } - } else { - i = decode(buf, facilitynames); - if (i < 0) { - (void)snprintf(ebuf, sizeof ebuf, - "unknown facility name \"%s\"", - buf); - logerror(ebuf); - return; - } - f->f_pmask[i >> 3] = pri; - f->f_pcmp[i >> 3] = pri_cmp; - } - while (*p == ',' || *p == ' ') - p++; - } - - p = q; - } - - /* skip to action part */ - while (*p == '\t' || *p == ' ') - p++; - - switch (*p) { - case '@': - port = (char *)p; - p = strsep(&port, ":"); - (void)strlcpy(f->f_un.f_forw.f_hname, ++p, - sizeof(f->f_un.f_forw.f_hname)); - memset(&hints, 0, sizeof(hints)); - hints.ai_family = family; - hints.ai_socktype = SOCK_DGRAM; - error = getaddrinfo(f->f_un.f_forw.f_hname, port ? port : "syslog", &hints, - &res); - if (error) { - logerror(gai_strerror(error)); - break; - } - f->f_un.f_forw.f_addr = res; - f->f_type = F_FORW; - break; - - case '/': - /* Delay opening files until we're ready to log to them */ - f->f_file = -1; - if (strncmp(p, _PATH_DEV, sizeof(_PATH_DEV)-1) == 0) - f->f_type = F_CHECKTTY; - else - f->f_type = F_FILE; - (void)strlcpy(f->f_un.f_fname, p, sizeof(f->f_un.f_fname)); - break; - - case '|': - f->f_un.f_pipe.f_pid = 0; - (void)strlcpy(f->f_un.f_fname, p + 1, sizeof(f->f_un.f_fname)); - f->f_type = F_PIPE; - break; - - case '*': - f->f_type = F_WALL; - break; - - default: - for (i = 0; i < MAXUNAMES && *p; i++) { - for (q = p; *q && *q != ','; ) - q++; - (void)strncpy(f->f_un.f_uname[i], p, UT_NAMESIZE); - if ((q - p) > UT_NAMESIZE) - f->f_un.f_uname[i][UT_NAMESIZE] = '\0'; - else - f->f_un.f_uname[i][q - p] = '\0'; - while (*q == ',' || *q == ' ') - q++; - p = q; - } - f->f_type = F_USERS; - break; - } -} - - -/* - * Decode a symbolic name to a numeric value - */ -static int -decode(const char *name, CODE *codetab) -{ - CODE *c; - char *p, buf[40]; - - if (isdigit(*name)) - return (atoi(name)); - - for (p = buf; *name && p < &buf[sizeof(buf) - 1]; p++, name++) { - if (isupper(*name)) - *p = tolower(*name); - else - *p = *name; - } - *p = '\0'; - for (c = codetab; c->c_name; c++) - if (!strcmp(buf, c->c_name)) - return (c->c_val); - - return (-1); -} - -static void -markit(void) -{ - struct filed *f; - dq_t q, next; - - now = time((time_t *)NULL); - MarkSeq += TIMERINTVL; - if (MarkInterval && (MarkSeq >= MarkInterval)) { - logmsg(LOG_INFO, "-- MARK --", - LocalHostName, ADDDATE|MARK); - MarkSeq = 0; - } - - for (f = Files; f; f = f->f_next) { - if (f->f_prevcount && now >= REPEATTIME(f)) { - dprintf("flush %s: repeated %d times, %d sec.\n", - TypeNames[f->f_type], f->f_prevcount, - repeatinterval[f->f_repeatcount]); - fprintlog(f, 0, (char *)NULL); - BACKOFF(f); - } - } - - /* Walk the dead queue, and see if we should signal somebody. */ - for (q = TAILQ_FIRST(&deadq_head); q != NULL; q = next) { - next = TAILQ_NEXT(q, dq_entries); - - switch (q->dq_timeout) { - case 0: - /* Already signalled once, try harder now. */ - if (kill(q->dq_pid, SIGKILL) != 0) - (void)deadq_remove(q->dq_pid); - break; - - case 1: - /* - * Timed out on dead queue, send terminate - * signal. Note that we leave the removal - * from the dead queue to reapchild(), which - * will also log the event (unless the process - * didn't even really exist, in case we simply - * drop it from the dead queue). - */ - if (kill(q->dq_pid, SIGTERM) != 0) - (void)deadq_remove(q->dq_pid); - /* FALLTHROUGH */ - - default: - q->dq_timeout--; - } - } - MarkSet = 0; - (void)alarm(TIMERINTVL); -} - -/* - * fork off and become a daemon, but wait for the child to come online - * before returing to the parent, or we get disk thrashing at boot etc. - * Set a timer so we don't hang forever if it wedges. - */ -static int -waitdaemon(int nochdir, int noclose, int maxwait) -{ - int fd; - int status; - pid_t pid, childpid; - - switch (childpid = fork()) { - case -1: - return (-1); - case 0: - break; - default: - signal(SIGALRM, timedout); - alarm(maxwait); - while ((pid = wait3(&status, 0, NULL)) != -1) { - if (WIFEXITED(status)) - errx(1, "child pid %d exited with return code %d", - pid, WEXITSTATUS(status)); - if (WIFSIGNALED(status)) - errx(1, "child pid %d exited on signal %d%s", - pid, WTERMSIG(status), - WCOREDUMP(status) ? " (core dumped)" : - ""); - if (pid == childpid) /* it's gone... */ - break; - } - exit(0); - } - - if (setsid() == -1) - return (-1); - - if (!nochdir) - (void)chdir("/"); - - if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); - if (fd > 2) - (void)close (fd); - } - return (getppid()); -} - -/* - * We get a SIGALRM from the child when it's running and finished doing it's - * fsync()'s or O_SYNC writes for all the boot messages. - * - * We also get a signal from the kernel if the timer expires, so check to - * see what happened. - */ -static void -timedout(int sig ) -{ - int left; - left = alarm(0); - signal(SIGALRM, SIG_DFL); - if (left == 0) - errx(1, "timed out waiting for child"); - else - _exit(0); -} - -/* - * Add `s' to the list of allowable peer addresses to accept messages - * from. - * - * `s' is a string in the form: - * - * [*]domainname[:{servicename|portnumber|*}] - * - * or - * - * netaddr/maskbits[:{servicename|portnumber|*}] - * - * Returns -1 on error, 0 if the argument was valid. - */ -static int -allowaddr(char *s) -{ - char *cp1, *cp2; - struct allowedpeer ap; - struct servent *se; - int masklen = -1, i; - struct addrinfo hints, *res; - struct in_addr *addrp, *maskp; - u_int32_t *addr6p, *mask6p; - char ip[NI_MAXHOST]; - -#ifdef INET6 - if (*s != '[' || (cp1 = strchr(s + 1, ']')) == NULL) -#endif - cp1 = s; - if ((cp1 = strrchr(cp1, ':'))) { - /* service/port provided */ - *cp1++ = '\0'; - if (strlen(cp1) == 1 && *cp1 == '*') - /* any port allowed */ - ap.port = 0; - else if ((se = getservbyname(cp1, "udp"))) { - ap.port = ntohs(se->s_port); - } else { - ap.port = strtol(cp1, &cp2, 0); - if (*cp2 != '\0') - return (-1); /* port not numeric */ - } - } else { - if ((se = getservbyname("syslog", "udp"))) - ap.port = ntohs(se->s_port); - else - /* sanity, should not happen */ - ap.port = 514; - } - - if ((cp1 = strchr(s, '/')) != NULL && - strspn(cp1 + 1, "0123456789") == strlen(cp1 + 1)) { - *cp1 = '\0'; - if ((masklen = atoi(cp1 + 1)) < 0) - return (-1); - } -#ifdef INET6 - if (*s == '[') { - cp2 = s + strlen(s) - 1; - if (*cp2 == ']') { - ++s; - *cp2 = '\0'; - } else { - cp2 = NULL; - } - } else { - cp2 = NULL; - } -#endif - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_DGRAM; - hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; - if (getaddrinfo(s, NULL, &hints, &res) == 0) { - ap.isnumeric = 1; - memcpy(&ap.a_addr, res->ai_addr, res->ai_addrlen); - memset(&ap.a_mask, 0, sizeof(ap.a_mask)); - ap.a_mask.ss_family = res->ai_family; - if (res->ai_family == AF_INET) { - ap.a_mask.ss_len = sizeof(struct sockaddr_in); - maskp = &((struct sockaddr_in *)&ap.a_mask)->sin_addr; - addrp = &((struct sockaddr_in *)&ap.a_addr)->sin_addr; - if (masklen < 0) { - /* use default netmask */ - if (IN_CLASSA(ntohl(addrp->s_addr))) - maskp->s_addr = htonl(IN_CLASSA_NET); - else if (IN_CLASSB(ntohl(addrp->s_addr))) - maskp->s_addr = htonl(IN_CLASSB_NET); - else - maskp->s_addr = htonl(IN_CLASSC_NET); - } else if (masklen <= 32) { - /* convert masklen to netmask */ - if (masklen == 0) - maskp->s_addr = 0; - else - maskp->s_addr = htonl(~((1 << (32 - masklen)) - 1)); - } else { - freeaddrinfo(res); - return (-1); - } - /* Lose any host bits in the network number. */ - addrp->s_addr &= maskp->s_addr; - } -#ifdef INET6 - else if (res->ai_family == AF_INET6 && masklen <= 128) { - ap.a_mask.ss_len = sizeof(struct sockaddr_in6); - if (masklen < 0) - masklen = 128; - mask6p = (u_int32_t *)&((struct sockaddr_in6 *)&ap.a_mask)->sin6_addr; - /* convert masklen to netmask */ - while (masklen > 0) { - if (masklen < 32) { - *mask6p = htonl(~(0xffffffff >> masklen)); - break; - } - *mask6p++ = 0xffffffff; - masklen -= 32; - } - /* Lose any host bits in the network number. */ - mask6p = (u_int32_t *)&((struct sockaddr_in6 *)&ap.a_mask)->sin6_addr; - addr6p = (u_int32_t *)&((struct sockaddr_in6 *)&ap.a_addr)->sin6_addr; - for (i = 0; i < 4; i++) - addr6p[i] &= mask6p[i]; - } -#endif - else { - freeaddrinfo(res); - return (-1); - } - freeaddrinfo(res); - } else { - /* arg `s' is domain name */ - ap.isnumeric = 0; - ap.a_name = s; - if (cp1) - *cp1 = '/'; -#ifdef INET6 - if (cp2) { - *cp2 = ']'; - --s; - } -#endif - } - - if (Debug) { - printf("allowaddr: rule %d: ", NumAllowed); - if (ap.isnumeric) { - printf("numeric, "); - getnameinfo((struct sockaddr *)&ap.a_addr, - ((struct sockaddr *)&ap.a_addr)->sa_len, - ip, sizeof ip, NULL, 0, - NI_NUMERICHOST | withscopeid); - printf("addr = %s, ", ip); - getnameinfo((struct sockaddr *)&ap.a_mask, - ((struct sockaddr *)&ap.a_mask)->sa_len, - ip, sizeof ip, NULL, 0, - NI_NUMERICHOST | withscopeid); - printf("mask = %s; ", ip); - } else { - printf("domainname = %s; ", ap.a_name); - } - printf("port = %d\n", ap.port); - } - - if ((AllowedPeers = realloc(AllowedPeers, - ++NumAllowed * sizeof(struct allowedpeer))) - == NULL) { - logerror("realloc"); - exit(1); - } - memcpy(&AllowedPeers[NumAllowed - 1], &ap, sizeof(struct allowedpeer)); - return (0); -} - -/* - * Validate that the remote peer has permission to log to us. - */ -static int -validate(struct sockaddr *sa, const char *hname) -{ - int i, j, reject; - size_t l1, l2; - char *cp, name[NI_MAXHOST], ip[NI_MAXHOST], port[NI_MAXSERV]; - struct allowedpeer *ap; - struct sockaddr_in *sin4, *a4p = NULL, *m4p = NULL; - struct sockaddr_in6 *sin6, *a6p = NULL, *m6p = NULL; - struct addrinfo hints, *res; - u_short sport; - - if (NumAllowed == 0) - /* traditional behaviour, allow everything */ - return (1); - - (void)strlcpy(name, hname, sizeof(name)); - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_DGRAM; - hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; - if (getaddrinfo(name, NULL, &hints, &res) == 0) - freeaddrinfo(res); - else if (strchr(name, '.') == NULL) { - strlcat(name, ".", sizeof name); - strlcat(name, LocalDomain, sizeof name); - } - if (getnameinfo(sa, sa->sa_len, ip, sizeof ip, port, sizeof port, - NI_NUMERICHOST | withscopeid | NI_NUMERICSERV) != 0) - return (0); /* for safety, should not occur */ - dprintf("validate: dgram from IP %s, port %s, name %s;\n", - ip, port, name); - sport = atoi(port); - - /* now, walk down the list */ - for (i = 0, ap = AllowedPeers; i < NumAllowed; i++, ap++) { - if (ap->port != 0 && ap->port != sport) { - dprintf("rejected in rule %d due to port mismatch.\n", i); - continue; - } - - if (ap->isnumeric) { - if (ap->a_addr.ss_family != sa->sa_family) { - dprintf("rejected in rule %d due to address family mismatch.\n", i); - continue; - } - if (ap->a_addr.ss_family == AF_INET) { - sin4 = (struct sockaddr_in *)sa; - a4p = (struct sockaddr_in *)&ap->a_addr; - m4p = (struct sockaddr_in *)&ap->a_mask; - if ((sin4->sin_addr.s_addr & m4p->sin_addr.s_addr) - != a4p->sin_addr.s_addr) { - dprintf("rejected in rule %d due to IP mismatch.\n", i); - continue; - } - } -#ifdef INET6 - else if (ap->a_addr.ss_family == AF_INET6) { - sin6 = (struct sockaddr_in6 *)sa; - a6p = (struct sockaddr_in6 *)&ap->a_addr; - m6p = (struct sockaddr_in6 *)&ap->a_mask; -#ifdef NI_WITHSCOPEID - if (a6p->sin6_scope_id != 0 && - sin6->sin6_scope_id != a6p->sin6_scope_id) { - dprintf("rejected in rule %d due to scope mismatch.\n", i); - continue; - } -#endif - reject = 0; - for (j = 0; j < 16; j += 4) { - if ((*(u_int32_t *)&sin6->sin6_addr.s6_addr[j] & *(u_int32_t *)&m6p->sin6_addr.s6_addr[j]) - != *(u_int32_t *)&a6p->sin6_addr.s6_addr[j]) { - ++reject; - break; - } - } - if (reject) { - dprintf("rejected in rule %d due to IP mismatch.\n", i); - continue; - } - } -#endif - else - continue; - } else { - cp = ap->a_name; - l1 = strlen(name); - if (*cp == '*') { - /* allow wildmatch */ - cp++; - l2 = strlen(cp); - if (l2 > l1 || memcmp(cp, &name[l1 - l2], l2) != 0) { - dprintf("rejected in rule %d due to name mismatch.\n", i); - continue; - } - } else { - /* exact match */ - l2 = strlen(cp); - if (l2 != l1 || memcmp(cp, name, l1) != 0) { - dprintf("rejected in rule %d due to name mismatch.\n", i); - continue; - } - } - } - dprintf("accepted in rule %d.\n", i); - return (1); /* hooray! */ - } - return (0); -} - -/* - * Fairly similar to popen(3), but returns an open descriptor, as - * opposed to a FILE *. - */ -static int -p_open(const char *prog, pid_t *pid) -{ - int pfd[2], nulldesc, i; - sigset_t omask, mask; - char *argv[4]; /* sh -c cmd NULL */ - char errmsg[200]; - - if (pipe(pfd) == -1) - return (-1); - if ((nulldesc = open(_PATH_DEVNULL, O_RDWR)) == -1) - /* we are royally screwed anyway */ - return (-1); - - sigemptyset(&mask); - sigaddset(&mask, SIGALRM); - sigaddset(&mask, SIGHUP); - sigprocmask(SIG_BLOCK, &mask, &omask); - switch ((*pid = fork())) { - case -1: - sigprocmask(SIG_SETMASK, &omask, 0); - close(nulldesc); - return (-1); - - case 0: - /* XXX should check for NULL return */ - argv[0] = strdup("sh"); - argv[1] = strdup("-c"); - argv[2] = strdup(prog); - argv[3] = NULL; - if (argv[0] == NULL || argv[1] == NULL || argv[2] == NULL) { - logerror("strdup"); - exit(1); - } - - alarm(0); - (void)setsid(); /* Avoid catching SIGHUPs. */ - - /* - * Throw away pending signals, and reset signal - * behaviour to standard values. - */ - signal(SIGALRM, SIG_IGN); - signal(SIGHUP, SIG_IGN); - sigprocmask(SIG_SETMASK, &omask, 0); - signal(SIGPIPE, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - signal(SIGALRM, SIG_DFL); - signal(SIGHUP, SIG_DFL); - - dup2(pfd[0], STDIN_FILENO); - dup2(nulldesc, STDOUT_FILENO); - dup2(nulldesc, STDERR_FILENO); - for (i = getdtablesize(); i > 2; i--) - (void)close(i); - - (void)execvp(_PATH_BSHELL, argv); - _exit(255); - } - - sigprocmask(SIG_SETMASK, &omask, 0); - close(nulldesc); - close(pfd[0]); - /* - * Avoid blocking on a hung pipe. With O_NONBLOCK, we are - * supposed to get an EWOULDBLOCK on writev(2), which is - * caught by the logic above anyway, which will in turn close - * the pipe, and fork a new logging subprocess if necessary. - * The stale subprocess will be killed some time later unless - * it terminated itself due to closing its input pipe (so we - * get rid of really dead puppies). - */ - if (fcntl(pfd[1], F_SETFL, O_NONBLOCK) == -1) { - /* This is bad. */ - (void)snprintf(errmsg, sizeof errmsg, - "Warning: cannot change pipe to PID %d to " - "non-blocking behaviour.", - (int)*pid); - logerror(errmsg); - } - return (pfd[1]); -} - -static void -deadq_enter(pid_t pid, const char *name) -{ - dq_t p; - int status; - - /* - * Be paranoid, if we can't signal the process, don't enter it - * into the dead queue (perhaps it's already dead). If possible, - * we try to fetch and log the child's status. - */ - if (kill(pid, 0) != 0) { - if (waitpid(pid, &status, WNOHANG) > 0) - log_deadchild(pid, status, name); - return; - } - - p = malloc(sizeof(struct deadq_entry)); - if (p == NULL) { - logerror("malloc"); - exit(1); - } - - p->dq_pid = pid; - p->dq_timeout = DQ_TIMO_INIT; - TAILQ_INSERT_TAIL(&deadq_head, p, dq_entries); -} - -static int -deadq_remove(pid_t pid) -{ - dq_t q; - - TAILQ_FOREACH(q, &deadq_head, dq_entries) { - if (q->dq_pid == pid) { - TAILQ_REMOVE(&deadq_head, q, dq_entries); - free(q); - return (1); - } - } - - return (0); -} - -static void -log_deadchild(pid_t pid, int status, const char *name) -{ - int code; - char buf[256]; - const char *reason; - - errno = 0; /* Keep strerror() stuff out of logerror messages. */ - if (WIFSIGNALED(status)) { - reason = "due to signal"; - code = WTERMSIG(status); - } else { - reason = "with status"; - code = WEXITSTATUS(status); - if (code == 0) - return; - } - (void)snprintf(buf, sizeof buf, - "Logging subprocess %d (%s) exited %s %d.", - pid, name, reason, code); - logerror(buf); -} - -static int * -socksetup(int af, const char *bindhostname) -{ - struct addrinfo hints, *res, *r; - int error, maxs, *s, *socks; - - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_PASSIVE; - hints.ai_family = af; - hints.ai_socktype = SOCK_DGRAM; - error = getaddrinfo(bindhostname, "syslog", &hints, &res); - if (error) { - logerror(gai_strerror(error)); - errno = 0; - die(0); - } - - /* Count max number of sockets we may open */ - for (maxs = 0, r = res; r; r = r->ai_next, maxs++); - socks = malloc((maxs+1) * sizeof(int)); - if (socks == NULL) { - logerror("couldn't allocate memory for sockets"); - die(0); - } - - *socks = 0; /* num of sockets counter at start of array */ - s = socks + 1; - for (r = res; r; r = r->ai_next) { - *s = socket(r->ai_family, r->ai_socktype, r->ai_protocol); - if (*s < 0) { - logerror("socket"); - continue; - } - if (r->ai_family == AF_INET6) { - int on = 1; - if (setsockopt(*s, IPPROTO_IPV6, IPV6_V6ONLY, - (char *)&on, sizeof (on)) < 0) { - logerror("setsockopt"); - close(*s); - continue; - } - } - if (bind(*s, r->ai_addr, r->ai_addrlen) < 0) { - close(*s); - logerror("bind"); - continue; - } - - (*socks)++; - s++; - } - - if (*socks == 0) { - free(socks); - if (Debug) - return (NULL); - else - die(0); - } - if (res) - freeaddrinfo(res); - - return (socks); -} diff --git a/syslogd.tproj/ttymsg.c b/syslogd.tproj/ttymsg.c deleted file mode 100644 index 7f7a4ce..0000000 --- a/syslogd.tproj/ttymsg.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 1989, 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. - */ - -#ifndef lint -static const char sccsid[] = "@(#)ttymsg.c 8.2 (Berkeley) 11/16/93"; -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ttymsg.h" - -/* - * Display the contents of a uio structure on a terminal. Used by wall(1), - * syslogd(8), and talkd(8). Forks and finishes in child if write would block, - * waiting up to tmout seconds. Returns pointer to error string on unexpected - * error; string is not newline-terminated. Various "normal" errors are - * ignored (exclusive-use, lack of permission, etc.). - */ -const char * -ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout) -{ - struct iovec localiov[7]; - ssize_t left, wret; - int cnt, fd; - static char device[MAXNAMLEN] = _PATH_DEV; - static char errbuf[1024]; - int forked; - - forked = 0; - if (iovcnt > (int)(sizeof(localiov) / sizeof(localiov[0]))) - return ("too many iov's (change code in wall/ttymsg.c)"); - - strlcpy(device + sizeof(_PATH_DEV) - 1, line, sizeof(device)); - if (strchr(device + sizeof(_PATH_DEV) - 1, '/')) { - /* A slash is an attempt to break security... */ - (void) snprintf(errbuf, sizeof(errbuf), - "Too many '/' in \"%s\"", device); - return (errbuf); - } - - /* - * open will fail on slip lines or exclusive-use lines - * if not running as root; not an error. - */ - if ((fd = open(device, O_WRONLY|O_NONBLOCK, 0)) < 0) { - if (errno == EBUSY || errno == EACCES) - return (NULL); - (void) snprintf(errbuf, sizeof(errbuf), "%s: %s", device, - strerror(errno)); - return (errbuf); - } - - for (cnt = 0, left = 0; cnt < iovcnt; ++cnt) - left += iov[cnt].iov_len; - - for (;;) { - wret = writev(fd, iov, iovcnt); - if (wret >= left) - break; - if (wret >= 0) { - left -= wret; - if (iov != localiov) { - bcopy(iov, localiov, - iovcnt * sizeof(struct iovec)); - iov = localiov; - } - for (cnt = 0; (size_t)wret >= iov->iov_len; ++cnt) { - wret -= iov->iov_len; - ++iov; - --iovcnt; - } - if (wret) { - iov->iov_base = (char *)iov->iov_base + wret; - iov->iov_len -= wret; - } - continue; - } - if (errno == EWOULDBLOCK) { - int cpid; - - if (forked) { - (void) close(fd); - _exit(1); - } - cpid = fork(); - if (cpid < 0) { - (void) snprintf(errbuf, sizeof(errbuf), - "fork: %s", strerror(errno)); - (void) close(fd); - return (errbuf); - } - if (cpid) { /* parent */ - (void) close(fd); - return (NULL); - } - forked++; - /* wait at most tmout seconds */ - (void) signal(SIGALRM, SIG_DFL); - (void) signal(SIGTERM, SIG_DFL); /* XXX */ - (void) sigsetmask(0); - (void) alarm((u_int)tmout); - (void) fcntl(fd, F_SETFL, 0); /* clear O_NONBLOCK */ - continue; - } - /* - * We get ENODEV on a slip line if we're running as root, - * and EIO if the line just went away. - */ - if (errno == ENODEV || errno == EIO) - break; - (void) close(fd); - if (forked) - _exit(1); - (void) snprintf(errbuf, sizeof(errbuf), - "%s: %s", device, strerror(errno)); - return (errbuf); - } - - (void) close(fd); - if (forked) - _exit(0); - return (NULL); -} diff --git a/syslogd.tproj/ttymsg.h b/syslogd.tproj/ttymsg.h deleted file mode 100644 index 625c22d..0000000 --- a/syslogd.tproj/ttymsg.h +++ /dev/null @@ -1,3 +0,0 @@ -/* $FreeBSD: src/usr.bin/wall/ttymsg.h,v 1.1 2001/09/09 14:23:31 dd Exp $ */ - -const char *ttymsg(struct iovec *, int, const char *, int); diff --git a/talk.tproj/Makefile b/talk.tproj/Makefile index 6a97894..81c52ce 100644 --- a/talk.tproj/Makefile +++ b/talk.tproj/Makefile @@ -17,7 +17,7 @@ HFILES = talk.h talk_ctl.h CFILES = ctl.c ctl_transact.c display.c get_addrs.c get_names.c\ init_disp.c invite.c io.c look_up.c msgs.c talk.c -OTHERSRCS = Makefile.preamble Makefile talk.1 +OTHERSRCS = Makefile.preamble Makefile talk.1 Makefile.postamble MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/talk.tproj/Makefile.postamble b/talk.tproj/Makefile.postamble new file mode 100644 index 0000000..c29d177 --- /dev/null +++ b/talk.tproj/Makefile.postamble @@ -0,0 +1,3 @@ +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man1 + install -c -m 444 talk.1 $(DSTROOT)/usr/share/man/man1/talk.1 diff --git a/talk.tproj/ctl.c b/talk.tproj/ctl.c index 1817074..d1c016b 100644 --- a/talk.tproj/ctl.c +++ b/talk.tproj/ctl.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/ctl_transact.c b/talk.tproj/ctl_transact.c index c0a93b5..85474dd 100644 --- a/talk.tproj/ctl_transact.c +++ b/talk.tproj/ctl_transact.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/display.c b/talk.tproj/display.c index 6644ec1..6a725a6 100644 --- a/talk.tproj/display.c +++ b/talk.tproj/display.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/get_addrs.c b/talk.tproj/get_addrs.c index 7877eab..ce728c5 100644 --- a/talk.tproj/get_addrs.c +++ b/talk.tproj/get_addrs.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/get_names.c b/talk.tproj/get_names.c index 58d5e84..adf43bc 100644 --- a/talk.tproj/get_names.c +++ b/talk.tproj/get_names.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/init_disp.c b/talk.tproj/init_disp.c index 7def0d3..1332107 100644 --- a/talk.tproj/init_disp.c +++ b/talk.tproj/init_disp.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/invite.c b/talk.tproj/invite.c index d879366..47fbf44 100644 --- a/talk.tproj/invite.c +++ b/talk.tproj/invite.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/io.c b/talk.tproj/io.c index b32b1e1..7d6fd55 100644 --- a/talk.tproj/io.c +++ b/talk.tproj/io.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/look_up.c b/talk.tproj/look_up.c index ea96da9..3d46cb3 100644 --- a/talk.tproj/look_up.c +++ b/talk.tproj/look_up.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/msgs.c b/talk.tproj/msgs.c index 5fc3927..7e1edb1 100644 --- a/talk.tproj/msgs.c +++ b/talk.tproj/msgs.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/talk.c b/talk.tproj/talk.c index c2145d3..3690d01 100644 --- a/talk.tproj/talk.c +++ b/talk.tproj/talk.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/talk.h b/talk.tproj/talk.h index 5e29a54..2458247 100644 --- a/talk.tproj/talk.h +++ b/talk.tproj/talk.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talk.tproj/talk_ctl.h b/talk.tproj/talk_ctl.h index d73c089..bfe8416 100644 --- a/talk.tproj/talk_ctl.h +++ b/talk.tproj/talk_ctl.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talkd.tproj/Makefile b/talkd.tproj/Makefile index e727fa6..30285e6 100644 --- a/talkd.tproj/Makefile +++ b/talkd.tproj/Makefile @@ -17,7 +17,7 @@ HFILES = talkd.h CFILES = announce.c print.c process.c table.c talkd.c OTHERSRCS = Makefile Makefile.dist Makefile.postamble Makefile.preamble\ - talkd.8 + talkd.8 ntalk.plist MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/talkd.tproj/Makefile.postamble b/talkd.tproj/Makefile.postamble index 9d4f92c..62e6095 100644 --- a/talkd.tproj/Makefile.postamble +++ b/talkd.tproj/Makefile.postamble @@ -111,3 +111,6 @@ STRIPFLAGS = VPATH += :../wall.tproj +after_install: + mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons" + cp ntalk.plist "$(DSTROOT)/System/Library/LaunchDaemons/" diff --git a/talkd.tproj/announce.c b/talkd.tproj/announce.c index 4c6ee5f..cda84a1 100644 --- a/talkd.tproj/announce.c +++ b/talkd.tproj/announce.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talkd.tproj/ntalk.plist b/talkd.tproj/ntalk.plist new file mode 100644 index 0000000..2e63da2 --- /dev/null +++ b/talkd.tproj/ntalk.plist @@ -0,0 +1,29 @@ + + + + + Disabled + + Label + com.apple.ntalkd + ProgramArguments + + /usr/libexec/ntalkd + + inetdCompatibility + + Wait + + + Sockets + + Listeners + + SockServiceName + ntalk + SockType + dgram + + + + diff --git a/talkd.tproj/print.c b/talkd.tproj/print.c index d4222b3..74f7aa8 100644 --- a/talkd.tproj/print.c +++ b/talkd.tproj/print.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talkd.tproj/process.c b/talkd.tproj/process.c index d9a87a2..c7d7b2c 100644 --- a/talkd.tproj/process.c +++ b/talkd.tproj/process.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talkd.tproj/table.c b/talkd.tproj/table.c index 5b6ee3f..df3fb23 100644 --- a/talkd.tproj/table.c +++ b/talkd.tproj/table.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talkd.tproj/talkd.c b/talkd.tproj/talkd.c index 540e17e..7281351 100644 --- a/talkd.tproj/talkd.c +++ b/talkd.tproj/talkd.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/talkd.tproj/talkd.h b/talkd.tproj/talkd.h index afb5692..9a686c5 100644 --- a/talkd.tproj/talkd.h +++ b/talkd.tproj/talkd.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/telnet.tproj/Makefile b/telnet.tproj/Makefile index a1b8b2a..5b2c075 100644 --- a/telnet.tproj/Makefile +++ b/telnet.tproj/Makefile @@ -18,7 +18,7 @@ HFILES = externs.h fdset.h general.h krb4-proto.h ring.h types.h\ CFILES = authenc.c commands.c main.c network.c ring.c sys_bsd.c\ telnet.c terminal.c tn3270.c utilities.c -OTHERSRCS = Makefile.preamble Makefile README telnet.1 Makefile.dist +OTHERSRCS = Makefile.preamble Makefile README telnet.1 Makefile.dist Makefile.postamble MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/telnet.tproj/Makefile.postamble b/telnet.tproj/Makefile.postamble new file mode 100644 index 0000000..e1a5207 --- /dev/null +++ b/telnet.tproj/Makefile.postamble @@ -0,0 +1,3 @@ +after_install: + install -d $(DSTROOT)/usr/share/man/man1 + install -c -m 444 telnet.1 $(DSTROOT)/usr/share/man/man1 diff --git a/telnet.tproj/krb4-proto.h b/telnet.tproj/krb4-proto.h index 595b654..9f3f0b0 100644 --- a/telnet.tproj/krb4-proto.h +++ b/telnet.tproj/krb4-proto.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/telnet.tproj/telnet.c b/telnet.tproj/telnet.c index 3f4ccba..aaf3906 100644 --- a/telnet.tproj/telnet.c +++ b/telnet.tproj/telnet.c @@ -56,7 +56,6 @@ static const char sccsid[] = "@(#)telnet.c 8.4 (Berkeley) 5/30/95"; #include #include #include -#include #include #include @@ -1324,6 +1323,7 @@ slc_check(void) } unsigned char slc_reply[128]; +unsigned char const * const slc_reply_eom = &slc_reply[sizeof(slc_reply)]; unsigned char *slc_replyp; void @@ -1339,6 +1339,14 @@ slc_start_reply(void) void slc_add_reply(unsigned char func, unsigned char flags, cc_t value) { + /* A sequence of up to 6 bytes my be written for this member of the SLC + * suboption list by this function. The end of negotiation command, + * which is written by slc_end_reply(), will require 2 additional + * bytes. Do not proceed unless there is sufficient space for these + * items. + */ + if (&slc_replyp[6+2] > slc_reply_eom) + return; if ((*slc_replyp++ = func) == IAC) *slc_replyp++ = IAC; if ((*slc_replyp++ = flags) == IAC) @@ -1523,11 +1531,11 @@ env_opt_add(unsigned char *ep) return; } vp = env_getvalue(ep); - if (opt_replyp + (vp ? strlen((char *)vp) : 0) + - strlen((char *)ep) + 6 > opt_replyend) + if (opt_replyp + 2*(vp ? strlen((char *)vp) : 0) + + 2*strlen((char *)ep) + 6 > opt_replyend) { int len; - opt_replyend += OPT_REPLY_SIZE; + opt_replyend += OPT_REPLY_SIZE + 2*strlen((char *)ep) + 2*(vp ? strlen((char *)vp) : 0); len = opt_replyend - opt_reply; opt_reply = (unsigned char *)realloc(opt_reply, len); if (opt_reply == NULL) { diff --git a/telnet.tproj/tn3270.c b/telnet.tproj/tn3270.c index 7edae66..875d386 100644 --- a/telnet.tproj/tn3270.c +++ b/telnet.tproj/tn3270.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/telnetd.tproj/Makefile b/telnetd.tproj/Makefile index 15956b4..b254b4d 100644 --- a/telnetd.tproj/Makefile +++ b/telnetd.tproj/Makefile @@ -17,7 +17,7 @@ HFILES = defs.h ext.h pathnames.h telnetd.h CFILES = global.c slc.c state.c sys_term.c telnetd.c\ termstat.c utility.c vasprintf.c strlcpy.c -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble telnetd.8 +OTHERSRCS = Makefile.preamble Makefile Makefile.postamble telnetd.8 telnet.plist MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/telnetd.tproj/Makefile.postamble b/telnetd.tproj/Makefile.postamble index 1394e5c..d73e455 100644 --- a/telnetd.tproj/Makefile.postamble +++ b/telnetd.tproj/Makefile.postamble @@ -112,3 +112,5 @@ STRIPFLAGS = after_install: install -o root -g wheel -m 755 -d $(DSTROOT)/usr/share/man/man8 install -o root -g wheel -m 644 -c telnetd.8 $(DSTROOT)/usr/share/man/man8 + mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons" + cp telnet.plist "$(DSTROOT)/System/Library/LaunchDaemons/" diff --git a/telnetd.tproj/telnet.plist b/telnetd.tproj/telnet.plist new file mode 100644 index 0000000..1ef785b --- /dev/null +++ b/telnetd.tproj/telnet.plist @@ -0,0 +1,29 @@ + + + + + Disabled + + Label + com.apple.telnetd + ProgramArguments + + /usr/libexec/telnetd + + inetdCompatibility + + Wait + + + Sockets + + Listeners + + SockServiceName + telnet + Bonjour + + + + + diff --git a/telnetd.tproj/vasprintf.c b/telnetd.tproj/vasprintf.c index 1bc5d7f..ad4aed6 100644 --- a/telnetd.tproj/vasprintf.c +++ b/telnetd.tproj/vasprintf.c @@ -33,13 +33,14 @@ static char rcsid[] = "$FreeBSD: src/lib/libc/stdio/vasprintf.c,v 1.12 2001/01/2 #include #include +#include #include int vasprintf(str, fmt, ap) char **str; const char *fmt; - _BSD_VA_LIST_ ap; + va_list ap; { int ret; FILE f; diff --git a/tftp.tproj/Makefile b/tftp.tproj/Makefile index e28658a..e0fe8f1 100644 --- a/tftp.tproj/Makefile +++ b/tftp.tproj/Makefile @@ -12,11 +12,11 @@ NAME = tftp PROJECTVERSION = 2.8 PROJECT_TYPE = Tool -HFILES = extern.h tftpsubs.h +HFILES = extern.h tftpsubs.h tftp.h CFILES = main.c tftp.c tftpsubs.c -OTHERSRCS = Makefile.preamble Makefile tftp.1 +OTHERSRCS = Makefile.preamble Makefile tftp.1 Makefile.postamble MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/tftp.tproj/Makefile.postamble b/tftp.tproj/Makefile.postamble new file mode 100644 index 0000000..22d6cdd --- /dev/null +++ b/tftp.tproj/Makefile.postamble @@ -0,0 +1,3 @@ +after_install: + install -d $(DSTROOT)/usr/share/man/man1 + install -c -m 444 tftp.1 $(DSTROOT)/usr/share/man/man1 diff --git a/tftp.tproj/extern.h b/tftp.tproj/extern.h index 5bee6a0..6cdac3d 100644 --- a/tftp.tproj/extern.h +++ b/tftp.tproj/extern.h @@ -1,27 +1,5 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ +/* $NetBSD: extern.h,v 1.3 2003/08/07 11:16:13 agc Exp $ */ + /* * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -34,11 +12,7 @@ * 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 + * 3. 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. * @@ -58,4 +32,4 @@ */ void recvfile __P((int, char *, char *)); -void tftp_sendfile __P((int, char *, char *)); +void sendfile __P((int, char *, char *)); diff --git a/tftp.tproj/main.c b/tftp.tproj/main.c index cef16e5..1202ab9 100644 --- a/tftp.tproj/main.c +++ b/tftp.tproj/main.c @@ -1,27 +1,5 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ +/* $NetBSD: main.c,v 1.19 2003/10/02 23:31:52 itojun Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -34,11 +12,7 @@ * 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 + * 3. 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. * @@ -55,11 +29,15 @@ * SUCH DAMAGE. */ - +#include #ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1983, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#if 0 +static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: main.c,v 1.19 2003/10/02 23:31:52 itojun Exp $"); +#endif #endif /* not lint */ /* Many bug fixes are from Jim Guyton */ @@ -69,13 +47,15 @@ static char copyright[] = */ #include #include -#include #include #include +#include "tftp.h" #include +#include +#include #include #include #include @@ -88,21 +68,23 @@ static char copyright[] = #include "extern.h" #define TIMEOUT 5 /* secs between rexmt's */ - -struct sockaddr_in peeraddr; +#define LBUFLEN 200 /* size of input buffer */ +#define MAXSEGSIZE 65464 +struct sockaddr_storage peeraddr; int f; -short port; int trace; int verbose; +int tsize=0; +int tout=0; +int def_blksize=SEGSIZE; +int blksize=SEGSIZE; int connected; char mode[32]; -char line[BUFSIZ]; +char line[LBUFLEN]; int margc; char *margv[20]; char *prompt = "tftp"; jmp_buf toplevel; -void intr(); -struct servent *sp; void get __P((int, char **)); void help __P((int, char **)); @@ -111,12 +93,20 @@ void put __P((int, char **)); void quit __P((int, char **)); void setascii __P((int, char **)); void setbinary __P((int, char **)); +void setpeer0 __P((char *, char *)); void setpeer __P((int, char **)); void setrexmt __P((int, char **)); void settimeout __P((int, char **)); void settrace __P((int, char **)); void setverbose __P((int, char **)); +void setblksize __P((int, char **)); +void settsize __P((int, char **)); +void settimeoutopt __P((int, char **)); void status __P((int, char **)); +char *tail __P((char *)); +int main __P((int, char *[])); +void intr __P((int)); +struct cmd *getcmd __P((char *)); static __dead void command __P((void)); @@ -135,6 +125,9 @@ struct cmd { char vhelp[] = "toggle verbose mode"; char thelp[] = "toggle packet tracing"; +char tshelp[] = "toggle extended tsize option"; +char tohelp[] = "toggle extended timeout option"; +char blhelp[] = "set an alternative blocksize (def. 512)"; char chelp[] = "connect to remote tftp"; char qhelp[] = "exit tftp"; char hhelp[] = "print help information"; @@ -154,103 +147,168 @@ struct cmd cmdtab[] = { { "get", rhelp, get }, { "quit", qhelp, quit }, { "verbose", vhelp, setverbose }, + { "blksize", blhelp, setblksize }, + { "tsize", tshelp, settsize }, { "trace", thelp, settrace }, { "status", sthelp, status }, { "binary", bnhelp, setbinary }, { "ascii", ashelp, setascii }, { "rexmt", xhelp, setrexmt }, { "timeout", ihelp, settimeout }, + { "tout", tohelp, settimeoutopt }, { "?", hhelp, help }, { 0 } }; -struct cmd *getcmd(); -char *tail(); -char *index(); -char *rindex(); - int main(argc, argv) int argc; char *argv[]; { - struct sockaddr_in sin; + int c; - sp = getservbyname("tftp", "udp"); - if (sp == 0) { - fprintf(stderr, "tftp: udp/tftp: unknown service\n"); - exit(1); - } - f = socket(AF_INET, SOCK_DGRAM, 0); - if (f < 0) { - perror("tftp: socket"); - exit(3); - } - bzero((char *)&sin, sizeof(sin)); - sin.sin_family = AF_INET; - if (bind(f, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - perror("tftp: bind"); - exit(1); - } + f = -1; strcpy(mode, "netascii"); signal(SIGINT, intr); - if (argc > 1) { + + setprogname(argv[0]); + while ((c = getopt(argc, argv, "e")) != -1) { + switch (c) { + case 'e': + blksize = MAXSEGSIZE; + strcpy(mode, "octet"); + tsize = 1; + tout = 1; + break; + default: + printf("usage: %s [-e] host-name [port]\n", + getprogname()); + exit(1); + } + } + argc -= optind; + argv += optind; + + if (argc >= 1) { if (setjmp(toplevel) != 0) exit(0); + argc++; + argv--; setpeer(argc, argv); } if (setjmp(toplevel) != 0) (void)putchar('\n'); command(); + return (0); } char hostname[100]; +void +setpeer0(host, port) + char *host; + char *port; +{ + struct addrinfo hints, *res0, *res; + int error, soopt; + struct sockaddr_storage ss; + char *cause = "unknown"; + + if (connected) { + close(f); + f = -1; + } + connected = 0; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_protocol = IPPROTO_UDP; + hints.ai_flags = AI_CANONNAME; + if (!port) + port = "tftp"; + error = getaddrinfo(host, port, &hints, &res0); + if (error) { + warnx("%s", gai_strerror(error)); + return; + } + + for (res = res0; res; res = res->ai_next) { + if (res->ai_addrlen > sizeof(peeraddr)) + continue; + f = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (f < 0) { + cause = "socket"; + continue; + } + + memset(&ss, 0, sizeof(ss)); + ss.ss_family = res->ai_family; + ss.ss_len = res->ai_addrlen; + if (bind(f, (struct sockaddr *)&ss, ss.ss_len) < 0) { + cause = "bind"; + close(f); + f = -1; + continue; + } + + break; + } + + if (f >= 0) { + soopt = 65536; + if (setsockopt(f, SOL_SOCKET, SO_SNDBUF, &soopt, sizeof(soopt)) + < 0) { + close(f); + f = -1; + cause = "setsockopt SNDBUF"; + } + if (setsockopt(f, SOL_SOCKET, SO_RCVBUF, &soopt, sizeof(soopt)) + < 0) { + close(f); + f = -1; + cause = "setsockopt RCVBUF"; + } + } + + if (f < 0) + warn("%s", cause); + else { + /* res->ai_addr <= sizeof(peeraddr) is guaranteed */ + memcpy(&peeraddr, res->ai_addr, res->ai_addrlen); + if (res->ai_canonname) { + (void) strlcpy(hostname, res->ai_canonname, + sizeof(hostname)); + } else + (void) strlcpy(hostname, host, sizeof(hostname)); + connected = 1; + } + + freeaddrinfo(res0); +} + void setpeer(argc, argv) int argc; char *argv[]; { - struct hostent *host; if (argc < 2) { strcpy(line, "Connect "); printf("(to) "); - fgets(&line[strlen(line)], BUFSIZ-strlen(line)-1, stdin); + fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin); makeargv(); argc = margc; argv = margv; } - if (argc > 3) { - printf("usage: %s host-name [port]\n", argv[0]); + if ((argc < 2) || (argc > 3)) { + printf("usage: %s [-e] host-name [port]\n", getprogname()); return; } - host = gethostbyname(argv[1]); - if (host) { - peeraddr.sin_family = host->h_addrtype; - bcopy(host->h_addr, &peeraddr.sin_addr, host->h_length); - strcpy(hostname, host->h_name); - } else { - peeraddr.sin_family = AF_INET; - peeraddr.sin_addr.s_addr = inet_addr(argv[1]); - if (peeraddr.sin_addr.s_addr == -1) { - connected = 0; - printf("%s: unknown host\n", argv[1]); - return; - } - strcpy(hostname, argv[1]); - } - port = sp->s_port; - if (argc == 3) { - port = atoi(argv[2]); - if (port < 0) { - printf("%s: bad port number\n", argv[2]); - connected = 0; - return; - } - port = htons(port); - } - connected = 1; + if (argc == 2) + setpeer0(argv[1], NULL); + else + setpeer0(argv[1], argv[2]); } struct modes { @@ -271,7 +329,7 @@ modecmd(argc, argv) int argc; char *argv[]; { - register struct modes *p; + struct modes *p; char *sep; if (argc < 2) { @@ -338,13 +396,13 @@ put(argc, argv) char *argv[]; { int fd; - register int n; - register char *cp, *targ; + int n; + char *cp, *targ; if (argc < 2) { strcpy(line, "send "); printf("(file) "); - fgets(&line[strlen(line)], BUFSIZ-strlen(line)-1, stdin); + fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin); makeargv(); argc = margc; argv = margv; @@ -354,28 +412,22 @@ put(argc, argv) return; } targ = argv[argc - 1]; - if (index(argv[argc - 1], ':')) { + if (strrchr(argv[argc - 1], ':')) { char *cp; - struct hostent *hp; for (n = 1; n < argc - 1; n++) - if (index(argv[n], ':')) { + if (strchr(argv[n], ':')) { putusage(argv[0]); return; } cp = argv[argc - 1]; - targ = index(cp, ':'); + targ = strrchr(cp, ':'); *targ++ = 0; - hp = gethostbyname(cp); - if (hp == NULL) { - fprintf(stderr, "tftp: %s: ", cp); - herror((char *)NULL); - return; + if (cp[0] == '[' && cp[strlen(cp) - 1] == ']') { + cp[strlen(cp) - 1] = '\0'; + cp++; } - bcopy(hp->h_addr, (caddr_t)&peeraddr.sin_addr, hp->h_length); - peeraddr.sin_family = hp->h_addrtype; - connected = 1; - strcpy(hostname, hp->h_name); + setpeer0(cp, NULL); } if (!connected) { printf("No target machine specified.\n"); @@ -385,32 +437,30 @@ put(argc, argv) cp = argc == 2 ? tail(targ) : argv[1]; fd = open(cp, O_RDONLY); if (fd < 0) { - fprintf(stderr, "tftp: "); perror(cp); + warn("%s", cp); return; } if (verbose) printf("putting %s to %s:%s [%s]\n", cp, hostname, targ, mode); - peeraddr.sin_port = port; - tftp_sendfile(fd, targ, mode); + sendfile(fd, targ, mode); return; } /* this assumes the target is a directory */ /* on a remote unix system. hmmmm. */ - cp = index(targ, '\0'); + cp = strchr(targ, '\0'); *cp++ = '/'; for (n = 1; n < argc - 1; n++) { strcpy(cp, tail(argv[n])); fd = open(argv[n], O_RDONLY); if (fd < 0) { - fprintf(stderr, "tftp: "); perror(argv[n]); + warn("%s", argv[n]); continue; } if (verbose) printf("putting %s to %s:%s [%s]\n", argv[n], hostname, targ, mode); - peeraddr.sin_port = port; - tftp_sendfile(fd, targ, mode); + sendfile(fd, targ, mode); } } @@ -431,14 +481,14 @@ get(argc, argv) char *argv[]; { int fd; - register int n; - register char *cp; + int n; + char *cp; char *src; if (argc < 2) { strcpy(line, "get "); printf("(files) "); - fgets(&line[strlen(line)], BUFSIZ-strlen(line)-1, stdin); + fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin); makeargv(); argc = margc; argv = margv; @@ -449,55 +499,49 @@ get(argc, argv) } if (!connected) { for (n = 1; n < argc ; n++) - if (index(argv[n], ':') == 0) { + if (strrchr(argv[n], ':') == 0) { getusage(argv[0]); return; } } for (n = 1; n < argc ; n++) { - src = index(argv[n], ':'); + src = strrchr(argv[n], ':'); if (src == NULL) src = argv[n]; else { - struct hostent *hp; - + char *cp; *src++ = 0; - hp = gethostbyname(argv[n]); - if (hp == NULL) { - fprintf(stderr, "tftp: %s: ", argv[n]); - herror((char *)NULL); - continue; + cp = argv[n]; + if (cp[0] == '[' && cp[strlen(cp) - 1] == ']') { + cp[strlen(cp) - 1] = '\0'; + cp++; } - bcopy(hp->h_addr, (caddr_t)&peeraddr.sin_addr, - hp->h_length); - peeraddr.sin_family = hp->h_addrtype; - connected = 1; - strcpy(hostname, hp->h_name); + setpeer0(cp, NULL); + if (!connected) + continue; } if (argc < 4) { cp = argc == 3 ? argv[2] : tail(src); fd = creat(cp, 0644); if (fd < 0) { - fprintf(stderr, "tftp: "); perror(cp); + warn("%s", cp); return; } if (verbose) printf("getting from %s:%s to %s [%s]\n", hostname, src, cp, mode); - peeraddr.sin_port = port; recvfile(fd, src, mode); break; } cp = tail(src); /* new .. jdg */ fd = creat(cp, 0644); if (fd < 0) { - fprintf(stderr, "tftp: "); perror(cp); + warn("%s", cp); continue; } if (verbose) printf("getting from %s:%s to %s [%s]\n", hostname, src, cp, mode); - peeraddr.sin_port = port; recvfile(fd, src, mode); } } @@ -510,6 +554,33 @@ getusage(s) printf(" %s file file ... file if connected\n", s); } +void +setblksize(argc, argv) + int argc; + char *argv[]; +{ + int t; + + if (argc < 2) { + strcpy(line, "blksize "); + printf("(blksize) "); + fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin); + makeargv(); + argc = margc; + argv = margv; + } + if (argc != 2) { + printf("usage: %s value\n", argv[0]); + return; + } + t = atoi(argv[1]); + if (t < 8 || t > 65464) + printf("%s: bad value\n", argv[1]); + else + blksize = t; +} + +int def_rexmtval = TIMEOUT; int rexmtval = TIMEOUT; void @@ -522,7 +593,7 @@ setrexmt(argc, argv) if (argc < 2) { strcpy(line, "Rexmt-timeout "); printf("(value) "); - fgets(&line[strlen(line)], BUFSIZ-strlen(line)-1, stdin); + fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin); makeargv(); argc = margc; argv = margv; @@ -550,7 +621,7 @@ settimeout(argc, argv) if (argc < 2) { strcpy(line, "Maximum-timeout "); printf("(value) "); - fgets(&line[strlen(line)], BUFSIZ-strlen(line)-1, stdin); + fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin); makeargv(); argc = margc; argv = margv; @@ -582,7 +653,8 @@ status(argc, argv) } void -intr() +intr(dummy) + int dummy; { signal(SIGALRM, SIG_IGN); @@ -594,10 +666,10 @@ char * tail(filename) char *filename; { - register char *s; + char *s; while (*filename) { - s = rindex(filename, '/'); + s = strrchr(filename, '/'); if (s == NULL) break; if (s[1]) @@ -613,18 +685,18 @@ tail(filename) static __dead void command() { - register struct cmd *c; + struct cmd *c; for (;;) { printf("%s> ", prompt); - if (fgets(line, BUFSIZ-1, stdin) == 0) { + if (fgets(line, LBUFLEN, stdin) == 0) { if (feof(stdin)) { exit(0); } else { continue; } } - if (line[0] == 0) + if ((line[0] == 0) || (line[0] == '\n')) continue; makeargv(); if (margc == 0) @@ -644,11 +716,11 @@ command() struct cmd * getcmd(name) - register char *name; + char *name; { - register char *p, *q; - register struct cmd *c, *found; - register int nmatches, longest; + char *p, *q; + struct cmd *c, *found; + int nmatches, longest; longest = 0; nmatches = 0; @@ -677,18 +749,18 @@ getcmd(name) static void makeargv() { - register char *cp; - register char **argp = margv; + char *cp; + char **argp = margv; margc = 0; for (cp = line; *cp;) { - while (isspace(*cp)) + while (isspace((unsigned char)*cp)) cp++; if (*cp == '\0') break; *argp++ = cp; margc += 1; - while (*cp != '\0' && !isspace(*cp)) + while (*cp != '\0' && !isspace((unsigned char)*cp)) cp++; if (*cp == '\0') break; @@ -714,7 +786,7 @@ help(argc, argv) int argc; char *argv[]; { - register struct cmd *c; + struct cmd *c; if (argc == 1) { printf("Commands may be abbreviated. Commands are:\n\n"); @@ -723,7 +795,7 @@ help(argc, argv) return; } while (--argc > 0) { - register char *arg; + char *arg; arg = *++argv; c = getcmd(arg); if (c == (struct cmd *)-1) @@ -752,3 +824,21 @@ setverbose(argc, argv) verbose = !verbose; printf("Verbose mode %s.\n", verbose ? "on" : "off"); } + +void +settsize(argc, argv) + int argc; + char **argv; +{ + tsize = !tsize; + printf("Tsize mode %s.\n", tsize ? "on" : "off"); +} + +void +settimeoutopt(argc, argv) + int argc; + char **argv; +{ + tout = !tout; + printf("Timeout option %s.\n", tout ? "on" : "off"); +} diff --git a/tftp.tproj/tftp.1 b/tftp.tproj/tftp.1 index b2c5a16..604609d 100644 --- a/tftp.tproj/tftp.1 +++ b/tftp.tproj/tftp.1 @@ -1,3 +1,5 @@ +.\" $NetBSD: tftp.1,v 1.18 2003/08/07 11:16:14 agc Exp $ +.\" .\" Copyright (c) 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" @@ -9,11 +11,7 @@ .\" 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 +.\" 3. 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. .\" @@ -31,35 +29,51 @@ .\" .\" @(#)tftp.1 8.2 (Berkeley) 4/18/94 .\" -.Dd April 18, 1994 +.Dd June 11, 2003 .Dt TFTP 1 -.Os BSD 4.3 +.Os .Sh NAME .Nm tftp .Nd trivial file transfer program .Sh SYNOPSIS -.Nm tftp +.Nm +.Op Fl e .Op Ar host +.Op Ar port .Sh DESCRIPTION -.Nm Tftp +.Nm is the user interface to the Internet .Tn TFTP (Trivial File Transfer Protocol), which allows users to transfer files to and from a remote machine. The remote .Ar host +(and optional +.Ar port ) may be specified on the command line, in which case -.Nm tftp +.Nm uses .Ar host -as the default host for future transfers (see the +(and +.Ar port ) +as the default for future transfers (see the .Cm connect command below). +.Pp +The optional +.Fl e +argument sets a binary transfer mode as well as setting the extended options +as if +.Cm tout , +.Cm tsize , +and +.Cm blksize 65464 , +had been given. .Sh COMMANDS Once -.Nm tftp +.Nm is running, it issues the prompt -.LI tftp> +.Ql tftp\*[Gt] and recognizes the following commands: .Pp .Bl -tag -width verbose -compact @@ -72,6 +86,19 @@ Shorthand for "mode ascii" .It Cm binary Shorthand for "mode binary" .Pp +.It Cm blksize Ar blk-size +Set the tftp blksize option to +.Ar blk-size +octets (8-bit bytes). Since the number of blocks in a tftp +.Cm get +or +.Cm put +is 65535, the default block size of 512 bytes only allows a maximum of +just under 32 megabytes to be transferred. The value given for +.Ar blk-size +must be between 8 and 65464, inclusive. +Note that many servers will not respect this option. +.Pp .It Cm connect Ar host-name Op Ar port Set the .Ar host @@ -87,7 +114,7 @@ does not maintain connections between transfers; thus, the .Cm connect command does not actually create a connection, but merely remembers what host is to be used for transfers. -You do not have to use the +You do not have to use the .Cm connect command; the remote host can be specified as part of the .Cm get @@ -110,7 +137,7 @@ If the latter form is used, the last hostname specified becomes the default for future transfers. .Pp .It Cm mode Ar transfer-mode -Set the mode for transfers; +Set the mode for transfers; .Ar transfer-mode may be one of .Em ascii @@ -134,12 +161,17 @@ If the latter form is used, the hostname specified becomes the default for future transfers. If the remote-directory form is used, the remote host is assumed to be a -.Tn UNIX +.Ux machine. +If you need to specify IPv6 numeric address to +.Ar hosts , +wrap them using square bracket like +.Ar [hosts]:filename +to disambiguate the colon. .Pp .It Cm quit Exit -.Nm tftp . +.Nm . An end of file also exits. .Pp .It Cm rexmt Ar retransmission-timeout @@ -151,23 +183,37 @@ Show current status. .It Cm timeout Ar total-transmission-timeout Set the total transmission timeout, in seconds. .Pp +.It Cm tout +Toggle the tftp "timeout" option. If enabled, the client will pass its +.Ar retransmission-timeout +to the server. +Note that many servers will not respect this option. +.Pp .It Cm trace Toggle packet tracing. .Pp +.It Cm tsize +Toggle the tftp "tsize" option. If enabled, the client will pass and +request the filesize of a file at the beginning of a file transfer. +Note that many servers will not respect this option. +.Pp .It Cm verbose Toggle verbose mode. .El -.Sh BUGS -.Pp -Because there is no user-login or validation within -the -.Tn TFTP -protocol, the remote site will probably have some -sort of file-access restrictions in place. The -exact methods are specific to each site and therefore -difficult to document here. .Sh HISTORY The .Nm command appeared in .Bx 4.3 . +IPv6 support was implemented by WIDE/KAME project in 1999. +TFTP options were implemented by Wasabi Systems, Inc., in 2003, +and first appeared in +.Nx 2.0 . +.Sh SECURITY CONSIDERATIONS +Because there is no user-login or validation within +the +.Tn TFTP +protocol, the remote site will probably have some +sort of file-access restrictions in place. +The exact methods are specific to each site and therefore +difficult to document here. diff --git a/tftp.tproj/tftp.c b/tftp.tproj/tftp.c index 8e6e3f8..048c970 100644 --- a/tftp.tproj/tftp.c +++ b/tftp.tproj/tftp.c @@ -1,27 +1,5 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ +/* $NetBSD: tftp.c,v 1.18 2003/08/07 11:16:14 agc Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -34,11 +12,7 @@ * 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 + * 3. 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. * @@ -55,6 +29,14 @@ * SUCH DAMAGE. */ +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: tftp.c,v 1.18 2003/08/07 11:16:14 agc Exp $"); +#endif +#endif /* not lint */ /* Many bug fixes are from Jim Guyton */ @@ -62,81 +44,154 @@ * TFTP User Program -- Protocol Machines */ #include +#include #include +#include #include #include -#include +#include "tftp.h" +#include #include #include #include #include +#include +#include #include +#include #include "extern.h" #include "tftpsubs.h" -extern int errno; - -extern struct sockaddr_in peeraddr; /* filled in by main */ +extern struct sockaddr_storage peeraddr; /* filled in by main */ extern int f; /* the opened socket */ extern int trace; extern int verbose; +extern int def_rexmtval; extern int rexmtval; extern int maxtimeout; +extern int tsize; +extern int tout; +extern int def_blksize; +extern int blksize; -extern jmp_buf toplevel; /* filled in by main */ - -#define PKTSIZE SEGSIZE+4 char ackbuf[PKTSIZE]; int timeout; +extern jmp_buf toplevel; jmp_buf timeoutbuf; -static void nak __P((int)); -static int makerequest __P((int, const char *, struct tftphdr *, const char *)); +static void nak __P((int, struct sockaddr *)); +static int makerequest __P((int, const char *, struct tftphdr *, const char *, off_t)); static void printstats __P((const char *, unsigned long)); static void startclock __P((void)); static void stopclock __P((void)); static void timer __P((int)); static void tpacket __P((const char *, struct tftphdr *, int)); +static int cmpport __P((struct sockaddr *, struct sockaddr *)); + +static void get_options(struct tftphdr *, int); + +static void +get_options(struct tftphdr *ap, int size) +{ + unsigned long val; + char *opt, *endp, *nextopt, *valp; + int l; + + size -= 2; /* skip over opcode */ + opt = ap->th_stuff; + endp = opt + size - 1; + *endp = '\0'; + + while (opt < endp) { + l = strlen(opt) + 1; + valp = opt + l; + if (valp < endp) { + val = strtoul(valp, NULL, 10); + l = strlen(valp) + 1; + nextopt = valp + l; + if (val == ULONG_MAX && errno == ERANGE) { + /* Report illegal value */ + opt = nextopt; + continue; + } + } else { + /* Badly formed OACK */ + break; + } + if (strcmp(opt, "tsize") == 0) { + /* cool, but we'll ignore it */ + } else if (strcmp(opt, "timeout") == 0) { + if (val >= 1 && val <= 255) { + rexmtval = val; + } else { + /* Report error? */ + } + } else if (strcmp(opt, "blksize") == 0) { + if (val >= 8 && val <= MAXSEGSIZE) { + blksize = val; + } else { + /* Report error? */ + } + } else { + /* unknown option */ + } + opt = nextopt; + } +} /* * Send the requested file. */ void -tftp_sendfile(fd, name, mode) +sendfile(fd, name, mode) int fd; char *name; char *mode; { - register struct tftphdr *ap; /* data and ack packets */ - struct tftphdr *r_init(), *dp; - register int n; - volatile int block, size, convert; + struct tftphdr *ap; /* data and ack packets */ + struct tftphdr *dp; + int n; + volatile unsigned int block; + volatile int size, convert; volatile unsigned long amount; - struct sockaddr_in from; + struct sockaddr_storage from; + struct stat sbuf; + off_t filesize=0; int fromlen; FILE *file; + struct sockaddr_storage peer; + struct sockaddr_storage serv; /* valid server port number */ startclock(); /* start stat's clock */ dp = r_init(); /* reset fillbuf/read-ahead code */ ap = (struct tftphdr *)ackbuf; + if (tsize) { + if (fstat(fd, &sbuf) == 0) { + filesize = sbuf.st_size; + } else { + filesize = -1ULL; + } + } file = fdopen(fd, "r"); convert = !strcmp(mode, "netascii"); block = 0; amount = 0; + memcpy(&peer, &peeraddr, peeraddr.ss_len); + memset(&serv, 0, sizeof(serv)); signal(SIGALRM, timer); do { if (block == 0) - size = makerequest(WRQ, name, dp, mode) - 4; + size = makerequest(WRQ, name, dp, mode, filesize) - 4; else { /* size = read(fd, dp->th_data, SEGSIZE); */ - size = readit(file, &dp, convert); + size = readit(file, &dp, blksize, convert); if (size < 0) { - nak(errno + 100); + nak(errno + 100, (struct sockaddr *)&peer); break; } dp->th_opcode = htons((u_short)DATA); @@ -148,12 +203,13 @@ send_data: if (trace) tpacket("sent", dp, size + 4); n = sendto(f, dp, size + 4, 0, - (struct sockaddr *)&peeraddr, sizeof(peeraddr)); + (struct sockaddr *)&peer, peer.ss_len); if (n != size + 4) { - perror("tftp: sendto"); + warn("sendto"); goto abort; } - read_ahead(file, convert); + if (block) + read_ahead(file, blksize, convert); for ( ; ; ) { alarm(rexmtval); do { @@ -163,10 +219,17 @@ send_data: } while (n <= 0); alarm(0); if (n < 0) { - perror("tftp: recvfrom"); + warn("recvfrom"); goto abort; } - peeraddr.sin_port = from.sin_port; /* added */ + if (!serv.ss_family) + serv = from; + else if (!cmpport((struct sockaddr *)&serv, + (struct sockaddr *)&from)) { + warn("server port mismatch"); + goto abort; + } + peer = from; if (trace) tpacket("received", ap, n); /* should verify packet came from server */ @@ -180,13 +243,24 @@ send_data: if (ap->th_opcode == ACK) { int j; + if (ap->th_block == 0) { + /* + * If the extended options are enabled, + * the server just refused 'em all. + * The only one that _really_ + * matters is blksize, but we'll + * clear timeout, too. + */ + blksize = def_blksize; + rexmtval = def_rexmtval; + } if (ap->th_block == block) { break; } /* On an error, try to synchronize * both sides. */ - j = synchnet(f); + j = synchnet(f, blksize+4); if (j && trace) { printf("discarded %d packets\n", j); @@ -195,11 +269,19 @@ send_data: goto send_data; } } + if (ap->th_opcode == OACK) { + if (block == 0) { + blksize = def_blksize; + rexmtval = def_rexmtval; + get_options(ap, n); + break; + } + } } if (block > 0) amount += size; block++; - } while (size == SEGSIZE || block == 1); + } while (size == blksize || block == 1); abort: fclose(file); stopclock(); @@ -216,15 +298,18 @@ recvfile(fd, name, mode) char *name; char *mode; { - register struct tftphdr *ap; - struct tftphdr *dp, *w_init(); - register int n; - volatile int block, size, firsttrip; + struct tftphdr *ap; + struct tftphdr *dp; + int n, oack=0; + volatile unsigned int block; + volatile int size, firsttrip; volatile unsigned long amount; - struct sockaddr_in from; - int fromlen; + struct sockaddr_storage from; + int fromlen, readlen; FILE *file; volatile int convert; /* true if converting crlf -> lf */ + struct sockaddr_storage peer; + struct sockaddr_storage serv; /* valid server port number */ startclock(); dp = w_init(); @@ -234,15 +319,19 @@ recvfile(fd, name, mode) block = 1; firsttrip = 1; amount = 0; + memcpy(&peer, &peeraddr, peeraddr.ss_len); + memset(&serv, 0, sizeof(serv)); signal(SIGALRM, timer); do { if (firsttrip) { - size = makerequest(RRQ, name, ap, mode); + size = makerequest(RRQ, name, ap, mode, 0); + readlen = PKTSIZE; firsttrip = 0; } else { ap->th_opcode = htons((u_short)ACK); ap->th_block = htons((u_short)(block)); + readlen = blksize+4; size = 4; block++; } @@ -251,10 +340,10 @@ recvfile(fd, name, mode) send_ack: if (trace) tpacket("sent", ap, size); - if (sendto(f, ackbuf, size, 0, (struct sockaddr *)&peeraddr, - sizeof(peeraddr)) != size) { + if (sendto(f, ackbuf, size, 0, (struct sockaddr *)&peer, + peer.ss_len) != size) { alarm(0); - perror("tftp: sendto"); + warn("sendto"); goto abort; } write_behind(file, convert); @@ -262,15 +351,22 @@ send_ack: alarm(rexmtval); do { fromlen = sizeof(from); - n = recvfrom(f, dp, PKTSIZE, 0, + n = recvfrom(f, dp, readlen, 0, (struct sockaddr *)&from, &fromlen); } while (n <= 0); alarm(0); if (n < 0) { - perror("tftp: recvfrom"); + warn("recvfrom"); goto abort; } - peeraddr.sin_port = from.sin_port; /* added */ + if (!serv.ss_family) + serv = from; + else if (!cmpport((struct sockaddr *)&serv, + (struct sockaddr *)&from)) { + warn("server port mismatch"); + goto abort; + } + peer = from; if (trace) tpacket("received", dp, n); /* should verify client address */ @@ -284,13 +380,18 @@ send_ack: if (dp->th_opcode == DATA) { int j; + if (dp->th_block == 1 && !oack) { + /* no OACK, revert to defaults */ + blksize = def_blksize; + rexmtval = def_rexmtval; + } if (dp->th_block == block) { break; /* have next packet */ } /* On an error, try to synchronize * both sides. */ - j = synchnet(f); + j = synchnet(f, blksize); if (j && trace) { printf("discarded %d packets\n", j); } @@ -298,20 +399,33 @@ send_ack: goto send_ack; /* resend ack */ } } + if (dp->th_opcode == OACK) { + if (block == 1) { + oack = 1; + blksize = def_blksize; + rexmtval = def_rexmtval; + get_options(dp, n); + ap->th_opcode = htons(ACK); + ap->th_block = 0; + readlen = blksize+4; + size = 4; + goto send_ack; + } + } } /* size = write(fd, dp->th_data, n - 4); */ size = writeit(file, &dp, n - 4, convert); if (size < 0) { - nak(errno + 100); + nak(errno + 100, (struct sockaddr *)&peer); break; } amount += size; - } while (size == SEGSIZE); + } while (size == blksize || block == 1); abort: /* ok to ack, since user */ ap->th_opcode = htons((u_short)ACK); /* has seen err msg */ ap->th_block = htons((u_short)block); - (void) sendto(f, ackbuf, 4, 0, (struct sockaddr *)&peeraddr, - sizeof(peeraddr)); + (void) sendto(f, ackbuf, 4, 0, (struct sockaddr *)&peer, + peer.ss_len); write_behind(file, convert); /* flush last buffer */ fclose(file); stopclock(); @@ -320,28 +434,57 @@ abort: /* ok to ack, since user */ } static int -makerequest(request, name, tp, mode) +makerequest(request, name, tp, mode, filesize) int request; const char *name; struct tftphdr *tp; const char *mode; + off_t filesize; { - register char *cp; + char *cp; tp->th_opcode = htons((u_short)request); +#ifndef __SVR4 cp = tp->th_stuff; +#else + cp = (void *)&tp->th_stuff; +#endif strcpy(cp, name); cp += strlen(name); *cp++ = '\0'; strcpy(cp, mode); cp += strlen(mode); *cp++ = '\0'; + if (tsize) { + strcpy(cp, "tsize"); + cp += strlen(cp); + *cp++ = '\0'; + sprintf(cp, "%lu", (unsigned long) filesize); + cp += strlen(cp); + *cp++ = '\0'; + } + if (tout) { + strcpy(cp, "timeout"); + cp += strlen(cp); + *cp++ = '\0'; + sprintf(cp, "%d", rexmtval); + cp += strlen(cp); + *cp++ = '\0'; + } + if (blksize != SEGSIZE) { + strcpy(cp, "blksize"); + cp += strlen(cp); + *cp++ = '\0'; + sprintf(cp, "%d", blksize); + cp += strlen(cp); + *cp++ = '\0'; + } return (cp - (char *)tp); } -struct errmsg { +const struct errmsg { int e_code; - char *e_msg; + const char *e_msg; } errmsgs[] = { { EUNDEF, "Undefined error code" }, { ENOTFOUND, "File not found" }, @@ -351,6 +494,7 @@ struct errmsg { { EBADID, "Unknown transfer ID" }, { EEXISTS, "File already exists" }, { ENOUSER, "No such user" }, + { EOPTNEG, "Option negotiation failed" }, { -1, 0 } }; @@ -361,31 +505,34 @@ struct errmsg { * offset by 100. */ static void -nak(error) +nak(error, peer) int error; + struct sockaddr *peer; { - register struct errmsg *pe; - register struct tftphdr *tp; + const struct errmsg *pe; + struct tftphdr *tp; int length; - char *strerror(); + size_t msglen; tp = (struct tftphdr *)ackbuf; tp->th_opcode = htons((u_short)ERROR); - tp->th_code = htons((u_short)error); + msglen = sizeof(ackbuf) - (&tp->th_msg[0] - ackbuf); for (pe = errmsgs; pe->e_code >= 0; pe++) if (pe->e_code == error) break; if (pe->e_code < 0) { - pe->e_msg = strerror(error - 100); tp->th_code = EUNDEF; + strlcpy(tp->th_msg, strerror(error - 100), msglen); + } else { + tp->th_code = htons((u_short)error); + strlcpy(tp->th_msg, pe->e_msg, msglen); } - strcpy(tp->th_msg, pe->e_msg); - length = strlen(pe->e_msg) + 4; + length = strlen(tp->th_msg); + msglen = &tp->th_msg[length + 1] - ackbuf; if (trace) - tpacket("sent", tp, length); - if (sendto(f, ackbuf, length, 0, (struct sockaddr *)&peeraddr, - sizeof(peeraddr)) != length) - perror("nak"); + tpacket("sent", tp, (int)msglen); + if (sendto(f, ackbuf, msglen, 0, peer, peer->sa_len) != msglen) + warn("nak"); } static void @@ -395,12 +542,12 @@ tpacket(s, tp, n) int n; { static char *opcodes[] = - { "#0", "RRQ", "WRQ", "DATA", "ACK", "ERROR" }; - register char *cp, *file; + { "#0", "RRQ", "WRQ", "DATA", "ACK", "ERROR", "OACK" }; + char *cp, *file, *endp, *opt, *spc; u_short op = ntohs(tp->th_opcode); - char *index(); + int i, o; - if (op < RRQ || op > ERROR) + if (op < RRQ || op > OACK) printf("%s opcode=%x ", s, op); else printf("%s %s ", s, opcodes[op]); @@ -409,9 +556,31 @@ tpacket(s, tp, n) case RRQ: case WRQ: n -= 2; - file = cp = tp->th_stuff; - cp = index(cp, '\0'); - printf("\n", file, cp + 1); +#ifndef __SVR4 + cp = tp->th_stuff; +#else + cp = (void *) &tp->th_stuff; +#endif + endp = cp + n - 1; + if (*endp != '\0') { /* Shouldn't happen, but... */ + *endp = '\0'; + } + file = cp; + cp = strchr(cp, '\0') + 1; + printf("\n"); break; case DATA: @@ -425,6 +594,30 @@ tpacket(s, tp, n) case ERROR: printf("\n", ntohs(tp->th_code), tp->th_msg); break; + + case OACK: + o = 0; + n -= 2; + cp = tp->th_stuff; + endp = cp + n - 1; + if (*endp != '\0') { /* Shouldn't happen, but... */ + *endp = '\0'; + } + printf("<"); + spc = ""; + while (cp < endp) { + i = strlen(cp) + 1; + if (o) { + printf("%s%s=%s", spc, opt, cp); + spc = ", "; + } else { + opt = cp; + } + o = (o+1) % 2; + cp += i; + } + printf(">\n"); + break; } } @@ -451,11 +644,12 @@ printstats(direction, amount) unsigned long amount; { double delta; - /* compute delta in 1/10's second units */ + + /* compute delta in 1/10's second units */ delta = ((tstop.tv_sec*10.)+(tstop.tv_usec/100000)) - ((tstart.tv_sec*10.)+(tstart.tv_usec/100000)); delta = delta/10.; /* back to seconds */ - printf("%s %d bytes in %.1f seconds", direction, amount, delta); + printf("%s %ld bytes in %.1f seconds", direction, amount, delta); if (verbose) printf(" [%.0f bits/sec]", (amount*8.)/delta); putchar('\n'); @@ -473,3 +667,20 @@ timer(sig) } longjmp(timeoutbuf, 1); } + +static int +cmpport(sa, sb) + struct sockaddr *sa; + struct sockaddr *sb; +{ + char a[NI_MAXSERV], b[NI_MAXSERV]; + + if (getnameinfo(sa, sa->sa_len, NULL, 0, a, sizeof(a), NI_NUMERICSERV)) + return 0; + if (getnameinfo(sb, sb->sa_len, NULL, 0, b, sizeof(b), NI_NUMERICSERV)) + return 0; + if (strcmp(a, b) != 0) + return 0; + + return 1; +} diff --git a/tftp.tproj/tftp.h b/tftp.tproj/tftp.h new file mode 100644 index 0000000..70c3356 --- /dev/null +++ b/tftp.tproj/tftp.h @@ -0,0 +1,84 @@ +/* $NetBSD: tftp.h,v 1.8 2003/08/07 09:44:12 agc Exp $ */ + +/* + * 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. 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. + * + * @(#)tftp.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _ARPA_TFTP_H_ +#define _ARPA_TFTP_H_ + +/* + * Trivial File Transfer Protocol (IEN-133) + */ +#define SEGSIZE 512 /* data segment size */ +#define MAXSEGSIZE 65464 /* maximum negotiated data segment size */ + +#define PKTSIZE SEGSIZE + 4 +#define MAXPKTSIZE MAXSEGSIZE + 4 + +/* + * Packet types. + */ +#define RRQ 01 /* read request */ +#define WRQ 02 /* write request */ +#define DATA 03 /* data packet */ +#define ACK 04 /* acknowledgement */ +#define ERROR 05 /* error code */ +#define OACK 06 /* option acknowledgement */ + +struct tftphdr { + short th_opcode; /* packet type */ + union { + unsigned short tu_block; /* block # */ + short tu_code; /* error code */ + char tu_stuff[1]; /* request packet stuff */ + } th_u; + char th_data[1]; /* data or error string */ +}; + +#define th_block th_u.tu_block +#define th_code th_u.tu_code +#define th_stuff th_u.tu_stuff +#define th_msg th_data + +/* + * Error codes. + */ +#define EUNDEF 0 /* not defined */ +#define ENOTFOUND 1 /* file not found */ +#define EACCESS 2 /* access violation */ +#define ENOSPACE 3 /* disk full or allocation exceeded */ +#define EBADOP 4 /* illegal TFTP operation */ +#define EBADID 5 /* unknown transfer ID */ +#define EEXISTS 6 /* file already exists */ +#define ENOUSER 7 /* no such user */ +#define EOPTNEG 8 /* option negotiation failed */ + +#endif /* _ARPA_TFTP_H_ */ diff --git a/tftp.tproj/tftpsubs.c b/tftp.tproj/tftpsubs.c index 38a5e1c..89fb0e4 100644 --- a/tftp.tproj/tftpsubs.c +++ b/tftp.tproj/tftpsubs.c @@ -1,27 +1,5 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ +/* $NetBSD: tftpsubs.c,v 1.8 2003/08/07 11:16:14 agc Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -34,11 +12,7 @@ * 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 + * 3. 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. * @@ -55,6 +29,14 @@ * SUCH DAMAGE. */ +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tftpsubs.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: tftpsubs.c,v 1.8 2003/08/07 11:16:14 agc Exp $"); +#endif +#endif /* not lint */ /* Simple minded read-ahead/write-behind subroutines for tftp user and server. Written originally with multiple buffers in mind, but current @@ -71,18 +53,16 @@ #include #include #include -#include +#include "tftp.h" #include #include #include "tftpsubs.h" -#define PKTSIZE SEGSIZE+4 /* should be moved to tftp.h */ - struct bf { int counter; /* size of data in buffer, or flag */ - char buf[PKTSIZE]; /* room for data packet */ + char buf[MAXPKTSIZE]; /* room for data packet */ } bfs[2]; /* Values for bf.counter */ @@ -97,10 +77,19 @@ static int current; /* index of buffer in use */ int newline = 0; /* fillbuf: in middle of newline expansion */ int prevchar = -1; /* putbuf: previous char (cr check) */ -static struct tftphdr *rw_init(); +static struct tftphdr *rw_init __P((int)); -struct tftphdr *w_init() { return rw_init(0); } /* write-behind */ -struct tftphdr *r_init() { return rw_init(1); } /* read-ahead */ +struct tftphdr * +w_init() /* write-behind */ +{ + return rw_init(0); +} + +struct tftphdr * +r_init() /* read-ahead */ +{ + return rw_init(1); +} static struct tftphdr * rw_init(x) /* init for either read-ahead or write-behind */ @@ -115,14 +104,14 @@ rw_init(x) /* init for either read-ahead or write-behind */ return (struct tftphdr *)bfs[0].buf; } - /* Have emptied current buffer by sending to net and getting ack. Free it and return next buffer filled with data. */ int -readit(file, dpp, convert) +readit(file, dpp, amt, convert) FILE *file; /* file opened for read */ struct tftphdr **dpp; + int amt; int convert; /* if true, convert to ascii */ { struct bf *b; @@ -132,7 +121,7 @@ readit(file, dpp, convert) b = &bfs[current]; /* look at new buffer */ if (b->counter == BF_FREE) /* if it's empty */ - read_ahead(file, convert); /* fill it */ + read_ahead(file, amt, convert); /* fill it */ /* assert(b->counter != BF_FREE);*//* check */ *dpp = (struct tftphdr *)b->buf; /* set caller's ptr */ return b->counter; @@ -143,13 +132,14 @@ readit(file, dpp, convert) * conversions are lf -> cr,lf and cr -> cr, nul */ void -read_ahead(file, convert) +read_ahead(file, amt, convert) FILE *file; /* file opened for read */ + int amt; /* number of bytes to read */ int convert; /* if true, convert to ascii */ { - register int i; - register char *p; - register int c; + int i; + char *p; + int c; struct bf *b; struct tftphdr *dp; @@ -161,12 +151,12 @@ read_ahead(file, convert) dp = (struct tftphdr *)b->buf; if (convert == 0) { - b->counter = read(fileno(file), dp->th_data, SEGSIZE); + b->counter = read(fileno(file), dp->th_data, amt); return; } p = dp->th_data; - for (i = 0 ; i < SEGSIZE; i++) { + for (i = 0 ; i < amt; i++) { if (newline) { if (prevchar == '\n') c = '\n'; /* lf to cr,lf */ @@ -219,9 +209,9 @@ write_behind(file, convert) { char *buf; int count; - register int ct; - register char *p; - register int c; /* current character */ + int ct; + char *p; + int c; /* current character */ struct bf *b; struct tftphdr *dp; @@ -272,12 +262,13 @@ skipit: */ int -synchnet(f) +synchnet(f, bsize) int f; /* socket to flush */ + int bsize; /* size of buffer to sync */ { int i, j = 0; char rbuf[PKTSIZE]; - struct sockaddr_in from; + struct sockaddr_storage from; int fromlen; while (1) { diff --git a/tftp.tproj/tftpsubs.h b/tftp.tproj/tftpsubs.h index 76c0737..98284f8 100644 --- a/tftp.tproj/tftpsubs.h +++ b/tftp.tproj/tftpsubs.h @@ -1,27 +1,5 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ +/* $NetBSD: tftpsubs.h,v 1.4 2003/08/07 11:16:14 agc Exp $ */ + /* * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -34,11 +12,7 @@ * 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 + * 3. 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. * @@ -61,11 +35,13 @@ * Prototypes for read-ahead/write-behind subroutines for tftp user and * server. */ + + struct tftphdr *r_init __P((void)); -void read_ahead __P((FILE *, int)); -int readit __P((FILE *, struct tftphdr **, int)); +void read_ahead __P((FILE *, int, int)); +int readit __P((FILE *, struct tftphdr **, int, int)); -int synchnet __P((int)); +int synchnet __P((int, int)); struct tftphdr *w_init __P((void)); int write_behind __P((FILE *, int)); diff --git a/tftpd.tproj/Makefile b/tftpd.tproj/Makefile index 8ce74c9..cdcc207 100644 --- a/tftpd.tproj/Makefile +++ b/tftpd.tproj/Makefile @@ -12,9 +12,10 @@ NAME = tftpd PROJECTVERSION = 2.8 PROJECT_TYPE = Tool -CFILES = tftpd.c +HFILES = tftp.h tftpsubs.h +CFILES = tftpd.c tftpsubs.c -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble tftpd.8 +OTHERSRCS = Makefile.preamble Makefile Makefile.postamble tftpd.8 tftp.plist tftp.plist-SERVER MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles @@ -28,9 +29,6 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) -HEADER_PATHS = -I../tftp.tproj - - NEXTSTEP_BUILD_OUTPUT_DIR = /$(USER)/BUILD NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc diff --git a/tftpd.tproj/Makefile.postamble b/tftpd.tproj/Makefile.postamble index 95730dc..f5423b9 100644 --- a/tftpd.tproj/Makefile.postamble +++ b/tftpd.tproj/Makefile.postamble @@ -109,8 +109,11 @@ STRIPFLAGS = # owned by the top-level Makefile API and no context has been set up for where # derived files should go. -VPATH += :../tftp.tproj - after_install: mkdir -p "$(DSTROOT)/usr/share/man/man8" cp tftpd.8 "$(DSTROOT)/usr/share/man/man8/" + mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons" + cp tftp.plist "$(DSTROOT)/System/Library/LaunchDaemons/" + cp tftp.plist-SERVER "$(DSTROOT)/System/Library/LaunchDaemons/" + mkdir -p "$(DSTROOT)/private/tftpboot/private" + ln -s / "$(DSTROOT)/private/tftpboot/private/tftpboot" diff --git a/tftpd.tproj/Makefile.preamble b/tftpd.tproj/Makefile.preamble index 8a2e16a..dcbd1c8 100644 --- a/tftpd.tproj/Makefile.preamble +++ b/tftpd.tproj/Makefile.preamble @@ -116,6 +116,4 @@ OTHER_HELP_DIRS = # Don't add more rules here unless you want the first one to be the default # target for make! Put all your targets in Makefile.postamble. -OTHER_OFILES = tftpsubs.o - -include ../Makefile.include diff --git a/tftpd.tproj/tftp.h b/tftpd.tproj/tftp.h new file mode 100644 index 0000000..70c3356 --- /dev/null +++ b/tftpd.tproj/tftp.h @@ -0,0 +1,84 @@ +/* $NetBSD: tftp.h,v 1.8 2003/08/07 09:44:12 agc Exp $ */ + +/* + * 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. 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. + * + * @(#)tftp.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _ARPA_TFTP_H_ +#define _ARPA_TFTP_H_ + +/* + * Trivial File Transfer Protocol (IEN-133) + */ +#define SEGSIZE 512 /* data segment size */ +#define MAXSEGSIZE 65464 /* maximum negotiated data segment size */ + +#define PKTSIZE SEGSIZE + 4 +#define MAXPKTSIZE MAXSEGSIZE + 4 + +/* + * Packet types. + */ +#define RRQ 01 /* read request */ +#define WRQ 02 /* write request */ +#define DATA 03 /* data packet */ +#define ACK 04 /* acknowledgement */ +#define ERROR 05 /* error code */ +#define OACK 06 /* option acknowledgement */ + +struct tftphdr { + short th_opcode; /* packet type */ + union { + unsigned short tu_block; /* block # */ + short tu_code; /* error code */ + char tu_stuff[1]; /* request packet stuff */ + } th_u; + char th_data[1]; /* data or error string */ +}; + +#define th_block th_u.tu_block +#define th_code th_u.tu_code +#define th_stuff th_u.tu_stuff +#define th_msg th_data + +/* + * Error codes. + */ +#define EUNDEF 0 /* not defined */ +#define ENOTFOUND 1 /* file not found */ +#define EACCESS 2 /* access violation */ +#define ENOSPACE 3 /* disk full or allocation exceeded */ +#define EBADOP 4 /* illegal TFTP operation */ +#define EBADID 5 /* unknown transfer ID */ +#define EEXISTS 6 /* file already exists */ +#define ENOUSER 7 /* no such user */ +#define EOPTNEG 8 /* option negotiation failed */ + +#endif /* _ARPA_TFTP_H_ */ diff --git a/tftpd.tproj/tftp.plist b/tftpd.tproj/tftp.plist new file mode 100644 index 0000000..7010bc4 --- /dev/null +++ b/tftpd.tproj/tftp.plist @@ -0,0 +1,33 @@ + + + + + Disabled + + Label + com.apple.tftpd + ProgramArguments + + /usr/libexec/tftpd + -s + /private/tftpboot + + inetdCompatibility + + Wait + + + InitGroups + + Sockets + + Listeners + + SockServiceName + tftp + SockType + dgram + + + + diff --git a/tftpd.tproj/tftp.plist-SERVER b/tftpd.tproj/tftp.plist-SERVER new file mode 100644 index 0000000..e31e08b --- /dev/null +++ b/tftpd.tproj/tftp.plist-SERVER @@ -0,0 +1,33 @@ + + + + + Disabled + + Label + com.apple.tftpd + ProgramArguments + + /usr/libexec/tftpd + -i + /private/tftpboot + + inetdCompatibility + + Wait + + + InitGroups + + Sockets + + Listeners + + SockServiceName + tftp + SockType + dgram + + + + diff --git a/tftpd.tproj/tftpd.8 b/tftpd.tproj/tftpd.8 index b891872..7254fc8 100644 --- a/tftpd.tproj/tftpd.8 +++ b/tftpd.tproj/tftpd.8 @@ -1,3 +1,5 @@ +.\" $NetBSD: tftpd.8,v 1.21 2003/08/07 09:46:53 agc Exp $ +.\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -9,11 +11,7 @@ .\" 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 +.\" 3. 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. .\" @@ -29,35 +27,36 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)tftpd.8 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/libexec/tftpd/tftpd.8,v 1.16 2002/07/06 19:19:43 charnier Exp $ +.\" from: @(#)tftpd.8 8.1 (Berkeley) 6/4/93 .\" -.Dd September 14, 2000 +.Dd June 11, 2003 .Dt TFTPD 8 .Os .Sh NAME .Nm tftpd -.Nd Internet Trivial File Transfer Protocol server +.Nd +.Tn DARPA +Internet Trivial File Transfer Protocol server .Sh SYNOPSIS -.Nm /usr/libexec/tftpd -.Op Fl cCln +.Nm +.Op Fl d +.Op Fl g Ar group +.Op Fl i +.Op Fl l +.Op Fl n .Op Fl s Ar directory .Op Fl u Ar user .Op Ar directory ... .Sh DESCRIPTION -The .Nm -utility is a server which supports the -Internet Trivial File Transfer -Protocol -.Pq Tn RFC 1350 . +is a server which supports the +.Tn DARPA +Trivial File Transfer Protocol. The .Tn TFTP -server operates -at the port indicated in the +server operates at the port indicated in the .Ql tftp -service description; -see +service description; see .Xr services 5 . The server is normally started by .Xr inetd 8 . @@ -67,13 +66,13 @@ The use of does not require an account or password on the remote system. Due to the lack of authentication information, .Nm -will allow only publicly readable files to be -accessed. -Files containing the string ``/\|\fB.\|.\fP\|/'' or starting with -``\|\fB.\|.\fP\|/'' are not allowed. -Files may be written only if they already exist and are publicly writable. +will allow only publicly readable files to be accessed. +Filenames beginning in ``\|\fB.\|.\fP\|/'' or +containing ``/\|\fB.\|.\fP\|/'' are not allowed. +Files may be written to only if they already exist and are publicly writable. +.Pp Note that this extends the concept of -.Dq public +.Qq public to include all users on all hosts that can be reached through the network; this may not be appropriate on all systems, and its implications @@ -90,110 +89,138 @@ names are prefixed by the one of the given directories. The given directories are also treated as a search path for relative filename requests. .Pp -The -.Fl s -option provides additional security by changing -.Nm Ns No 's -root directory, thereby prohibiting accesses outside of the specified -.Ar directory . -Because -.Xr chroot 2 -requires super-user privileges, -.Nm -must be run as root. -However, after performing the -.Fn chroot , -.Nm -will set its user id to that of the specified -.Ar user , -or -.Dq nobody -if no -.Fl u -option is specified. -.Pp The options are: -.Bl -tag -width Ds -.It Fl c -Changes the default root directory of a connecting host via chroot based on the -connecting IP address. -This prevents multiple clients from writing to the same file at the same time. -If the directory does not exist, the client connection is refused. -The -.Fl s -option is required for -.Fl c -and the specified -.Ar directory -is used as a base. -.It Fl C -Operates the same as -.Fl c -except it falls back to -.Fl s Ns No 's -.Ar directory -if a directory does not exist for the client's IP. +.Bl -tag -width "directory" +.It Fl d +Enable verbose debugging messages to +.Xr syslogd 8 . +.It Fl g Ar group +Change gid to that of +.Ar group +on startup. +If this isn't specified, the gid is set to that of the +.Ar user +specified with +.Fl u . +.It Fl i +Enable insecure mode, no +.Xr realpath 3 . .It Fl l -Log all requests using -.Xr syslog 3 -with the facility of -.Dv LOG_FTP . -Note: Logging of -.Dv LOG_FTP -messages -must also be enabled in the syslog configuration file, -.Xr syslog.conf 5 . +Logs all requests using +.Xr syslog 3 . .It Fl n -Suppress negative acknowledgement of requests for nonexistent +Suppresses negative acknowledgement of requests for nonexistent relative filenames. .It Fl s Ar directory -Cause -.Nm -to change its root directory to -.Pa directory . -After changing roots but before accepting commands, .Nm -will switch credentials to an unprivileged user. +will +.Xr chroot 2 +to +.Ar directory +on startup. +This is recommended for security reasons (so that files other than +those in the +.Pa /tftpboot +directory aren't accessible). +If the remote host passes the directory name as part of the +file name to transfer, you may have to create a symbolic link +from +.Sq tftpboot +to +.Sq \&. +under +.Pa /tftpboot . .It Fl u Ar user -Switch credentials to +Change uid to that of .Ar user -(default -.Dq nobody ) -when the -.Fl s -option is used. -The user must be specified by name, not a numeric UID. +on startup. +If +.Fl u +isn't given, +.Ar user +defaults to +.Dq nobody . +If +.Fl g +isn't also given, change the gid to that of +.Ar user +as well. .El .Sh SEE ALSO .Xr tftp 1 , -.Xr chroot 2 , -.Xr inetd 8 , -.Xr syslogd 8 +.Xr inetd 8 .Rs -.%A K. R. Sollins -.%T The TFTP Protocol (Revision 2) +.%R RFC +.%N 1350 .%D July 1992 -.%O RFC 1350, STD 33 +.%T "The TFTP Protocol (Revision 2)" +.Re +.Rs +.%R RFC +.%N 2347 +.%D May 1998 +.%T "TFTP Option Extension" +.Re +.Rs +.%R RFC +.%N 2348 +.%D May 1998 +.%T "TFTP Blocksize Option" +.Re +.Rs +.%R RFC +.%N 2349 +.%D May 1998 +.%T "TFTP Timeout Interval and Transfer Size Options" .Re .Sh HISTORY The .Nm -utility appeared in -.Bx 4.2 ; -the +command appeared in +.Bx 4.2 . +.Pp +The .Fl s -option was introduced in -.Fx 2.2 , -the +flag appeared in +.Nx 1.0 . +.Pp +The +.Fl g +and .Fl u -option was introduced in -.Fx 4.2 , -and the -.Fl c -option was introduced in -.Fx 4.3 . +flags appeared in +.Nx 1.4 . +.Pp +IPv6 support was implemented by WIDE/KAME project in 1999. +.Pp +TFTP options were implemented by Wasabi Systems, Inc., in 2003, +and first appeared in +NetBSD 2.0 . .Sh BUGS Files larger than 33488896 octets (65535 blocks) cannot be transferred -without client and server supporting blocksize negotiation (RFC1783). +without client and server supporting blocksize negotiation (RFCs +2347 and 2348). .Pp Many tftp clients will not transfer files over 16744448 octets (32767 blocks). +.Sh SECURITY CONSIDERATIONS +You are +.Em strongly +advised to set up +.Nm +using the +.Fl s +flag in conjunction with the name of the directory that +contains the files that +.Nm +will serve to remote hosts (e.g., +.Pa /tftpboot ) . +This ensures that only the files that should be served +to remote hosts can be accessed by them. +.Pp +Because there is no user-login or validation within +the +.Tn TFTP +protocol, the remote site will probably have some +sort of file-access restrictions in place. +The exact methods are specific to each site and therefore +difficult to document here. diff --git a/tftpd.tproj/tftpd.c b/tftpd.tproj/tftpd.c index 20146c0..d8043c4 100644 --- a/tftpd.tproj/tftpd.c +++ b/tftpd.tproj/tftpd.c @@ -1,3 +1,27 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* $NetBSD: tftpd.c,v 1.28 2004/05/05 20:15:45 kleink Exp $ */ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -10,11 +34,7 @@ * 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 + * 3. 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. * @@ -31,18 +51,15 @@ * SUCH DAMAGE. */ +#include #ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1983, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); #if 0 static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: tftpd.c,v 1.28 2004/05/05 20:15:45 kleink Exp $"); #endif -static const char rcsid[] = - "$FreeBSD: src/libexec/tftpd/tftpd.c,v 1.18 2001/02/02 10:52:58 asmodai Exp $"; #endif /* not lint */ /* @@ -56,15 +73,15 @@ static const char rcsid[] = #include #include #include -#include #include -#include +#include "tftp.h" #include #include #include #include +#include #include #include #include @@ -73,23 +90,29 @@ static const char rcsid[] = #include #include #include +#include #include #include "tftpsubs.h" +#define DEFAULTUSER "nobody" + #define TIMEOUT 5 int peer; int rexmtval = TIMEOUT; int maxtimeout = 5*TIMEOUT; -#define PKTSIZE SEGSIZE+4 -char buf[PKTSIZE]; +char buf[MAXPKTSIZE]; char ackbuf[PKTSIZE]; -struct sockaddr_in from; +char oackbuf[PKTSIZE]; +struct sockaddr_storage from; int fromlen; +int debug; -void tftp __P((struct tftphdr *, int)); +int tftp_opt_tsize = 0; +int tftp_blksize = SEGSIZE; +int tftp_tsize = 0; /* * Null-terminated directory prefix list for absolute pathname requests and @@ -105,50 +128,106 @@ static struct dirlist { } dirs[MAXDIRS+1]; static int suppress_naks; static int logging; -static int ipchroot; +static int insecure=0; +static int secure; +static char *securedir; -static char *errtomsg __P((int)); -static void nak __P((int)); -static char * __P(verifyhost(struct sockaddr_in *)); +struct formats; + +static const char *errtomsg(int); +static void nak(int); +static void tftp(struct tftphdr *, int); +static void usage(void); +static char *verifyhost(struct sockaddr *); +void justquit(int); +int main(int, char **); +void recvfile(struct formats *, int, int); +void sendfile(struct formats *, int, int); +void timer(int); +static const char *opcode(int); +int validate_access(char **, int); + +struct formats { + const char *f_mode; + int (*f_validate)(char **, int); + void (*f_send)(struct formats *, int, int); + void (*f_recv)(struct formats *, int, int); + int f_convert; +} formats[] = { + { "netascii", validate_access, sendfile, recvfile, 1 }, + { "octet", validate_access, sendfile, recvfile, 0 }, + { 0 } +}; + +static void +usage(void) +{ + + syslog(LOG_ERR, + "Usage: %s [-diln] [-u user] [-g group] [-s directory] [directory ...]", + getprogname()); + exit(1); +} int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { - register struct tftphdr *tp; - register int n; - int ch, on; - struct sockaddr_in sin; - char *chroot_dir = NULL; - struct passwd *nobody; - char *chuser = "nobody"; - - openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_FTP); - while ((ch = getopt(argc, argv, "cClns:u:")) != -1) { + struct sockaddr_storage me; + struct passwd *pwent; + struct group *grent; + struct tftphdr *tp; + char *tgtuser, *tgtgroup, *ep; + int n, ch, on, fd; + int len, soopt; + uid_t curuid, tgtuid; + gid_t curgid, tgtgid; + long nid; + + n = 0; + fd = 0; + tzset(); + openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_DAEMON); + tgtuser = DEFAULTUSER; + tgtgroup = NULL; + curuid = getuid(); + curgid = getgid(); + + while ((ch = getopt(argc, argv, "dg:ilns:u:")) != -1) switch (ch) { - case 'c': - ipchroot = 1; + case 'd': + debug++; break; - case 'C': - ipchroot = 2; + + case 'g': + tgtgroup = optarg; + break; + + case 'i': + insecure = 1; break; + case 'l': logging = 1; break; + case 'n': suppress_naks = 1; break; + case 's': - chroot_dir = optarg; + secure = 1; + securedir = optarg; break; + case 'u': - chuser = optarg; + tgtuser = optarg; break; + default: - syslog(LOG_WARNING, "ignoring unknown option -%c", ch); + usage(); + break; } - } + if (optind < argc) { struct dirlist *dirp; @@ -162,22 +241,84 @@ main(argc, argv) } } } - else if (chroot_dir) { - dirs->name = "/"; - dirs->len = 1; - } - if (ipchroot && chroot_dir == NULL) { - syslog(LOG_ERR, "-c requires -s"); + + if (*tgtuser == '\0' || (tgtgroup != NULL && *tgtgroup == '\0')) + usage(); + + nid = (strtol(tgtuser, &ep, 10)); + if (*ep == '\0') { + if (nid > UID_MAX) { + syslog(LOG_ERR, "uid %ld is too large", nid); + exit(1); + } + pwent = getpwuid((uid_t)nid); + } else + pwent = getpwnam(tgtuser); + if (pwent == NULL) { + syslog(LOG_ERR, "unknown user `%s'", tgtuser); exit(1); } + tgtuid = pwent->pw_uid; + tgtgid = pwent->pw_gid; + + if (tgtgroup != NULL) { + nid = (strtol(tgtgroup, &ep, 10)); + if (*ep == '\0') { + if (nid > GID_MAX) { + syslog(LOG_ERR, "gid %ld is too large", nid); + exit(1); + } + grent = getgrgid((gid_t)nid); + } else + grent = getgrnam(tgtgroup); + if (grent != NULL) + tgtgid = grent->gr_gid; + else { + syslog(LOG_ERR, "unknown group `%s'", tgtgroup); + exit(1); + } + } + + if (secure) { + if (chdir(securedir) < 0) { + syslog(LOG_ERR, "chdir %s: %m", securedir); + exit(1); + } + if (chroot(".")) { + syslog(LOG_ERR, "chroot: %m"); + exit(1); + } + } + + if (logging) + syslog(LOG_DEBUG, "running as user `%s' (%d), group `%s' (%d)", + tgtuser, tgtuid, tgtgroup ? tgtgroup : "(unspecified)", + tgtgid); + if (curgid != tgtgid) { + if (setgid(tgtgid)) { + syslog(LOG_ERR, "setgid to %d: %m", (int)tgtgid); + exit(1); + } + if (setgroups(0, NULL)) { + syslog(LOG_ERR, "setgroups: %m"); + exit(1); + } + } + + if (curuid != tgtuid) { + if (setuid(tgtuid)) { + syslog(LOG_ERR, "setuid to %d: %m", (int)tgtuid); + exit(1); + } + } on = 1; - if (ioctl(0, FIONBIO, &on) < 0) { + if (ioctl(fd, FIONBIO, &on) < 0) { syslog(LOG_ERR, "ioctl(FIONBIO): %m"); exit(1); } fromlen = sizeof (from); - n = recvfrom(0, buf, sizeof (buf), 0, + n = recvfrom(fd, buf, sizeof (buf), 0, (struct sockaddr *)&from, &fromlen); if (n < 0) { syslog(LOG_ERR, "recvfrom: %m"); @@ -216,7 +357,7 @@ main(argc, argv) * a single request from a single client. */ j = sizeof from; - i = recvfrom(0, buf, sizeof (buf), 0, + i = recvfrom(fd, buf, sizeof (buf), 0, (struct sockaddr *)&from, &j); if (i > 0) { n = i; @@ -235,56 +376,54 @@ main(argc, argv) } /* - * Since we exit here, we should do that only after the above - * recvfrom to keep inetd from constantly forking should there - * be a problem. See the above comment about system clogging. + * remember what address this was sent to, so we can respond on the + * same interface */ - if (chroot_dir) { - if (ipchroot) { - char tempchroot[MAXPATHLEN]; - char *tempaddr; - struct stat sb; - int statret; - - tempaddr = inet_ntoa(from.sin_addr); - snprintf(tempchroot, sizeof(tempchroot), "%s/%s", chroot_dir, tempaddr); - statret = stat(tempchroot, &sb); - if ((sb.st_mode & S_IFDIR) && - (statret == 0 || (statret == -1 && ipchroot == 1))) - chroot_dir = tempchroot; - } - /* Must get this before chroot because /etc might go away */ - if ((nobody = getpwnam(chuser)) == NULL) { - syslog(LOG_ERR, "%s: no such user", chuser); - exit(1); - } - if (chroot(chroot_dir)) { - syslog(LOG_ERR, "chroot: %s: %m", chroot_dir); - exit(1); + len = sizeof(me); + if (getsockname(fd, (struct sockaddr *)&me, &len) == 0) { + switch (me.ss_family) { + case AF_INET: + ((struct sockaddr_in *)&me)->sin_port = 0; + break; + case AF_INET6: + ((struct sockaddr_in6 *)&me)->sin6_port = 0; + break; + default: + /* unsupported */ + break; } - chdir( "/" ); - setuid(nobody->pw_uid); + } else { + memset(&me, 0, sizeof(me)); + me.ss_family = from.ss_family; + me.ss_len = from.ss_len; } - from.sin_family = AF_INET; alarm(0); - close(0); + close(fd); close(1); - peer = socket(AF_INET, SOCK_DGRAM, 0); + peer = socket(from.ss_family, SOCK_DGRAM, 0); if (peer < 0) { syslog(LOG_ERR, "socket: %m"); exit(1); } - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - if (bind(peer, (struct sockaddr *)&sin, sizeof (sin)) < 0) { + if (bind(peer, (struct sockaddr *)&me, me.ss_len) < 0) { syslog(LOG_ERR, "bind: %m"); exit(1); } - if (connect(peer, (struct sockaddr *)&from, sizeof(from)) < 0) { + if (connect(peer, (struct sockaddr *)&from, from.ss_len) < 0) { syslog(LOG_ERR, "connect: %m"); exit(1); } + soopt = 65536; /* larger than we'll ever need */ + if (setsockopt(peer, SOL_SOCKET, SO_SNDBUF, (void *) &soopt, sizeof(soopt)) < 0) { + syslog(LOG_ERR, "set SNDBUF: %m"); + exit(1); + } + if (setsockopt(peer, SOL_SOCKET, SO_RCVBUF, (void *) &soopt, sizeof(soopt)) < 0) { + syslog(LOG_ERR, "set RCVBUF: %m"); + exit(1); + } + tp = (struct tftphdr *)buf; tp->th_opcode = ntohs(tp->th_opcode); if (tp->th_opcode == RRQ || tp->th_opcode == WRQ) @@ -292,38 +431,213 @@ main(argc, argv) exit(1); } -struct formats; -int validate_access __P((char **, int)); -void xmitfile __P((struct formats *)); -void recvfile __P((struct formats *)); +static int +blk_handler(struct tftphdr *tp, char *opt, char *val, char *ack, + int *ackl, int *ec) +{ + unsigned long bsize; + char *endp; + int l; -struct formats { - char *f_mode; - int (*f_validate) __P((char **, int)); - void (*f_send) __P((struct formats *)); - void (*f_recv) __P((struct formats *)); - int f_convert; -} formats[] = { - { "netascii", validate_access, xmitfile, recvfile, 1 }, - { "octet", validate_access, xmitfile, recvfile, 0 }, -#ifdef notdef - { "mail", validate_user, sendmail, recvmail, 1 }, -#endif - { 0 } + /* + * On these failures, we could just ignore the blocksize option. + * Perhaps that should be a command-line option. + */ + errno = 0; + bsize = strtoul(val, &endp, 10); + if ((bsize == ULONG_MAX && errno == ERANGE) || *endp) { + syslog(LOG_NOTICE, "%s: %s request for %s: " + "illegal value %s for blksize option", + verifyhost((struct sockaddr *)&from), + tp->th_opcode == WRQ ? "write" : "read", + tp->th_stuff, val); + return 0; + } + if (bsize < 8 || bsize > 65464) { + syslog(LOG_NOTICE, "%s: %s request for %s: " + "out of range value %s for blksize option", + verifyhost((struct sockaddr *)&from), + tp->th_opcode == WRQ ? "write" : "read", + tp->th_stuff, val); + return 0; + } + + tftp_blksize = bsize; + strcpy(ack + *ackl, "blksize"); + *ackl += 8; + l = sprintf(ack + *ackl, "%lu", bsize); + *ackl += l + 1; + + return 0; +} + +static int +timeout_handler(struct tftphdr *tp, char *opt, char *val, char *ack, + int *ackl, int *ec) +{ + unsigned long tout; + char *endp; + int l; + + errno = 0; + tout = strtoul(val, &endp, 10); + if ((tout == ULONG_MAX && errno == ERANGE) || *endp) { + syslog(LOG_NOTICE, "%s: %s request for %s: " + "illegal value %s for timeout option", + verifyhost((struct sockaddr *)&from), + tp->th_opcode == WRQ ? "write" : "read", + tp->th_stuff, val); + return 0; + } + if (tout < 1 || tout > 255) { + syslog(LOG_NOTICE, "%s: %s request for %s: " + "out of range value %s for timeout option", + verifyhost((struct sockaddr *)&from), + tp->th_opcode == WRQ ? "write" : "read", + tp->th_stuff, val); + return 0; + } + + rexmtval = tout; + strcpy(ack + *ackl, "timeout"); + *ackl += 8; + l = sprintf(ack + *ackl, "%lu", tout); + *ackl += l + 1; + + /* + * Arbitrarily pick a maximum timeout on a request to 3 + * retransmissions if the interval timeout is more than + * one minute. Longest possible timeout is therefore + * 3 * 255 - 1, or 764 seconds. + */ + if (rexmtval > 60) { + maxtimeout = rexmtval * 3; + } else { + maxtimeout = rexmtval * 5; + } + + return 0; +} + +static int +tsize_handler(struct tftphdr *tp, char *opt, char *val, char *ack, + int *ackl, int *ec) +{ + unsigned long fsize; + char *endp; + + /* + * Maximum file even with extended tftp is 65535 blocks of + * length 65464, or 4290183240 octets (4784056 less than 2^32). + * unsigned long is at least 32 bits on all NetBSD archs. + */ + + errno = 0; + fsize = strtoul(val, &endp, 10); + if ((fsize == ULONG_MAX && errno == ERANGE) || *endp) { + syslog(LOG_NOTICE, "%s: %s request for %s: " + "illegal value %s for tsize option", + verifyhost((struct sockaddr *)&from), + tp->th_opcode == WRQ ? "write" : "read", + tp->th_stuff, val); + return 0; + } + if (fsize > (unsigned long) 65535 * 65464) { + syslog(LOG_NOTICE, "%s: %s request for %s: " + "out of range value %s for tsize option", + verifyhost((struct sockaddr *)&from), + tp->th_opcode == WRQ ? "write" : "read", + tp->th_stuff, val); + return 0; + } + + tftp_opt_tsize = 1; + tftp_tsize = fsize; + /* + * We will report this later -- either replying with the fsize (WRQ) + * or replying with the actual filesize (RRQ). + */ + + return 0; +} + +struct tftp_options { + char *o_name; + int (*o_handler)(struct tftphdr *, char *, char *, char *, + int *, int *); +} options[] = { + { "blksize", blk_handler }, + { "timeout", timeout_handler }, + { "tsize", tsize_handler }, + { NULL, NULL } }; +/* + * Get options for an extended tftp session. Stuff the ones we + * recognize in oackbuf. + */ +static int +get_options(struct tftphdr *tp, char *cp, int size, char *ackb, + int *alen, int *err) +{ + struct tftp_options *op; + char *option, *value, *endp; + int r, rv=0, ec=0; + + endp = cp + size; + while (cp < endp) { + option = cp; + while (*cp && cp < endp) { + *cp = tolower(*cp); + cp++; + } + if (*cp) { + /* if we have garbage at the end, just ignore it */ + break; + } + cp++; /* skip over NUL */ + value = cp; + while (*cp && cp < endp) { + cp++; + } + if (*cp) { + /* if we have garbage at the end, just ignore it */ + break; + } + cp++; + for (op = options; op->o_name; op++) { + if (strcmp(op->o_name, option) == 0) + break; + } + if (op->o_name) { + r = op->o_handler(tp, option, value, ackb, alen, &ec); + if (r < 0) { + rv = -1; + break; + } + rv++; + } /* else ignore unknown options */ + } + + if (rv < 0) + *err = ec; + + return rv; +} + /* * Handle initial connection protocol. */ -void -tftp(tp, size) - struct tftphdr *tp; - int size; +static void +tftp(struct tftphdr *tp, int size) { - register char *cp; - int first = 1, ecode; - register struct formats *pf; - char *filename, *mode; + struct formats *pf; + char *cp; + char *filename, *mode; + int first, ecode, alen, etftp=0, r; + + first = 1; + mode = NULL; filename = cp = tp->th_stuff; again: @@ -351,9 +665,32 @@ again: nak(EBADOP); exit(1); } + /* + * cp currently points to the NUL byte following the mode. + * + * If we have some valid options, then let's assume that we're + * now dealing with an extended tftp session. Note that if we + * don't get any options, then we *must* assume that we do not + * have an extended tftp session. If we get options, we fill + * in the ack buf to acknowledge them. If we skip that, then + * the client *must* assume that we are not using an extended + * session. + */ + size -= (++cp - (char *) tp); + if (size > 0 && *cp) { + alen = 2; /* Skip over opcode */ + r = get_options(tp, cp, size, oackbuf, &alen, &ecode); + if (r > 0) { + etftp = 1; + } else if (r < 0) { + nak(ecode); + exit(1); + } + } ecode = (*pf->f_validate)(&filename, tp->th_opcode); if (logging) { - syslog(LOG_INFO, "%s: %s request for %s: %s", verifyhost(&from), + syslog(LOG_INFO, "%s: %s request for %s: %s", + verifyhost((struct sockaddr *)&from), tp->th_opcode == WRQ ? "write" : "read", filename, errtomsg(ecode)); } @@ -367,10 +704,26 @@ again: nak(ecode); exit(1); } + + if (etftp) { + struct tftphdr *oack_h; + + if (tftp_opt_tsize) { + int l; + + strcpy(oackbuf + alen, "tsize"); + alen += 6; + l = sprintf(oackbuf + alen, "%u", tftp_tsize); + alen += l + 1; + } + oack_h = (struct tftphdr *) oackbuf; + oack_h->th_opcode = htons(OACK); + } + if (tp->th_opcode == WRQ) - (*pf->f_recv)(pf); + (*pf->f_recv)(pf, etftp, alen); else - (*pf->f_send)(pf); + (*pf->f_send)(pf, etftp, alen); exit(0); } @@ -385,20 +738,29 @@ FILE *file; * If we were invoked with arguments * from inetd then the file must also be * in one of the given directory prefixes. - * Note also, full path name must be - * given as we have no login directory. */ int -validate_access(filep, mode) - char **filep; - int mode; +validate_access(char **filep, int mode) { - struct stat stbuf; - int fd; - struct dirlist *dirp; - static char pathname[MAXPATHLEN]; - char *filename = *filep; - + struct stat stbuf; + struct dirlist *dirp; + static char pathname[MAXPATHLEN]; + int fd; + char *filename; +#ifdef __APPLE__ + static char resolved_path[PATH_MAX+1]; + bzero(resolved_path,PATH_MAX+1); + if(insecure) { + filename = *filep; + } else { + if (realpath(*filep, resolved_path)==NULL) { + return (EACCESS); + } + filename = resolved_path; + } +#else + filename = *filep; +#endif /* * Prevent tricksters from getting around the directory restrictions */ @@ -423,7 +785,7 @@ validate_access(filep, mode) return (EACCESS); if (stat(filename, &stbuf) < 0) return (errno == ENOENT ? ENOTFOUND : EACCESS); - if ((stbuf.st_mode & S_IFMT) != S_IFREG) + if (!S_ISREG(stbuf.st_mode)) return (ENOTFOUND); if (mode == RRQ) { if ((stbuf.st_mode & S_IROTH) == 0) @@ -433,44 +795,65 @@ validate_access(filep, mode) return (EACCESS); } } else { - int err; - /* * Relative file name: search the approved locations for it. - * Don't allow write requests that avoid directory - * restrictions. */ if (!strncmp(filename, "../", 3)) return (EACCESS); /* - * If the file exists in one of the directories and isn't - * readable, continue looking. However, change the error code - * to give an indication that the file exists. + * Find the first file that exists in any of the directories, + * check access on it. */ - err = ENOTFOUND; - for (dirp = dirs; dirp->name != NULL; dirp++) { - snprintf(pathname, sizeof(pathname), "%s/%s", - dirp->name, filename); - if (stat(pathname, &stbuf) == 0 && - (stbuf.st_mode & S_IFMT) == S_IFREG) { - if ((stbuf.st_mode & S_IROTH) != 0) { + if (dirs[0].name != NULL) { + for (dirp = dirs; dirp->name != NULL; dirp++) { + snprintf(pathname, sizeof pathname, "%s/%s", + dirp->name, filename); + if (stat(pathname, &stbuf) == 0 && + (stbuf.st_mode & S_IFMT) == S_IFREG) { break; } - err = EACCESS; } + if (dirp->name == NULL) + return (ENOTFOUND); + if (mode == RRQ && !(stbuf.st_mode & S_IROTH)) + return (EACCESS); + if (mode == WRQ && !(stbuf.st_mode & S_IWOTH)) + return (EACCESS); + filename = pathname; + *filep = filename; + } else { + /* + * If there's no directory list, take our cue from the + * absolute file request check above (*filename == '/'), + * and allow access to anything. + */ + if (stat(filename, &stbuf) < 0) + return (errno == ENOENT ? ENOTFOUND : EACCESS); + if (!S_ISREG(stbuf.st_mode)) + return (ENOTFOUND); + if (mode == RRQ) { + if ((stbuf.st_mode & S_IROTH) == 0) + return (EACCESS); + } else { + if ((stbuf.st_mode & S_IWOTH) == 0) + return (EACCESS); + } + *filep = filename; } - if (dirp->name == NULL) - return (err); - *filep = filename = pathname; } - fd = open(filename, mode == RRQ ? O_RDONLY : O_WRONLY|O_TRUNC); + + if (tftp_opt_tsize && mode == RRQ) + tftp_tsize = (unsigned long) stbuf.st_size; + + fd = open(filename, mode == RRQ ? O_RDONLY : O_WRONLY | O_TRUNC); if (fd < 0) return (errno + 100); file = fdopen(fd, (mode == RRQ)? "r":"w"); if (file == NULL) { - return errno+100; + close(fd); + return (errno + 100); } return (0); } @@ -479,7 +862,7 @@ int timeout; jmp_buf timeoutbuf; void -timer() +timer(int dummy) { timeout += rexmtval; @@ -488,126 +871,199 @@ timer() longjmp(timeoutbuf, 1); } +static const char * +opcode(int code) +{ + static char buf[64]; + + switch (code) { + case RRQ: + return "RRQ"; + case WRQ: + return "WRQ"; + case DATA: + return "DATA"; + case ACK: + return "ACK"; + case ERROR: + return "ERROR"; + case OACK: + return "OACK"; + default: + (void)snprintf(buf, sizeof(buf), "*code %d*", code); + return buf; + } +} + /* * Send the requested file. */ void -xmitfile(pf) - struct formats *pf; +sendfile(struct formats *pf, int etftp, int acklength) { - struct tftphdr *dp, *r_init(); - register struct tftphdr *ap; /* ack packet */ - register int size, n; - volatile unsigned short block; + volatile unsigned int block; + struct tftphdr *dp; + struct tftphdr *ap; /* ack packet */ + int size, n; signal(SIGALRM, timer); - dp = r_init(); ap = (struct tftphdr *)ackbuf; - block = 1; + if (etftp) { + dp = (struct tftphdr *)oackbuf; + size = acklength - 4; + block = 0; + } else { + dp = r_init(); + size = 0; + block = 1; + } + do { - size = readit(file, &dp, pf->f_convert); - if (size < 0) { - nak(errno + 100); - goto abort; + if (block > 0) { + size = readit(file, &dp, tftp_blksize, pf->f_convert); + if (size < 0) { + nak(errno + 100); + goto abort; + } + dp->th_opcode = htons((u_short)DATA); + dp->th_block = htons((u_short)block); } - dp->th_opcode = htons((u_short)DATA); - dp->th_block = htons((u_short)block); timeout = 0; (void)setjmp(timeoutbuf); send_data: - if (send(peer, dp, size + 4, 0) != size + 4) { - syslog(LOG_ERR, "write: %m"); + if (!etftp && debug) + syslog(LOG_DEBUG, "Send DATA %u", block); + if ((n = send(peer, dp, size + 4, 0)) != size + 4) { + syslog(LOG_ERR, "tftpd: write: %m"); goto abort; } - read_ahead(file, pf->f_convert); + if (block) + read_ahead(file, tftp_blksize, pf->f_convert); for ( ; ; ) { alarm(rexmtval); /* read the ack */ - n = recv(peer, ackbuf, sizeof (ackbuf), 0); + n = recv(peer, ackbuf, tftp_blksize, 0); alarm(0); if (n < 0) { - syslog(LOG_ERR, "read: %m"); + syslog(LOG_ERR, "tftpd: read: %m"); goto abort; } ap->th_opcode = ntohs((u_short)ap->th_opcode); ap->th_block = ntohs((u_short)ap->th_block); - - if (ap->th_opcode == ERROR) + switch (ap->th_opcode) { + case ERROR: goto abort; - if (ap->th_opcode == ACK) { + case ACK: + if (ap->th_block == 0) { + etftp = 0; + acklength = 0; + dp = r_init(); + goto done; + } if (ap->th_block == block) - break; + goto done; + if (debug) + syslog(LOG_DEBUG, "Resync ACK %u != %u", + (unsigned int)ap->th_block, block); /* Re-synchronize with the other side */ - (void) synchnet(peer); + (void) synchnet(peer, tftp_blksize); if (ap->th_block == (block -1)) goto send_data; + default: + syslog(LOG_INFO, "Received %s in sendfile\n", + opcode(dp->th_opcode)); } } +done: + if (debug) + syslog(LOG_DEBUG, "Received ACK for block %u", block); block++; - } while (size == SEGSIZE); + } while (size == tftp_blksize || block == 1); abort: (void) fclose(file); } void -justquit() +justquit(int dummy) { + exit(0); } - /* * Receive a file. */ void -recvfile(pf) - struct formats *pf; +recvfile(struct formats *pf, int etftp, int acklength) { - struct tftphdr *dp, *w_init(); - register struct tftphdr *ap; /* ack buffer */ - register int n, size; - volatile unsigned short block; + volatile unsigned int block; + struct tftphdr *dp; + struct tftphdr *ap; /* ack buffer */ + int n, size; signal(SIGALRM, timer); dp = w_init(); - ap = (struct tftphdr *)ackbuf; + ap = (struct tftphdr *)oackbuf; block = 0; do { timeout = 0; - ap->th_opcode = htons((u_short)ACK); - ap->th_block = htons((u_short)block); + if (etftp == 0) { + ap = (struct tftphdr *)ackbuf; + ap->th_opcode = htons((u_short)ACK); + ap->th_block = htons((u_short)block); + acklength = 4; + } + if (debug) + syslog(LOG_DEBUG, "Sending ACK for block %u\n", block); block++; (void) setjmp(timeoutbuf); send_ack: - if (send(peer, ackbuf, 4, 0) != 4) { - syslog(LOG_ERR, "write: %m"); + if (send(peer, ap, acklength, 0) != acklength) { + syslog(LOG_ERR, "tftpd: write: %m"); goto abort; } write_behind(file, pf->f_convert); for ( ; ; ) { alarm(rexmtval); - n = recv(peer, dp, PKTSIZE, 0); + n = recv(peer, dp, tftp_blksize + 4, 0); alarm(0); if (n < 0) { /* really? */ - syslog(LOG_ERR, "read: %m"); + syslog(LOG_ERR, "tftpd: read: %m"); goto abort; } + etftp = 0; dp->th_opcode = ntohs((u_short)dp->th_opcode); dp->th_block = ntohs((u_short)dp->th_block); - if (dp->th_opcode == ERROR) + if (debug) + syslog(LOG_DEBUG, "Received %s for block %u", + opcode(dp->th_opcode), + (unsigned int)dp->th_block); + + switch (dp->th_opcode) { + case ERROR: goto abort; - if (dp->th_opcode == DATA) { - if (dp->th_block == block) { - break; /* normal */ - } + case DATA: + if (dp->th_block == block) + goto done; /* normal */ + if (debug) + syslog(LOG_DEBUG, "Resync %u != %u", + (unsigned int)dp->th_block, block); /* Re-synchronize with the other side */ - (void) synchnet(peer); + (void) synchnet(peer, tftp_blksize); if (dp->th_block == (block-1)) goto send_ack; /* rexmit */ + break; + default: + syslog(LOG_INFO, "Received %s in recvfile\n", + opcode(dp->th_opcode)); + break; } } +done: + if (debug) + syslog(LOG_DEBUG, "Got block %u", block); /* size = write(file, dp->th_data, n - 4); */ size = writeit(file, &dp, n - 4, pf->f_convert); if (size != (n-4)) { /* ahem */ @@ -615,12 +1071,14 @@ send_ack: else nak(ENOSPACE); goto abort; } - } while (size == SEGSIZE); + } while (size == tftp_blksize); write_behind(file, pf->f_convert); (void) fclose(file); /* close data file */ ap->th_opcode = htons((u_short)ACK); /* send the "final" ack */ ap->th_block = htons((u_short)(block)); + if (debug) + syslog(LOG_DEBUG, "Send final ACK %u", block); (void) send(peer, ackbuf, 4, 0); signal(SIGALRM, justquit); /* just quit on timeout */ @@ -636,9 +1094,9 @@ abort: return; } -struct errmsg { - int e_code; - char *e_msg; +const struct errmsg { + int e_code; + const char *e_msg; } errmsgs[] = { { EUNDEF, "Undefined error code" }, { ENOTFOUND, "File not found" }, @@ -648,22 +1106,23 @@ struct errmsg { { EBADID, "Unknown transfer ID" }, { EEXISTS, "File already exists" }, { ENOUSER, "No such user" }, + { EOPTNEG, "Option negotiation failed" }, { -1, 0 } }; -static char * -errtomsg(error) - int error; +static const char * +errtomsg(int error) { - static char buf[20]; - register struct errmsg *pe; + static char ebuf[20]; + const struct errmsg *pe; + if (error == 0) - return "success"; + return ("success"); for (pe = errmsgs; pe->e_code >= 0; pe++) if (pe->e_code == error) - return pe->e_msg; - snprintf(buf, sizeof(buf), "error %d", error); - return buf; + return (pe->e_msg); + snprintf(ebuf, sizeof(ebuf), "error %d", error); + return (ebuf); } /* @@ -673,41 +1132,40 @@ errtomsg(error) * offset by 100. */ static void -nak(error) - int error; +nak(int error) { - register struct tftphdr *tp; - int length; - register struct errmsg *pe; + const struct errmsg *pe; + struct tftphdr *tp; + int length; + size_t msglen; tp = (struct tftphdr *)buf; tp->th_opcode = htons((u_short)ERROR); - tp->th_code = htons((u_short)error); + msglen = sizeof(buf) - (&tp->th_msg[0] - buf); for (pe = errmsgs; pe->e_code >= 0; pe++) if (pe->e_code == error) break; if (pe->e_code < 0) { - pe->e_msg = strerror(error - 100); tp->th_code = EUNDEF; /* set 'undef' errorcode */ + strlcpy(tp->th_msg, strerror(error - 100), msglen); + } else { + tp->th_code = htons((u_short)error); + strlcpy(tp->th_msg, pe->e_msg, msglen); } - strcpy(tp->th_msg, pe->e_msg); - length = strlen(pe->e_msg); - tp->th_msg[length] = '\0'; - length += 5; - if (send(peer, buf, length, 0) != length) + if (debug) + syslog(LOG_DEBUG, "Send NACK %s", tp->th_msg); + length = strlen(tp->th_msg); + msglen = &tp->th_msg[length + 1] - buf; + if (send(peer, buf, msglen, 0) != msglen) syslog(LOG_ERR, "nak: %m"); } static char * -verifyhost(fromp) - struct sockaddr_in *fromp; +verifyhost(struct sockaddr *fromp) { - struct hostent *hp; + static char hbuf[MAXHOSTNAMELEN]; - hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof(fromp->sin_addr), - fromp->sin_family); - if(hp) - return hp->h_name; - else - return inet_ntoa(fromp->sin_addr); + if (getnameinfo(fromp, fromp->sa_len, hbuf, sizeof(hbuf), NULL, 0, 0)) + strlcpy(hbuf, "?", sizeof(hbuf)); + return (hbuf); } diff --git a/tftpd.tproj/tftpsubs.c b/tftpd.tproj/tftpsubs.c new file mode 100644 index 0000000..89fb0e4 --- /dev/null +++ b/tftpd.tproj/tftpsubs.c @@ -0,0 +1,285 @@ +/* $NetBSD: tftpsubs.c,v 1.8 2003/08/07 11:16:14 agc Exp $ */ + +/* + * 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. 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. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tftpsubs.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: tftpsubs.c,v 1.8 2003/08/07 11:16:14 agc Exp $"); +#endif +#endif /* not lint */ + +/* Simple minded read-ahead/write-behind subroutines for tftp user and + server. Written originally with multiple buffers in mind, but current + implementation has two buffer logic wired in. + + Todo: add some sort of final error check so when the write-buffer + is finally flushed, the caller can detect if the disk filled up + (or had an i/o error) and return a nak to the other side. + + Jim Guyton 10/85 + */ + +#include +#include +#include +#include +#include "tftp.h" + +#include +#include + +#include "tftpsubs.h" + +struct bf { + int counter; /* size of data in buffer, or flag */ + char buf[MAXPKTSIZE]; /* room for data packet */ +} bfs[2]; + + /* Values for bf.counter */ +#define BF_ALLOC -3 /* alloc'd but not yet filled */ +#define BF_FREE -2 /* free */ +/* [-1 .. SEGSIZE] = size of data in the data buffer */ + +static int nextone; /* index of next buffer to use */ +static int current; /* index of buffer in use */ + + /* control flags for crlf conversions */ +int newline = 0; /* fillbuf: in middle of newline expansion */ +int prevchar = -1; /* putbuf: previous char (cr check) */ + +static struct tftphdr *rw_init __P((int)); + +struct tftphdr * +w_init() /* write-behind */ +{ + return rw_init(0); +} + +struct tftphdr * +r_init() /* read-ahead */ +{ + return rw_init(1); +} + +static struct tftphdr * +rw_init(x) /* init for either read-ahead or write-behind */ + int x; /* zero for write-behind, one for read-head */ +{ + newline = 0; /* init crlf flag */ + prevchar = -1; + bfs[0].counter = BF_ALLOC; /* pass out the first buffer */ + current = 0; + bfs[1].counter = BF_FREE; + nextone = x; /* ahead or behind? */ + return (struct tftphdr *)bfs[0].buf; +} + +/* Have emptied current buffer by sending to net and getting ack. + Free it and return next buffer filled with data. + */ +int +readit(file, dpp, amt, convert) + FILE *file; /* file opened for read */ + struct tftphdr **dpp; + int amt; + int convert; /* if true, convert to ascii */ +{ + struct bf *b; + + bfs[current].counter = BF_FREE; /* free old one */ + current = !current; /* "incr" current */ + + b = &bfs[current]; /* look at new buffer */ + if (b->counter == BF_FREE) /* if it's empty */ + read_ahead(file, amt, convert); /* fill it */ +/* assert(b->counter != BF_FREE);*//* check */ + *dpp = (struct tftphdr *)b->buf; /* set caller's ptr */ + return b->counter; +} + +/* + * fill the input buffer, doing ascii conversions if requested + * conversions are lf -> cr,lf and cr -> cr, nul + */ +void +read_ahead(file, amt, convert) + FILE *file; /* file opened for read */ + int amt; /* number of bytes to read */ + int convert; /* if true, convert to ascii */ +{ + int i; + char *p; + int c; + struct bf *b; + struct tftphdr *dp; + + b = &bfs[nextone]; /* look at "next" buffer */ + if (b->counter != BF_FREE) /* nop if not free */ + return; + nextone = !nextone; /* "incr" next buffer ptr */ + + dp = (struct tftphdr *)b->buf; + + if (convert == 0) { + b->counter = read(fileno(file), dp->th_data, amt); + return; + } + + p = dp->th_data; + for (i = 0 ; i < amt; i++) { + if (newline) { + if (prevchar == '\n') + c = '\n'; /* lf to cr,lf */ + else c = '\0'; /* cr to cr,nul */ + newline = 0; + } + else { + c = getc(file); + if (c == EOF) break; + if (c == '\n' || c == '\r') { + prevchar = c; + c = '\r'; + newline = 1; + } + } + *p++ = c; + } + b->counter = (int)(p - dp->th_data); +} + +/* Update count associated with the buffer, get new buffer + from the queue. Calls write_behind only if next buffer not + available. + */ +int +writeit(file, dpp, ct, convert) + FILE *file; + struct tftphdr **dpp; + int ct, convert; +{ + bfs[current].counter = ct; /* set size of data to write */ + current = !current; /* switch to other buffer */ + if (bfs[current].counter != BF_FREE) /* if not free */ + (void)write_behind(file, convert); /* flush it */ + bfs[current].counter = BF_ALLOC; /* mark as alloc'd */ + *dpp = (struct tftphdr *)bfs[current].buf; + return ct; /* this is a lie of course */ +} + +/* + * Output a buffer to a file, converting from netascii if requested. + * CR,NUL -> CR and CR,LF => LF. + * Note spec is undefined if we get CR as last byte of file or a + * CR followed by anything else. In this case we leave it alone. + */ +int +write_behind(file, convert) + FILE *file; + int convert; +{ + char *buf; + int count; + int ct; + char *p; + int c; /* current character */ + struct bf *b; + struct tftphdr *dp; + + b = &bfs[nextone]; + if (b->counter < -1) /* anything to flush? */ + return 0; /* just nop if nothing to do */ + + count = b->counter; /* remember byte count */ + b->counter = BF_FREE; /* reset flag */ + dp = (struct tftphdr *)b->buf; + nextone = !nextone; /* incr for next time */ + buf = dp->th_data; + + if (count <= 0) return -1; /* nak logic? */ + + if (convert == 0) + return write(fileno(file), buf, count); + + p = buf; + ct = count; + while (ct--) { /* loop over the buffer */ + c = *p++; /* pick up a character */ + if (prevchar == '\r') { /* if prev char was cr */ + if (c == '\n') /* if have cr,lf then just */ + fseek(file, -1, 1); /* smash lf on top of the cr */ + else + if (c == '\0') /* if have cr,nul then */ + goto skipit; /* just skip over the putc */ + /* else just fall through and allow it */ + } + putc(c, file); +skipit: + prevchar = c; + } + return count; +} + + +/* When an error has occurred, it is possible that the two sides + * are out of synch. Ie: that what I think is the other side's + * response to packet N is really their response to packet N-1. + * + * So, to try to prevent that, we flush all the input queued up + * for us on the network connection on our host. + * + * We return the number of packets we flushed (mostly for reporting + * when trace is active). + */ + +int +synchnet(f, bsize) + int f; /* socket to flush */ + int bsize; /* size of buffer to sync */ +{ + int i, j = 0; + char rbuf[PKTSIZE]; + struct sockaddr_storage from; + int fromlen; + + while (1) { + (void) ioctl(f, FIONREAD, &i); + if (i) { + j++; + fromlen = sizeof from; + (void) recvfrom(f, rbuf, sizeof (rbuf), 0, + (struct sockaddr *)&from, &fromlen); + } else { + return(j); + } + } +} diff --git a/tftpd.tproj/tftpsubs.h b/tftpd.tproj/tftpsubs.h new file mode 100644 index 0000000..98284f8 --- /dev/null +++ b/tftpd.tproj/tftpsubs.h @@ -0,0 +1,48 @@ +/* $NetBSD: tftpsubs.h,v 1.4 2003/08/07 11:16:14 agc Exp $ */ + +/* + * Copyright (c) 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. 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. + * + * @(#)tftpsubs.h 8.1 (Berkeley) 6/6/93 + */ + +/* + * Prototypes for read-ahead/write-behind subroutines for tftp user and + * server. + */ + + +struct tftphdr *r_init __P((void)); +void read_ahead __P((FILE *, int, int)); +int readit __P((FILE *, struct tftphdr **, int, int)); + +int synchnet __P((int, int)); + +struct tftphdr *w_init __P((void)); +int write_behind __P((FILE *, int)); +int writeit __P((FILE *, struct tftphdr **, int, int)); diff --git a/timed.tproj/timed.tproj/acksend.c b/timed.tproj/timed.tproj/acksend.c index cd16920..af1aea0 100644 --- a/timed.tproj/timed.tproj/acksend.c +++ b/timed.tproj/timed.tproj/acksend.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/byteorder.c b/timed.tproj/timed.tproj/byteorder.c index 849eccf..97bb911 100644 --- a/timed.tproj/timed.tproj/byteorder.c +++ b/timed.tproj/timed.tproj/byteorder.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/candidate.c b/timed.tproj/timed.tproj/candidate.c index 715f9d5..a271db5 100644 --- a/timed.tproj/timed.tproj/candidate.c +++ b/timed.tproj/timed.tproj/candidate.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/cksum.c b/timed.tproj/timed.tproj/cksum.c index beda5b6..e50e438 100644 --- a/timed.tproj/timed.tproj/cksum.c +++ b/timed.tproj/timed.tproj/cksum.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/correct.c b/timed.tproj/timed.tproj/correct.c index a216abc..f092bca 100644 --- a/timed.tproj/timed.tproj/correct.c +++ b/timed.tproj/timed.tproj/correct.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/extern.h b/timed.tproj/timed.tproj/extern.h index fcc8457..00f9d35 100644 --- a/timed.tproj/timed.tproj/extern.h +++ b/timed.tproj/timed.tproj/extern.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/globals.h b/timed.tproj/timed.tproj/globals.h index 7388669..82cfc53 100644 --- a/timed.tproj/timed.tproj/globals.h +++ b/timed.tproj/timed.tproj/globals.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/master.c b/timed.tproj/timed.tproj/master.c index 76fb0df..ddd3215 100644 --- a/timed.tproj/timed.tproj/master.c +++ b/timed.tproj/timed.tproj/master.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/measure.c b/timed.tproj/timed.tproj/measure.c index b193959..6b809b2 100644 --- a/timed.tproj/timed.tproj/measure.c +++ b/timed.tproj/timed.tproj/measure.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/networkdelta.c b/timed.tproj/timed.tproj/networkdelta.c index cbcf1ee..51576f6 100644 --- a/timed.tproj/timed.tproj/networkdelta.c +++ b/timed.tproj/timed.tproj/networkdelta.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/pathnames.h b/timed.tproj/timed.tproj/pathnames.h index c524215..1a3faf3 100644 --- a/timed.tproj/timed.tproj/pathnames.h +++ b/timed.tproj/timed.tproj/pathnames.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/readmsg.c b/timed.tproj/timed.tproj/readmsg.c index ac25ec8..88efb49 100644 --- a/timed.tproj/timed.tproj/readmsg.c +++ b/timed.tproj/timed.tproj/readmsg.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/slave.c b/timed.tproj/timed.tproj/slave.c index 293e4bc..0b72058 100644 --- a/timed.tproj/timed.tproj/slave.c +++ b/timed.tproj/timed.tproj/slave.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timed.tproj/timed.c b/timed.tproj/timed.tproj/timed.c index 95d440a..01fa981 100644 --- a/timed.tproj/timed.tproj/timed.c +++ b/timed.tproj/timed.tproj/timed.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timedc.tproj/cmds.c b/timed.tproj/timedc.tproj/cmds.c index 335c76e..a844190 100644 --- a/timed.tproj/timedc.tproj/cmds.c +++ b/timed.tproj/timedc.tproj/cmds.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timedc.tproj/cmdtab.c b/timed.tproj/timedc.tproj/cmdtab.c index 3e01d9d..546a206 100644 --- a/timed.tproj/timedc.tproj/cmdtab.c +++ b/timed.tproj/timedc.tproj/cmdtab.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timedc.tproj/extern.h b/timed.tproj/timedc.tproj/extern.h index 3316c68..22e2e29 100644 --- a/timed.tproj/timedc.tproj/extern.h +++ b/timed.tproj/timedc.tproj/extern.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timedc.tproj/timedc.c b/timed.tproj/timedc.tproj/timedc.c index f80160f..63e2884 100644 --- a/timed.tproj/timedc.tproj/timedc.c +++ b/timed.tproj/timedc.tproj/timedc.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/timed.tproj/timedc.tproj/timedc.h b/timed.tproj/timedc.tproj/timedc.h index 5faabdc..43ca72c 100644 --- a/timed.tproj/timedc.tproj/timedc.h +++ b/timed.tproj/timedc.tproj/timedc.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/traceroute.tproj/Makefile b/traceroute.tproj/Makefile index 75c293b..486b365 100644 --- a/traceroute.tproj/Makefile +++ b/traceroute.tproj/Makefile @@ -12,10 +12,11 @@ NAME = traceroute PROJECTVERSION = 2.8 PROJECT_TYPE = Tool -CFILES = traceroute.c +CFILES = traceroute.c ifaddrlist.c findsaddr-socket.c version.c OTHERSRCS = Makefile.preamble Makefile Makefile.postamble mean.awk\ - median.awk README traceroute.8 + median.awk README traceroute.8 traceroute.h findsaddr.h\ + ifaddrlist.h gnuc.h MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/traceroute.tproj/Makefile.preamble b/traceroute.tproj/Makefile.preamble index 019c674..f4192ae 100644 --- a/traceroute.tproj/Makefile.preamble +++ b/traceroute.tproj/Makefile.preamble @@ -16,7 +16,7 @@ ## (e.g. change -O to -O2), see Makefile.postamble. # Flags passed to compiler (in addition to -g, -O, etc) -OTHER_CFLAGS = +OTHER_CFLAGS = -DHAVE_SOCKADDR_SA_LEN # Flags passed to ld (in addition to -ObjC, etc.) OTHER_LDFLAGS = diff --git a/traceroute.tproj/findsaddr-socket.c b/traceroute.tproj/findsaddr-socket.c new file mode 100644 index 0000000..472df12 --- /dev/null +++ b/traceroute.tproj/findsaddr-socket.c @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2000 + * 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 Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory 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. + * + * $FreeBSD: src/contrib/traceroute/findsaddr-socket.c,v 1.2 2002/07/30 04:49:13 fenner Exp $ + */ + +/* XXX Yes this is WAY too complicated */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Id: findsaddr-socket.c,v 1.3 2005/02/12 00:04:09 lindak Exp $ (LBL)"; +#endif + +#include +#include +#include +#include +#ifdef HAVE_SYS_SOCKIO_H +#include +#endif +#include /* concession to AIX */ + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "gnuc.h" +#ifdef HAVE_OS_PROTO_H +#include "os-proto.h" +#endif + +#include "findsaddr.h" + +#ifdef HAVE_SOCKADDR_SA_LEN +#define SALEN(sa) ((sa)->sa_len) +#else +#define SALEN(sa) salen(sa) +#endif + +#ifndef roundup +#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ +#endif + +struct rtmsg { + struct rt_msghdr rtmsg; + u_char data[512]; +}; + +static struct rtmsg rtmsg = { + { 0, RTM_VERSION, RTM_GET, 0, + RTF_UP | RTF_GATEWAY | RTF_HOST | RTF_STATIC, + RTA_DST | RTA_IFA, 0, 0, 0, 0, 0, { 0 } }, + { 0 } +}; + +#ifndef HAVE_SOCKADDR_SA_LEN +static int salen(struct sockaddr *); +#endif + +/* + * Return the source address for the given destination address + */ +const char * +findsaddr(register const struct sockaddr_in *to, + register struct sockaddr_in *from) +{ + register struct rt_msghdr *rp; + register u_char *cp; + + register struct sockaddr_in *sp, *ifa; + register struct sockaddr *sa; + register int s, size, cc, seq, i; + register pid_t pid; + static char errbuf[512]; + + s = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC); + if (s < 0) { + sprintf(errbuf, "socket: %.128s", strerror(errno)); + return (errbuf); + } + + seq = 0; + pid = getpid(); + + rp = &rtmsg.rtmsg; + rp->rtm_seq = ++seq; + cp = (u_char *)(rp + 1); + + sp = (struct sockaddr_in *)cp; + *sp = *to; + cp += roundup(SALEN((struct sockaddr *)sp), sizeof(u_int32_t)); + + size = cp - (u_char *)rp; + rp->rtm_msglen = size; + + cc = write(s, (char *)rp, size); + if (cc < 0) { + sprintf(errbuf, "write: %.128s", strerror(errno)); + close(s); + return (errbuf); + } + if (cc != size) { + sprintf(errbuf, "short write (%d != %d)", cc, size); + close(s); + return (errbuf); + } + + size = sizeof(rtmsg); + do { + memset(rp, 0, size); + cc = read(s, (char *)rp, size); + if (cc < 0) { + sprintf(errbuf, "read: %.128s", strerror(errno)); + close(s); + return (errbuf); + } + + } while (rp->rtm_seq != seq || rp->rtm_pid != pid); + close(s); + + + if (rp->rtm_version != RTM_VERSION) { + sprintf(errbuf, "bad version %d", rp->rtm_version); + return (errbuf); + } + if (rp->rtm_msglen > cc) { + sprintf(errbuf, "bad msglen %d > %d", rp->rtm_msglen, cc); + return (errbuf); + } + if (rp->rtm_errno != 0) { + sprintf(errbuf, "rtm_errno: %.128s", strerror(rp->rtm_errno)); + return (errbuf); + } + + /* Find the interface sockaddr */ + cp = (u_char *)(rp + 1); + for (i = 1; i != 0; i <<= 1) + if ((i & rp->rtm_addrs) != 0) { + sa = (struct sockaddr *)cp; + switch (i) { + + case RTA_IFA: + if (sa->sa_family == AF_INET) { + ifa = (struct sockaddr_in *)cp; + if (ifa->sin_addr.s_addr != 0) { + *from = *ifa; + return (NULL); + } + } + break; + + default: + break; + /* empty */ + } + + if (SALEN(sa) == 0) + cp += sizeof(long); + else + cp += roundup(SALEN(sa), sizeof(long)); + } + + return ("failed!"); +} + +#ifndef HAVE_SOCKADDR_SA_LEN +static int +salen(struct sockaddr *sa) +{ + switch (sa->sa_family) { + + case AF_INET: + return (sizeof(struct sockaddr_in)); + + case AF_LINK: + return (sizeof(struct sockaddr_dl)); + + default: + return (sizeof(struct sockaddr)); + } +} +#endif diff --git a/traceroute.tproj/findsaddr.h b/traceroute.tproj/findsaddr.h new file mode 100644 index 0000000..49ed9e1 --- /dev/null +++ b/traceroute.tproj/findsaddr.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2000 + * 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: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * @(#) $Id: findsaddr.h,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL) + */ +const char *findsaddr(const struct sockaddr_in *, struct sockaddr_in *); diff --git a/traceroute.tproj/gnuc.h b/traceroute.tproj/gnuc.h new file mode 100644 index 0000000..b7239bb --- /dev/null +++ b/traceroute.tproj/gnuc.h @@ -0,0 +1,43 @@ +/* @(#) $Header: /cvs/root/network_cmds/traceroute.tproj/gnuc.h,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL) */ + +/* Define __P() macro, if necessary */ +#ifndef __P +#if __STDC__ +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +/* inline foo */ +#ifdef __GNUC__ +#define inline __inline +#else +#define inline +#endif + +/* + * Handle new and old "dead" routine prototypes + * + * For example: + * + * __dead void foo(void) __attribute__((volatile)); + * + */ +#ifdef __GNUC__ +#ifndef __dead +#define __dead volatile +#endif +#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +#ifndef __attribute__ +#define __attribute__(args) +#endif +#endif +#else +#ifndef __dead +#define __dead +#endif +#ifndef __attribute__ +#define __attribute__(args) +#endif +#endif diff --git a/traceroute.tproj/ifaddrlist.c b/traceroute.tproj/ifaddrlist.c new file mode 100644 index 0000000..99fe7d8 --- /dev/null +++ b/traceroute.tproj/ifaddrlist.c @@ -0,0 +1,180 @@ +/* + * Copyright (c) 1997, 1998, 1999, 2000 + * 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 Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory 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. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Id: ifaddrlist.c,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL)"; +#endif + +#include +#include +#include +#include +#ifdef HAVE_SYS_SOCKIO_H +#include +#endif +#include /* concession to AIX */ + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "gnuc.h" +#ifdef HAVE_OS_PROTO_H +#include "os-proto.h" +#endif + +#include "ifaddrlist.h" + +/* + * Return the interface list + */ +int +ifaddrlist(register struct ifaddrlist **ipaddrp, register char *errbuf) +{ + register int fd, nipaddr; +#ifdef HAVE_SOCKADDR_SA_LEN + register int n; +#endif + register struct ifreq *ifrp, *ifend, *ifnext, *mp; + register struct sockaddr_in *sin; + register struct ifaddrlist *al; + struct ifconf ifc; + struct ifreq ibuf[(32 * 1024) / sizeof(struct ifreq)], ifr; +#define MAX_IPADDR (sizeof(ibuf) / sizeof(ibuf[0])) + static struct ifaddrlist ifaddrlist[MAX_IPADDR]; + char device[sizeof(ifr.ifr_name) + 1]; + + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) { + (void)sprintf(errbuf, "socket: %s", strerror(errno)); + return (-1); + } + ifc.ifc_len = sizeof(ibuf); + ifc.ifc_buf = (caddr_t)ibuf; + + if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0 || + ifc.ifc_len < sizeof(struct ifreq)) { + if (errno == EINVAL) + (void)sprintf(errbuf, + "SIOCGIFCONF: ifreq struct too small (%d bytes)", + sizeof(ibuf)); + else + (void)sprintf(errbuf, "SIOCGIFCONF: %s", + strerror(errno)); + (void)close(fd); + return (-1); + } + ifrp = ibuf; + ifend = (struct ifreq *)((char *)ibuf + ifc.ifc_len); + + al = ifaddrlist; + mp = NULL; + nipaddr = 0; + for (; ifrp < ifend; ifrp = ifnext) { +#ifdef HAVE_SOCKADDR_SA_LEN + n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name); + if (n < sizeof(*ifrp)) + ifnext = ifrp + 1; + else + ifnext = (struct ifreq *)((char *)ifrp + n); + if (ifrp->ifr_addr.sa_family != AF_INET) + continue; +#else + ifnext = ifrp + 1; +#endif + /* + * Need a template to preserve address info that is + * used below to locate the next entry. (Otherwise, + * SIOCGIFFLAGS stomps over it because the requests + * are returned in a union.) + */ + strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name)); + if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) { + if (errno == ENXIO) + continue; + (void)sprintf(errbuf, "SIOCGIFFLAGS: %.*s: %s", + (int)sizeof(ifr.ifr_name), ifr.ifr_name, + strerror(errno)); + (void)close(fd); + return (-1); + } + + /* Must be up */ + if ((ifr.ifr_flags & IFF_UP) == 0) + continue; + + + (void)strncpy(device, ifr.ifr_name, sizeof(ifr.ifr_name)); + device[sizeof(device) - 1] = '\0'; +#ifdef sun + /* Ignore sun virtual interfaces */ + if (strchr(device, ':') != NULL) + continue; +#endif + if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) { + (void)sprintf(errbuf, "SIOCGIFADDR: %s: %s", + device, strerror(errno)); + (void)close(fd); + return (-1); + } + + if (nipaddr >= MAX_IPADDR) { + (void)sprintf(errbuf, "Too many interfaces (%d)", + MAX_IPADDR); + (void)close(fd); + return (-1); + } + sin = (struct sockaddr_in *)&ifr.ifr_addr; + al->addr = sin->sin_addr.s_addr; + al->device = strdup(device); + ++al; + ++nipaddr; + } + (void)close(fd); + + *ipaddrp = ifaddrlist; + return (nipaddr); +} diff --git a/traceroute.tproj/ifaddrlist.h b/traceroute.tproj/ifaddrlist.h new file mode 100644 index 0000000..877cb4b --- /dev/null +++ b/traceroute.tproj/ifaddrlist.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 1997 + * 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: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * @(#) $Header: /cvs/root/network_cmds/traceroute.tproj/ifaddrlist.h,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL) + */ + +struct ifaddrlist { + u_int32_t addr; + char *device; +}; + +int ifaddrlist(struct ifaddrlist **, char *); diff --git a/traceroute.tproj/traceroute.8 b/traceroute.tproj/traceroute.8 index 5a1ca4c..dc8722d 100644 --- a/traceroute.tproj/traceroute.8 +++ b/traceroute.tproj/traceroute.8 @@ -1,40 +1,19 @@ -.\" Copyright (c) 1990, 1991, 1993 +.\" Copyright (c) 1989, 1995, 1996, 1997, 1999, 2000 .\" The Regents of the University of California. All rights reserved. .\" -.\" This code is derived from software contributed to Berkeley by -.\" Van Jacobson. +.\" Redistribution and use in source and binary forms are permitted +.\" provided that the above copyright notice and this paragraph are +.\" duplicated in all such forms and that any documentation, +.\" advertising materials, and other materials related to such +.\" distribution and use acknowledge that the software was developed +.\" by the University of California, Berkeley. The name of the +.\" University may not be used to endorse or promote products derived +.\" from this software without specific prior written permission. +.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.\" 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. -.\" -.\" @(#)traceroute.8 8.2 (Berkeley) 6/1/94 -.\" -.Dd June 1, 1994 +.Dd September 21, 2000 .Dt TRACEROUTE 8 .Os BSD 4.3 .Sh NAME @@ -42,16 +21,19 @@ .Nd print the route packets take to network host .Sh SYNOPSIS .Nm traceroute +.Op Fl dFISdnrvx +.Op Fl f Ar first_ttl +.Op Fl g Ar gateway +.Op Fl i Ar iface +.Op Fl M Ar first_ttl .Op Fl m Ar max_ttl -.Op Fl n +.Op Fl P Ar proto .Op Fl p Ar port .Op Fl q Ar nqueries -.Op Fl r -.Bk -words .Op Fl s Ar src_addr -.Ek .Op Fl t Ar tos .Op Fl w Ar waittime +.Op Fl z Ar pausemsecs .Ar host .Op Ar packetsize .Sh DESCRIPTION @@ -67,24 +49,67 @@ response from each gateway along the path to some host. .Pp The only mandatory parameter is the destination host name or IP number. -The default probe datagram length is 38 bytes, but this may be increased +The default probe datagram length is 40 bytes, but this may be increased by specifying a packet size (in bytes) after the destination host name. .Pp Other options are: .Bl -tag -width Ds +.It Fl f Ar first_ttl +Set the initial time-to-live used in the first outgoing probe packet. +.It Fl F +Set the "don't fragment" bit. +.It Fl d +Enable socket level debugging. +.It Fl g Ar gateway +Specify a loose source route gateway (8 maximum). +.It Fl i Ar iface +Specify a network interface to obtain the source IP address for +outgoing probe packets. This is normally only useful on a multi-homed +host. (See the +.Fl s +flag for another way to do this.) +.It Fl I +Use +.Tn ICMP +ECHO instead of +.Tn UDP +datagrams. (A synonym for "-P icmp"). +.It Fl M Ar first_ttl +Set the initial time-to-live value used in outgoing probe packets. +The default is 1, i.e., start with the first hop. .It Fl m Ar max_ttl Set the max time-to-live (max number of hops) used in outgoing probe -packets. The default is 30 hops (the same default used for +packets. The default is +.Em net.inet.ip.ttl +hops (the same default used for .Tn TCP connections). .It Fl n Print hop addresses numerically rather than symbolically and numerically (saves a nameserver address-to-name lookup for each gateway found on the path). +.It Fl P Ar proto +Send packets of specified IP protocol. The currently supported protocols +are: +.Tn UDP +, +.Tn TCP +, +.Tn GRE +and +.Tn ICMP +Other protocols may also be specified (either by name or by number), though +.Nm traceroute +does not implement any special knowledge of their packet formats. This +option is useful for determining which router along a path may be +blocking packets based on IP protocol number. But see BUGS below. .It Fl p Ar port -Set the base +Protocol specific. For .Tn UDP +and +.Tn TCP, +sets the base .Ar port number used in probes (default is 33434). .Nm Traceroute @@ -122,7 +147,11 @@ force the source address to be something other than the IP address of the interface the probe packet is sent on. If the IP address is not one of this machine's interface addresses, an error is returned and nothing is sent. -.ne 1i +(See the +.Fl i +flag for another way to do this.) +.It Fl S +Print a summary of how many probes were not answered for each hop. .It Fl t Ar tos Set the .Em type-of-service @@ -130,7 +159,7 @@ in probe packets to the following value (default zero). The value must be a decimal integer in the range 0 to 255. This option can be used to see if different types-of-service result in different paths. (If you are not running a -.Bx 4.3 tahoe +.Bx 4.4 or later system, this may be academic since the normal network services like telnet and ftp don't let you control the .Dv TOS ) . @@ -152,8 +181,23 @@ and .Dv UNREACHABLE Ns s are listed. .It Fl w -Set the time (in seconds) to wait for a response to a probe (default 3 -sec.). +Set the time (in seconds) to wait for a response to a probe (default 5 sec.). +.It Fl x +Toggle IP checksums. Normally, this prevents traceroute from calculating +IP checksums. In some cases, the operating system can overwrite parts of +the outgoing packet but not recalculate the checksum (so in some cases +the default is to not calculate checksums and using +.Fl x +causes them to be calculated). Note that checksums are usually required +for the last hop when using +.Tn ICMP +ECHO probes ( +.Fl I +). So they are always calculated when using ICMP. +.It Fl z Ar pausemsecs +Set the time (in milliseconds) to pause between probes (default 0). +Some systems such as Solaris and routers such as Ciscos rate limit +ICMP messages. A good value to use with this this is 500 (e.g. 1/2 second). .El .Pp This program attempts to trace the route an IP packet would follow to some @@ -167,7 +211,9 @@ with a ttl of one and increase by one until we get an .Tn ICMP "port unreachable" (which means we got to "host") or hit a max (which -defaults to 30 hops & can be changed with the +defaults to +.Em net.inet.ip.ttl +hops & can be changed with the .Fl m flag). Three probes (changed with @@ -176,7 +222,7 @@ flag) are sent at each ttl setting and a line is printed showing the ttl, address of the gateway and round trip time of each probe. If the probe answers come from different gateways, the address of each responding system will -be printed. If there is no response within a 3 sec. timeout +be printed. If there is no response within a 5 sec. timeout interval (changed with the .Fl w flag), a "*" is printed for that @@ -194,7 +240,7 @@ flag). A sample use and output might be: .Bd -literal [yak 71]% traceroute nis.nsf.net. -traceroute to nis.nsf.net (35.1.1.48), 30 hops max, 56 byte packet +traceroute to nis.nsf.net (35.1.1.48), 64 hops max, 38 byte packet 1 helios.ee.lbl.gov (128.3.112.1) 19 ms 19 ms 0 ms 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms @@ -223,7 +269,7 @@ doesn't supply address-to-name translations for its A more interesting example is: .Bd -literal [yak 72]% traceroute allspice.lcs.mit.edu. -traceroute to allspice.lcs.mit.edu (18.26.0.115), 30 hops max +traceroute to allspice.lcs.mit.edu (18.26.0.115), 64 hops max 1 helios.ee.lbl.gov (128.3.112.1) 0 ms 0 ms 0 ms 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 19 ms 19 ms 19 ms 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 19 ms 19 ms @@ -303,17 +349,27 @@ non-standard software, expect to see this problem frequently and/or take care picking the target host of your probes. +.Pp Other possible annotations after the time are .Sy !H , .Sy !N , +or .Sy !P -(got a host, network or protocol unreachable, respectively), +(host, network or protocol unreachable), .Sy !S -or +(source route failed), .Sy !F -(source route failed or fragmentation needed \- neither of these should -ever occur and the associated gateway is busted if you see one). If -almost all the probes result in some kind of unreachable, +(fragmentation needed \- the RFC1191 Path MTU Discovery value is displayed), +.Sy !X +(communication administratively prohibited), +.Sy !V +(host precedence violation), +.Sy !C +(precedence cutoff in effect), or +.Sy ! +(ICMP unreachable code ). +These are defined by RFC1812 (which supersedes RFC1716). +If almost all the probes result in some kind of unreachable, .Nm traceroute will give up and exit. .Pp @@ -330,8 +386,13 @@ C. Philip Wood, Tim Seaver and Ken Adelman. .Sh SEE ALSO .Xr netstat 1 , .Xr ping 8 -.Sh HISTORY -The +.Sh BUGS +When using protocols other than UDP, functionality is reduced. +In particular, the last packet will often appear to be lost, because +even though it reaches the destination host, there's no way to know +that because no ICMP message is sent back. +In the TCP case, .Nm -command -.Bt +should listen for a RST from the destination host (or an intermediate +router that's filtering packets), but this is not implemented yet. + diff --git a/traceroute.tproj/traceroute.c b/traceroute.tproj/traceroute.c index 0ef659f..3fa8108 100644 --- a/traceroute.tproj/traceroute.c +++ b/traceroute.tproj/traceroute.c @@ -1,72 +1,35 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -/*- - * Copyright (c) 1990, 1993 + * Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000 * The Regents of the University of California. All rights reserved. * - * This code is derived from software contributed to Berkeley by - * Van Jacobson. - * * 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. + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1990, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)traceroute.c 8.1 (Berkeley) 6/6/93"; -#endif /* not lint */ +static const char copyright[] = + "@(#) Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000\n\ +The Regents of the University of California. All rights reserved.\n"; +#if 0 +static const char rcsid[] = + "@(#)$Id: traceroute.c,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL)"; +#endif +static const char rcsid[] = + "$FreeBSD: src/contrib/traceroute/traceroute.c,v 1.26 2004/04/17 18:44:23 pb Exp $"; +#endif /* * traceroute host - trace the route ip packets follow going to "host". @@ -77,9 +40,9 @@ static char sccsid[] = "@(#)traceroute.c 8.1 (Berkeley) 6/6/93"; * icmp "time exceeded" reply from a gateway. We start our probes * with a ttl of one and increase by one until we get an icmp "port * unreachable" (which means we got to "host") or hit a max (which - * defaults to 30 hops & can be changed with the -m flag). Three - * probes (change with -q flag) are sent at each ttl setting and a - * line is printed showing the ttl, address of the gateway and + * defaults to net.inet.ip.ttl hops & can be changed with the -m flag). + * Three probes (change with -q flag) are sent at each ttl setting and + * a line is printed showing the ttl, address of the gateway and * round trip time of each probe. If the probe answers come from * different gateways, the address of each responding system will * be printed. If there is no response within a 5 sec. timeout @@ -94,7 +57,7 @@ static char sccsid[] = "@(#)traceroute.c 8.1 (Berkeley) 6/6/93"; * A sample use might be: * * [yak 71]% traceroute nis.nsf.net. - * traceroute to nis.nsf.net (35.1.1.48), 30 hops max, 56 byte packet + * traceroute to nis.nsf.net (35.1.1.48), 64 hops max, 56 byte packet * 1 helios.ee.lbl.gov (128.3.112.1) 19 ms 19 ms 0 ms * 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms * 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms @@ -114,7 +77,7 @@ static char sccsid[] = "@(#)traceroute.c 8.1 (Berkeley) 6/6/93"; * A more interesting example is: * * [yak 72]% traceroute allspice.lcs.mit.edu. - * traceroute to allspice.lcs.mit.edu (18.26.0.115), 30 hops max + * traceroute to allspice.lcs.mit.edu (18.26.0.115), 64 hops max * 1 helios.ee.lbl.gov (128.3.112.1) 0 ms 0 ms 0 ms * 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 19 ms 19 ms 19 ms * 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 19 ms 19 ms @@ -235,141 +198,389 @@ static char sccsid[] = "@(#)traceroute.c 8.1 (Berkeley) 6/6/93"; * back to yourself. Unfortunately, SO many gateways botch source * routing, the thing is almost worthless. Maybe one day... * - * -- Van Jacobson (van@helios.ee.lbl.gov) + * -- Van Jacobson (van@ee.lbl.gov) * Tue Dec 20 03:50:13 PST 1988 */ #include -#include -#include #include #include +#ifdef HAVE_SYS_SELECT_H +#include +#endif +#include +#ifdef HAVE_SYS_SYSCTL_H +#include +#endif +#include #include #include #include +#include #include #include +#include +#include +#include #include +#ifdef IPSEC +#include +#include /* XXX */ +#endif /* IPSEC */ + +#include +#include +#include +#include +#ifdef HAVE_MALLOC_H +#include +#endif +#include #include #include -#include #include #include #include -#define MAXPACKET 65535 /* max ip packet size */ -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 64 +#include "gnuc.h" +#ifdef HAVE_OS_PROTO_H +#include "os-proto.h" +#endif + +/* rfc1716 */ +#ifndef ICMP_UNREACH_FILTER_PROHIB +#define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohibited filter */ #endif +#ifndef ICMP_UNREACH_HOST_PRECEDENCE +#define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host precedence violation */ +#endif +#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF +#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */ +#endif + +#include "findsaddr.h" +#include "ifaddrlist.h" +#include "traceroute.h" -#ifndef FD_SET -#define NFDBITS (8*sizeof(fd_set)) -#define FD_SETSIZE NFDBITS -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) -#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) +/* Maximum number of gateways (include room for one noop) */ +#define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(u_int32_t))) + +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 64 #endif #define Fprintf (void)fprintf -#define Sprintf (void)sprintf #define Printf (void)printf -/* - * format of a (udp) probe packet. - */ -struct opacket { - struct ip ip; - struct udphdr udp; +/* What a GRE packet header looks like */ +struct grehdr { + u_int16_t flags; + u_int16_t proto; + u_int16_t length; /* PPTP version of these fields */ + u_int16_t callId; +}; +#ifndef IPPROTO_GRE +#define IPPROTO_GRE 47 +#endif + +/* For GRE, we prepare what looks like a PPTP packet */ +#define GRE_PPTP_PROTO 0x880b + +/* Host name and address list */ +struct hostinfo { + char *name; + int n; + u_int32_t *addrs; +}; + +/* Data section of the probe packet */ +struct outdata { u_char seq; /* sequence number of this packet */ u_char ttl; /* ttl packet left with */ struct timeval tv; /* time packet left */ }; +#ifndef HAVE_ICMP_NEXTMTU +/* Path MTU Discovery (RFC1191) */ +struct my_pmtu { + u_short ipm_void; + u_short ipm_nextmtu; +}; +#endif + u_char packet[512]; /* last inbound (icmp) packet */ -struct opacket *outpacket; /* last output (udp) packet */ -int wait_for_reply __P((int, struct sockaddr_in *)); -void send_probe __P((int, int)); -double deltaT __P((struct timeval *, struct timeval *)); -int packet_ok __P((u_char *, int, struct sockaddr_in *, int)); -void print __P((u_char *, int, struct sockaddr_in *)); -void tvsub __P((struct timeval *, struct timeval *)); -char *inetname __P((struct in_addr)); -void usage __P(()); +struct ip *outip; /* last output ip packet */ +u_char *outp; /* last output inner protocol packet */ + +/* loose source route gateway list (including room for final destination) */ +u_int32_t gwlist[NGATEWAYS + 1]; int s; /* receive (icmp) socket file descriptor */ int sndsock; /* send (udp) socket file descriptor */ -struct timezone tz; /* leftover */ struct sockaddr whereto; /* Who to try to reach */ -int datalen; /* How much data */ - -char *source = 0; +struct sockaddr wherefrom; /* Who we are */ +int packlen; /* total length of packet */ +int protlen; /* length of protocol part of packet */ +int minpacket; /* min ip packet size */ +int maxpacket = 32 * 1024; /* max ip packet size */ +int pmtu; /* Path MTU Discovery (RFC1191) */ +u_int pausemsecs; + +char *prog; +char *source; char *hostname; +char *device; +static const char devnull[] = "/dev/null"; int nprobes = 3; -int max_ttl = 30; +int max_ttl; +int first_ttl = 1; u_short ident; -u_short port = 32768+666; /* start udp dest port # for probe packets */ +u_short port; /* protocol specific base "port" */ + int options; /* socket options */ int verbose; int waittime = 5; /* time to wait for response (in seconds) */ int nflag; /* print addresses numerically */ +#ifdef CANT_HACK_IPCKSUM +int doipcksum = 0; /* don't calculate ip checksums by default */ +#else +int doipcksum = 1; /* calculate ip checksums by default */ +#endif +int optlen; /* length of ip options */ + +extern int optind; +extern int opterr; +extern char *optarg; + +/* Forwards */ +double deltaT(struct timeval *, struct timeval *); +void freehostinfo(struct hostinfo *); +void getaddr(u_int32_t *, char *); +struct hostinfo *gethostinfo(char *); +u_short in_cksum(u_short *, int); +char *inetname(struct in_addr); +int main(int, char **); +u_short p_cksum(struct ip *, u_short *, int); +int packet_ok(u_char *, int, struct sockaddr_in *, int); +char *pr_type(u_char); +void print(u_char *, int, struct sockaddr_in *); +#ifdef IPSEC +int setpolicy __P((int so, char *policy)); +#endif +void send_probe(int, int); +struct outproto *setproto(char *); +int str2val(const char *, const char *, int, int); +void tvsub(struct timeval *, struct timeval *); +void usage(void); +int wait_for_reply(int, struct sockaddr_in *, const struct timeval *); +#ifndef HAVE_USLEEP +int usleep(u_int); +#endif + +void udp_prep(struct outdata *); +int udp_check(const u_char *, int); +void tcp_prep(struct outdata *); +int tcp_check(const u_char *, int); +void gre_prep(struct outdata *); +int gre_check(const u_char *, int); +void gen_prep(struct outdata *); +int gen_check(const u_char *, int); +void icmp_prep(struct outdata *); +int icmp_check(const u_char *, int); + +/* Descriptor structure for each outgoing protocol we support */ +struct outproto { + char *name; /* name of protocol */ + u_char num; /* IP protocol number */ + u_short hdrlen; /* max size of protocol header */ + u_short port; /* default base protocol-specific "port" */ + void (*prepare)(struct outdata *); + /* finish preparing an outgoing packet */ + int (*check)(const u_char *, int); + /* check an incoming packet */ +}; + +/* List of supported protocols. The first one is the default. The last + one is the handler for generic protocols not explicitly listed. */ +struct outproto protos[] = { + { + "udp", + IPPROTO_UDP, + sizeof(struct udphdr), + 32768 + 666, + udp_prep, + udp_check + }, + { + "tcp", + IPPROTO_TCP, + sizeof(struct tcphdr), + 32768 + 666, + tcp_prep, + tcp_check + }, + { + "gre", + IPPROTO_GRE, + sizeof(struct grehdr), + GRE_PPTP_PROTO, + gre_prep, + gre_check + }, + { + "icmp", + IPPROTO_ICMP, + sizeof(struct icmp), + 0, + icmp_prep, + icmp_check + }, + { + NULL, + 0, + 2 * sizeof(u_short), + 0, + gen_prep, + gen_check + }, +}; +struct outproto *proto = &protos[0]; int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char **argv) { - extern char *optarg; - extern int optind; - struct hostent *hp; - struct protoent *pe; - struct sockaddr_in from, *to; - int ch, i, on, probe, seq, tos, ttl; - - on = 1; - seq = tos = 0; - to = (struct sockaddr_in *)&whereto; - while ((ch = getopt(argc, argv, "dm:np:q:rs:t:w:v")) != EOF) - switch(ch) { + register int op, code, n; + register char *cp; + register const char *err; + register u_int32_t *ap; + register struct sockaddr_in *from = (struct sockaddr_in *)&wherefrom; + register struct sockaddr_in *to = (struct sockaddr_in *)&whereto; + register struct hostinfo *hi; + int on = 1; + register struct protoent *pe; + register int ttl, probe, i; + register int seq = 0; + int tos = 0, settos = 0; + register int lsrr = 0; + register u_short off = 0; + struct ifaddrlist *al; + char errbuf[132]; + int requestPort = -1; + int sump = 0; + int sockerrno; + + /* Insure the socket fds won't be 0, 1 or 2 */ + if (open(devnull, O_RDONLY) < 0 || + open(devnull, O_RDONLY) < 0 || + open(devnull, O_RDONLY) < 0) { + Fprintf(stderr, "%s: open \"%s\": %s\n", + prog, devnull, strerror(errno)); + exit(1); + } + /* + * Do the setuid-required stuff first, then lose priveleges ASAP. + * Do error checking for these two calls where they appeared in + * the original code. + */ + cp = "icmp"; + pe = getprotobyname(cp); + if (pe) { + if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0) + sockerrno = errno; + else if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) + sockerrno = errno; + } + + setuid(getuid()); + +#ifdef IPCTL_DEFTTL + { + int mib[4] = { CTL_NET, PF_INET, IPPROTO_IP, IPCTL_DEFTTL }; + size_t sz = sizeof(max_ttl); + + if (sysctl(mib, 4, &max_ttl, &sz, NULL, 0) == -1) { + perror("sysctl(net.inet.ip.ttl)"); + exit(1); + } + } +#else + max_ttl = 30; +#endif + + if (argv[0] == NULL) + prog = "traceroute"; + else if ((cp = strrchr(argv[0], '/')) != NULL) + prog = cp + 1; + else + prog = argv[0]; + + opterr = 0; + while ((op = getopt(argc, argv, "dFInrSvxf:g:i:M:m:P:p:q:s:t:w:z:")) != EOF) + switch (op) { + case 'd': options |= SO_DEBUG; break; - case 'm': - max_ttl = atoi(optarg); - if (max_ttl <= 1) { + + case 'f': + case 'M': /* FreeBSD compat. */ + first_ttl = str2val(optarg, "first ttl", 1, 255); + break; + + case 'F': + off = IP_DF; + break; + + case 'g': + if (lsrr >= NGATEWAYS) { Fprintf(stderr, - "traceroute: max ttl must be >1.\n"); + "%s: No more than %d gateways\n", + prog, NGATEWAYS); exit(1); } + getaddr(gwlist + lsrr, optarg); + ++lsrr; + break; + + case 'i': + device = optarg; + break; + + case 'I': + proto = setproto("icmp"); + break; + + case 'm': + max_ttl = str2val(optarg, "max ttl", 1, 255); break; + case 'n': - nflag++; + ++nflag; break; + + case 'P': + proto = setproto(optarg); + break; + case 'p': - port = atoi(optarg); - if (port < 1) { - Fprintf(stderr, - "traceroute: port must be >0.\n"); - exit(1); - } + requestPort = (u_short)str2val(optarg, "port", + 1, (1 << 16) - 1); break; + case 'q': - nprobes = atoi(optarg); - if (nprobes < 1) { - Fprintf(stderr, - "traceroute: nprobes must be >0.\n"); - exit(1); - } + nprobes = str2val(optarg, "nprobes", 1, -1); break; + case 'r': options |= SO_DONTROUTE; break; + case 's': /* * set the ip source address of the outbound @@ -377,267 +588,583 @@ main(argc, argv) */ source = optarg; break; + + case 'S': + sump = 1; + break; + case 't': - tos = atoi(optarg); - if (tos < 0 || tos > 255) { - Fprintf(stderr, - "traceroute: tos must be 0 to 255.\n"); - exit(1); - } + tos = str2val(optarg, "tos", 0, 255); + ++settos; break; + case 'v': - verbose++; + ++verbose; + break; + + case 'x': + doipcksum = (doipcksum == 0); break; + case 'w': - waittime = atoi(optarg); - if (waittime <= 1) { - Fprintf(stderr, - "traceroute: wait must be >1 sec.\n"); - exit(1); - } + waittime = str2val(optarg, "wait time", + 2, 24 * 60 * 60); break; + + case 'z': + pausemsecs = str2val(optarg, "pause msecs", + 0, 60 * 60 * 1000); + break; + default: usage(); } - argc -= optind; - argv += optind; - if (argc < 1) - usage(); - - setlinebuf (stdout); + /* Set requested port, if any, else default for this protocol */ + port = (requestPort != -1) ? requestPort : proto->port; - (void) bzero((char *)&whereto, sizeof(struct sockaddr)); - to->sin_family = AF_INET; - to->sin_addr.s_addr = inet_addr(*argv); - if (to->sin_addr.s_addr != -1) - hostname = *argv; - else { - hp = gethostbyname(*argv); - if (hp) { - to->sin_family = hp->h_addrtype; - bcopy(hp->h_addr, (caddr_t)&to->sin_addr, hp->h_length); - hostname = hp->h_name; - } else { - (void)fprintf(stderr, - "traceroute: unknown host %s\n", *argv); - exit(1); - } - } - if (*++argv) - datalen = atoi(*argv); - if (datalen < 0 || datalen >= MAXPACKET - sizeof(struct opacket)) { + if (first_ttl > max_ttl) { Fprintf(stderr, - "traceroute: packet size must be 0 <= s < %ld.\n", - MAXPACKET - sizeof(struct opacket)); + "%s: first ttl (%d) may not be greater than max ttl (%d)\n", + prog, first_ttl, max_ttl); exit(1); } - datalen += sizeof(struct opacket); - outpacket = (struct opacket *)malloc((unsigned)datalen); - if (! outpacket) { - perror("traceroute: malloc"); + + if (!doipcksum) + Fprintf(stderr, "%s: Warning: ip checksums disabled\n", prog); + + if (lsrr > 0) + optlen = (lsrr + 1) * sizeof(gwlist[0]); + minpacket = sizeof(*outip) + proto->hdrlen + sizeof(struct outdata) + optlen; + packlen = minpacket; /* minimum sized packet */ + + /* Process destination and optional packet size */ + switch (argc - optind) { + + case 2: + packlen = str2val(argv[optind + 1], + "packet length", minpacket, maxpacket); + /* Fall through */ + + case 1: + hostname = argv[optind]; + hi = gethostinfo(hostname); + setsin(to, hi->addrs[0]); + if (hi->n > 1) + Fprintf(stderr, + "%s: Warning: %s has multiple addresses; using %s\n", + prog, hostname, inet_ntoa(to->sin_addr)); + hostname = hi->name; + hi->name = NULL; + freehostinfo(hi); + break; + + default: + usage(); + } + +#ifdef HAVE_SETLINEBUF + setlinebuf (stdout); +#else + setvbuf(stdout, NULL, _IOLBF, 0); +#endif + + protlen = packlen - sizeof(*outip) - optlen; + + outip = (struct ip *)malloc((unsigned)packlen); + if (outip == NULL) { + Fprintf(stderr, "%s: malloc: %s\n", prog, strerror(errno)); exit(1); } - (void) bzero((char *)outpacket, datalen); - outpacket->ip.ip_dst = to->sin_addr; - outpacket->ip.ip_tos = tos; - outpacket->ip.ip_v = IPVERSION; - outpacket->ip.ip_id = 0; + memset((char *)outip, 0, packlen); + + outip->ip_v = IPVERSION; + if (settos) + outip->ip_tos = tos; +#ifdef BYTESWAP_IP_HDR + outip->ip_len = htons(packlen); + outip->ip_off = htons(off); +#else + outip->ip_len = packlen; + outip->ip_off = off; +#endif + outip->ip_p = proto->num; + outp = (u_char *)(outip + 1); +#ifdef HAVE_RAW_OPTIONS + if (lsrr > 0) { + register u_char *optlist; + + optlist = outp; + outp += optlen; + + /* final hop */ + gwlist[lsrr] = to->sin_addr.s_addr; + + outip->ip_dst.s_addr = gwlist[0]; + + /* force 4 byte alignment */ + optlist[0] = IPOPT_NOP; + /* loose source route option */ + optlist[1] = IPOPT_LSRR; + i = lsrr * sizeof(gwlist[0]); + optlist[2] = i + 3; + /* Pointer to LSRR addresses */ + optlist[3] = IPOPT_MINOFF; + memcpy(optlist + 4, gwlist + 1, i); + } else +#endif + outip->ip_dst = to->sin_addr; + outip->ip_hl = (outp - (u_char *)outip) >> 2; ident = (getpid() & 0xffff) | 0x8000; - if ((pe = getprotobyname("icmp")) == NULL) { - Fprintf(stderr, "icmp: unknown protocol\n"); - exit(10); + if (pe == NULL) { + Fprintf(stderr, "%s: unknown protocol %s\n", prog, cp); + exit(1); } - if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0) { - perror("traceroute: icmp socket"); - exit(5); + if (s < 0) { + errno = sockerrno; + Fprintf(stderr, "%s: icmp socket: %s\n", prog, strerror(errno)); + exit(1); } if (options & SO_DEBUG) - (void) setsockopt(s, SOL_SOCKET, SO_DEBUG, - (char *)&on, sizeof(on)); + (void)setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&on, + sizeof(on)); if (options & SO_DONTROUTE) - (void) setsockopt(s, SOL_SOCKET, SO_DONTROUTE, - (char *)&on, sizeof(on)); + (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on, + sizeof(on)); - if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) { - perror("traceroute: raw socket"); - exit(5); +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) + if (setpolicy(s, "in bypass") < 0) + errx(1, "%s", ipsec_strerror()); + + if (setpolicy(s, "out bypass") < 0) + errx(1, "%s", ipsec_strerror()); +#endif /* defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) */ + + if (sndsock < 0) { + errno = sockerrno; + Fprintf(stderr, "%s: raw socket: %s\n", prog, strerror(errno)); + exit(1); } + +#if defined(IP_OPTIONS) && !defined(HAVE_RAW_OPTIONS) + if (lsrr > 0) { + u_char optlist[MAX_IPOPTLEN]; + + cp = "ip"; + if ((pe = getprotobyname(cp)) == NULL) { + Fprintf(stderr, "%s: unknown protocol %s\n", prog, cp); + exit(1); + } + + /* final hop */ + gwlist[lsrr] = to->sin_addr.s_addr; + ++lsrr; + + /* force 4 byte alignment */ + optlist[0] = IPOPT_NOP; + /* loose source route option */ + optlist[1] = IPOPT_LSRR; + i = lsrr * sizeof(gwlist[0]); + optlist[2] = i + 3; + /* Pointer to LSRR addresses */ + optlist[3] = IPOPT_MINOFF; + memcpy(optlist + 4, gwlist, i); + + if ((setsockopt(sndsock, pe->p_proto, IP_OPTIONS, + (char *)optlist, i + sizeof(gwlist[0]))) < 0) { + Fprintf(stderr, "%s: IP_OPTIONS: %s\n", + prog, strerror(errno)); + exit(1); + } + } +#endif + #ifdef SO_SNDBUF - if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&datalen, - sizeof(datalen)) < 0) { - perror("traceroute: SO_SNDBUF"); - exit(6); + if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&packlen, + sizeof(packlen)) < 0) { + Fprintf(stderr, "%s: SO_SNDBUF: %s\n", prog, strerror(errno)); + exit(1); } -#endif SO_SNDBUF +#endif #ifdef IP_HDRINCL if (setsockopt(sndsock, IPPROTO_IP, IP_HDRINCL, (char *)&on, - sizeof(on)) < 0) { - perror("traceroute: IP_HDRINCL"); - exit(6); + sizeof(on)) < 0) { + Fprintf(stderr, "%s: IP_HDRINCL: %s\n", prog, strerror(errno)); + exit(1); } -#endif IP_HDRINCL +#else +#ifdef IP_TOS + if (settos && setsockopt(sndsock, IPPROTO_IP, IP_TOS, + (char *)&tos, sizeof(tos)) < 0) { + Fprintf(stderr, "%s: setsockopt tos %d: %s\n", + prog, tos, strerror(errno)); + exit(1); + } +#endif +#endif if (options & SO_DEBUG) - (void) setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, - (char *)&on, sizeof(on)); + (void)setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, (char *)&on, + sizeof(on)); if (options & SO_DONTROUTE) - (void) setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE, - (char *)&on, sizeof(on)); - - if (source) { - (void) bzero((char *)&from, sizeof(struct sockaddr)); - from.sin_family = AF_INET; - from.sin_addr.s_addr = inet_addr(source); - if (from.sin_addr.s_addr == -1) { - Printf("traceroute: unknown host %s\n", source); + (void)setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE, (char *)&on, + sizeof(on)); + + /* Get the interface address list */ + n = ifaddrlist(&al, errbuf); + if (n < 0) { + Fprintf(stderr, "%s: ifaddrlist: %s\n", prog, errbuf); + exit(1); + } + if (n == 0) { + Fprintf(stderr, + "%s: Can't find any network interfaces\n", prog); + exit(1); + } + + /* Look for a specific device */ + if (device != NULL) { + for (i = n; i > 0; --i, ++al) + if (strcmp(device, al->device) == 0) + break; + if (i <= 0) { + Fprintf(stderr, "%s: Can't find interface %.32s\n", + prog, device); exit(1); } - outpacket->ip.ip_src = from.sin_addr; -#ifndef IP_HDRINCL - if (bind(sndsock, (struct sockaddr *)&from, sizeof(from)) < 0) { - perror ("traceroute: bind:"); - exit (1); + } + + /* Determine our source address */ + if (source == NULL) { + /* + * If a device was specified, use the interface address. + * Otherwise, try to determine our source address. + */ + if (device != NULL) + setsin(from, al->addr); + else if ((err = findsaddr(to, from)) != NULL) { + Fprintf(stderr, "%s: findsaddr: %s\n", + prog, err); + exit(1); + } + } else { + hi = gethostinfo(source); + source = hi->name; + hi->name = NULL; + /* + * If the device was specified make sure it + * corresponds to the source address specified. + * Otherwise, use the first address (and warn if + * there are more than one). + */ + if (device != NULL) { + for (i = hi->n, ap = hi->addrs; i > 0; --i, ++ap) + if (*ap == al->addr) + break; + if (i <= 0) { + Fprintf(stderr, + "%s: %s is not on interface %.32s\n", + prog, source, device); + exit(1); + } + setsin(from, *ap); + } else { + setsin(from, hi->addrs[0]); + if (hi->n > 1) + Fprintf(stderr, + "%s: Warning: %s has multiple addresses; using %s\n", + prog, source, inet_ntoa(from->sin_addr)); } -#endif IP_HDRINCL + freehostinfo(hi); } - Fprintf(stderr, "traceroute to %s (%s)", hostname, - inet_ntoa(to->sin_addr)); + outip->ip_src = from->sin_addr; + + /* Check the source address (-s), if any, is valid */ + if (bind(sndsock, (struct sockaddr *)from, sizeof(*from)) < 0) { + Fprintf(stderr, "%s: bind: %s\n", + prog, strerror(errno)); + exit (1); + } + +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) + if (setpolicy(sndsock, "in bypass") < 0) + errx(1, "%s", ipsec_strerror()); + + if (setpolicy(sndsock, "out bypass") < 0) + errx(1, "%s", ipsec_strerror()); +#endif /* defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) */ + + Fprintf(stderr, "%s to %s (%s)", + prog, hostname, inet_ntoa(to->sin_addr)); if (source) Fprintf(stderr, " from %s", source); - Fprintf(stderr, ", %d hops max, %d byte packets\n", max_ttl, datalen); - (void) fflush(stderr); + Fprintf(stderr, ", %d hops max, %d byte packets\n", max_ttl, packlen); + (void)fflush(stderr); - for (ttl = 1; ttl <= max_ttl; ++ttl) { - u_long lastaddr = 0; + for (ttl = first_ttl; ttl <= max_ttl; ++ttl) { + u_int32_t lastaddr = 0; + int gotlastaddr = 0; int got_there = 0; int unreachable = 0; + int sentfirst = 0; + int loss; Printf("%2d ", ttl); - for (probe = 0; probe < nprobes; ++probe) { - int cc; + for (probe = 0, loss = 0; probe < nprobes; ++probe) { + register int cc; struct timeval t1, t2; struct timezone tz; - struct ip *ip; - - (void) gettimeofday(&t1, &tz); - send_probe(++seq, ttl); - while (cc = wait_for_reply(s, &from)) { - (void) gettimeofday(&t2, &tz); - if ((i = packet_ok(packet, cc, &from, seq))) { - if (from.sin_addr.s_addr != lastaddr) { - print(packet, cc, &from); - lastaddr = from.sin_addr.s_addr; - } - Printf(" %g ms", deltaT(&t1, &t2)); - switch(i - 1) { - case ICMP_UNREACH_PORT: + register struct ip *ip; + struct outdata outdata; + + if (sentfirst && pausemsecs > 0) + usleep(pausemsecs * 1000); + /* Prepare outgoing data */ + outdata.seq = ++seq; + outdata.ttl = ttl; + + /* Avoid alignment problems by copying bytewise: */ + (void)gettimeofday(&t1, &tz); + memcpy(&outdata.tv, &t1, sizeof(outdata.tv)); + + /* Finalize and send packet */ + (*proto->prepare)(&outdata); + send_probe(seq, ttl); + ++sentfirst; + + /* Wait for a reply */ + while ((cc = wait_for_reply(s, from, &t1)) != 0) { + double T; + int precis; + + (void)gettimeofday(&t2, &tz); + i = packet_ok(packet, cc, from, seq); + /* Skip short packet */ + if (i == 0) + continue; + if (!gotlastaddr || + from->sin_addr.s_addr != lastaddr) { + print(packet, cc, from); + lastaddr = from->sin_addr.s_addr; + ++gotlastaddr; + } + T = deltaT(&t1, &t2); +#ifdef SANE_PRECISION + if (T >= 1000.0) + precis = 0; + else if (T >= 100.0) + precis = 1; + else if (T >= 10.0) + precis = 2; + else +#endif + precis = 3; + Printf(" %.*f ms", precis, T); + if (i == -2) { #ifndef ARCHAIC - ip = (struct ip *)packet; - if (ip->ip_ttl <= 1) - Printf(" !"); -#endif ARCHAIC - ++got_there; - break; - case ICMP_UNREACH_NET: - ++unreachable; - Printf(" !N"); - break; - case ICMP_UNREACH_HOST: - ++unreachable; - Printf(" !H"); - break; - case ICMP_UNREACH_PROTOCOL: - ++got_there; - Printf(" !P"); - break; - case ICMP_UNREACH_NEEDFRAG: - ++unreachable; - Printf(" !F"); - break; - case ICMP_UNREACH_SRCFAIL: - ++unreachable; - Printf(" !S"); - break; - } + ip = (struct ip *)packet; + if (ip->ip_ttl <= 1) + Printf(" !"); +#endif + ++got_there; + break; + } + /* time exceeded in transit */ + if (i == -1) + break; + code = i - 1; + switch (code) { + + case ICMP_UNREACH_PORT: +#ifndef ARCHAIC + ip = (struct ip *)packet; + if (ip->ip_ttl <= 1) + Printf(" !"); +#endif + ++got_there; + break; + + case ICMP_UNREACH_NET: + ++unreachable; + Printf(" !N"); + break; + + case ICMP_UNREACH_HOST: + ++unreachable; + Printf(" !H"); + break; + + case ICMP_UNREACH_PROTOCOL: + ++got_there; + Printf(" !P"); + break; + + case ICMP_UNREACH_NEEDFRAG: + ++unreachable; + Printf(" !F-%d", pmtu); + break; + + case ICMP_UNREACH_SRCFAIL: + ++unreachable; + Printf(" !S"); + break; + + case ICMP_UNREACH_FILTER_PROHIB: + ++unreachable; + Printf(" !X"); + break; + + case ICMP_UNREACH_HOST_PRECEDENCE: + ++unreachable; + Printf(" !V"); + break; + + case ICMP_UNREACH_PRECEDENCE_CUTOFF: + ++unreachable; + Printf(" !C"); + break; + + default: + ++unreachable; + Printf(" !<%d>", code); break; } + break; } - if (cc == 0) + if (cc == 0) { + loss++; Printf(" *"); - (void) fflush(stdout); + } + (void)fflush(stdout); + } + if (sump) { + Printf(" (%d%% loss)", (loss * 100) / nprobes); } putchar('\n'); - if (got_there || unreachable >= nprobes-1) - exit(0); + if (got_there || + (unreachable > 0 && unreachable >= nprobes - 1)) + break; } + exit(0); } int -wait_for_reply(sock, from) - int sock; - struct sockaddr_in *from; +wait_for_reply(register int sock, register struct sockaddr_in *fromp, + register const struct timeval *tp) { - fd_set fds; - struct timeval wait; - int cc = 0; - int fromlen = sizeof (*from); - - FD_ZERO(&fds); - FD_SET(sock, &fds); - wait.tv_sec = waittime; wait.tv_usec = 0; + fd_set *fdsp; + size_t nfds; + struct timeval now, wait; + struct timezone tz; + register int cc = 0; + register int error; + int fromlen = sizeof(*fromp); + + nfds = howmany(sock + 1, NFDBITS); + if ((fdsp = malloc(nfds * sizeof(fd_mask))) == NULL) + err(1, "malloc"); + memset(fdsp, 0, nfds * sizeof(fd_mask)); + FD_SET(sock, fdsp); + + wait.tv_sec = tp->tv_sec + waittime; + wait.tv_usec = tp->tv_usec; + (void)gettimeofday(&now, &tz); + tvsub(&wait, &now); + if (wait.tv_sec < 0) { + wait.tv_sec = 0; + wait.tv_usec = 1; + } - if (select(sock+1, &fds, (fd_set *)0, (fd_set *)0, &wait) > 0) - cc=recvfrom(s, (char *)packet, sizeof(packet), 0, - (struct sockaddr *)from, &fromlen); + error = select(sock + 1, fdsp, NULL, NULL, &wait); + if (error == -1 && errno == EINVAL) { + Fprintf(stderr, "%s: botched select() args\n", prog); + exit(1); + } + if (error > 0) + cc = recvfrom(sock, (char *)packet, sizeof(packet), 0, + (struct sockaddr *)fromp, &fromlen); + free(fdsp); return(cc); } - void -send_probe(seq, ttl) - int seq, ttl; +send_probe(int seq, int ttl) { - struct opacket *op = outpacket; - struct ip *ip = &op->ip; - struct udphdr *up = &op->udp; - int i; + register int cc; + + outip->ip_ttl = ttl; + outip->ip_id = htons(ident + seq); + + /* XXX undocumented debugging hack */ + if (verbose > 1) { + register const u_short *sp; + register int nshorts, i; + + sp = (u_short *)outip; + nshorts = (u_int)packlen / sizeof(u_short); + i = 0; + Printf("[ %d bytes", packlen); + while (--nshorts >= 0) { + if ((i++ % 8) == 0) + Printf("\n\t"); + Printf(" %04x", ntohs(*sp++)); + } + if (packlen & 1) { + if ((i % 8) == 0) + Printf("\n\t"); + Printf(" %02x", *(u_char *)sp); + } + Printf("]\n"); + } - ip->ip_off = 0; - ip->ip_hl = sizeof(*ip) >> 2; - ip->ip_p = IPPROTO_UDP; - ip->ip_len = datalen; - ip->ip_ttl = ttl; - ip->ip_v = IPVERSION; - ip->ip_id = htons(ident+seq); - - up->uh_sport = htons(ident); - up->uh_dport = htons(port+seq); - up->uh_ulen = htons((u_short)(datalen - sizeof(struct ip))); - up->uh_sum = 0; - - op->seq = seq; - op->ttl = ttl; - (void) gettimeofday(&op->tv, &tz); - - i = sendto(sndsock, (char *)outpacket, datalen, 0, &whereto, - sizeof(struct sockaddr)); - if (i < 0 || i != datalen) { - if (i<0) - perror("sendto"); - Printf("traceroute: wrote %s %d chars, ret=%d\n", hostname, - datalen, i); - (void) fflush(stdout); +#if !defined(IP_HDRINCL) && defined(IP_TTL) + if (setsockopt(sndsock, IPPROTO_IP, IP_TTL, + (char *)&ttl, sizeof(ttl)) < 0) { + Fprintf(stderr, "%s: setsockopt ttl %d: %s\n", + prog, ttl, strerror(errno)); + exit(1); + } +#endif + + cc = sendto(sndsock, (char *)outip, + packlen, 0, &whereto, sizeof(whereto)); + if (cc < 0 || cc != packlen) { + if (cc < 0) + Fprintf(stderr, "%s: sendto: %s\n", + prog, strerror(errno)); + Printf("%s: wrote %s %d chars, ret=%d\n", + prog, hostname, packlen, cc); + (void)fflush(stdout); } } +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) +int +setpolicy(so, policy) + int so; + char *policy; +{ + char *buf; + + buf = ipsec_set_policy(policy, strlen(policy)); + if (buf == NULL) { + warnx("%s", ipsec_strerror()); + return -1; + } + (void)setsockopt(so, IPPROTO_IP, IP_IPSEC_POLICY, + buf, ipsec_get_policylen(buf)); + + free(buf); + + return 0; +} +#endif double -deltaT(t1p, t2p) - struct timeval *t1p, *t2p; +deltaT(struct timeval *t1p, struct timeval *t2p) { register double dt; @@ -646,13 +1173,11 @@ deltaT(t1p, t2p) return (dt); } - /* * Convert an ICMP "type" field to a printable string. */ char * -pr_type(t) - u_char t; +pr_type(register u_char t) { static char *ttab[] = { "Echo Reply", "ICMP 1", "ICMP 2", "Dest Unreachable", @@ -662,25 +1187,21 @@ pr_type(t) "Info Reply" }; - if(t > 16) + if (t > 16) return("OUT-OF-RANGE"); return(ttab[t]); } - int -packet_ok(buf, cc, from, seq) - u_char *buf; - int cc; - struct sockaddr_in *from; - int seq; +packet_ok(register u_char *buf, int cc, register struct sockaddr_in *from, + register int seq) { register struct icmp *icp; - u_char type, code; - int hlen; + register u_char type, code; + register int hlen; #ifndef ARCHAIC - struct ip *ip; + register struct ip *ip; ip = (struct ip *) buf; hlen = ip->ip_hl << 2; @@ -694,46 +1215,171 @@ packet_ok(buf, cc, from, seq) icp = (struct icmp *)(buf + hlen); #else icp = (struct icmp *)buf; -#endif ARCHAIC - type = icp->icmp_type; code = icp->icmp_code; +#endif + type = icp->icmp_type; + code = icp->icmp_code; + /* Path MTU Discovery (RFC1191) */ + if (code != ICMP_UNREACH_NEEDFRAG) + pmtu = 0; + else { +#ifdef HAVE_ICMP_NEXTMTU + pmtu = ntohs(icp->icmp_nextmtu); +#else + pmtu = ntohs(((struct my_pmtu *)&icp->icmp_void)->ipm_nextmtu); +#endif + } + if (type == ICMP_ECHOREPLY + && proto->num == IPPROTO_ICMP + && (*proto->check)((u_char *)icp, (u_char)seq)) + return -2; if ((type == ICMP_TIMXCEED && code == ICMP_TIMXCEED_INTRANS) || type == ICMP_UNREACH) { struct ip *hip; - struct udphdr *up; + u_char *inner; hip = &icp->icmp_ip; hlen = hip->ip_hl << 2; - up = (struct udphdr *)((u_char *)hip + hlen); - if (hlen + 12 <= cc && hip->ip_p == IPPROTO_UDP && - up->uh_sport == htons(ident) && - up->uh_dport == htons(port+seq)) - return (type == ICMP_TIMXCEED? -1 : code+1); + inner = (u_char *)((u_char *)hip + hlen); + if (hlen + 12 <= cc + && hip->ip_p == proto->num + && (*proto->check)(inner, (u_char)seq)) + return (type == ICMP_TIMXCEED ? -1 : code + 1); } #ifndef ARCHAIC if (verbose) { - int i; - u_long *lp = (u_long *)&icp->icmp_ip; - - Printf("\n%d bytes from %s to %s", cc, - inet_ntoa(from->sin_addr), inet_ntoa(ip->ip_dst)); - Printf(": icmp type %d (%s) code %d\n", type, pr_type(type), - icp->icmp_code); - for (i = 4; i < cc ; i += sizeof(long)) - Printf("%2d: x%8.8lx\n", i, *lp++); + register int i; + u_int32_t *lp = (u_int32_t *)&icp->icmp_ip; + + Printf("\n%d bytes from %s to ", cc, inet_ntoa(from->sin_addr)); + Printf("%s: icmp type %d (%s) code %d\n", + inet_ntoa(ip->ip_dst), type, pr_type(type), icp->icmp_code); + for (i = 4; i < cc ; i += sizeof(*lp)) + Printf("%2d: x%8.8x\n", i, *lp++); } -#endif ARCHAIC +#endif return(0); } +void +icmp_prep(struct outdata *outdata) +{ + struct icmp *const icmpheader = (struct icmp *) outp; + + icmpheader->icmp_type = ICMP_ECHO; + icmpheader->icmp_id = htons(ident); + icmpheader->icmp_seq = htons(outdata->seq); + icmpheader->icmp_cksum = 0; + icmpheader->icmp_cksum = in_cksum((u_short *)icmpheader, protlen); + if (icmpheader->icmp_cksum == 0) + icmpheader->icmp_cksum = 0xffff; +} + +int +icmp_check(const u_char *data, int seq) +{ + struct icmp *const icmpheader = (struct icmp *) data; + + return (icmpheader->icmp_id == htons(ident) + && icmpheader->icmp_seq == htons(seq)); +} + +void +udp_prep(struct outdata *outdata) +{ + struct udphdr *const outudp = (struct udphdr *) outp; + + outudp->uh_sport = htons(ident); + outudp->uh_dport = htons(port + outdata->seq); + outudp->uh_ulen = htons((u_short)protlen); + outudp->uh_sum = 0; + if (doipcksum) { + u_short sum = p_cksum(outip, (u_short*)outudp, protlen); + outudp->uh_sum = (sum) ? sum : 0xffff; + } + + return; +} + +int +udp_check(const u_char *data, int seq) +{ + struct udphdr *const udp = (struct udphdr *) data; + + return (ntohs(udp->uh_sport) == ident + && ntohs(udp->uh_dport) == port + seq); +} + +void +tcp_prep(struct outdata *outdata) +{ + struct tcphdr *const tcp = (struct tcphdr *) outp; + + tcp->th_sport = htons(ident); + tcp->th_dport = htons(port + outdata->seq); + tcp->th_seq = (tcp->th_sport << 16) | tcp->th_dport; + tcp->th_ack = 0; + tcp->th_off = 5; + tcp->th_flags = TH_SYN; + tcp->th_sum = 0; + + if (doipcksum) { + u_short sum = p_cksum(outip, (u_short*)tcp, protlen); + tcp->th_sum = (sum) ? sum : 0xffff; + } +} + +int +tcp_check(const u_char *data, int seq) +{ + struct tcphdr *const tcp = (struct tcphdr *) data; + + return (ntohs(tcp->th_sport) == ident + && ntohs(tcp->th_dport) == port + seq); +} void -print(buf, cc, from) - u_char *buf; - int cc; - struct sockaddr_in *from; +gre_prep(struct outdata *outdata) { - struct ip *ip; - int hlen; + struct grehdr *const gre = (struct grehdr *) outp; + + gre->flags = htons(0x2001); + gre->proto = htons(port); + gre->length = 0; + gre->callId = htons(ident + outdata->seq); +} + +int +gre_check(const u_char *data, int seq) +{ + struct grehdr *const gre = (struct grehdr *) data; + + return(ntohs(gre->proto) == port + && ntohs(gre->callId) == ident + seq); +} + +void +gen_prep(struct outdata *outdata) +{ + u_int16_t *const ptr = (u_int16_t *) outp; + + ptr[0] = htons(ident); + ptr[1] = htons(port + outdata->seq); +} + +int +gen_check(const u_char *data, int seq) +{ + u_int16_t *const ptr = (u_int16_t *) data; + + return(ntohs(ptr[0]) == ident + && ntohs(ptr[1]) == port + seq); +} + +void +print(register u_char *buf, register int cc, register struct sockaddr_in *from) +{ + register struct ip *ip; + register int hlen; ip = (struct ip *) buf; hlen = ip->ip_hl << 2; @@ -743,21 +1389,39 @@ print(buf, cc, from) Printf(" %s", inet_ntoa(from->sin_addr)); else Printf(" %s (%s)", inetname(from->sin_addr), - inet_ntoa(from->sin_addr)); + inet_ntoa(from->sin_addr)); if (verbose) - Printf (" %d bytes to %s", cc, inet_ntoa (ip->ip_dst)); + Printf(" %d bytes to %s", cc, inet_ntoa (ip->ip_dst)); } +/* + * Checksum routine for UDP and TCP headers. + */ +u_short +p_cksum(struct ip *ip, u_short *data, int len) +{ + static struct ipovly ipo; + u_short sumh, sumd; + u_long sumt; + + ipo.ih_pr = ip->ip_p; + ipo.ih_len = htons(len); + ipo.ih_src = ip->ip_src; + ipo.ih_dst = ip->ip_dst; + + sumh = in_cksum((u_short*)&ipo, sizeof(ipo)); /* pseudo ip hdr cksum */ + sumd = in_cksum((u_short*)data, len); /* payload data cksum */ + sumt = (sumh << 16) | (sumd); + + return ~in_cksum((u_short*)&sumt, sizeof(sumt)); +} -#ifdef notyet /* * Checksum routine for Internet Protocol family headers (C Version) */ u_short -in_cksum(addr, len) - u_short *addr; - int len; +in_cksum(register u_short *addr, register int len) { register int nleft = len; register u_short *w = addr; @@ -787,73 +1451,228 @@ in_cksum(addr, len) answer = ~sum; /* truncate to 16 bits */ return (answer); } -#endif notyet /* * Subtract 2 timeval structs: out = out - in. - * Out is assumed to be >= in. + * Out is assumed to be within about LONG_MAX seconds of in. */ void -tvsub(out, in) - register struct timeval *out, *in; +tvsub(register struct timeval *out, register struct timeval *in) { + if ((out->tv_usec -= in->tv_usec) < 0) { - out->tv_sec--; + --out->tv_sec; out->tv_usec += 1000000; } out->tv_sec -= in->tv_sec; } - /* * Construct an Internet address representation. * If the nflag has been supplied, give * numeric value, otherwise try for symbolic name. */ char * -inetname(in) - struct in_addr in; +inetname(struct in_addr in) { register char *cp; - static char line[50]; - struct hostent *hp; - static char domain[MAXHOSTNAMELEN + 1]; + register struct hostent *hp; static int first = 1; + static char domain[MAXHOSTNAMELEN + 1], line[MAXHOSTNAMELEN + 1]; if (first && !nflag) { first = 0; - if (gethostname(domain, MAXHOSTNAMELEN) == 0 && - (cp = index(domain, '.'))) - (void) strcpy(domain, cp + 1); - else - domain[0] = 0; + if (gethostname(domain, sizeof(domain) - 1) < 0) + domain[0] = '\0'; + else { + cp = strchr(domain, '.'); + if (cp == NULL) { + hp = gethostbyname(domain); + if (hp != NULL) + cp = strchr(hp->h_name, '.'); + } + if (cp == NULL) + domain[0] = '\0'; + else { + ++cp; + (void)strncpy(domain, cp, sizeof(domain) - 1); + domain[sizeof(domain) - 1] = '\0'; + } + } } - cp = 0; if (!nflag && in.s_addr != INADDR_ANY) { - hp = gethostbyaddr((char *)&in, sizeof (in), AF_INET); - if (hp) { - if ((cp = index(hp->h_name, '.')) && - !strcmp(cp + 1, domain)) - *cp = 0; - cp = hp->h_name; + hp = gethostbyaddr((char *)&in, sizeof(in), AF_INET); + if (hp != NULL) { + if ((cp = strchr(hp->h_name, '.')) != NULL && + strcmp(cp + 1, domain) == 0) + *cp = '\0'; + (void)strncpy(line, hp->h_name, sizeof(line) - 1); + line[sizeof(line) - 1] = '\0'; + return (line); } } - if (cp) - (void) strcpy(line, cp); - else { - in.s_addr = ntohl(in.s_addr); -#define C(x) ((x) & 0xff) - Sprintf(line, "%lu.%lu.%lu.%lu", C(in.s_addr >> 24), - C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr)); + return (inet_ntoa(in)); +} + +struct hostinfo * +gethostinfo(register char *hostname) +{ + register int n; + register struct hostent *hp; + register struct hostinfo *hi; + register char **p; + register u_int32_t addr, *ap; + + if (strlen(hostname) > 64) { + Fprintf(stderr, "%s: hostname \"%.32s...\" is too long\n", + prog, hostname); + exit(1); + } + hi = calloc(1, sizeof(*hi)); + if (hi == NULL) { + Fprintf(stderr, "%s: calloc %s\n", prog, strerror(errno)); + exit(1); } - return (line); + addr = inet_addr(hostname); + if ((int32_t)addr != -1) { + hi->name = strdup(hostname); + hi->n = 1; + hi->addrs = calloc(1, sizeof(hi->addrs[0])); + if (hi->addrs == NULL) { + Fprintf(stderr, "%s: calloc %s\n", + prog, strerror(errno)); + exit(1); + } + hi->addrs[0] = addr; + return (hi); + } + + hp = gethostbyname(hostname); + if (hp == NULL) { + Fprintf(stderr, "%s: unknown host %s\n", prog, hostname); + exit(1); + } + if (hp->h_addrtype != AF_INET || hp->h_length != 4) { + Fprintf(stderr, "%s: bad host %s\n", prog, hostname); + exit(1); + } + hi->name = strdup(hp->h_name); + for (n = 0, p = hp->h_addr_list; *p != NULL; ++n, ++p) + continue; + hi->n = n; + hi->addrs = calloc(n, sizeof(hi->addrs[0])); + if (hi->addrs == NULL) { + Fprintf(stderr, "%s: calloc %s\n", prog, strerror(errno)); + exit(1); + } + for (ap = hi->addrs, p = hp->h_addr_list; *p != NULL; ++ap, ++p) + memcpy(ap, *p, sizeof(*ap)); + return (hi); +} + +void +freehostinfo(register struct hostinfo *hi) +{ + if (hi->name != NULL) { + free(hi->name); + hi->name = NULL; + } + free((char *)hi->addrs); + free((char *)hi); +} + +void +getaddr(register u_int32_t *ap, register char *hostname) +{ + register struct hostinfo *hi; + + hi = gethostinfo(hostname); + *ap = hi->addrs[0]; + freehostinfo(hi); } void -usage() +setsin(register struct sockaddr_in *sin, register u_int32_t addr) { - (void)fprintf(stderr, -"usage: traceroute [-dnrv] [-m max_ttl] [-p port#] [-q nqueries]\n\t\ -[-s src_addr] [-t tos] [-w wait] host [data size]\n"); + + memset(sin, 0, sizeof(*sin)); +#ifdef HAVE_SOCKADDR_SA_LEN + sin->sin_len = sizeof(*sin); +#endif + sin->sin_family = AF_INET; + sin->sin_addr.s_addr = addr; +} + +/* String to value with optional min and max. Handles decimal and hex. */ +int +str2val(register const char *str, register const char *what, + register int mi, register int ma) +{ + register const char *cp; + register int val; + char *ep; + + if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { + cp = str + 2; + val = (int)strtol(cp, &ep, 16); + } else + val = (int)strtol(str, &ep, 10); + if (*ep != '\0') { + Fprintf(stderr, "%s: \"%s\" bad value for %s \n", + prog, str, what); + exit(1); + } + if (val < mi && mi >= 0) { + if (mi == 0) + Fprintf(stderr, "%s: %s must be >= %d\n", + prog, what, mi); + else + Fprintf(stderr, "%s: %s must be > %d\n", + prog, what, mi - 1); + exit(1); + } + if (val > ma && ma >= 0) { + Fprintf(stderr, "%s: %s must be <= %d\n", prog, what, ma); + exit(1); + } + return (val); +} + +struct outproto * +setproto(char *pname) +{ + struct outproto *proto; + int i; + + for (i = 0; protos[i].name != NULL; i++) { + if (strcasecmp(protos[i].name, pname) == 0) { + break; + } + } + proto = &protos[i]; + if (proto->name == NULL) { /* generic handler */ + struct protoent *pe; + u_long pnum; + + /* Determine the IP protocol number */ + if ((pe = getprotobyname(pname)) != NULL) + pnum = pe->p_proto; + else + pnum = str2val(optarg, "proto number", 1, 255); + proto->num = pnum; + } + return proto; +} + +void +usage(void) +{ + extern char version[]; + + Fprintf(stderr, "Version %s\n", version); + Fprintf(stderr, + "Usage: %s [-dFInrSvx] [-g gateway] [-i iface] [-f first_ttl]\n" + "\t[-m max_ttl] [-p port] [-P proto] [-q nqueries] [-s src_addr]\n" + "\t[-t tos] [-w waittime] [-z pausemsecs] host [packetlen]\n", prog); exit(1); } diff --git a/traceroute.tproj/traceroute.h b/traceroute.tproj/traceroute.h new file mode 100644 index 0000000..31154d8 --- /dev/null +++ b/traceroute.tproj/traceroute.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2000 + * 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: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * @(#) $Id: traceroute.h,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL) + */ + +extern char *prog; + +void setsin(struct sockaddr_in *, u_int32_t); diff --git a/traceroute.tproj/version.c b/traceroute.tproj/version.c new file mode 100644 index 0000000..680dcd4 --- /dev/null +++ b/traceroute.tproj/version.c @@ -0,0 +1 @@ +char version[] = "1.4a12+Darwin"; diff --git a/trpt.tproj/Makefile b/trpt.tproj/Makefile index 5b58165..779a7d3 100644 --- a/trpt.tproj/Makefile +++ b/trpt.tproj/Makefile @@ -28,6 +28,8 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) +HEADER_PATHS =\ + -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/ NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc diff --git a/trpt.tproj/Makefile.postamble b/trpt.tproj/Makefile.postamble index a38e0df..254f38a 100644 --- a/trpt.tproj/Makefile.postamble +++ b/trpt.tproj/Makefile.postamble @@ -108,3 +108,7 @@ STRIPFLAGS = # Makefile API), which are rules that get invoked before and after the install # target runs. Such rules should be specified with the '::' syntax rather than # a single colon. + +after_install: + install -d $(DSTROOT)/usr/share/man/man8 + install -c -m 444 trpt.8 $(DSTROOT)/usr/share/man/man8/trpt.8 diff --git a/trpt.tproj/trpt.c b/trpt.tproj/trpt.c index 4677cc5..0f1f66a 100644 --- a/trpt.tproj/trpt.c +++ b/trpt.tproj/trpt.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/wall.tproj/Makefile.postamble b/wall.tproj/Makefile.postamble index 851f5b0..43234e7 100644 --- a/wall.tproj/Makefile.postamble +++ b/wall.tproj/Makefile.postamble @@ -121,3 +121,7 @@ STRIPFLAGS = # # Note: on MS Windows, executables, have an extension, so rules and dependencies # for generated tools should use $(EXECUTABLE_EXT) on the end. + +after_install: + install -d $(DSTROOT)/usr/share/man/man1 + install -c -m 444 wall.1 $(DSTROOT)/usr/share/man/man1/wall.1 diff --git a/ypbind.tproj/yp.x b/ypbind.tproj/yp.x index 901b12e..cf2be0c 100644 --- a/ypbind.tproj/yp.x +++ b/ypbind.tproj/yp.x @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypbind.tproj/ypbind.c b/ypbind.tproj/ypbind.c index 61f7b8a..bad58c0 100644 --- a/ypbind.tproj/ypbind.c +++ b/ypbind.tproj/ypbind.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypcat.tproj/ypcat.c b/ypcat.tproj/ypcat.c index 5529348..72e4e45 100644 --- a/ypcat.tproj/ypcat.c +++ b/ypcat.tproj/ypcat.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypmatch.tproj/ypmatch.c b/ypmatch.tproj/ypmatch.c index aca45bf..5f78260 100644 --- a/ypmatch.tproj/ypmatch.c +++ b/ypmatch.tproj/ypmatch.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/yppoll.tproj/yppoll.c b/yppoll.tproj/yppoll.c index 77f877a..5f1ddc5 100644 --- a/yppoll.tproj/yppoll.c +++ b/yppoll.tproj/yppoll.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/yppush.tproj/ypdb.c b/yppush.tproj/ypdb.c index 9530e42..c9bd178 100644 --- a/yppush.tproj/ypdb.c +++ b/yppush.tproj/ypdb.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/yppush.tproj/ypdb.h b/yppush.tproj/ypdb.h index 61e9547..45b0a7f 100644 --- a/yppush.tproj/ypdb.h +++ b/yppush.tproj/ypdb.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/yppush.tproj/ypdef.h b/yppush.tproj/ypdef.h index ade70ef..89970d7 100644 --- a/yppush.tproj/ypdef.h +++ b/yppush.tproj/ypdef.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/yppush.tproj/yplib_host.c b/yppush.tproj/yplib_host.c index 275211b..70b914b 100644 --- a/yppush.tproj/yplib_host.c +++ b/yppush.tproj/yplib_host.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/yppush.tproj/yplib_host.h b/yppush.tproj/yplib_host.h index 32d43cd..038fb68 100644 --- a/yppush.tproj/yplib_host.h +++ b/yppush.tproj/yplib_host.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/yppush.tproj/yppush.c b/yppush.tproj/yppush.c index 3249369..56aa157 100644 --- a/yppush.tproj/yppush.c +++ b/yppush.tproj/yppush.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -68,6 +67,7 @@ static char rcsid[] = "$OpenBSD: yppush.c,v 1.10 1997/11/10 05:49:17 deraadt Exp #include #include #include +#include #include #include #include diff --git a/yppush.tproj/yppush.h b/yppush.tproj/yppush.h index a84ccd1..9aa8dc5 100644 --- a/yppush.tproj/yppush.h +++ b/yppush.tproj/yppush.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/yppush.tproj/yppush_err.c b/yppush.tproj/yppush_err.c index 9ec329d..31f74e8 100644 --- a/yppush.tproj/yppush_err.c +++ b/yppush.tproj/yppush_err.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/yppush.tproj/yppush_proc.c b/yppush.tproj/yppush_proc.c index dec62eb..601a7cb 100644 --- a/yppush.tproj/yppush_proc.c +++ b/yppush.tproj/yppush_proc.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/yppush.tproj/yppush_svc.c b/yppush.tproj/yppush_svc.c index 80006ae..f3c19dc 100644 --- a/yppush.tproj/yppush_svc.c +++ b/yppush.tproj/yppush_svc.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/yppush.tproj/yppush_xdr.c b/yppush.tproj/yppush_xdr.c index 59da531..d8ad787 100644 --- a/yppush.tproj/yppush_xdr.c +++ b/yppush.tproj/yppush_xdr.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypserv.tproj/acl.c b/ypserv.tproj/acl.c index 6f0f1f5..4ac671d 100644 --- a/ypserv.tproj/acl.c +++ b/ypserv.tproj/acl.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -121,7 +120,7 @@ int size; } int -acl_check_host(addr) +yp_acl_check_host(addr) struct in_addr *addr; { struct aclent *p; @@ -175,7 +174,7 @@ struct in_addr *addr; } int -acl_init(file) +yp_acl_init(file) char *file; { char data_line[1024]; @@ -477,7 +476,7 @@ char *file; } int -acl_securenet(file) +yp_acl_securenet(file) char *file; { char data_line[1024]; @@ -630,7 +629,7 @@ char *file; } void -acl_reset() +yp_acl_reset() { struct aclent *p; diff --git a/ypserv.tproj/acl.h b/ypserv.tproj/acl.h index e5bc46a..fc5afa5 100644 --- a/ypserv.tproj/acl.h +++ b/ypserv.tproj/acl.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -100,10 +99,10 @@ struct aclent *next; }; __BEGIN_DECLS -int acl_check_host __P((struct in_addr *)); -int acl_init __P((char *)); -int acl_securenet __P((char *)); -void acl_reset __P((void)); +int yp_acl_check_host __P((struct in_addr *)); +int yp_acl_init __P((char *)); +int yp_acl_securenet __P((char *)); +void yp_acl_reset __P((void)); __END_DECLS #endif /* !_ACL_H_ */ diff --git a/ypserv.tproj/yp.h b/ypserv.tproj/yp.h index ec9b22d..cfe590b 100644 --- a/ypserv.tproj/yp.h +++ b/ypserv.tproj/yp.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypserv.tproj/ypdb.c b/ypserv.tproj/ypdb.c index 9530e42..c9bd178 100644 --- a/ypserv.tproj/ypdb.c +++ b/ypserv.tproj/ypdb.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypserv.tproj/ypdb.h b/ypserv.tproj/ypdb.h index 61e9547..45b0a7f 100644 --- a/ypserv.tproj/ypdb.h +++ b/ypserv.tproj/ypdb.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypserv.tproj/ypdef.h b/ypserv.tproj/ypdef.h index ade70ef..89970d7 100644 --- a/ypserv.tproj/ypdef.h +++ b/ypserv.tproj/ypdef.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypserv.tproj/yplog.c b/ypserv.tproj/yplog.c index a791cc7..3460c9a 100644 --- a/ypserv.tproj/yplog.c +++ b/ypserv.tproj/yplog.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypserv.tproj/yplog.h b/ypserv.tproj/yplog.h index d9a7254..c517042 100644 --- a/ypserv.tproj/yplog.h +++ b/ypserv.tproj/yplog.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -56,9 +55,11 @@ #ifndef _YPLOG_H_ #define _YPLOG_H_ +#include + __BEGIN_DECLS void yplog __P((const char *, ...)); -void vyplog __P((const char *, _BSD_VA_LIST_)); +void vyplog __P((const char *, va_list)); void ypopenlog __P((void)); void ypcloselog __P((void)); __END_DECLS diff --git a/ypserv.tproj/ypserv.c b/ypserv.tproj/ypserv.c index e38c696..f9c0e2b 100644 --- a/ypserv.tproj/ypserv.c +++ b/ypserv.tproj/ypserv.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -407,9 +406,9 @@ char *argv[]; } if (aclfile != NULL) { - (void)acl_init(aclfile); + (void)yp_acl_init(aclfile); } else { - (void)acl_securenet(YP_SECURENET_FILE); + (void)yp_acl_securenet(YP_SECURENET_FILE); } if (xflag) { exit(1); @@ -549,12 +548,12 @@ sig_child() void sig_hup() { - acl_reset(); + yp_acl_reset(); if (aclfile != NULL) { yplog("sig_hup: reread %s",aclfile); - (void)acl_init(aclfile); + (void)yp_acl_init(aclfile); } else { yplog("sig_hup: reread %s",YP_SECURENET_FILE); - (void)acl_securenet(YP_SECURENET_FILE); + (void)yp_acl_securenet(YP_SECURENET_FILE); } } diff --git a/ypserv.tproj/ypserv_db.c b/ypserv.tproj/ypserv_db.c index 88c9ab5..b7b6469 100644 --- a/ypserv.tproj/ypserv_db.c +++ b/ypserv.tproj/ypserv_db.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypserv.tproj/ypserv_proc.c b/ypserv.tproj/ypserv_proc.c index 1aeb533..e9b389e 100644 --- a/ypserv.tproj/ypserv_proc.c +++ b/ypserv.tproj/ypserv_proc.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -103,7 +102,7 @@ ypproc_null_2_svc(argp, rqstp) { static char *result; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); YPLOG("null_2: caller=[%s].%d, auth_ok=%s", inet_ntoa(caller->sin_addr), ntohs(caller->sin_port), TORF(ok)); @@ -125,7 +124,7 @@ ypproc_domain_2_svc(argp, rqstp) { static bool_t result; /* is domain_served? */ struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); static char domain_path[MAXPATHLEN]; struct stat finfo; @@ -155,7 +154,7 @@ ypproc_domain_nonack_2_svc(argp, rqstp) { static bool_t result; /* is domain served? */ struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); static char domain_path[MAXPATHLEN]; struct stat finfo; @@ -190,7 +189,7 @@ ypproc_match_2_svc(argp, rqstp) { static ypresp_val res; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure = ypdb_secure(argp->domain,argp->map); if (strchr(argp->domain, '/') || strchr(argp->map, '/')) @@ -227,7 +226,7 @@ ypproc_first_2_svc(argp, rqstp) { static ypresp_key_val res; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure = ypdb_secure(argp->domain,argp->map); if (strchr(argp->domain, '/') || strchr(argp->map, '/')) @@ -263,7 +262,7 @@ ypproc_next_2_svc(argp, rqstp) { static ypresp_key_val res; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure = ypdb_secure(argp->domain,argp->map); if (strchr(argp->domain, '/') || strchr(argp->map, '/')) @@ -300,7 +299,7 @@ ypproc_xfr_2_svc(argp, rqstp) { static ypresp_xfr res; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); pid_t pid; char tid[11]; char prog[11]; @@ -352,7 +351,7 @@ ypproc_clear_2_svc(argp, rqstp) { static char *res; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); YPLOG( "clear_2: caller=[%s].%d, auth_ok=%s, opt=%s", inet_ntoa(caller->sin_addr), ntohs(caller->sin_port), TORF(ok), @@ -388,7 +387,7 @@ ypproc_all_2_svc(argp, rqstp) static ypresp_all res; pid_t pid; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure = ypdb_secure(argp->domain,argp->map); if (strchr(argp->domain, '/') || strchr(argp->map, '/')) @@ -440,7 +439,7 @@ ypproc_master_2_svc(argp, rqstp) static ypresp_master res; static peername nopeer = ""; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure = ypdb_secure(argp->domain,argp->map); if (strchr(argp->domain, '/') || strchr(argp->map, '/')) @@ -491,7 +490,7 @@ ypproc_order_2_svc(argp, rqstp) { static ypresp_order res; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure = ypdb_secure(argp->domain,argp->map); if (strchr(argp->domain, '/')) @@ -529,7 +528,7 @@ ypproc_maplist_2_svc(argp, rqstp) { static ypresp_maplist res; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); static char domain_path[MAXPATHLEN]; struct stat finfo; DIR *dirp = NULL; @@ -620,7 +619,7 @@ ypproc_null_1_svc(argp, rqstp) { static char *result; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); YPLOG("null_1: caller=[%s].%d, auth_ok=%s", inet_ntoa(caller->sin_addr), ntohs(caller->sin_port), TORF(ok)); @@ -642,7 +641,7 @@ ypproc_domain_1_svc(argp, rqstp) { static bool_t result; /* is domain_served? */ struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); static char domain_path[MAXPATHLEN]; struct stat finfo; @@ -672,7 +671,7 @@ ypproc_domain_nonack_1_svc(argp, rqstp) { static bool_t result; /* is domain served? */ struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); static char domain_path[MAXPATHLEN]; struct stat finfo; @@ -707,7 +706,7 @@ ypproc_match_1_svc(argp, rqstp) { static ypresponse res; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure; if (strchr(argp->ypmatch_req_domain, '/') || @@ -762,7 +761,7 @@ ypproc_first_1_svc(argp, rqstp) { static ypresponse res; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure; if (strchr(argp->ypfirst_req_domain, '/') || @@ -814,7 +813,7 @@ ypproc_next_1_svc(argp, rqstp) { static ypresponse res; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure; if (strchr(argp->ypnext_req_domain, '/') || @@ -871,7 +870,7 @@ ypproc_poll_1_svc(argp, rqstp) ypresp_order order; ypresp_master master; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure; if (strchr(argp->yppoll_req_domain, '/') || @@ -921,7 +920,7 @@ ypproc_push_1_svc(argp, rqstp) struct svc_req *rqstp; { struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure; pid_t pid; char yppush_proc[] = YPPUSH_PROC; @@ -969,7 +968,7 @@ ypproc_pull_1_svc(argp, rqstp) struct svc_req *rqstp; { struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure; pid_t pid; char ypxfr_proc[] = YPXFR_PROC; @@ -1018,7 +1017,7 @@ ypproc_get_1_svc(argp, rqstp) { char *res; struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt); - int ok = acl_check_host(&caller->sin_addr); + int ok = yp_acl_check_host(&caller->sin_addr); int secure; pid_t pid; char ypxfr_proc[] = YPXFR_PROC; diff --git a/ypserv.tproj/ypserv_xdr.c b/ypserv.tproj/ypserv_xdr.c index f7d47cf..2e1fb2a 100644 --- a/ypserv.tproj/ypserv_xdr.c +++ b/ypserv.tproj/ypserv_xdr.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypserv.tproj/ypserv_xdr_v1.c b/ypserv.tproj/ypserv_xdr_v1.c index d77755d..3870f58 100644 --- a/ypserv.tproj/ypserv_xdr_v1.c +++ b/ypserv.tproj/ypserv_xdr_v1.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypserv.tproj/ypv1.h b/ypserv.tproj/ypv1.h index 431ce33..d378f83 100644 --- a/ypserv.tproj/ypv1.h +++ b/ypserv.tproj/ypv1.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypset.tproj/ypset.c b/ypset.tproj/ypset.c index 834ca8a..cddc148 100644 --- a/ypset.tproj/ypset.c +++ b/ypset.tproj/ypset.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypwhich.tproj/ypwhich.c b/ypwhich.tproj/ypwhich.c index 9b8b736..523e1d0 100644 --- a/ypwhich.tproj/ypwhich.c +++ b/ypwhich.tproj/ypwhich.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypxfr.tproj/ypdb.c b/ypxfr.tproj/ypdb.c index 9530e42..c9bd178 100644 --- a/ypxfr.tproj/ypdb.c +++ b/ypxfr.tproj/ypdb.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypxfr.tproj/ypdb.h b/ypxfr.tproj/ypdb.h index 61e9547..45b0a7f 100644 --- a/ypxfr.tproj/ypdb.h +++ b/ypxfr.tproj/ypdb.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypxfr.tproj/ypdef.h b/ypxfr.tproj/ypdef.h index ade70ef..89970d7 100644 --- a/ypxfr.tproj/ypdef.h +++ b/ypxfr.tproj/ypdef.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypxfr.tproj/yplib_host.c b/ypxfr.tproj/yplib_host.c index 275211b..70b914b 100644 --- a/ypxfr.tproj/yplib_host.c +++ b/ypxfr.tproj/yplib_host.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypxfr.tproj/yplib_host.h b/ypxfr.tproj/yplib_host.h index 32d43cd..038fb68 100644 --- a/ypxfr.tproj/yplib_host.h +++ b/ypxfr.tproj/yplib_host.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypxfr.tproj/yplog.c b/ypxfr.tproj/yplog.c index a791cc7..3460c9a 100644 --- a/ypxfr.tproj/yplog.c +++ b/ypxfr.tproj/yplog.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypxfr.tproj/yplog.h b/ypxfr.tproj/yplog.h index d9a7254..c517042 100644 --- a/ypxfr.tproj/yplog.h +++ b/ypxfr.tproj/yplog.h @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -56,9 +55,11 @@ #ifndef _YPLOG_H_ #define _YPLOG_H_ +#include + __BEGIN_DECLS void yplog __P((const char *, ...)); -void vyplog __P((const char *, _BSD_VA_LIST_)); +void vyplog __P((const char *, va_list)); void ypopenlog __P((void)); void ypcloselog __P((void)); __END_DECLS diff --git a/ypxfr.tproj/ypxfr.c b/ypxfr.tproj/ypxfr.c index ee763f7..faa88bf 100644 --- a/ypxfr.tproj/ypxfr.c +++ b/ypxfr.tproj/ypxfr.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/ypxfr.tproj/ypxfr_xdr.c b/ypxfr.tproj/ypxfr_xdr.c index a7d2458..460addf 100644 --- a/ypxfr.tproj/ypxfr_xdr.c +++ b/ypxfr.tproj/ypxfr_xdr.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */