From 2fc1e207eccd68aee093ed29dae719e77bac17dd Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 18 Feb 2005 00:27:08 +0000 Subject: [PATCH] system_cmds-336.tar.gz --- APPLE_LICENSE | 695 +++++++-------- Makefile | 4 +- Makefile.preamble | 1 + PB.project | 2 + ac.tproj/ac.c | 21 +- accton.tproj/accton.c | 21 +- arch.tproj/arch.c | 21 +- at.tproj/Makefile | 6 +- at.tproj/Makefile.postamble | 2 +- at.tproj/at.1 | 18 +- at.tproj/at.c | 1235 ++++++++++++++++---------- at.tproj/at.h | 37 +- at.tproj/panic.c | 96 +- at.tproj/panic.h | 44 +- at.tproj/parsetime.c | 476 +++++----- at.tproj/parsetime.h | 37 +- at.tproj/pathnames.h | 21 +- at.tproj/perm.c | 60 +- at.tproj/perm.h | 28 +- at.tproj/privs.h | 86 +- atrun.tproj/Makefile | 6 +- atrun.tproj/Makefile.postamble | 5 + atrun.tproj/PB.project | 2 +- atrun.tproj/atrun.c | 662 ++++++++------ atrun.tproj/atrun.h | 21 +- atrun.tproj/com.apple.atrun.plist | 16 + audit.tproj/Makefile | 50 ++ audit.tproj/Makefile.postamble | 86 ++ audit.tproj/Makefile.preamble | 19 + audit.tproj/PB.project | 32 + audit.tproj/audit.1 | 43 + audit.tproj/audit.c | 91 ++ audit.tproj/auditd_control.defs | 25 + auditd.tproj/Makefile | 52 ++ auditd.tproj/Makefile.postamble | 121 +++ auditd.tproj/Makefile.preamble | 18 + auditd.tproj/PB.project | 38 + auditd.tproj/audit_triggers.defs | 1 + auditd.tproj/audit_warn.c | 207 +++++ auditd.tproj/auditd.8 | 48 + auditd.tproj/auditd.c | 791 +++++++++++++++++ auditd.tproj/auditd.h | 51 ++ auditd.tproj/auditd_control.defs | 39 + auditd.tproj/rc.audit | 25 + chkpasswd.tproj/Makefile | 2 +- chkpasswd.tproj/Makefile.postamble | 4 + chkpasswd.tproj/chkpasswd.8 | 53 ++ chkpasswd.tproj/ds_passwd.c | 21 +- chkpasswd.tproj/file_passwd.c | 21 +- chkpasswd.tproj/netinfo_passwd.c | 21 +- chkpasswd.tproj/nis_passwd.c | 21 +- chkpasswd.tproj/passwd.c | 21 +- chkpasswd.tproj/stringops.c | 21 +- chkpasswd.tproj/stringops.h | 21 +- chpass.tproj/chpass.c | 68 +- chpass.tproj/chpass.h | 23 +- chpass.tproj/directory_service.c | 411 +++++---- chpass.tproj/directory_service.h | 2 +- chpass.tproj/ds_pw_util.c | 21 +- chpass.tproj/edit.c | 21 +- chpass.tproj/field.c | 21 +- chpass.tproj/pathnames.h | 21 +- chpass.tproj/pw_copy.c | 21 +- chpass.tproj/pw_copy.h | 21 +- chpass.tproj/table.c | 21 +- chpass.tproj/util.c | 21 +- dmesg.tproj/Makefile.postamble | 4 + dmesg.tproj/dmesg.c | 21 +- dynamic_pager.tproj/dynamic_pager.8 | 3 + dynamic_pager.tproj/dynamic_pager.c | 25 +- fs_usage.tproj/Makefile | 1 - fs_usage.tproj/fs_usage.1 | 2 +- fs_usage.tproj/fs_usage.c | 237 +++-- getconf.tproj/limits.gperf | 5 +- getconf.tproj/pathconf.gperf | 5 +- getconf.tproj/sysconf.gperf | 9 + getty.tproj/Makefile.postamble | 6 + getty.tproj/extern.h | 21 +- getty.tproj/gettytab.h | 21 +- getty.tproj/init.c | 21 +- getty.tproj/main.c | 27 +- getty.tproj/pathnames.h | 21 +- getty.tproj/subr.c | 25 +- hostinfo.tproj/hostinfo.c | 22 +- iostat.tproj/iostat.c | 26 +- kdump.tproj/Makefile | 2 +- kdump.tproj/kdump.c | 159 ++-- kdump.tproj/mkioctls | 8 +- kdump.tproj/syscalls.c | 810 +++++++++-------- kgmon.tproj/Makefile.postamble | 4 + kgmon.tproj/kgmon.c | 21 +- ktrace.tproj/Makefile | 1 + ktrace.tproj/ktrace.c | 54 +- ktrace.tproj/ktrace.h | 9 + ktrace.tproj/subr.c | 37 +- latency.tproj/latency.c | 24 +- login.tproj/Makefile | 2 +- login.tproj/PB.project | 2 +- login.tproj/klogin.c | 21 +- login.tproj/login.c | 402 +++++++-- login.tproj/pathnames.h | 21 +- makekey.tproj/Makefile.postamble | 3 + makekey.tproj/makekey.c | 21 +- mkfile.tproj/mkfile.c | 21 +- nvram.tproj/nvram.c | 71 +- pagesize.tproj/Makefile.postamble | 2 + passwd.tproj/ds_passwd.c | 68 +- passwd.tproj/file_passwd.c | 27 +- passwd.tproj/netinfo_passwd.c | 23 +- passwd.tproj/nis_passwd.c | 21 +- passwd.tproj/passwd.1 | 7 +- passwd.tproj/passwd.c | 42 +- passwd.tproj/stringops.c | 21 +- passwd.tproj/stringops.h | 21 +- pt_chown.tproj/Makefile | 46 + pt_chown.tproj/Makefile.postamble | 2 + pt_chown.tproj/Makefile.preamble | 1 + pt_chown.tproj/PB.project | 37 + pt_chown.tproj/pt_chown.c | 103 +++ pwd_mkdb.tproj/pw_scan.h | 21 +- reboot.tproj/Makefile.postamble | 3 +- reboot.tproj/reboot.c | 10 +- sa.tproj/Makefile | 51 ++ sa.tproj/Makefile.postamble | 104 +++ sa.tproj/Makefile.preamble | 140 +++ sa.tproj/PB.project | 26 + sa.tproj/extern.h | 97 ++ sa.tproj/main.c | 556 ++++++++++++ sa.tproj/pathnames.h | 35 + sa.tproj/pdb.c | 424 +++++++++ sa.tproj/sa.8 | 237 +++++ sa.tproj/usrdb.c | 288 ++++++ sadc.tproj/sadc.c | 134 +-- sar.tproj/Makefile | 1 - sc_usage.tproj/sc_usage.c | 21 +- sc_usage.tproj/trace.codes | 198 +++-- shutdown.tproj/Makefile | 2 +- shutdown.tproj/Makefile.postamble | 4 + shutdown.tproj/PB.project | 2 +- shutdown.tproj/pathnames.h | 21 +- shutdown.tproj/shutdown.c | 71 +- sync.tproj/Makefile | 2 +- sync.tproj/Makefile.postamble | 3 + sync.tproj/sync.c | 21 +- sysctl.tproj/sysctl.8 | 8 +- sysctl.tproj/sysctl.c | 57 +- update.tproj/disk_power.h | 23 +- update.tproj/update.c | 21 +- utmp_update.tproj/Makefile | 46 + utmp_update.tproj/Makefile.postamble | 2 + utmp_update.tproj/PB.project | 37 + utmp_update.tproj/utmp_update.c | 147 +++ vipw.tproj/pw_util.c | 21 +- vipw.tproj/pw_util.h | 21 +- vipw.tproj/vipw.c | 21 +- vm_stat.tproj/vm_stat.c | 21 +- zdump.tproj/Makefile.postamble | 6 +- zdump.tproj/zdump.8 | 63 +- zdump.tproj/zdump.c | 121 ++- zic.tproj/Makefile | 2 +- zic.tproj/Makefile.postamble | 26 +- zic.tproj/datfiles/Theory | 506 +++++++++++ zic.tproj/datfiles/asia | 150 ++-- zic.tproj/datfiles/australasia | 101 ++- zic.tproj/datfiles/backward | 11 +- zic.tproj/datfiles/europe | 79 +- zic.tproj/datfiles/leapseconds | 39 +- zic.tproj/datfiles/northamerica | 269 ++++-- zic.tproj/datfiles/southamerica | 238 ++++- zic.tproj/datfiles/zone.tab | 409 +++++++++ zic.tproj/ialloc.c | 48 +- zic.tproj/private.h | 173 +--- zic.tproj/scheck.c | 46 +- zic.tproj/tzfile.h | 213 ----- zic.tproj/zic.8 | 485 +++++----- zic.tproj/zic.c | 469 +++++----- 176 files changed, 10747 insertions(+), 4458 deletions(-) create mode 100644 atrun.tproj/Makefile.postamble create mode 100644 atrun.tproj/com.apple.atrun.plist create mode 100644 audit.tproj/Makefile create mode 100644 audit.tproj/Makefile.postamble create mode 100644 audit.tproj/Makefile.preamble create mode 100644 audit.tproj/PB.project create mode 100644 audit.tproj/audit.1 create mode 100644 audit.tproj/audit.c create mode 100644 audit.tproj/auditd_control.defs create mode 100644 auditd.tproj/Makefile create mode 100644 auditd.tproj/Makefile.postamble create mode 100644 auditd.tproj/Makefile.preamble create mode 100644 auditd.tproj/PB.project create mode 100644 auditd.tproj/audit_triggers.defs create mode 100644 auditd.tproj/audit_warn.c create mode 100644 auditd.tproj/auditd.8 create mode 100644 auditd.tproj/auditd.c create mode 100644 auditd.tproj/auditd.h create mode 100644 auditd.tproj/auditd_control.defs create mode 100644 auditd.tproj/rc.audit create mode 100644 chkpasswd.tproj/chkpasswd.8 create mode 100644 pt_chown.tproj/Makefile create mode 100644 pt_chown.tproj/Makefile.postamble create mode 100644 pt_chown.tproj/Makefile.preamble create mode 100644 pt_chown.tproj/PB.project create mode 100644 pt_chown.tproj/pt_chown.c create mode 100644 sa.tproj/Makefile create mode 100644 sa.tproj/Makefile.postamble create mode 100644 sa.tproj/Makefile.preamble create mode 100644 sa.tproj/PB.project create mode 100644 sa.tproj/extern.h create mode 100644 sa.tproj/main.c create mode 100644 sa.tproj/pathnames.h create mode 100644 sa.tproj/pdb.c create mode 100644 sa.tproj/sa.8 create mode 100644 sa.tproj/usrdb.c create mode 100644 sync.tproj/Makefile.postamble create mode 100644 utmp_update.tproj/Makefile create mode 100644 utmp_update.tproj/Makefile.postamble create mode 100644 utmp_update.tproj/PB.project create mode 100644 utmp_update.tproj/utmp_update.c create mode 100644 zic.tproj/datfiles/Theory create mode 100644 zic.tproj/datfiles/zone.tab delete mode 100644 zic.tproj/tzfile.h diff --git a/APPLE_LICENSE b/APPLE_LICENSE index fe81a60..e7aa7d0 100644 --- a/APPLE_LICENSE +++ b/APPLE_LICENSE @@ -1,344 +1,349 @@ -APPLE PUBLIC SOURCE LICENSE -Version 2.0 - August 6, 2003 + APPLE PUBLIC SOURCE LICENSE + Version 1.0 - March 16, 1999 Please read this License carefully before downloading this software. -By downloading or using this software, you are agreeing to be bound by -the terms of this License. If you do not or cannot agree to the terms -of this License, please do not download or use the software. - -1. General; Definitions. This License applies to any program or other -work which Apple Computer, Inc. ("Apple") makes publicly available and -which contains a notice placed by Apple identifying such program or -work as "Original Code" and stating that it is subject to the terms of -this Apple Public Source License version 2.0 ("License"). As used in -this License: - -1.1 "Applicable Patent Rights" mean: (a) in the case where Apple is -the grantor of rights, (i) claims of patents that are now or hereafter -acquired, owned by or assigned to Apple and (ii) that cover subject -matter contained in the Original Code, but only to the extent -necessary to use, reproduce and/or distribute the Original Code -without infringement; and (b) in the case where You are the grantor of -rights, (i) claims of patents that are now or hereafter acquired, -owned by or assigned to You and (ii) that cover subject matter in Your -Modifications, taken alone or in combination with Original Code. - -1.2 "Contributor" means any person or entity that creates or -contributes to the creation of Modifications. - -1.3 "Covered Code" means the Original Code, Modifications, the -combination of Original Code and any Modifications, and/or any -respective portions thereof. - -1.4 "Externally Deploy" means: (a) to sublicense, distribute or -otherwise make Covered Code available, directly or indirectly, to -anyone other than You; and/or (b) to use Covered Code, alone or as -part of a Larger Work, in any way to provide a service, including but -not limited to delivery of content, through electronic communication -with a client other than You. - -1.5 "Larger Work" means a work which combines Covered Code or portions -thereof with code not governed by the terms of this License. - -1.6 "Modifications" mean any addition to, deletion from, and/or change -to, the substance and/or structure of the Original Code, any previous -Modifications, the combination of Original Code and any previous -Modifications, and/or any respective portions thereof. When code is -released as a series of files, a Modification is: (a) any addition to -or deletion from the contents of a file containing Covered Code; -and/or (b) any new file or other representation of computer program -statements that contains any part of Covered Code. - -1.7 "Original Code" means (a) the Source Code of a program or other -work as originally made available by Apple under this License, -including the Source Code of any updates or upgrades to such programs -or works made available by Apple under this License, and that has been -expressly identified by Apple as such in the header file(s) of such -work; and (b) the object code compiled from such Source Code and -originally made available by Apple under this License. - -1.8 "Source Code" means the human readable form of a program or other -work that is suitable for making modifications to it, including all -modules it contains, plus any associated interface definition files, -scripts used to control compilation and installation of an executable -(object code). - -1.9 "You" or "Your" means an individual or a legal entity exercising -rights under this License. For legal entities, "You" or "Your" -includes any entity which controls, is controlled by, or is under -common control with, You, where "control" means (a) the power, direct -or indirect, to cause the direction or management of such entity, -whether by contract or otherwise, or (b) ownership of fifty percent -(50%) or more of the outstanding shares or beneficial ownership of -such entity. - -2. Permitted Uses; Conditions & Restrictions. Subject to the terms -and conditions of this License, Apple hereby grants You, effective on -the date You accept this License and download the Original Code, a -world-wide, royalty-free, non-exclusive license, to the extent of -Apple's Applicable Patent Rights and copyrights covering the Original -Code, to do the following: - -2.1 Unmodified Code. You may use, reproduce, display, perform, -internally distribute within Your organization, and Externally Deploy -verbatim, unmodified copies of the Original Code, for commercial or -non-commercial purposes, provided that in each instance: - -(a) You must retain and reproduce in all copies of Original Code the -copyright and other proprietary notices and disclaimers of Apple as -they appear in the Original Code, and keep intact all notices in the -Original Code that refer to this License; and - -(b) You must include a copy of this License with every copy of Source -Code of Covered Code and documentation You distribute or Externally -Deploy, and You may not offer or impose any terms on such Source Code -that alter or restrict this License or the recipients' rights -hereunder, except as permitted under Section 6. - -2.2 Modified Code. You may modify Covered Code and use, reproduce, -display, perform, internally distribute within Your organization, and -Externally Deploy Your Modifications and Covered Code, for commercial -or non-commercial purposes, provided that in each instance You also -meet all of these conditions: - -(a) You must satisfy all the conditions of Section 2.1 with respect to -the Source Code of the Covered Code; - -(b) You must duplicate, to the extent it does not already exist, the -notice in Exhibit A in each file of the Source Code of all Your -Modifications, and cause the modified files to carry prominent notices -stating that You changed the files and the date of any change; and - -(c) If You Externally Deploy Your Modifications, You must make -Source Code of all Your Externally Deployed Modifications either -available to those to whom You have Externally Deployed Your -Modifications, or publicly available. Source Code of Your Externally -Deployed Modifications must be released under the terms set forth in -this License, including the license grants set forth in Section 3 -below, for as long as you Externally Deploy the Covered Code or twelve -(12) months from the date of initial External Deployment, whichever is -longer. You should preferably distribute the Source Code of Your -Externally Deployed Modifications electronically (e.g. download from a -web site). - -2.3 Distribution of Executable Versions. In addition, if You -Externally Deploy Covered Code (Original Code and/or Modifications) in -object code, executable form only, You must include a prominent -notice, in the code itself as well as in related documentation, -stating that Source Code of the Covered Code is available under the -terms of this License with information on how and where to obtain such -Source Code. - -2.4 Third Party Rights. You expressly acknowledge and agree that -although Apple and each Contributor grants the licenses to their -respective portions of the Covered Code set forth herein, no -assurances are provided by Apple or any Contributor that the Covered -Code does not infringe the patent or other intellectual property -rights of any other entity. Apple and each Contributor disclaim any -liability to You for claims brought by any other entity based on -infringement of intellectual property rights or otherwise. As a -condition to exercising the rights and licenses granted hereunder, You -hereby assume sole responsibility to secure any other intellectual -property rights needed, if any. For example, if a third party patent -license is required to allow You to distribute the Covered Code, it is -Your responsibility to acquire that license before distributing the -Covered Code. - -3. Your Grants. In consideration of, and as a condition to, the -licenses granted to You under this License, You hereby grant to any -person or entity receiving or distributing Covered Code under this -License a non-exclusive, royalty-free, perpetual, irrevocable license, -under Your Applicable Patent Rights and other intellectual property -rights (other than patent) owned or controlled by You, to use, -reproduce, display, perform, modify, sublicense, distribute and -Externally Deploy Your Modifications of the same scope and extent as -Apple's licenses under Sections 2.1 and 2.2 above. - -4. Larger Works. You may create a Larger Work by combining Covered -Code with other code not governed by the terms of this License and -distribute the Larger Work as a single product. In each such instance, -You must make sure the requirements of this License are fulfilled for -the Covered Code or any portion thereof. - -5. Limitations on Patent License. Except as expressly stated in -Section 2, no other patent rights, express or implied, are granted by -Apple herein. Modifications and/or Larger Works may require additional -patent licenses from Apple which Apple may grant in its sole -discretion. - -6. Additional Terms. You may choose to offer, and to charge a fee for, -warranty, support, indemnity or liability obligations and/or other -rights consistent with the scope of the license granted herein -("Additional Terms") to one or more recipients of Covered Code. -However, You may do so only on Your own behalf and as Your sole -responsibility, and not on behalf of Apple or any Contributor. You -must obtain the recipient's agreement that any such Additional Terms -are offered by You alone, and You hereby agree to indemnify, defend -and hold Apple and every Contributor harmless for any liability -incurred by or claims asserted against Apple or such Contributor by -reason of any such Additional Terms. - -7. Versions of the License. Apple may publish revised and/or new -versions of this License from time to time. Each version will be given -a distinguishing version number. Once Original Code has been published -under a particular version of this License, You may continue to use it -under the terms of that version. You may also choose to use such -Original Code under the terms of any subsequent version of this -License published by Apple. No one other than Apple has the right to -modify the terms applicable to Covered Code created under this -License. - -8. NO WARRANTY OR SUPPORT. The Covered Code may contain in whole or in -part pre-release, untested, or not fully tested works. The Covered -Code may contain errors that could cause failures or loss of data, and -may be incomplete or contain inaccuracies. You expressly acknowledge -and agree that use of the Covered Code, or any portion thereof, is at -Your sole and entire risk. THE COVERED CODE IS PROVIDED "AS IS" AND -WITHOUT WARRANTY, UPGRADES OR SUPPORT OF ANY KIND AND APPLE AND -APPLE'S LICENSOR(S) (COLLECTIVELY REFERRED TO AS "APPLE" FOR THE -PURPOSES OF SECTIONS 8 AND 9) AND ALL CONTRIBUTORS EXPRESSLY DISCLAIM -ALL WARRANTIES AND/OR CONDITIONS, EXPRESS OR IMPLIED, INCLUDING, BUT -NOT LIMITED TO, THE IMPLIED WARRANTIES AND/OR CONDITIONS OF -MERCHANTABILITY, OF SATISFACTORY QUALITY, OF FITNESS FOR A PARTICULAR -PURPOSE, OF ACCURACY, OF QUIET ENJOYMENT, AND NONINFRINGEMENT OF THIRD -PARTY RIGHTS. APPLE AND EACH CONTRIBUTOR DOES NOT WARRANT AGAINST -INTERFERENCE WITH YOUR ENJOYMENT OF THE COVERED CODE, THAT THE -FUNCTIONS CONTAINED IN THE COVERED CODE WILL MEET YOUR REQUIREMENTS, -THAT THE OPERATION OF THE COVERED CODE WILL BE UNINTERRUPTED OR -ERROR-FREE, OR THAT DEFECTS IN THE COVERED CODE WILL BE CORRECTED. NO -ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY APPLE, AN APPLE -AUTHORIZED REPRESENTATIVE OR ANY CONTRIBUTOR SHALL CREATE A WARRANTY. -You acknowledge that the Covered Code is not intended for use in the -operation of nuclear facilities, aircraft navigation, communication -systems, or air traffic control machines in which case the failure of -the Covered Code could lead to death, personal injury, or severe -physical or environmental damage. - -9. LIMITATION OF LIABILITY. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO -EVENT SHALL APPLE OR ANY CONTRIBUTOR BE LIABLE FOR ANY INCIDENTAL, -SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING -TO THIS LICENSE OR YOUR USE OR INABILITY TO USE THE COVERED CODE, OR -ANY PORTION THEREOF, WHETHER UNDER A THEORY OF CONTRACT, WARRANTY, -TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY OR OTHERWISE, EVEN IF -APPLE OR SUCH CONTRIBUTOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES AND NOTWITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE OF ANY -REMEDY. SOME JURISDICTIONS DO NOT ALLOW THE LIMITATION OF LIABILITY OF -INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION MAY NOT APPLY -TO YOU. In no event shall Apple's total liability to You for all -damages (other than as may be required by applicable law) under this -License exceed the amount of fifty dollars ($50.00). - -10. Trademarks. This License does not grant any rights to use the -trademarks or trade names "Apple", "Apple Computer", "Mac", "Mac OS", -"QuickTime", "QuickTime Streaming Server" or any other trademarks, -service marks, logos or trade names belonging to Apple (collectively -"Apple Marks") or to any trademark, service mark, logo or trade name -belonging to any Contributor. You agree not to use any Apple Marks in -or as part of the name of products derived from the Original Code or -to endorse or promote products derived from the Original Code other -than as expressly permitted by and in strict compliance at all times -with Apple's third party trademark usage guidelines which are posted -at http://www.apple.com/legal/guidelinesfor3rdparties.html. - -11. Ownership. Subject to the licenses granted under this License, -each Contributor retains all rights, title and interest in and to any -Modifications made by such Contributor. Apple retains all rights, -title and interest in and to the Original Code and any Modifications -made by or on behalf of Apple ("Apple Modifications"), and such Apple -Modifications will not be automatically subject to this License. Apple -may, at its sole discretion, choose to license such Apple -Modifications under this License, or on different terms from those -contained in this License or may choose not to license them at all. +By downloading and using this software, you are agreeing to be bound +by the terms of this License. If you do not or cannot agree to the +terms of this License, please do not download or use the software. + +1. General; Definitions. This License applies to any program or other + work which Apple Computer, Inc. ("Apple") publicly announces as + subject to this Apple Public Source License and which contains a + notice placed by Apple identifying such program or work as "Original + Code" and stating that it is subject to the terms of this Apple + Public Source License version 1.0 (or subsequent version thereof), + as it may be revised from time to time by Apple ("License"). As + used in this License: + +1.1 "Applicable Patents" mean: (a) in the case where Apple is the + grantor of rights, (i) patents or patent applications that are now + or hereafter acquired, owned by or assigned to Apple and (ii) whose + claims cover subject matter contained in the Original Code, but only + to the extent necessary to use, reproduce and/or distribute the + Original Code without infringement; and (b) in the case where You + are the grantor of rights, (i) patents and patent applications that + are now or hereafter acquired, owned by or assigned to You and (ii) + whose claims cover subject matter in Your Modifications, taken alone + or in combination with Original Code. + +1.2 "Covered Code" means the Original Code, Modifications, the + combination of Original Code and any Modifications, and/or any + respective portions thereof. + +1.3 "Deploy" means to use, sublicense or distribute Covered Code other + than for Your internal research and development (R&D), and includes + without limitation, any and all internal use or distribution of + Covered Code within Your business or organization except for R&D + use, as well as direct or indirect sublicensing or distribution of + Covered Code by You to any third party in any form or manner. + +1.4 "Larger Work" means a work which combines Covered Code or portions + thereof with code not governed by the terms of this License. + +1.5 "Modifications" mean any addition to, deletion from, and/or change + to, the substance and/or structure of Covered Code. When code is + released as a series of files, a Modification is: (a) any addition + to or deletion from the contents of a file containing Covered Code; + and/or (b) any new file or other representation of computer program + statements that contains any part of Covered Code. + +1.6 "Original Code" means the Source Code of a program or other work + as originally made available by Apple under this License, including + the Source Code of any updates or upgrades to such programs or works + made available by Apple under this License, and that has been + expressly identified by Apple as such in the header file(s) of such + work. + +1.7 "Source Code" means the human readable form of a program or other + work that is suitable for making modifications to it, including all + modules it contains, plus any associated interface definition files, + scripts used to control compilation and installation of an + executable (object code). + +1.8 "You" or "Your" means an individual or a legal entity exercising + rights under this License. For legal entities, "You" or "Your" + includes any entity which controls, is controlled by, or is under + common control with, You, where "control" means (a) the power, + direct or indirect, to cause the direction or management of such + entity, whether by contract or otherwise, or (b) ownership of fifty + percent (50%) or more of the outstanding shares or beneficial + ownership of such entity. + +2. Permitted Uses; Conditions & Restrictions. Subject to the terms + and conditions of this License, Apple hereby grants You, effective + on the date You accept this License and download the Original Code, + a world-wide, royalty-free, non-exclusive license, to the extent of + Apple's Applicable Patents and copyrights covering the Original + Code, to do the following: + +2.1 You may use, copy, modify and distribute Original Code, with or + without Modifications, solely for Your internal research and + development, provided that You must in each instance: + +(a) retain and reproduce in all copies of Original Code the copyright +and other proprietary notices and disclaimers of Apple as they appear +in the Original Code, and keep intact all notices in the Original Code +that refer to this License; + +(b) include a copy of this License with every copy of Source Code of +Covered Code and documentation You distribute, and You may not offer +or impose any terms on such Source Code that alter or restrict this +License or the recipients' rights hereunder, except as permitted under +Section 6; and + +(c) completely and accurately document all Modifications that you have +made and the date of each such Modification, designate the version of +the Original Code you used, prominently include a file carrying such +information with the Modifications, and duplicate the notice in +Exhibit A in each file of the Source Code of all such Modifications. + +2.2 You may Deploy Covered Code, provided that You must in each + instance: + +(a) satisfy all the conditions of Section 2.1 with respect to the +Source Code of the Covered Code; + +(b) make all Your Deployed Modifications publicly available in Source +Code form via electronic distribution (e.g. download from a web site) +under the terms of this License and subject to the license grants set +forth in Section 3 below, and any additional terms You may choose to +offer under Section 6. You must continue to make the Source Code of +Your Deployed Modifications available for as long as you Deploy the +Covered Code or twelve (12) months from the date of initial +Deployment, whichever is longer; + +(c) must notify Apple and other third parties of how to obtain Your +Deployed Modifications by filling out and submitting the required +information found at +http://www.apple.com/publicsource/modifications.html; and + +(d) if you Deploy Covered Code in object code, executable form only, +include a prominent notice, in the code itself as well as in related +documentation, stating that Source Code of the Covered Code is +available under the terms of this License with information on how and +where to obtain such Source Code. + +3. Your Grants. In consideration of, and as a condition to, the + licenses granted to You under this License: + +(a) You hereby grant to Apple and all third parties a non-exclusive, +royalty-free license, under Your Applicable Patents and other +intellectual property rights owned or controlled by You, to use, +reproduce, modify, distribute and Deploy Your Modifications of the +same scope and extent as Apple's licenses under Sections 2.1 and 2.2; +and + +(b) You hereby grant to Apple and its subsidiaries a non-exclusive, +worldwide, royalty-free, perpetual and irrevocable license, under Your +Applicable Patents and other intellectual property rights owned or +controlled by You, to use, reproduce, execute, compile, display, +perform, modify or have modified (for Apple and/or its subsidiaries), +sublicense and distribute Your Modifications, in any form, through +multiple tiers of distribution. + +4. Larger Works. You may create a Larger Work by combining Covered + Code with other code not governed by the terms of this License and + distribute the Larger Work as a single product. In each such + instance, You must make sure the requirements of this License are + fulfilled for the Covered Code or any portion thereof. + +5. Limitations on Patent License. Except as expressly stated in + Section 2, no other patent rights, express or implied, are granted + by Apple herein. Modifications and/or Larger Works may require + additional patent licenses from Apple which Apple may grant in its + sole discretion. + +6. Additional Terms. You may choose to offer, and to charge a fee + for, warranty, support, indemnity or liability obligations and/or + other rights consistent with the scope of the license granted herein + ("Additional Terms") to one or more recipients of Covered + Code. However, You may do so only on Your own behalf and as Your + sole responsibility, and not on behalf of Apple. You must obtain the + recipient's agreement that any such Additional Terms are offered by + You alone, and You hereby agree to indemnify, defend and hold Apple + harmless for any liability incurred by or claims asserted against + Apple by reason of any such Additional Terms. + +7. Versions of the License. Apple may publish revised and/or new + versions of this License from time to time. Each version will be + given a distinguishing version number. Once Original Code has been + published under a particular version of this License, You may + continue to use it under the terms of that version. You may also + choose to use such Original Code under the terms of any subsequent + version of this License published by Apple. No one other than Apple + has the right to modify the terms applicable to Covered Code created + under this License. + +8. NO WARRANTY OR SUPPORT. The Original Code may contain in whole or + in part pre-release, untested, or not fully tested works. The + Original Code may contain errors that could cause failures or loss + of data, and may be incomplete or contain inaccuracies. You + expressly acknowledge and agree that use of the Original Code, or + any portion thereof, is at Your sole and entire risk. THE ORIGINAL + CODE IS PROVIDED "AS IS" AND WITHOUT WARRANTY, UPGRADES OR SUPPORT + OF ANY KIND AND APPLE AND APPLE'S LICENSOR(S) (FOR THE PURPOSES OF + SECTIONS 8 AND 9, APPLE AND APPLE'S LICENSOR(S) ARE COLLECTIVELY + REFERRED TO AS "APPLE") EXPRESSLY DISCLAIM ALL WARRANTIES AND/OR + CONDITIONS, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES AND/OR CONDITIONS OF MERCHANTABILITY OR + SATISFACTORY QUALITY AND FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT OF THIRD PARTY RIGHTS. APPLE DOES NOT WARRANT THAT + THE FUNCTIONS CONTAINED IN THE ORIGINAL CODE WILL MEET YOUR + REQUIREMENTS, OR THAT THE OPERATION OF THE ORIGINAL CODE WILL BE + UNINTERRUPTED OR ERROR-FREE, OR THAT DEFECTS IN THE ORIGINAL CODE + WILL BE CORRECTED. NO ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN + BY APPLE OR AN APPLE AUTHORIZED REPRESENTATIVE SHALL CREATE A + WARRANTY OR IN ANY WAY INCREASE THE SCOPE OF THIS WARRANTY. You + acknowledge that the Original Code is not intended for use in the + operation of nuclear facilities, aircraft navigation, communication + systems, or air traffic control machines in which case the failure + of the Original Code could lead to death, personal injury, or severe + physical or environmental damage. + +9. Liability. + +9.1 Infringement. If any of the Original Code becomes the subject of + a claim of infringement ("Affected Original Code"), Apple may, at + its sole discretion and option: (a) attempt to procure the rights + necessary for You to continue using the Affected Original Code; (b) + modify the Affected Original Code so that it is no longer + infringing; or (c) terminate Your rights to use the Affected + Original Code, effective immediately upon Apple's posting of a + notice to such effect on the Apple web site that is used for + implementation of this License. + +9.2 LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES SHALL APPLE BE + LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL + DAMAGES ARISING OUT OF OR RELATING TO THIS LICENSE OR YOUR USE OR + INABILITY TO USE THE ORIGINAL CODE, OR ANY PORTION THEREOF, WHETHER + UNDER A THEORY OF CONTRACT, WARRANTY, TORT (INCLUDING NEGLIGENCE), + PRODUCTS LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF + THE POSSIBILITY OF SUCH DAMAGES AND NOTWITHSTANDING THE FAILURE OF + ESSENTIAL PURPOSE OF ANY REMEDY. In no event shall Apple's total + liability to You for all damages under this License exceed the + amount of fifty dollars ($50.00). + +10. Trademarks. This License does not grant any rights to use the + trademarks or trade names "Apple", "Apple Computer", "Mac OS X", + "Mac OS X Server" or any other trademarks or trade names belonging + to Apple (collectively "Apple Marks") and no Apple Marks may be + used to endorse or promote products derived from the Original Code + other than as permitted by and in strict compliance at all times + with Apple's third party trademark usage guidelines which are + posted at http://www.apple.com/legal/guidelinesfor3rdparties.html. + +11. Ownership. Apple retains all rights, title and interest in and to + the Original Code and any Modifications made by or on behalf of + Apple ("Apple Modifications"), and such Apple Modifications will + not be automatically subject to this License. Apple may, at its + sole discretion, choose to license such Apple Modifications under + this License, or on different terms from those contained in this + License or may choose not to license them at all. Apple's + development, use, reproduction, modification, sublicensing and + distribution of Covered Code will not be subject to this License. 12. Termination. -12.1 Termination. This License and the rights granted hereunder will -terminate: +12.1 Termination. This License and the rights granted hereunder will + terminate: (a) automatically without notice from Apple if You fail to comply with any term(s) of this License and fail to cure such breach within 30 -days of becoming aware of such breach; - -(b) immediately in the event of the circumstances described in Section -13.5(b); or - -(c) automatically without notice from Apple if You, at any time during -the term of this License, commence an action for patent infringement -against Apple; provided that Apple did not first commence -an action for patent infringement against You in that instance. - -12.2 Effect of Termination. Upon termination, You agree to immediately -stop any further use, reproduction, modification, sublicensing and -distribution of the Covered Code. All sublicenses to the Covered Code -which have been properly granted prior to termination shall survive -any termination of this License. Provisions which, by their nature, -should remain in effect beyond the termination of this License shall -survive, including but not limited to Sections 3, 5, 8, 9, 10, 11, -12.2 and 13. No party will be liable to any other for compensation, -indemnity or damages of any sort solely as a result of terminating -this License in accordance with its terms, and termination of this -License will be without prejudice to any other right or remedy of -any party. - -13. Miscellaneous. - -13.1 Government End Users. The Covered Code is a "commercial item" as -defined in FAR 2.101. Government software and technical data rights in -the Covered Code include only those rights customarily provided to the -public as defined in this License. This customary commercial license -in technical data and software is provided in accordance with FAR -12.211 (Technical Data) and 12.212 (Computer Software) and, for -Department of Defense purchases, DFAR 252.227-7015 (Technical Data -- -Commercial Items) and 227.7202-3 (Rights in Commercial Computer -Software or Computer Software Documentation). Accordingly, all U.S. -Government End Users acquire Covered Code with only those rights set -forth herein. - -13.2 Relationship of Parties. This License will not be construed as -creating an agency, partnership, joint venture or any other form of -legal association between or among You, Apple or any Contributor, and -You will not represent to the contrary, whether expressly, by -implication, appearance or otherwise. - -13.3 Independent Development. Nothing in this License will impair -Apple's right to acquire, license, develop, have others develop for -it, market and/or distribute technology or products that perform the -same or similar functions as, or otherwise compete with, -Modifications, Larger Works, technology or products that You may -develop, produce, market or distribute. - -13.4 Waiver; Construction. Failure by Apple or any Contributor to -enforce any provision of this License will not be deemed a waiver of -future enforcement of that or any other provision. Any law or -regulation which provides that the language of a contract shall be -construed against the drafter will not apply to this License. - -13.5 Severability. (a) If for any reason a court of competent -jurisdiction finds any provision of this License, or portion thereof, -to be unenforceable, that provision of the License will be enforced to -the maximum extent permissible so as to effect the economic benefits -and intent of the parties, and the remainder of this License will -continue in full force and effect. (b) Notwithstanding the foregoing, -if applicable law prohibits or restricts You from fully and/or -specifically complying with Sections 2 and/or 3 or prevents the -enforceability of either of those Sections, this License will -immediately terminate and You must immediately discontinue any use of -the Covered Code and destroy all copies of it that are in your -possession or control. - -13.6 Dispute Resolution. Any litigation or other dispute resolution -between You and Apple relating to this License shall take place in the -Northern District of California, and You and Apple hereby consent to -the personal jurisdiction of, and venue in, the state and federal -courts within that District with respect to this License. The -application of the United Nations Convention on Contracts for the -International Sale of Goods is expressly excluded. - -13.7 Entire Agreement; Governing Law. This License constitutes the -entire agreement between the parties with respect to the subject -matter hereof. This License shall be governed by the laws of the -United States and the State of California, except that body of -California law concerning conflicts of law. +days of becoming aware of such breach; (b) immediately in the event of +the circumstances described in Sections 9.1 and/or 13.6(b); or (c) +automatically without notice from Apple if You, at any time during the +term of this License, commence an action for patent infringement +against Apple. + +12.2 Effect of Termination. Upon termination, You agree to + immediately stop any further use, reproduction, modification and + distribution of the Covered Code, or Affected Original Code in the + case of termination under Section 9.1, and to destroy all copies of + the Covered Code or Affected Original Code (in the case of + termination under Section 9.1) that are in your possession or + control. All sublicenses to the Covered Code which have been + properly granted prior to termination shall survive any termination + of this License. Provisions which, by their nature, should remain + in effect beyond the termination of this License shall survive, + including but not limited to Sections 3, 5, 8, 9, 10, 11, 12.2 and + 13. Neither party will be liable to the other for compensation, + indemnity or damages of any sort solely as a result of terminating + this License in accordance with its terms, and termination of this + License will be without prejudice to any other right or remedy of + either party. + +13. Miscellaneous. + +13.1 Export Law Assurances. You may not use or otherwise export or + re-export the Original Code except as authorized by United States + law and the laws of the jurisdiction in which the Original Code was + obtained. In particular, but without limitation, the Original Code + may not be exported or re-exported (a) into (or to a national or + resident of) any U.S. embargoed country or (b) to anyone on the + U.S. Treasury Department's list of Specially Designated Nationals + or the U.S. Department of Commerce's Table of Denial Orders. By + using the Original Code, You represent and warrant that You are not + located in, under control of, or a national or resident of any such + country or on any such list. + +13.2 Government End Users. The Covered Code is a "commercial item" as + defined in FAR 2.101. Government software and technical data + rights in the Covered Code include only those rights customarily + provided to the public as defined in this License. This customary + commercial license in technical data and software is provided in + accordance with FAR 12.211 (Technical Data) and 12.212 (Computer + Software) and, for Department of Defense purchases, DFAR + 252.227-7015 (Technical Data -- Commercial Items) and 227.7202-3 + (Rights in Commercial Computer Software or Computer Software + Documentation). Accordingly, all U.S. Government End Users acquire + Covered Code with only those rights set forth herein. + +13.3 Relationship of Parties. This License will not be construed as + creating an agency, partnership, joint venture or any other form of + legal association between You and Apple, and You will not represent + to the contrary, whether expressly, by implication, appearance or + otherwise. + +13.4 Independent Development. Nothing in this License will impair + Apple's right to acquire, license, develop, have others develop for + it, market and/or distribute technology or products that perform + the same or similar functions as, or otherwise compete with, + Modifications, Larger Works, technology or products that You may + develop, produce, market or distribute. + +13.5 Waiver; Construction. Failure by Apple to enforce any provision + of this License will not be deemed a waiver of future enforcement + of that or any other provision. Any law or regulation which + provides that the language of a contract shall be construed against + the drafter will not apply to this License. + +13.6 Severability. (a) If for any reason a court of competent + jurisdiction finds any provision of this License, or portion + thereof, to be unenforceable, that provision of the License will be + enforced to the maximum extent permissible so as to effect the + economic benefits and intent of the parties, and the remainder of + this License will continue in full force and effect. (b) + Notwithstanding the foregoing, if applicable law prohibits or + restricts You from fully and/or specifically complying with + Sections 2 and/or 3 or prevents the enforceability of either of + those Sections, this License will immediately terminate and You + must immediately discontinue any use of the Covered Code and + destroy all copies of it that are in your possession or control. + +13.7 Dispute Resolution. Any litigation or other dispute resolution + between You and Apple relating to this License shall take place in + the Northern District of California, and You and Apple hereby + consent to the personal jurisdiction of, and venue in, the state + and federal courts within that District with respect to this + License. The application of the United Nations Convention on + Contracts for the International Sale of Goods is expressly + excluded. + +13.8 Entire Agreement; Governing Law. This License constitutes the + entire agreement between the parties with respect to the subject + matter hereof. This License shall be governed by the laws of the + United States and the State of California, except that body of + California law concerning conflicts of law. Where You are located in the province of Quebec, Canada, the following clause applies: The parties hereby confirm that they have requested @@ -346,22 +351,20 @@ that this License and all related documents be drafted in English. Les parties ont exige que le present contrat et tous les documents connexes soient rediges en anglais. -EXHIBIT A. +EXHIBIT A. -"Portions 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." diff --git a/Makefile b/Makefile index 0ab1d6a..6377bda 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ PROJECTVERSION = 2.8 PROJECT_TYPE = Aggregate TOOLS = dynamic_pager.tproj ac.tproj accton.tproj arch.tproj at.tproj\ + auditd.tproj audit.tproj\ atrun.tproj chkpasswd.tproj chpass.tproj dmesg.tproj\ getconf.tproj getty.tproj hostinfo.tproj iostat.tproj kgmon.tproj\ ktrace.tproj login.tproj makekey.tproj\ @@ -20,7 +21,8 @@ TOOLS = dynamic_pager.tproj ac.tproj accton.tproj arch.tproj at.tproj\ reboot.tproj shutdown.tproj sync.tproj sysctl.tproj\ update.tproj vipw.tproj zic.tproj zdump.tproj vm_stat.tproj\ zprint.tproj latency.tproj sc_usage.tproj fs_usage.tproj\ - kdump.tproj sadc.tproj sar.tproj + kdump.tproj sadc.tproj sar.tproj pt_chown.tproj sa.tproj\ + utmp_update.tproj LIBRARIES = dp_notify_lib diff --git a/Makefile.preamble b/Makefile.preamble index b15052f..7d83496 100644 --- a/Makefile.preamble +++ b/Makefile.preamble @@ -1,2 +1,3 @@ CLEAN_ALL_SUBPROJECTS = YES SUBPROJECTS = +OTHER_CFLAGS = -mdynamic-no-pic diff --git a/PB.project b/PB.project index d4f808d..300cc26 100644 --- a/PB.project +++ b/PB.project @@ -20,6 +20,8 @@ "arch.tproj", "at.tproj", "atrun.tproj", + "audit.tproj", + "auditd.tproj", "chkpasswd.tproj", "chpass.tproj", "dmesg.tproj", diff --git a/ac.tproj/ac.c b/ac.tproj/ac.c index 249b80a..f23915c 100644 --- a/ac.tproj/ac.c +++ b/ac.tproj/ac.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/accton.tproj/accton.c b/accton.tproj/accton.c index 40ec198..723c336 100644 --- a/accton.tproj/accton.c +++ b/accton.tproj/accton.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/arch.tproj/arch.c b/arch.tproj/arch.c index 7b5d5dc..0e140fe 100644 --- a/arch.tproj/arch.c +++ b/arch.tproj/arch.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/at.tproj/Makefile b/at.tproj/Makefile index c2335bf..2c36024 100644 --- a/at.tproj/Makefile +++ b/at.tproj/Makefile @@ -33,9 +33,11 @@ PROF_LIBS = $(LIBS) PROJECT_HEADERS = privs.h pathnames.h +NEXTSTEP_PB_CFLAGS += -D__FBSDID=__RCSID -DDAEMON_UID=1 -DDAEMON_GID=1 \ + -DDEFAULT_AT_QUEUE=\'a\' -DDEFAULT_BATCH_QUEUE=\'b\' \ + -DPERM_PATH=\"/var/at/\" -I/System/Library/Frameworks/System.framework/PrivateHeaders - -NEXTSTEP_BUILD_OUTPUT_DIR = /$(USER)/BUILD +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc diff --git a/at.tproj/Makefile.postamble b/at.tproj/Makefile.postamble index 266d5d6..8104d89 100644 --- a/at.tproj/Makefile.postamble +++ b/at.tproj/Makefile.postamble @@ -4,7 +4,7 @@ after_install:: $(LN) -f $(INSTALLED_PRODUCTS) $(DSTROOT)$(INSTALLDIR)/atq $(LN) -f $(INSTALLED_PRODUCTS) $(DSTROOT)$(INSTALLDIR)/atrm $(LN) -f $(INSTALLED_PRODUCTS) $(DSTROOT)$(INSTALLDIR)/batch - mkdir -p "$(DSTROOT)/private/var/at/spool" + install -o daemon -d "$(DSTROOT)/private/var/at/spool" touch "$(DSTROOT)/private/var/at/at.deny" mkdir -p "$(DSTROOT)/usr/share/man/man1" install -c -m 644 at.1 "$(DSTROOT)/usr/share/man/man1/at.1" diff --git a/at.tproj/at.1 b/at.tproj/at.1 index 47c2591..78a978e 100644 --- a/at.tproj/at.1 +++ b/at.tproj/at.1 @@ -27,7 +27,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $Id: at.1,v 1.3 2003/06/05 17:13:32 eseidel Exp $ +.\" $Id: at.1,v 1.5 2005/02/18 00:22:38 lindak Exp $ .\" .Dd December 5, 1993 .Dt "AT" 1 @@ -64,16 +64,12 @@ are all disabled by default on Mac OS X. Each of these commands depend on the execution of .Xr atrun 8 which has been disabled due to power management concerns. -Those who would like to use these commands, must first re-enable -.Nm /usr/libexec/atrun -by removing the leading '#' from the line +Those who would like to use these commands, must first (as root) re-enable +.Nm atrun +by running: .Bd -literal -#*/5 * * * * root /usr/libexec/atrun +launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist .Ed -in the file -.Pa /etc/crontab . -.Pa /etc/crontab -must be edited by root. .Sh DESCRIPTION The .Nm at @@ -207,9 +203,11 @@ Job-creation lock file. .It Pa /var/run/utmp .El .Sh SEE ALSO -.Xr crond 8 , +.Xr launchctl 1 , +.Xr launchd 8 , .Xr nice 1 , .Xr sh 1 , +.Xr compat 5 , .Xr atrun 8 .Sh AUTHOR .Bl -tag diff --git a/at.tproj/at.c b/at.tproj/at.c index f52e36e..48b1599 100644 --- a/at.tproj/at.c +++ b/at.tproj/at.c @@ -1,34 +1,9 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. +/* + * at.c : Put file into atrun queue + * Copyright (C) 1993, 1994 Thomas Koenig * - * @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@ - */ -/* - * at.c : Put file into atrun queue - * Copyright (C) 1993 Thomas Koenig - * - * Atrun & Atq modifications - * Copyright (C) 1993 David Parsons - * All rights reserved. + * Atrun & Atq modifications + * Copyright (C) 1993 David Parsons * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -42,7 +17,7 @@ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * IN NO EVENT SHALL THE AUTHOR(S) 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 @@ -51,16 +26,29 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +__FBSDID("$FreeBSD: src/usr.bin/at/at.c,v 1.29 2002/07/22 11:32:16 robert Exp $"); + #define _USE_BSD 1 /* System Headers */ -#include + +#include #include +#include #include #include #include +#include #include #include +#ifndef __FreeBSD__ +#include +#endif +#include +#ifdef __FreeBSD__ +#include +#endif #include #include #include @@ -70,523 +58,880 @@ #include #include +#ifdef __APPLE__ +#include +#else /* !__APPLE */ +#define COMPAT_MODE(a,b) (1) +#endif /* __APPLE__ */ + /* Local headers */ + #include "at.h" #include "panic.h" #include "parsetime.h" #include "pathnames.h" +#include "perm.h" + #define MAIN #include "privs.h" -#include "perm.h" /* Macros */ -#define ALARMC 10 /* Number of seconds to wait for timeout */ + +#ifndef ATJOB_DIR +#define ATJOB_DIR _PATH_ATJOBS +#endif + +#ifndef LFILE +#define LFILE ATJOB_DIR ".lockfile" +#endif + +#ifndef ATJOB_MX +#define ATJOB_MX 255 +#endif + +#define ALARMC 10 /* Number of seconds to wait for timeout */ #define SIZE 255 #define TIMESIZE 50 +enum { ATQ, ATRM, AT, BATCH, CAT }; /* what program we want to run */ + /* File scope variables */ -static char rcsid[] = "$Id: at.c,v 1.2 2003/10/15 22:48:12 lindak Exp $"; -char *no_export[] = + +const char *no_export[] = { - "TERM", "TERMCAP", "DISPLAY", "_" -}; -static send_mail = 0; + "TERM", "TERMCAP", "DISPLAY", "_" +} ; +static int send_mail = 0; /* External variables */ + extern char **environ; int fcreated; -char *namep; -char atfile[FILENAME_MAX]; +char atfile[] = ATJOB_DIR "12345678901234"; -char *atinput = (char *) 0; /* where to get input from */ +char *atinput = (char*)0; /* where to get input from */ char atqueue = 0; /* which queue to examine for jobs (atq) */ char atverify = 0; /* verify time instead of queuing job */ +char *namep; +int posixly_correct; /* Behave as per POSIX */ +/* http://www.opengroup.org/onlinepubs/009695399/utilities/at.html */ /* Function declarations */ -static void sigc __P((int signo)); -static void alarmc __P((int signo)); -static char *cwdname __P((void)); -static void writefile __P((time_t runtimer, char queue)); -static void list_jobs __P((void)); + +static void sigc(int signo); +static void alarmc(int signo); +static char *cwdname(void); +static void writefile(time_t runtimer, char queue); +static void list_jobs(long *, int); +static long nextjob(void); +static time_t ttime(const char *arg); +static int in_job_list(long, long *, int); +static long *get_job_list(int, char *[], int *); /* Signal catching functions */ -static void -sigc(signo) - int signo; +static void sigc(int signo __unused) { -/* If the user presses ^C, remove the spool file and exit +/* If the user presses ^C, remove the spool file and exit */ - if (fcreated) { - PRIV_START - unlink(atfile); - PRIV_END - } + if (fcreated) + { + PRIV_START + unlink(atfile); + PRIV_END + } - exit(EXIT_FAILURE); + _exit(EXIT_FAILURE); } -static void -alarmc(signo) - int signo; +static void alarmc(int signo __unused) { -/* Time out after some seconds - */ - panic("File locking timed out"); + char buf[1024]; + + /* Time out after some seconds. */ + strlcpy(buf, namep, sizeof(buf)); + strlcat(buf, ": file locking timed out\n", sizeof(buf)); + write(STDERR_FILENO, buf, strlen(buf)); + sigc(0); } /* Local functions */ -static char * -cwdname() +static char *cwdname(void) { /* Read in the current directory; the name will be overwritten on * subsequent calls. */ - static char *ptr = NULL; - static size_t size = SIZE; - - if (ptr == NULL) - ptr = (char *) malloc(size); - - while (1) { - if (ptr == NULL) - panic("Out of memory"); + static char *ptr = NULL; + static size_t size = SIZE; - if (getcwd(ptr, size - 1) != NULL) - return ptr; + if (ptr == NULL) + if ((ptr = malloc(size)) == NULL) + errx(EXIT_FAILURE, "virtual memory exhausted"); - if (errno != ERANGE) - perr("Cannot get directory"); + while (1) + { + if (ptr == NULL) + panic("out of memory"); + + if (getcwd(ptr, size-1) != NULL) + return ptr; + + if (errno != ERANGE) + perr("cannot get directory"); + + free (ptr); + size += SIZE; + if ((ptr = malloc(size)) == NULL) + errx(EXIT_FAILURE, "virtual memory exhausted"); + } +} - free(ptr); - size += SIZE; - ptr = (char *) malloc(size); +static long +nextjob() +{ + long jobno; + FILE *fid; + + if ((fid = fopen(ATJOB_DIR ".SEQ", "r+")) != (FILE*)0) { + if (fscanf(fid, "%5lx", &jobno) == 1) { + rewind(fid); + jobno = (1+jobno) % 0xfffff; /* 2^20 jobs enough? */ + fprintf(fid, "%05lx\n", jobno); } + else + jobno = EOF; + fclose(fid); + return jobno; + } + else if ((fid = fopen(ATJOB_DIR ".SEQ", "w")) != (FILE*)0) { + fprintf(fid, "%05lx\n", jobno = 1); + fclose(fid); + return 1; + } + return EOF; } static void -writefile(runtimer, queue) - time_t runtimer; - char queue; +writefile(time_t runtimer, char queue) { - /* - * This does most of the work if at or batch are invoked for - * writing a job. - */ - int i; - char *ap, *ppos, *mailname; - struct passwd *pass_entry; - struct stat statbuf; - int fdes, lockdes, fd2; - FILE *fp, *fpin; - struct sigaction act; - char **atenv; - int ch; - mode_t cmask; - struct flock lock; - - /* - * Install the signal handler for SIGINT; terminate after removing the - * spool file if necessary - */ - act.sa_handler = sigc; - sigemptyset(&(act.sa_mask)); - act.sa_flags = 0; +/* This does most of the work if at or batch are invoked for writing a job. + */ + long jobno; + char *ap, *ppos, *mailname; + struct passwd *pass_entry; + struct stat statbuf; + int fdes, lockdes, fd2; + FILE *fp, *fpin; + struct sigaction act; + char **atenv; + int ch; + mode_t cmask; + struct flock lock; + +#ifdef __FreeBSD__ + (void) setlocale(LC_TIME, ""); +#endif + +/* Install the signal handler for SIGINT; terminate after removing the + * spool file if necessary + */ + act.sa_handler = sigc; + sigemptyset(&(act.sa_mask)); + act.sa_flags = 0; + + sigaction(SIGINT, &act, NULL); + + ppos = atfile + strlen(ATJOB_DIR); + + /* Loop over all possible file names for running something at this + * particular time, see if a file is there; the first empty slot at any + * particular time is used. Lock the file LFILE first to make sure + * we're alone when doing this. + */ + + PRIV_START + + if ((lockdes = open(LFILE, O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR)) < 0) + perr("cannot open lockfile " LFILE); + + lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; + lock.l_len = 0; + + act.sa_handler = alarmc; + sigemptyset(&(act.sa_mask)); + act.sa_flags = 0; + + /* Set an alarm so a timeout occurs after ALARMC seconds, in case + * something is seriously broken. + */ + sigaction(SIGALRM, &act, NULL); + alarm(ALARMC); + fcntl(lockdes, F_SETLKW, &lock); + alarm(0); + + if ((jobno = nextjob()) == EOF) + perr("cannot generate job number"); + + sprintf(ppos, "%c%5lx%8lx", queue, + jobno, (unsigned long) (runtimer/60)); + + for(ap=ppos; *ap != '\0'; ap ++) + if (*ap == ' ') + *ap = '0'; + + if (stat(atfile, &statbuf) != 0) + if (errno != ENOENT) + perr("cannot access " ATJOB_DIR); + + /* Create the file. The x bit is only going to be set after it has + * been completely written out, to make sure it is not executed in the + * meantime. To make sure they do not get deleted, turn off their r + * bit. Yes, this is a kluge. + */ + cmask = umask(S_IRUSR | S_IWUSR | S_IXUSR); + if ((fdes = creat(atfile, O_WRONLY)) == -1) + perr("cannot create atjob file"); + + if ((fd2 = dup(fdes)) <0) + perr("error in dup() of job file"); + + if(fchown(fd2, real_uid, real_gid) != 0) + perr("cannot give away file"); + + PRIV_END + + /* We no longer need suid root; now we just need to be able to write + * to the directory, if necessary. + */ + + REDUCE_PRIV(DAEMON_UID, DAEMON_GID) + + /* We've successfully created the file; let's set the flag so it + * gets removed in case of an interrupt or error. + */ + fcreated = 1; + + /* Now we can release the lock, so other people can access it + */ + lock.l_type = F_UNLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; + lock.l_len = 0; + fcntl(lockdes, F_SETLKW, &lock); + close(lockdes); + + if((fp = fdopen(fdes, "w")) == NULL) + panic("cannot reopen atjob file"); + + /* Get the userid to mail to, first by trying getlogin(), + * then from LOGNAME, finally from getpwuid(). + */ + mailname = getlogin(); + if (mailname == NULL) + mailname = getenv("LOGNAME"); + + if ((mailname == NULL) || (mailname[0] == '\0') + || (strlen(mailname) >= MAXLOGNAME) || (getpwnam(mailname)==NULL)) + { + pass_entry = getpwuid(real_uid); + if (pass_entry != NULL) + mailname = pass_entry->pw_name; + } + + if (atinput != (char *) NULL) + { + fpin = freopen(atinput, "r", stdin); + if (fpin == NULL) + perr("cannot open input file"); + } + fprintf(fp, "#!/bin/sh\n# atrun uid=%ld gid=%ld\n# mail %.*s %d\n", + (long) real_uid, (long) real_gid, MAXLOGNAME - 1, mailname, + send_mail); + + /* Write out the umask at the time of invocation + */ + fprintf(fp, "umask %lo\n", (unsigned long) cmask); + + /* Write out the environment. Anything that may look like a + * special character to the shell is quoted, except for \n, which is + * done with a pair of "'s. Don't export the no_export list (such + * as TERM or DISPLAY) because we don't want these. + */ + for (atenv= environ; *atenv != NULL; atenv++) + { + int export = 1; + char *eqp; + + eqp = strchr(*atenv, '='); + if (ap == NULL) + eqp = *atenv; + else + { + size_t i; + for (i=0; i&2\n\t exit 1\n}\n"); - (void)strlcpy(atfile, _PATH_ATJOBS, sizeof atfile); - ppos = atfile + strlen(_PATH_ATJOBS); + while((ch = getchar()) != EOF) + fputc(ch, fp); - /* - * Loop over all possible file names for running something at this - * particular time, see if a file is there; the first empty slot at - * any particular time is used. Lock the file _PATH_LOCKFILE first - * to make sure we're alone when doing this. - */ + fprintf(fp, "\n"); + if (ferror(fp)) + panic("output error"); + + if (ferror(stdin)) + panic("input error"); - PRIV_START + fclose(fp); - if ((lockdes = open(_PATH_LOCKFILE, O_WRONLY | O_CREAT, 0600)) < 0) - perr2("Cannot open lockfile ", _PATH_LOCKFILE); + /* Set the x bit so that we're ready to start executing + */ - lock.l_type = F_WRLCK; - lock.l_whence = SEEK_SET; - lock.l_start = 0; - lock.l_len = 0; + if (fchmod(fd2, S_IRUSR | S_IWUSR | S_IXUSR) < 0) + perr("cannot give away file"); - act.sa_handler = alarmc; - sigemptyset(&(act.sa_mask)); - act.sa_flags = 0; + close(fd2); + if (posixly_correct) { + struct tm runtime; + char timestr[TIMESIZE]; + runtime = *localtime(&runtimer); + strftime(timestr, TIMESIZE, "%a %b %e %T %Y", &runtime); + fprintf(stderr, "job %ld at %s\n", jobno, timestr); + } else + fprintf(stderr, "Job %ld will be executed using /bin/sh\n", jobno); +} - /* - * Set an alarm so a timeout occurs after ALARMC seconds, in case - * something is seriously broken. - */ - sigaction(SIGALRM, &act, NULL); - alarm(ALARMC); - fcntl(lockdes, F_SETLKW, &lock); - alarm(0); - - for (i = 0; i < AT_MAXJOBS; i++) { - sprintf(ppos, "%c%8lx.%3x", queue, - (unsigned long) (runtimer / 60), i); - for (ap = ppos; *ap != '\0'; ap++) - if (*ap == ' ') - *ap = '0'; - - if (stat(atfile, &statbuf) != 0) { - if (errno == ENOENT) - break; - else - perr2("Cannot access ", _PATH_ATJOBS); - } - } /* for */ +static int +in_job_list(long job, long *joblist, int len) +{ + int i; - if (i >= AT_MAXJOBS) - panic("Too many jobs already"); + for (i = 0; i < len; i++) + if (job == joblist[i]) + return 1; - /* - * Create the file. The x bit is only going to be set after it has - * been completely written out, to make sure it is not executed in - * the meantime. To make sure they do not get deleted, turn off - * their r bit. Yes, this is a kluge. - */ - cmask = umask(S_IRUSR | S_IWUSR | S_IXUSR); - if ((fdes = creat(atfile, O_WRONLY)) == -1) - perr("Cannot create atjob file"); + return 0; +} - if ((fd2 = dup(fdes)) < 0) - perr("Error in dup() of job file"); +static void +list_one_job(char *name, long *joblist, int len, int *first) +{ + struct stat buf; + struct tm runtime; + unsigned long ctm; + char queue; + long jobno; + time_t runtimer; + char timestr[TIMESIZE]; + + if (stat(name, &buf) != 0) + perr("cannot stat in " ATJOB_DIR); + + /* See it's a regular file and has its x bit turned on and + * is the user's + */ + if (!S_ISREG(buf.st_mode) + || ((buf.st_uid != real_uid) && ! (real_uid == 0)) + || !(S_IXUSR & buf.st_mode || atverify)) + return; + + if(sscanf(name, "%c%5lx%8lx", &queue, &jobno, &ctm)!=3) + return; + + /* If jobs are given, only list those jobs */ + if (joblist && !in_job_list(jobno, joblist, len)) + return; + + if (atqueue && (queue != atqueue)) + return; + + runtimer = 60*(time_t) ctm; + runtime = *localtime(&runtimer); + strftime(timestr, TIMESIZE, "%a %b %e %T %Y", &runtime); + if (*first) { + if (!posixly_correct) + printf("Date\t\t\t\tOwner\t\tQueue\tJob#\n"); + *first=0; + } + if (posixly_correct) + printf("%ld\t%s\n", jobno, timestr); + else { + struct passwd *pw = getpwuid(buf.st_uid); + + printf("%s\t%s\t%c%s\t%s\n", + timestr, + pw ? pw->pw_name : "???", + queue, + (S_IXUSR & buf.st_mode) ? "":"(done)", + name); + } +} - if (fchown(fd2, real_uid, -1) != 0) - perr("Cannot give away file"); +static void +list_jobs(long *joblist, int len) +{ + /* List all a user's jobs in the queue, by looping through ATJOB_DIR, + * or everybody's if we are root + */ + DIR *spool; + struct dirent *dirent; + int first=1; + +#ifdef __FreeBSD__ + (void) setlocale(LC_TIME, ""); +#endif + + PRIV_START + + if (chdir(ATJOB_DIR) != 0) + perr("cannot change to " ATJOB_DIR); + + if (joblist) { /* Force order to match POSIX */ + char jobglob[32]; + glob_t g; + int i; - PRIV_END + sprintf(jobglob, "?%05lx*", joblist[0]); + g.gl_offs = 0; + glob(jobglob, GLOB_DOOFFS, NULL, &g); + for (i = 1; i < len; i++) { + sprintf(jobglob, "?%05lx*", joblist[i]); + glob(jobglob, GLOB_DOOFFS | GLOB_APPEND, NULL, &g); + } + for (i = 0; i < g.gl_pathc; i++) { + list_one_job(g.gl_pathv[i], joblist, len, &first); + } + globfree(&g); + } else { + if ((spool = opendir(".")) == NULL) + perr("cannot open " ATJOB_DIR); - /* - * We no longer need suid root; now we just need to be able to - * write to the directory, if necessary. + /* Loop over every file in the directory */ + while((dirent = readdir(spool)) != NULL) { + list_one_job(dirent->d_name, joblist, len, &first); + } + closedir(spool); + } + PRIV_END +} - REDUCE_PRIV(0); +static void +process_jobs(int argc, char **argv, int what) +{ + /* Delete every argument (job - ID) given + */ + int i; + struct stat buf; + DIR *spool; + struct dirent *dirent; + unsigned long ctm; + char queue; + long jobno; - /* - * We've successfully created the file; let's set the flag so it - * gets removed in case of an interrupt or error. - */ - fcreated = 1; + PRIV_START - /* Now we can release the lock, so other people can access it */ - lock.l_type = F_UNLCK; - lock.l_whence = SEEK_SET; - lock.l_start = 0; - lock.l_len = 0; - fcntl(lockdes, F_SETLKW, &lock); - close(lockdes); + if (chdir(ATJOB_DIR) != 0) + perr("cannot change to " ATJOB_DIR); - if ((fp = fdopen(fdes, "w")) == NULL) - panic("Cannot reopen atjob file"); + if ((spool = opendir(".")) == NULL) + perr("cannot open " ATJOB_DIR); - /* - * Get the userid to mail to, first by trying getlogin(), which - * reads /etc/utmp, then from LOGNAME, finally from getpwuid(). - */ - mailname = getlogin(); - if (mailname == NULL) - mailname = getenv("LOGNAME"); - - if ((mailname == NULL) || (mailname[0] == '\0') - || (strlen(mailname) > 8)) { - pass_entry = getpwuid(getuid()); - if (pass_entry != NULL) - mailname = pass_entry->pw_name; - } + PRIV_END - if (atinput != (char *) NULL) { - fpin = freopen(atinput, "r", stdin); - if (fpin == NULL) - perr("Cannot open input file"); - } - fprintf(fp, "#! /bin/sh\n# mail %8s %d\n", mailname, send_mail); + /* Loop over every file in the directory + */ + while((dirent = readdir(spool)) != NULL) { - /* Write out the umask at the time of invocation */ - fprintf(fp, "umask %lo\n", (unsigned long) cmask); + PRIV_START + if (stat(dirent->d_name, &buf) != 0) + perr("cannot stat in " ATJOB_DIR); + PRIV_END - /* - * Write out the environment. Anything that may look like a special - * character to the shell is quoted, except for \n, which is done - * with a pair of "'s. Dont't export the no_export list (such as - * TERM or DISPLAY) because we don't want these. - */ - for (atenv = environ; *atenv != NULL; atenv++) { - int export = 1; - char *eqp; - - eqp = strchr(*atenv, '='); - if (ap == NULL) - eqp = *atenv; - else { - int i; - - for (i = 0;i < sizeof(no_export) / - sizeof(no_export[0]); i++) { - export = export - && (strncmp(*atenv, no_export[i], - (size_t) (eqp - *atenv)) != 0); - } - eqp++; - } + if(sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm)!=3) + continue; - if (export) { - fwrite(*atenv, sizeof(char), eqp - *atenv, fp); - for (ap = eqp; *ap != '\0'; ap++) { - if (*ap == '\n') - fprintf(fp, "\"\n\""); - else { - if (!isalnum(*ap)) - fputc('\\', fp); - - fputc(*ap, fp); - } - } - fputs("; export ", fp); - fwrite(*atenv, sizeof(char), eqp - *atenv - 1, fp); - fputc('\n', fp); + for (i=optind; i < argc; i++) { + if (atoi(argv[i]) == jobno || strcmp(argv[i], dirent->d_name)==0) { + if ((buf.st_uid != real_uid) && !(real_uid == 0)) + errx(EXIT_FAILURE, "%s: not owner", argv[i]); + switch (what) { + case ATRM: - } - } - /* - * Cd to the directory at the time and write out all the commands - * the user supplies from stdin. - */ - fprintf(fp, "cd %s\n", cwdname()); + PRIV_START - while ((ch = getchar()) != EOF) - fputc(ch, fp); + if (unlink(dirent->d_name) != 0) + perr(dirent->d_name); - fprintf(fp, "\n"); - if (ferror(fp)) - panic("Output error"); + PRIV_END - if (ferror(stdin)) - panic("Input error"); + break; - fclose(fp); + case CAT: + { + FILE *fp; + int ch; - /* - * Set the x bit so that we're ready to start executing - */ - if (fchmod(fd2, S_IRUSR | S_IWUSR | S_IXUSR) < 0) - perr("Cannot give away file"); + PRIV_START - close(fd2); - fprintf(stderr, "Job %s will be executed using /bin/sh\n", ppos); -} + fp = fopen(dirent->d_name,"r"); -static void -list_jobs() -{ - /* - * List all a user's jobs in the queue, by looping through - * _PATH_ATJOBS, or everybody's if we are root - */ - struct passwd *pw; - DIR *spool; - struct dirent *dirent; - struct stat buf; - struct tm runtime; - unsigned long ctm; - char queue; - time_t runtimer; - char timestr[TIMESIZE]; - int first = 1; + PRIV_END - PRIV_START + if (!fp) { + perr("cannot open file"); + } + while((ch = getc(fp)) != EOF) { + putchar(ch); + } + } + break; + + default: + errx(EXIT_FAILURE, "internal error, process_jobs = %d", + what); + } + } + } + } +} /* process_jobs */ - if (chdir(_PATH_ATJOBS) != 0) - perr2("Cannot change to ", _PATH_ATJOBS); +#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2; - if ((spool = opendir(".")) == NULL) - perr2("Cannot open ", _PATH_ATJOBS); - - /* Loop over every file in the directory */ - while ((dirent = readdir(spool)) != NULL) { - if (stat(dirent->d_name, &buf) != 0) - perr2("Cannot stat in ", _PATH_ATJOBS); - - /* - * See it's a regular file and has its x bit turned on and - * is the user's - */ - if (!S_ISREG(buf.st_mode) - || ((buf.st_uid != real_uid) && !(real_uid == 0)) - || !(S_IXUSR & buf.st_mode || atverify)) - continue; - - if (sscanf(dirent->d_name, "%c%8lx", &queue, &ctm) != 2) - continue; - - if (atqueue && (queue != atqueue)) - continue; - - runtimer = 60 * (time_t) ctm; - runtime = *localtime(&runtimer); - strftime(timestr, TIMESIZE, "%X %x", &runtime); - if (first) { - printf("Date\t\t\tOwner\tQueue\tJob#\n"); - first = 0; - } - pw = getpwuid(buf.st_uid); - - printf("%s\t%s\t%c%s\t%s\n", - timestr, - pw ? pw->pw_name : "???", - queue, - (S_IXUSR & buf.st_mode) ? "" : "(done)", - dirent->d_name); +static time_t +ttime(const char *arg) +{ + /* + * This is pretty much a copy of stime_arg1() from touch.c. I changed + * the return value and the argument list because it's more convenient + * (IMO) to do everything in one place. - Joe Halpin + */ + struct timeval tv[2]; + time_t now; + struct tm *t; + int yearset; + char *p; + + if (gettimeofday(&tv[0], NULL)) + panic("Cannot get current time"); + + /* Start with the current time. */ + now = tv[0].tv_sec; + if ((t = localtime(&now)) == NULL) + panic("localtime"); + /* [[CC]YY]MMDDhhmm[.SS] */ + if ((p = strchr(arg, '.')) == NULL) + t->tm_sec = 0; /* Seconds defaults to 0. */ + else { + if (strlen(p + 1) != 2) + goto terr; + *p++ = '\0'; + t->tm_sec = ATOI2(p); + } + + yearset = 0; + switch(strlen(arg)) { + case 12: /* CCYYMMDDhhmm */ + t->tm_year = ATOI2(arg); + t->tm_year *= 100; + yearset = 1; + /* FALLTHROUGH */ + case 10: /* YYMMDDhhmm */ + if (yearset) { + yearset = ATOI2(arg); + t->tm_year += yearset; + } else { + yearset = ATOI2(arg); + t->tm_year = yearset + 2000; } - PRIV_END + t->tm_year -= 1900; /* Convert to UNIX time. */ + /* FALLTHROUGH */ + case 8: /* MMDDhhmm */ + t->tm_mon = ATOI2(arg); + --t->tm_mon; /* Convert from 01-12 to 00-11 */ + t->tm_mday = ATOI2(arg); + t->tm_hour = ATOI2(arg); + t->tm_min = ATOI2(arg); + break; + default: + goto terr; + } + + t->tm_isdst = -1; /* Figure out DST. */ + tv[0].tv_sec = tv[1].tv_sec = mktime(t); + if (tv[0].tv_sec != -1) + return tv[0].tv_sec; + else +terr: + panic( + "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]"); } -static void -delete_jobs(argc, argv) - int argc; - char **argv; +static long * +get_job_list(int argc, char *argv[], int *joblen) { - /* Delete every argument (job - ID) given */ - int i; - struct stat buf; - - PRIV_START - - if (chdir(_PATH_ATJOBS) != 0) - perr2("Cannot change to ", _PATH_ATJOBS); - - for (i = optind; i < argc; i++) { - if (stat(argv[i], &buf) != 0) - perr(argv[i]); - if ((buf.st_uid != real_uid) && !(real_uid == 0)) { - fprintf(stderr, "%s: Not owner\n", argv[i]); - exit(EXIT_FAILURE); - } - if (unlink(argv[i]) != 0) - perr(argv[i]); + int i, len; + long *joblist; + char *ep; + + joblist = NULL; + len = argc; + if (len > 0) { + if ((joblist = malloc(len * sizeof(*joblist))) == NULL) + panic("out of memory"); + + for (i = 0; i < argc; i++) { + errno = 0; + if ((joblist[i] = strtol(argv[i], &ep, 10)) < 0 || + ep == argv[i] || *ep != '\0' || errno) + panic("invalid job number"); } - PRIV_END -} /* delete_jobs */ + } -/* Global functions */ + *joblen = len; + return joblist; +} int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { - int c; - char queue = 'a'; - char *pgm; - - enum { - ATQ, ATRM, AT, BATCH - }; /* what program we want to run */ - int program = AT; /* our default program */ - char *options = "q:f:mv"; /* default options for at */ - time_t timer; - - RELINQUISH_PRIVS - - /* Eat any leading paths */ - if ((pgm = strrchr(argv[0], '/')) == NULL) - pgm = argv[0]; - else - pgm++; - - namep = pgm; - - /* find out what this program is supposed to do */ - if (strcmp(pgm, "atq") == 0) { - program = ATQ; - options = "q:v"; - } else if (strcmp(pgm, "atrm") == 0) { - program = ATRM; - options = ""; - } else if (strcmp(pgm, "batch") == 0) { - program = BATCH; - options = "f:mv"; + int c; + char queue = DEFAULT_AT_QUEUE; + char queue_set = 0; + char *pgm; + + int program = AT; /* our default program */ + const char *options = "q:f:t:rmvldbc"; /* default options for at */ + time_t timer; + long *joblist; + int joblen; + + posixly_correct = COMPAT_MODE("bin/at", "Unix2003"); + joblist = NULL; + joblen = 0; + timer = -1; + RELINQUISH_PRIVS + + /* Eat any leading paths + */ + if ((pgm = strrchr(argv[0], '/')) == NULL) + pgm = argv[0]; + else + pgm++; + + namep = pgm; + + /* find out what this program is supposed to do + */ + if (strcmp(pgm, "atq") == 0) { + program = ATQ; + options = "q:v"; + } + else if (strcmp(pgm, "atrm") == 0) { + program = ATRM; + options = ""; + } + else if (strcmp(pgm, "batch") == 0) { + program = BATCH; + options = "f:q:mv"; + } + + /* process whatever options we can process + */ + opterr=1; + while ((c=getopt(argc, argv, options)) != -1) + switch (c) { + case 'v': /* verify time settings */ + atverify = 1; + break; + + case 'm': /* send mail when job is complete */ + send_mail = 1; + break; + + case 'f': + atinput = optarg; + break; + + case 'q': /* specify queue */ + if (strlen(optarg) > 1) + usage(); + + atqueue = queue = *optarg; + if (!(islower(queue)||isupper(queue))) + usage(); + + queue_set = 1; + break; + + case 'd': + warnx("-d is deprecated; use -r instead"); + /* fall through to 'r' */ + + case 'r': + if (program != AT) + usage(); + + program = ATRM; + options = ""; + break; + + case 't': + if (program != AT) + usage(); + timer = ttime(optarg); + break; + + case 'l': + if (program != AT) + usage(); + + program = ATQ; + options = "q:"; + break; + + case 'b': + if (program != AT) + usage(); + + program = BATCH; + options = "f:q:mv"; + break; + + case 'c': + program = CAT; + options = ""; + break; + + default: + usage(); + break; } + /* end of options eating + */ - /* process whatever options we can process */ - opterr = 1; - while ((c = getopt(argc, argv, options)) != EOF) - switch (c) { - case 'v': /* verify time settings */ - atverify = 1; - break; - - case 'm': /* send mail when job is complete */ - send_mail = 1; - break; - - case 'f': - atinput = optarg; - break; - - case 'q': /* specify queue */ - if (strlen(optarg) > 1) - usage(); - - atqueue = queue = *optarg; - if ((!islower(queue)) || (queue > 'l')) - usage(); - break; - - default: - usage(); - break; - } - /* end of options eating */ + /* select our program + */ + if(!check_permission()) + errx(EXIT_FAILURE, "you do not have permission to use this program"); + switch (program) { + case ATQ: - /* select our program */ - if (!check_permission()) - { - fprintf(stderr, "You do not have permission to use %s.\n",namep); - exit(EXIT_FAILURE); - } - switch (program) { - case ATQ: + REDUCE_PRIV(DAEMON_UID, DAEMON_GID) - REDUCE_PRIV(0); + if (queue_set == 0) + joblist = get_job_list(argc - optind, argv + optind, &joblen); + list_jobs(joblist, joblen); + break; - list_jobs(); - break; + case ATRM: - case ATRM: + REDUCE_PRIV(DAEMON_UID, DAEMON_GID) - REDUCE_PRIV(0); + process_jobs(argc, argv, ATRM); + break; - delete_jobs(argc, argv); - break; + case CAT: - case AT: - timer = parsetime(argc, argv); - if (atverify) { - struct tm *tm = localtime(&timer); + process_jobs(argc, argv, CAT); + break; - fprintf(stderr, "%s\n", asctime(tm)); - } - writefile(timer, queue); - break; + case AT: + /* + * If timer is > -1, then the user gave the time with -t. In that + * case, it's already been set. If not, set it now. + */ + if (timer == -1) + timer = parsetime(argc, argv); - case BATCH: - writefile(time(NULL), 'b'); - break; + if (atverify) + { + struct tm *tm = localtime(&timer); + fprintf(stderr, "%s\n", asctime(tm)); + } + writefile(timer, queue); + break; - default: - panic("Internal error"); - break; + case BATCH: + if (queue_set) + queue = toupper(queue); + else + queue = DEFAULT_BATCH_QUEUE; + + if (argc > optind) + timer = parsetime(argc, argv); + else + timer = time(NULL); + + if (atverify) + { + struct tm *tm = localtime(&timer); + fprintf(stderr, "%s\n", asctime(tm)); } - exit(EXIT_SUCCESS); + + writefile(timer, queue); + break; + + default: + panic("internal error"); + break; + } + exit(EXIT_SUCCESS); } diff --git a/at.tproj/at.h b/at.tproj/at.h index a107751..ff8008d 100644 --- a/at.tproj/at.h +++ b/at.tproj/at.h @@ -1,31 +1,6 @@ -/* - * 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@ - */ -/* - * at.h - header for at(1) - * Copyright (c) 1993 by Thomas Koenig - * All rights reserved. +/* + * at.h - header for at(1) + * Copyright (C) 1993 Thomas Koenig * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,7 +14,7 @@ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * IN NO EVENT SHALL THE AUTHOR(S) 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 @@ -47,12 +22,10 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: at.h,v 1.1.1.2 2000/01/11 02:10:05 wsanchez Exp $ + * $FreeBSD: src/usr.bin/at/at.h,v 1.5 2001/07/24 14:15:51 obrien Exp $ */ extern int fcreated; extern char *namep; extern char atfile[]; extern char atverify; - -#define AT_MAXJOBS 255 /* max jobs outstanding per user */ diff --git a/at.tproj/panic.c b/at.tproj/panic.c index b4d8b76..76831a8 100644 --- a/at.tproj/panic.c +++ b/at.tproj/panic.c @@ -1,31 +1,6 @@ -/* - * 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@ - */ -/* - * panic.c - terminate fast in case of error - * Copyright (c) 1993 by Thomas Koenig - * All rights reserved. +/* + * panic.c - terminate fast in case of error + * Copyright (C) 1993 Thomas Koenig * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,7 +14,7 @@ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * IN NO EVENT SHALL THE AUTHOR(S) 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 @@ -48,8 +23,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +__FBSDID("$FreeBSD: src/usr.bin/at/panic.c,v 1.17 2002/05/16 00:47:14 tjr Exp $"); + /* System Headers */ +#include #include #include #include @@ -58,61 +37,56 @@ /* Local headers */ #include "panic.h" +#include "privs.h" #include "at.h" -/* File scope variables */ - -static char rcsid[] = "$Id: panic.c,v 1.1.1.2 2000/01/11 02:10:05 wsanchez Exp $"; - /* External variables */ /* Global functions */ -#ifdef __APPLE__ -__private_extern__ -#endif void -panic(a) - char *a; +panic(const char *a) { /* Something fatal has happened, print error message and exit. */ - fprintf(stderr, "%s: %s\n", namep, a); - if (fcreated) + if (fcreated) { + PRIV_START unlink(atfile); + PRIV_END + } - exit(EXIT_FAILURE); + errx(EXIT_FAILURE, "%s", a); } void -perr(a) - char *a; +perr(const char *a) { /* Some operating system error; print error message and exit. */ - perror(a); - if (fcreated) - unlink(atfile); + int serrno = errno; - exit(EXIT_FAILURE); -} + if (fcreated) { + PRIV_START + unlink(atfile); + PRIV_END + } -void -perr2(a, b) - char *a, *b; -{ - fprintf(stderr, "%s", a); - perr(b); + errno = serrno; + err(EXIT_FAILURE, "%s", a); } void usage(void) { -/* Print usage and exit. -*/ - fprintf(stderr, "Usage: at [-q x] [-f file] [-m] time\n" - " atq [-q x] [-v]\n" - " atrm [-q x] job ...\n" - " batch [-f file] [-m]\n"); - exit(EXIT_FAILURE); + /* Print usage and exit. */ + fprintf(stderr, "usage: at [-q x] [-f file] [-m] time\n" + " at -c job [job ...]\n" + " at [-f file] -t [[CC]YY]MMDDhhmm[.SS]\n" + " at -r job [job ...]\n" + " at -l -q queuename\n" + " at -l [job ...]\n" + " atq [-q x] [-v]\n" + " atrm job [job ...]\n" + " batch [-f file] [-m]\n"); + exit(EXIT_FAILURE); } diff --git a/at.tproj/panic.h b/at.tproj/panic.h index 5f40a37..d656d61 100644 --- a/at.tproj/panic.h +++ b/at.tproj/panic.h @@ -1,31 +1,6 @@ -/* - * 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@ - */ -/* - * panic.h - header for at(1) - * Copyright (c) 1993 Thomas Koenig - * All rights reserved. +/* + * panic.h - header for at(1) + * Copyright (C) 1993 Thomas Koenig * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,7 +14,7 @@ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * IN NO EVENT SHALL THE AUTHOR(S) 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 @@ -47,10 +22,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: panic.h,v 1.1.1.2 2000/01/11 02:10:05 wsanchez Exp $ + * $FreeBSD: src/usr.bin/at/panic.h,v 1.6 2002/01/13 20:21:08 mike Exp $ */ -void panic __P((char *a)); -void perr __P((char *a)); -void perr2 __P((char *a, char *b)); -void usage __P((void)); +#include + +void panic(const char *a) __dead2; +void perr(const char *a) __dead2; +void usage(void) __dead2; diff --git a/at.tproj/parsetime.c b/at.tproj/parsetime.c index 711d505..4f1b21e 100644 --- a/at.tproj/parsetime.c +++ b/at.tproj/parsetime.c @@ -1,34 +1,9 @@ -/* - * 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@ - */ /* - * parsetime.c - parse time for at(1) - * Copyright (C) 1993 Thomas Koenig + * parsetime.c - parse time for at(1) + * Copyright (C) 1993, 1994 Thomas Koenig * - * modifications for english-language times - * Copyright (C) 1993 David Parsons - * All rights reserved. + * modifications for English-language times + * Copyright (C) 1993 David Parsons * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -42,7 +17,7 @@ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * IN NO EVENT SHALL THE AUTHOR(S) 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 @@ -51,16 +26,22 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * at [NOW] PLUS NUMBER MINUTES|HOURS|DAYS|WEEKS + * DOT ::= ':'|'.' * /NUMBER [DOT NUMBER] [AM|PM]\ /[MONTH NUMBER [NUMBER]] \ * |NOON | |[TOMORROW] | - * |MIDNIGHT | |NUMBER [SLASH NUMBER [SLASH NUMBER]]| - * \TEATIME / \PLUS NUMBER MINUTES|HOURS|DAYS|WEEKS/ + * |MIDNIGHT | |[DAY OF WEEK] | + * \TEATIME / |NUMBER [SLASH NUMBER [SLASH NUMBER]]| + * \PLUS NUMBER MINUTES|HOURS|DAYS|WEEKS/ */ -/* $OpenBSD: parsetime.c,v 1.8 1999/03/21 04:04:42 alex Exp $ */ + +#include +__FBSDID("$FreeBSD: src/usr.bin/at/parsetime.c,v 1.25 2001/12/10 21:13:01 dwmalone Exp $"); /* System Headers */ #include +#include +#include #include #include #include @@ -68,12 +49,15 @@ #include #include #include -#include +#ifndef __FreeBSD__ +#include +#endif /* Local headers */ #include "at.h" #include "panic.h" +#include "parsetime.h" /* Structures and unions */ @@ -81,54 +65,81 @@ enum { /* symbols */ MIDNIGHT, NOON, TEATIME, PM, AM, TOMORROW, TODAY, NOW, - MINUTES, HOURS, DAYS, WEEKS, - NUMBER, PLUS, DOT, SLASH, ID, JUNK, + MINUTES, HOURS, DAYS, WEEKS, MONTHS, YEARS, + NUMBER, PLUS, DOT, COMMA, SLASH, ID, JUNK, JAN, FEB, MAR, APR, MAY, JUN, - JUL, AUG, SEP, OCT, NOV, DEC -}; + JUL, AUG, SEP, OCT, NOV, DEC, + SUN, MON, TUE, WED, THU, FRI, SAT, + UTC + }; -/* - * parse translation table - table driven parsers can be your FRIEND! +/* parse translation table - table driven parsers can be your FRIEND! */ struct { - char *name; /* token name */ + const char *name; /* token name */ int value; /* token id */ + int plural; /* is this plural? */ } Specials[] = { - { "midnight", MIDNIGHT }, /* 00:00:00 of today or tomorrow */ - { "noon", NOON }, /* 12:00:00 of today or tomorrow */ - { "teatime", TEATIME }, /* 16:00:00 of today or tomorrow */ - { "am", AM }, /* morning times for 0-12 clock */ - { "pm", PM }, /* evening times for 0-12 clock */ - { "tomorrow", TOMORROW }, /* execute 24 hours from time */ - { "today", TODAY }, /* execute today - don't advance time */ - { "now", NOW }, /* opt prefix for PLUS */ - - { "minute", MINUTES }, /* minutes multiplier */ - { "min", MINUTES }, - { "m", MINUTES }, - { "minutes", MINUTES }, /* (pluralized) */ - { "hour", HOURS }, /* hours ... */ - { "hr", HOURS }, /* abbreviated */ - { "h", HOURS }, - { "hours", HOURS }, /* (pluralized) */ - { "day", DAYS }, /* days ... */ - { "d", DAYS }, - { "days", DAYS }, /* (pluralized) */ - { "week", WEEKS }, /* week ... */ - { "w", WEEKS }, - { "weeks", WEEKS }, /* (pluralized) */ - { "jan", JAN }, - { "feb", FEB }, - { "mar", MAR }, - { "apr", APR }, - { "may", MAY }, - { "jun", JUN }, - { "jul", JUL }, - { "aug", AUG }, - { "sep", SEP }, - { "oct", OCT }, - { "nov", NOV }, - { "dec", DEC } + { "midnight", MIDNIGHT,0 }, /* 00:00:00 of today or tomorrow */ + { "noon", NOON,0 }, /* 12:00:00 of today or tomorrow */ + { "teatime", TEATIME,0 }, /* 16:00:00 of today or tomorrow */ + { "am", AM,0 }, /* morning times for 0-12 clock */ + { "pm", PM,0 }, /* evening times for 0-12 clock */ + { "tomorrow", TOMORROW,0 }, /* execute 24 hours from time */ + { "today", TODAY, 0 }, /* execute today - don't advance time */ + { "now", NOW,0 }, /* opt prefix for PLUS */ + + { "minute", MINUTES,0 }, /* minutes multiplier */ + { "minutes", MINUTES,1 }, /* (pluralized) */ + { "hour", HOURS,0 }, /* hours ... */ + { "hours", HOURS,1 }, /* (pluralized) */ + { "day", DAYS,0 }, /* days ... */ + { "days", DAYS,1 }, /* (pluralized) */ + { "week", WEEKS,0 }, /* week ... */ + { "weeks", WEEKS,1 }, /* (pluralized) */ + { "month", MONTHS,0 }, /* month ... */ + { "months", MONTHS,1 }, /* (pluralized) */ + { "year", YEARS,0 }, /* year ... */ + { "years", YEARS,1 }, /* (pluralized) */ + { "jan", JAN,0 }, + { "feb", FEB,0 }, + { "mar", MAR,0 }, + { "apr", APR,0 }, + { "may", MAY,0 }, + { "jun", JUN,0 }, + { "jul", JUL,0 }, + { "aug", AUG,0 }, + { "sep", SEP,0 }, + { "oct", OCT,0 }, + { "nov", NOV,0 }, + { "dec", DEC,0 }, + { "january", JAN,0 }, + { "february", FEB,0 }, + { "march", MAR,0 }, + { "april", APR,0 }, + { "may", MAY,0 }, + { "june", JUN,0 }, + { "july", JUL,0 }, + { "august", AUG,0 }, + { "september", SEP,0 }, + { "october", OCT,0 }, + { "november", NOV,0 }, + { "december", DEC,0 }, + { "sunday", SUN, 0 }, + { "sun", SUN, 0 }, + { "monday", MON, 0 }, + { "mon", MON, 0 }, + { "tuesday", TUE, 0 }, + { "tue", TUE, 0 }, + { "wednesday", WED, 0 }, + { "wed", WED, 0 }, + { "thursday", THU, 0 }, + { "thu", THU, 0 }, + { "friday", FRI, 0 }, + { "fri", FRI, 0 }, + { "saturday", SAT, 0 }, + { "sat", SAT, 0 }, + { "utc", UTC, 0 }, } ; /* File scope variables */ @@ -139,10 +150,9 @@ static char *sct; /* scanner - next char pointer in current argument */ static int need; /* scanner - need to advance to next argument */ static char *sc_token; /* scanner - token buffer */ -static size_t sc_len; /* scanner - lenght of token buffer */ +static size_t sc_len; /* scanner - length of token buffer */ static int sc_tokid; /* scanner - token id */ - -static char rcsid[] = "$Id: parsetime.c,v 1.2 2003/10/15 22:48:12 lindak Exp $"; +static int sc_tokplur; /* scanner - is token plural? */ /* Local functions */ @@ -150,13 +160,13 @@ static char rcsid[] = "$Id: parsetime.c,v 1.2 2003/10/15 22:48:12 lindak Exp $"; * parse a token, checking if it's something special to us */ static int -parse_token(arg) - char *arg; +parse_token(char *arg) { - int i; + size_t i; for (i=0; i<(sizeof Specials/sizeof Specials[0]); i++) if (strcasecmp(Specials[i].name, arg) == 0) { + sc_tokplur = Specials[i].plural; return sc_tokid = Specials[i].value; } @@ -169,37 +179,34 @@ parse_token(arg) * init_scanner() sets up the scanner to eat arguments */ static void -init_scanner(argc, argv) - int argc; - char **argv; +init_scanner(int argc, char **argv) { scp = argv; scc = argc; need = 1; sc_len = 1; - while (--argc > 0) - sc_len += strlen(*++argv); + while (argc-- > 0) + sc_len += strlen(*argv++); - sc_token = (char *) malloc(sc_len); - if (sc_token == NULL) - panic("Insufficient virtual memory"); + if ((sc_token = malloc(sc_len)) == NULL) + errx(EXIT_FAILURE, "virtual memory exhausted"); } /* init_scanner */ /* * token() fetches a token from the input stream */ static int -token() +token(void) { int idx; while (1) { memset(sc_token, 0, sc_len); sc_tokid = EOF; + sc_tokplur = 0; idx = 0; - /* - * if we need to read another argument, walk along the argument list; + /* if we need to read another argument, walk along the argument list; * when we fall off the arglist, we'll just return EOF forever */ if (need) { @@ -210,8 +217,7 @@ token() scc--; need = 0; } - /* - * eat whitespace now - if we walk off the end of the argument, + /* eat whitespace now - if we walk off the end of the argument, * we'll continue, which puts us up at the top of the while loop * to fetch the next argument in */ @@ -222,20 +228,19 @@ token() continue; } - /* - * preserve the first character of the new token + /* preserve the first character of the new token */ sc_token[0] = *sct++; - /* - * then see what it is + /* then see what it is */ if (isdigit(sc_token[0])) { while (isdigit(*sct)) sc_token[++idx] = *sct++; sc_token[++idx] = 0; return sc_tokid = NUMBER; - } else if (isalpha(sc_token[0])) { + } + else if (isalpha(sc_token[0])) { while (isalpha(*sct)) sc_token[++idx] = *sct++; sc_token[++idx] = 0; @@ -247,6 +252,8 @@ token() return sc_tokid = PLUS; else if (sc_token[0] == '/') return sc_tokid = SLASH; + else if (sc_token[0] == ',') + return sc_tokid = COMMA; else return sc_tokid = JUNK; } /* while (1) */ @@ -257,8 +264,7 @@ token() * plonk() gives an appropriate error message if a token is incorrect */ static void -plonk(tok) - int tok; +plonk(int tok) { panic((tok == EOF) ? "incomplete time" : "garbled time"); @@ -269,94 +275,70 @@ plonk(tok) * expect() gets a token and dies most horribly if it's not the token we want */ static void -expect(desired) - int desired; +expect(int desired) { if (token() != desired) plonk(sc_tokid); /* and we die here... */ } /* expect */ -/* - * dateadd() adds a number of minutes to a date. It is extraordinarily - * stupid regarding day-of-month overflow, and will most likely not - * work properly - */ -static void -dateadd(minutes, tm) - int minutes; - struct tm *tm; -{ - /* increment days */ - - while (minutes > 24*60) { - minutes -= 24*60; - tm->tm_mday++; - } - - /* increment hours */ - while (minutes > 60) { - minutes -= 60; - tm->tm_hour++; - if (tm->tm_hour > 23) { - tm->tm_mday++; - tm->tm_hour = 0; - } - } - - /* increment minutes */ - tm->tm_min += minutes; - - if (tm->tm_min > 59) { - tm->tm_hour++; - tm->tm_min -= 60; - - if (tm->tm_hour > 23) { - tm->tm_mday++; - tm->tm_hour = 0; - } - } -} /* dateadd */ - - /* * plus() parses a now + time * - * at [NOW] PLUS NUMBER [MINUTES|HOURS|DAYS|WEEKS] + * at [NOW] PLUS NUMBER [MINUTES|HOURS|DAYS|WEEKS|MONTHS|YEARS] * */ + static void -plus(tm) - struct tm *tm; +plus(struct tm *tm) { int delay; + int expectplur; expect(NUMBER); delay = atoi(sc_token); + expectplur = (delay != 1) ? 1 : 0; switch (token()) { + case YEARS: + tm->tm_year += delay; + break; + case MONTHS: + tm->tm_mon += delay; + break; case WEEKS: delay *= 7; case DAYS: - delay *= 24; + tm->tm_mday += delay; + break; case HOURS: - delay *= 60; + tm->tm_hour += delay; + break; case MINUTES: - dateadd(delay, tm); - return; + tm->tm_min += delay; + break; + default: + plonk(sc_tokid); + break; } - plonk(sc_tokid); + + if (expectplur != sc_tokplur) + warnx("pluralization is wrong"); + + tm->tm_isdst = -1; + if (mktime(tm) < 0) + plonk(sc_tokid); + } /* plus */ /* * tod() computes the time of day - * [NUMBER [DOT NUMBER] [AM|PM]] + * [NUMBER [DOT NUMBER] [AM|PM]] [UTC] */ static void -tod(tm) - struct tm *tm; +tod(struct tm *tm) { int hour, minute = 0; size_t tlen; @@ -364,8 +346,7 @@ tod(tm) hour = atoi(sc_token); tlen = strlen(sc_token); - /* - * first pick out the time of day - if it's 4 digits, we assume + /* first pick out the time of day - if it's 4 digits, we assume * a HHMM time, otherwise it's HH DOT MM time */ if (token() == DOT) { @@ -374,33 +355,58 @@ tod(tm) if (minute > 59) panic("garbled time"); token(); - } else if (tlen == 4) { + } + else if (tlen == 4) { minute = hour%100; if (minute > 59) - panic("garbeld time"); + panic("garbled time"); hour = hour/100; } - /* - * check if an AM or PM specifier was given + /* check if an AM or PM specifier was given */ - if (sc_tokid == AM || sc_tokid == PM) { + switch (sc_tokid) { + case AM: + case PM: if (hour > 12) panic("garbled time"); - if (sc_tokid == PM) - hour += 12; - token(); - } else if (hour > 23) - panic("garbled time"); + if (sc_tokid == PM) { + if (hour != 12) /* 12:xx PM is 12:xx, not 24:xx */ + hour += 12; + } else { + if (hour == 12) /* 12:xx AM is 00:xx, not 12:xx */ + hour = 0; + } + if (UTC != token()) + break; /* else fallthrough */ + + case UTC: + hour += tm->tm_gmtoff/(60*60); + while (hour < 0) + hour += 24; + minute += (tm->tm_gmtoff/60); + while (minute < 0) + minute += 60; + tm->tm_gmtoff = 0; + token(); + break; + default: + if (hour > 23) + panic("garbled time"); + break; + } - /* - * if we specify an absolute time, we don't want to bump the day even + /* if we specify an absolute time, we don't want to bump the day even * if we've gone past that time - but if we're specifying a time plus * a relative offset, it's okay to bump things + * If minutes are the same assume tomorrow was meant */ - if ((sc_tokid == EOF || sc_tokid == PLUS) && tm->tm_hour > hour) + if ((sc_tokid == EOF || sc_tokid == PLUS) && + ((tm->tm_hour > hour) || ((tm->tm_hour == hour) && (tm->tm_min >= minute)))) { tm->tm_mday++; + tm->tm_wday++; + } tm->tm_hour = hour; tm->tm_min = minute; @@ -415,25 +421,30 @@ tod(tm) * assign_date() assigns a date, wrapping to next year if needed */ static void -assign_date(tm, mday, mon, year) - struct tm *tm; - long mday, mon, year; +assign_date(struct tm *tm, long mday, long mon, long year) { - if (year > 99) { + /* + * Convert year into tm_year format (year - 1900). + * We may be given the year in 2 digit, 4 digit, or tm_year format. + */ + if (year != -1) { if (year >= TM_YEAR_BASE) - year -= TM_YEAR_BASE; - else - panic("garbled time"); - } else if (year != -1) { - /* - * check if the specified year is in the current century. - * allow for one year of user error as many people will - * enter n - 1 at the start of year n. - */ - if (year < tm->tm_year % 100 -1) - year += 100; - /* adjust fo the year 2000 and beyond */ - year += tm->tm_year - (tm->tm_year % 100); + year -= TM_YEAR_BASE; /* convert from 4 digit year */ + else if (year < 100) { + /* convert from 2 digit year */ + struct tm *lt; + time_t now; + + time(&now); + lt = localtime(&now); + + /* Convert to tm_year assuming current century */ + year += (lt->tm_year / 100) * 100; + + if (year == lt->tm_year - 1) year++; + else if (year < lt->tm_year) + year += 100; /* must be in next century */ + } } if (year < 0 && @@ -453,16 +464,16 @@ assign_date(tm, mday, mon, year) * * /[ NUMBER [NUMBER]] \ * |[TOMORROW] | + * |[DAY OF WEEK] | * |NUMBER [SLASH NUMBER [SLASH NUMBER]]| * \PLUS NUMBER MINUTES|HOURS|DAYS|WEEKS/ */ static void -month(tm) - struct tm *tm; +month(struct tm *tm) { - int year= (-1); - int mday, mon; - size_t tlen; + long year= (-1); + long mday = 0, wday, mon; + int tlen; switch (sc_tokid) { case PLUS: @@ -472,28 +483,52 @@ month(tm) case TOMORROW: /* do something tomorrow */ tm->tm_mday ++; + tm->tm_wday ++; case TODAY: /* force ourselves to stay in today - no further processing */ token(); break; case JAN: case FEB: case MAR: case APR: case MAY: case JUN: case JUL: case AUG: case SEP: case OCT: case NOV: case DEC: - /* - * do month mday [year] + /* do month mday [,year] */ mon = (sc_tokid-JAN); expect(NUMBER); mday = atol(sc_token); - if (token() == NUMBER) { - year = atol(sc_token); - token(); + if (token() == COMMA) { + if (token() == NUMBER) { + year = atol(sc_token); + token(); + } } assign_date(tm, mday, mon, year); + if (sc_tokid == PLUS) + plus(tm); + break; + + case SUN: case MON: case TUE: + case WED: case THU: case FRI: + case SAT: + /* do a particular day of the week + */ + wday = (sc_tokid-SUN); + + mday = tm->tm_mday; + + /* if this day is < today, then roll to next week + */ + if (wday < tm->tm_wday) + mday += 7 - (tm->tm_wday - wday); + else + mday += (wday - tm->tm_wday); + + tm->tm_wday = wday; + + assign_date(tm, mday, tm->tm_mon, tm->tm_year); break; case NUMBER: - /* - * get numeric MMDDYY, mm/dd/yy, or dd.mm.yy + /* get numeric MMDDYY, mm/dd/yy, or dd.mm.yy */ tlen = strlen(sc_token); mon = atol(sc_token); @@ -511,25 +546,27 @@ month(tm) token(); } - /* - * flip months and days for european timing + /* flip months and days for European timing */ if (sep == DOT) { int x = mday; mday = mon; mon = x; } - } else if (tlen == 6 || tlen == 8) { + } + else if (tlen == 6 || tlen == 8) { if (tlen == 8) { year = (mon % 10000) - TM_YEAR_BASE; mon /= 10000; - } else { + } + else { year = mon % 100; mon /= 100; } mday = mon % 100; mon /= 100; - } else + } + else panic("garbled time"); mon--; @@ -545,12 +582,9 @@ month(tm) /* Global functions */ time_t -parsetime(argc, argv) - int argc; - char **argv; +parsetime(int argc, char **argv) { -/* - * Do the argument parsing, die if necessary, and return the time the job +/* Do the argument parsing, die if necessary, and return the time the job * should be run. */ time_t nowtimer, runtimer; @@ -571,7 +605,11 @@ parsetime(argc, argv) init_scanner(argc-optind, argv+optind); switch (token()) { - case NOW: /* now is optional prefix for PLUS tree */ + case NOW: + if (scc < 1) { + return nowtimer; + } + /* now is optional prefix for PLUS tree */ expect(PLUS); case PLUS: plus(&runtime); @@ -582,8 +620,7 @@ parsetime(argc, argv) month(&runtime); break; - /* - * evil coding for TEATIME|NOON|MIDNIGHT - we've initialised + /* evil coding for TEATIME|NOON|MIDNIGHT - we've initialised * hr to zero up above, then fall into this case in such a * way so we add +12 +4 hours to it for teatime, +12 hours * to it for noon, and nothing at all for midnight, then @@ -595,20 +632,21 @@ parsetime(argc, argv) case NOON: hr += 12; case MIDNIGHT: - if (runtime.tm_hour >= hr) + if (runtime.tm_hour >= hr) { runtime.tm_mday++; + runtime.tm_wday++; + } runtime.tm_hour = hr; runtime.tm_min = 0; token(); - /* fall through to month setting */ + /* FALLTHROUGH to month setting */ default: month(&runtime); break; } /* ugly case statement */ expect(EOF); - /* - * adjust for daylight savings time + /* adjust for daylight savings time */ runtime.tm_isdst = -1; runtimer = mktime(&runtime); @@ -621,7 +659,7 @@ parsetime(argc, argv) panic("garbled time"); if (nowtimer > runtimer) - panic("Trying to travel back in time"); + panic("trying to travel back in time"); return runtimer; } /* parsetime */ diff --git a/at.tproj/parsetime.h b/at.tproj/parsetime.h index ef334a1..30c3f20 100644 --- a/at.tproj/parsetime.h +++ b/at.tproj/parsetime.h @@ -1,31 +1,6 @@ -/* - * 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@ - */ -/* - * at.h - header for at(1) - * Copyright (c) 1993 by Thomas Koenig - * All rights reserved. +/* + * at.h - header for at(1) + * Copyright (C) 1993 Thomas Koenig * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,15 +14,13 @@ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * IN NO EVENT SHALL THE AUTHOR(S) 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, WETHER 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. - * - * $Id: parsetime.h,v 1.1.1.2 2000/01/11 02:10:05 wsanchez Exp $ */ -time_t parsetime __P((int argc, char **argv)); +time_t parsetime(int argc, char **argv); diff --git a/at.tproj/pathnames.h b/at.tproj/pathnames.h index 209135f..daf1edc 100644 --- a/at.tproj/pathnames.h +++ b/at.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/at.tproj/perm.c b/at.tproj/perm.c index a2df820..872ce44 100644 --- a/at.tproj/perm.c +++ b/at.tproj/perm.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@ - */ /* * perm.c - check user permission for at(1) * Copyright (C) 1994 Thomas Koenig @@ -47,9 +23,13 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +__FBSDID("$FreeBSD: src/usr.bin/at/perm.c,v 1.13 2001/12/10 21:13:01 dwmalone Exp $"); + /* System Headers */ #include +#include #include #include #include @@ -60,9 +40,9 @@ /* Local headers */ -#include "privs.h" #include "at.h" -#include "pathnames.h" +#include "perm.h" +#include "privs.h" /* Macros */ @@ -70,10 +50,6 @@ /* Structures and unions */ -/* File scope variables */ - -static char rcsid[] = "$Id: perm.c,v 1.1.1.2 2000/01/11 02:10:05 wsanchez Exp $"; - /* Function declarations */ static int check_for_user(FILE *fp,const char *name); @@ -87,10 +63,8 @@ static int check_for_user(FILE *fp,const char *name) int found = 0; len = strlen(name); - if ((buffer = malloc(sizeof (char) * (len+2))) == NULL) { - fprintf(stderr, "malloc error!"); - exit(EXIT_FAILURE); - } + if ((buffer = malloc(len+2)) == NULL) + errx(EXIT_FAILURE, "virtual memory exhausted"); while(fgets(buffer, len+2, fp) != NULL) { @@ -106,7 +80,7 @@ static int check_for_user(FILE *fp,const char *name) return found; } /* Global functions */ -int check_permission() +int check_permission(void) { FILE *fp; uid_t uid = geteuid(); @@ -116,14 +90,11 @@ int check_permission() return 1; if ((pentry = getpwuid(uid)) == NULL) - { - perror("Cannot access user database"); - exit(EXIT_FAILURE); - } + err(EXIT_FAILURE, "cannot access user database"); PRIV_START - fp=fopen(_PATH_AT "at.allow","r"); + fp=fopen(PERM_PATH "at.allow","r"); PRIV_END @@ -131,12 +102,12 @@ int check_permission() { return check_for_user(fp, pentry->pw_name); } - else + else if (errno == ENOENT) { PRIV_START - fp=fopen(_PATH_AT "at.deny", "r"); + fp=fopen(PERM_PATH "at.deny", "r"); PRIV_END @@ -144,7 +115,10 @@ int check_permission() { return !check_for_user(fp, pentry->pw_name); } - perror("at.deny"); + else if (errno != ENOENT) + warn("at.deny"); } + else + warn("at.allow"); return 0; } diff --git a/at.tproj/perm.h b/at.tproj/perm.h index 30fb0ca..92d0e31 100644 --- a/at.tproj/perm.h +++ b/at.tproj/perm.h @@ -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@ - */ /* * perm.h - header for at(1) * Copyright (C) 1994 Thomas Koenig @@ -45,6 +21,8 @@ * THEORY OF LIABILITY, WETHER 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/usr.bin/at/perm.h,v 1.4 2001/12/02 12:26:18 markm Exp $ */ -int check_permission(); +int check_permission(void); diff --git a/at.tproj/privs.h b/at.tproj/privs.h index 5e6b226..9c5e39d 100644 --- a/at.tproj/privs.h +++ b/at.tproj/privs.h @@ -1,31 +1,6 @@ -/* - * 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@ - */ -/* - * privs.h - header for privileged operations - * Copyright (c) 1993 by Thomas Koenig - * All rights reserved. +/* + * privs.h - header for privileged operations + * Copyright (C) 1993 Thomas Koenig * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,7 +14,7 @@ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * IN NO EVENT SHALL THE AUTHOR(S) 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 @@ -47,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: privs.h,v 1.1.1.2 2000/01/11 02:10:05 wsanchez Exp $ + * $FreeBSD: src/usr.bin/at/privs.h,v 1.8 2001/09/04 16:15:51 ru Exp $ */ #ifndef _PRIVS_H @@ -55,22 +30,22 @@ #include -/* Relinquish privileges temporarily for a setuid program - * with the option of getting them back later. This is done by swapping - * the real and effective userid BSD style. Call RELINQUISH_PRIVS once - * at the beginning of the main program. This will cause all operatons +/* Relinquish privileges temporarily for a setuid or setgid program + * with the option of getting them back later. This is done by + * utilizing POSIX saved user and group IDs. Call RELINQUISH_PRIVS once + * at the beginning of the main program. This will cause all operations * to be executed with the real userid. When you need the privileges - * of the setuid invocation, call PRIV_START; when you no longer + * of the setuid/setgid invocation, call PRIV_START; when you no longer * need it, call PRIV_END. Note that it is an error to call PRIV_START * and not PRIV_END within the same function. * - * Use RELINQUISH_PRIVS_ROOT(a) if your program started out running + * Use RELINQUISH_PRIVS_ROOT(a,b) if your program started out running * as root, and you want to drop back the effective userid to a * and the effective group id to b, with the option to get them back * later. * * If you no longer need root privileges, but those of some other - * userid, you can call REDUCE_PRIV(a) when your effective + * userid/groupid, you can call REDUCE_PRIV(a,b) when your effective * is the user's. * * Problems: Do not use return between PRIV_START and PRIV_END; this @@ -80,7 +55,7 @@ * It is NOT safe to call exec(), system() or popen() with a user- * supplied program (i.e. without carefully checking PATH and any * library load paths) with relinquished privileges; the called program - * can aquire them just as easily. Set both effective and real userid + * can acquire them just as easily. Set both effective and real userid * to the real userid before calling any of them. */ @@ -89,28 +64,47 @@ extern #endif uid_t real_uid, effective_uid; +#ifndef MAIN +extern +#endif +gid_t real_gid, effective_gid; + #define RELINQUISH_PRIVS { \ real_uid = getuid(); \ effective_uid = geteuid(); \ + real_gid = getgid(); \ + effective_gid = getegid(); \ + setegid(real_gid); \ seteuid(real_uid); \ } -#define RELINQUISH_PRIVS_ROOT(a) { \ +#define RELINQUISH_PRIVS_ROOT(a, b) { \ real_uid = (a); \ effective_uid = geteuid(); \ + real_gid = (b); \ + effective_gid = getegid(); \ + setegid(real_gid); \ seteuid(real_uid); \ } #define PRIV_START { \ - seteuid(effective_uid); + if (seteuid(0)<0) perr("cannot regain privs"); \ + if (setegid(effective_gid)<0) perr("cannot reset gid"); \ + if (seteuid(effective_uid)<0) perr("cannot reset uid"); \ +} -#define PRIV_END \ - seteuid(real_uid); \ +#define PRIV_END { \ + if (seteuid(0)<0) perr("cannot regain privs"); \ + if (setegid(real_gid)<0) perr("cannot reset gid"); \ + if (seteuid(real_uid)<0) perr("cannot reset uid"); \ } -#define REDUCE_PRIV(a) { \ - seteuid(effective_uid); \ - real_uid = effective_uid = (a); \ - setuid(real_uid); \ +#define REDUCE_PRIV(a, b) { \ + PRIV_START \ + effective_uid = (a); \ + effective_gid = (b); \ + setregid((gid_t)-1, effective_gid); \ + setreuid((uid_t)-1, effective_uid); \ + PRIV_END \ } #endif diff --git a/atrun.tproj/Makefile b/atrun.tproj/Makefile index 8150fd1..64dcece 100644 --- a/atrun.tproj/Makefile +++ b/atrun.tproj/Makefile @@ -16,7 +16,9 @@ HFILES = atrun.h CFILES = atrun.c -OTHERSRCS = Makefile.preamble Makefile Makefile.dist atrun.8 +OTHERSRCS = Makefile.preamble Makefile Makefile.dist atrun.8 Makefile.postamble com.apple.atrun.plist + +NEXTSTEP_PB_CFLAGS += -DDAEMON_UID=1 -DDAEMON_GID=1 MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles @@ -30,7 +32,7 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) -HEADER_PATHS = -I../at +HEADER_PATHS = -I../at.tproj NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc diff --git a/atrun.tproj/Makefile.postamble b/atrun.tproj/Makefile.postamble new file mode 100644 index 0000000..f3a4add --- /dev/null +++ b/atrun.tproj/Makefile.postamble @@ -0,0 +1,5 @@ +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 atrun.8 $(DSTROOT)/usr/share/man/man8 + mkdir -p $(DSTROOT)/System/Library/LaunchDaemons + install -c -m 444 com.apple.atrun.plist $(DSTROOT)/System/Library/LaunchDaemons diff --git a/atrun.tproj/PB.project b/atrun.tproj/PB.project index e69c398..b323250 100644 --- a/atrun.tproj/PB.project +++ b/atrun.tproj/PB.project @@ -4,7 +4,7 @@ HEADERSEARCH = (../at); H_FILES = (atrun.h); OTHER_LINKED = (atrun.c); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.dist, atrun.8); + OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.dist, atrun.8, com.apple.atrun.plist); PRECOMPILED_HEADERS = (); PROJECT_HEADERS = (); PUBLIC_HEADERS = (); diff --git a/atrun.tproj/atrun.c b/atrun.tproj/atrun.c index 0634fb2..9d52ffa 100644 --- a/atrun.tproj/atrun.c +++ b/atrun.tproj/atrun.c @@ -1,31 +1,6 @@ -/* - * 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@ - */ -/* - * atrun.c - run jobs queued by at; run with root privileges. - * Copyright (c) 1993 by Thomas Koenig - * All rights reserved. +/* + * atrun.c - run jobs queued by at; run with root privileges. + * Copyright (C) 1993, 1994 Thomas Koenig * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,7 +14,7 @@ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * IN NO EVENT SHALL THE AUTHOR(S) 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 @@ -48,304 +23,479 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef lint +static const char rcsid[] = + "$FreeBSD: src/libexec/atrun/atrun.c,v 1.18 2004/07/11 17:37:32 stefanf Exp $"; +#endif /* not lint */ + /* System Headers */ #include #include #include #include +#include +#include #include -#include +#include +#include #include #include #include #include #include #include +#include #include #include -#include - +#include +#if 1 #include +#else +#include +#endif + +#if (MAXLOGNAME-1) > UT_NAMESIZE +#define LOGNAMESIZE UT_NAMESIZE +#else +#define LOGNAMESIZE (MAXLOGNAME-1) +#endif /* Local headers */ #define MAIN #include "privs.h" #include "pathnames.h" -#include "atrun.h" +/* Macros */ + +#ifndef ATJOB_DIR +#define ATJOB_DIR _PATH_ATJOBS +#endif + +#ifndef ATSPOOL_DIR +#define ATSPOOL_DIR _PATH_ATSPOOL +#endif + +#ifndef LOADAVG_MX +#define LOADAVG_MX 1.5 +#endif /* File scope variables */ -static char *namep; -static char rcsid[] = "$Id: atrun.c,v 1.1.1.2 2000/01/11 02:10:06 wsanchez Exp $"; +static int debug = 0; + +void perr(const char *a); +static void usage(void); /* Local functions */ -static void -perr(a) - const char *a; +static int +write_string(int fd, const char* a) { - syslog(LOG_ERR, "%s: %m", a); - exit(EXIT_FAILURE); + return write(fd, a, strlen(a)); } -static int -write_string(fd, a) - int fd; - const char *a; +#undef DEBUG_FORK +#ifdef DEBUG_FORK +static pid_t +myfork(void) { - return write(fd, a, strlen(a)); + pid_t res; + res = fork(); + if (res == 0) + kill(getpid(),SIGSTOP); + return res; } +#define fork myfork +#endif + static void -run_file(filename, uid, gid) - const char *filename; - uid_t uid; - gid_t gid; +run_file(const char *filename, uid_t uid, gid_t gid) { - /* - * Run a file by by spawning off a process which redirects I/O, - * spawns a subshell, then waits for it to complete and spawns another - * process to send mail to the user. - */ - pid_t pid; - int fd_out, fd_in; - int queue; - char mailbuf[9]; - char *mailname = NULL; - FILE *stream; - int send_mail = 0; - struct stat buf; - off_t size; - struct passwd *pentry; - int fflags; - - pid = fork(); - if (pid == -1) - perr("Cannot fork"); - else if (pid > 0) - return; - - /* - * Let's see who we mail to. Hopefully, we can read it from the - * command file; if not, send it to the owner, or, failing that, to - * root. - */ +/* Run a file by spawning off a process which redirects I/O, + * spawns a subshell, then waits for it to complete and sends + * mail to the user. + */ + pid_t pid; + int fd_out, fd_in; + int queue; + char mailbuf[LOGNAMESIZE + 1], fmt[49]; + char *mailname = NULL; + FILE *stream; + int send_mail = 0; + struct stat buf, lbuf; + off_t size; + struct passwd *pentry; + int fflags; + long nuid; + long ngid; + + + PRIV_START + + if (chmod(filename, S_IRUSR) != 0) + { + perr("cannot change file permissions"); + } + + PRIV_END + + pid = fork(); + if (pid == -1) + perr("cannot fork"); + + else if (pid != 0) + return; + + /* Let's see who we mail to. Hopefully, we can read it from + * the command file; if not, send it to the owner, or, failing that, + * to root. + */ + + pentry = getpwuid(uid); + if (pentry == NULL) + { + syslog(LOG_ERR,"Userid %lu not found - aborting job %s", + (unsigned long) uid, filename); + exit(EXIT_FAILURE); + } + PRIV_START + + stream=fopen(filename, "r"); + + PRIV_END + +#ifdef __FreeBSD__ + if (pentry->pw_expire && time(NULL) >= pentry->pw_expire) + { + syslog(LOG_ERR, "Userid %lu is expired - aborting job %s", + (unsigned long) uid, filename); + exit(EXIT_FAILURE); + } +#endif - PRIV_START + if (stream == NULL) + perr("cannot open input file"); - stream = fopen(filename, "r"); + if ((fd_in = dup(fileno(stream))) <0) + perr("error duplicating input file descriptor"); - PRIV_END + if (fstat(fd_in, &buf) == -1) + perr("error in fstat of input file descriptor"); - if (stream == NULL) - perr("Cannot open input file"); + if (lstat(filename, &lbuf) == -1) + perr("error in fstat of input file"); - if ((fd_in = dup(fileno(stream))) < 0) - perr("Error duplicating input file descriptor"); + if (S_ISLNK(lbuf.st_mode)) { + syslog(LOG_ERR,"Symbolic link encountered in job %s - aborting", + filename); + exit(EXIT_FAILURE); + } + if ((lbuf.st_dev != buf.st_dev) || (lbuf.st_ino != buf.st_ino) || + (lbuf.st_uid != buf.st_uid) || (lbuf.st_gid != buf.st_gid) || + (lbuf.st_size!=buf.st_size)) { + syslog(LOG_ERR,"Somebody changed files from under us for job %s - " + "aborting",filename); + exit(EXIT_FAILURE); + } + if (buf.st_nlink > 1) { + syslog(LOG_ERR,"Someboy is trying to run a linked script for job %s", + filename); + exit(EXIT_FAILURE); + } + if ((fflags = fcntl(fd_in, F_GETFD)) <0) + perr("error in fcntl"); - if ((fflags = fcntl(fd_in, F_GETFD)) < 0) - perr("Error in fcntl"); + fcntl(fd_in, F_SETFD, fflags & ~FD_CLOEXEC); - fcntl(fd_in, F_SETFD, fflags & ~FD_CLOEXEC); + snprintf(fmt, sizeof(fmt), + "#!/bin/sh\n# atrun uid=%%ld gid=%%ld\n# mail %%%ds %%d", + LOGNAMESIZE); + if (fscanf(stream, fmt, &nuid, &ngid, mailbuf, &send_mail) != 4) { + syslog(LOG_ERR,"File %s is in wrong format - aborting", filename); + exit(EXIT_FAILURE); + } + if (mailbuf[0] == '-') { + syslog(LOG_ERR,"illegal mail name %s in %s",mailbuf,filename); + exit(EXIT_FAILURE); + } + mailname = mailbuf; + if (nuid != uid) { + syslog(LOG_ERR,"Job %s - userid %ld does not match file uid %lu", + filename, nuid, (unsigned long)uid); + exit(EXIT_FAILURE); + } + if (ngid != gid) { + syslog(LOG_ERR,"Job %s - groupid %ld does not match file gid %lu", + filename, ngid, (unsigned long)gid); + exit(EXIT_FAILURE); + } + fclose(stream); + if (chdir(ATSPOOL_DIR) < 0) + perr("cannot chdir to " ATSPOOL_DIR); + + /* Create a file to hold the output of the job we are about to run. + * Write the mail header. + */ + if((fd_out=open(filename, + O_WRONLY | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) < 0) + perr("cannot create output file"); + + write_string(fd_out, "Subject: Output from your job "); + write_string(fd_out, filename); + write_string(fd_out, "\n\n"); + fstat(fd_out, &buf); + size = buf.st_size; + + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); + + pid = fork(); + if (pid < 0) + perr("error in fork"); + + else if (pid == 0) + { + char *nul = NULL; + char **nenvp = &nul; + + /* Set up things for the child; we want standard input from the input file, + * and standard output and error sent to our output file. + */ - if (fscanf(stream, "#! /bin/sh\n# mail %8s %d", mailbuf, &send_mail) == 2) { - mailname = mailbuf; - } else { - pentry = getpwuid(uid); - if (pentry == NULL) - mailname = "root"; - else - mailname = pentry->pw_name; - } - fclose(stream); - if (chdir(_PATH_ATSPOOL) < 0) - perr("Cannot chdir to " _PATH_ATSPOOL); + if (lseek(fd_in, (off_t) 0, SEEK_SET) < 0) + perr("error in lseek"); - /* - * Create a file to hold the output of the job we are about to - * run. Write the mail header. - */ - if ((fd_out = open(filename, - O_WRONLY | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) < 0) - perr("Cannot create output file"); + if (dup(fd_in) != STDIN_FILENO) + perr("error in I/O redirection"); + + if (dup(fd_out) != STDOUT_FILENO) + perr("error in I/O redirection"); + + if (dup(fd_out) != STDERR_FILENO) + perr("error in I/O redirection"); - write_string(fd_out, "Subject: Output from your job "); - write_string(fd_out, filename); - write_string(fd_out, "\n\n"); - fstat(fd_out, &buf); - size = buf.st_size; + close(fd_in); + close(fd_out); + if (chdir(ATJOB_DIR) < 0) + perr("cannot chdir to " ATJOB_DIR); - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); + queue = *filename; - pid = fork(); - if (pid < 0) - perr("Error in fork"); - else if (pid == 0) { - char *nul = NULL; - char **nenvp = &nul; + PRIV_START - /* - * Set up things for the child; we want standard input from - * the input file, and standard output and error sent to - * our output file. - */ + nice(tolower(queue) - 'a'); + + if (initgroups(pentry->pw_name,pentry->pw_gid)) + perr("cannot delete saved userids"); - if (lseek(fd_in, (off_t) 0, SEEK_SET) < 0) - perr("Error in lseek"); + if (setgid(gid) < 0 || setegid(pentry->pw_gid) < 0) + perr("cannot change group"); - if (dup(fd_in) != STDIN_FILENO) - perr("Error in I/O redirection"); + if (setlogin(pentry->pw_name)) + perr("cannot set login name"); - if (dup(fd_out) != STDOUT_FILENO) - perr("Error in I/O redirection"); + if (setuid(uid) < 0 || seteuid(uid) < 0) + perr("cannot set user id"); - if (dup(fd_out) != STDERR_FILENO) - perr("Error in I/O redirection"); + if (chdir(pentry->pw_dir)) + chdir("/"); - close(fd_in); - close(fd_out); - if (chdir(_PATH_ATJOBS) < 0) - perr("Cannot chdir to " _PATH_ATJOBS); + if(execle("/bin/sh","sh",(char *) NULL, nenvp) != 0) + perr("exec failed for /bin/sh"); - queue = *filename; + PRIV_END + } + /* We're the parent. Let's wait. + */ + close(fd_in); + close(fd_out); + waitpid(pid, (int *) NULL, 0); + + /* Send mail. Unlink the output file first, so it is deleted after + * the run. + */ + stat(filename, &buf); + if (open(filename, O_RDONLY) != STDIN_FILENO) + perr("open of jobfile failed"); + + unlink(filename); + if ((buf.st_size != size) || send_mail) + { + PRIV_START - PRIV_START + if (initgroups(pentry->pw_name,pentry->pw_gid)) + perr("cannot delete saved userids"); - if (queue > 'b') - nice(queue - 'b'); + if (setgid(gid) < 0 || setegid(pentry->pw_gid) < 0) + perr("cannot change group"); - if (setgid(gid) < 0) - perr("Cannot change group"); + if (setlogin(pentry->pw_name)) + perr("cannot set login name"); - if (setuid(uid) < 0) - perr("Cannot set user id"); + if (setuid(uid) < 0 || seteuid(uid) < 0) + perr("cannot set user id"); + if (chdir(pentry->pw_dir)) chdir("/"); - if (execle("/bin/sh", "sh", (char *) NULL, nenvp) != 0) - perr("Exec failed"); +#if 1 + execl(_PATH_SENDMAIL, "sendmail", "-F", "Atrun Service", + "-odi", "-oem", + mailname, (char *) NULL); +#else + execl(MAIL_CMD, MAIL_CMD, mailname, (char *) NULL); +#endif + perr("exec failed for mail command"); - PRIV_END - } - /* We're the parent. Let's wait. */ - close(fd_in); - close(fd_out); - waitpid(pid, (int *) NULL, 0); - - stat(filename, &buf); - if ((buf.st_size != size) || send_mail) { - /* Fork off a child for sending mail */ - pid = fork(); - if (pid < 0) - perr("Fork failed"); - else if (pid == 0) { - if (open(filename, O_RDONLY) != STDIN_FILENO) - perr("Cannot reopen output file"); - - execl(_PATH_SENDMAIL, _PATH_SENDMAIL, mailname, - (char *) NULL); - perr("Exec failed"); - } - waitpid(pid, (int *) NULL, 0); - } - unlink(filename); - exit(EXIT_SUCCESS); + PRIV_END + } + exit(EXIT_SUCCESS); } /* Global functions */ +/* Needed in gloadavg.c */ +void +perr(const char *a) +{ + if (debug) + { + warn("%s", a); + } + else + syslog(LOG_ERR, "%s: %m", a); + + exit(EXIT_FAILURE); +} + int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { - /* - * Browse through _PATH_ATJOBS, checking all the jobfiles wether - * they should be executed and or deleted. The queue is coded into - * the first byte of the job filename, the date (in minutes since - * Eon) as a hex number in the following eight bytes, followed by - * a dot and a serial number. A file which has not been executed - * yet is denoted by its execute - bit set. For those files which - * are to be executed, run_file() is called, which forks off a - * child which takes care of I/O redirection, forks off another - * child for execution and yet another one, optionally, for sending - * mail. Files which already have run are removed during the - * next invocation. +/* Browse through ATJOB_DIR, checking all the jobfiles wether they should + * be executed and or deleted. The queue is coded into the first byte of + * the job filename, the date (in minutes since Eon) as a hex number in the + * following eight bytes, followed by a dot and a serial number. A file + * which has not been executed yet is denoted by its execute - bit set. + * For those files which are to be executed, run_file() is called, which forks + * off a child which takes care of I/O redirection, forks off another child + * for execution and yet another one, optionally, for sending mail. + * Files which already have run are removed during the next invocation. + */ + DIR *spool; + struct dirent *dirent; + struct stat buf; + unsigned long ctm; + unsigned long jobno; + char queue; + time_t now, run_time; + char batch_name[] = "Z2345678901234"; + uid_t batch_uid; + gid_t batch_gid; + int c; + int run_batch; + double load_avg = LOADAVG_MX, la; + +/* We don't need root privileges all the time; running under uid and gid daemon + * is fine. + */ + + RELINQUISH_PRIVS_ROOT(DAEMON_UID, DAEMON_GID) + + openlog("atrun", LOG_PID, LOG_CRON); + + opterr = 0; + while((c=getopt(argc, argv, "dl:"))!= -1) + { + switch (c) + { + case 'l': + if (sscanf(optarg, "%lf", &load_avg) != 1) + perr("garbled option -l"); + if (load_avg <= 0.) + load_avg = LOADAVG_MX; + break; + + case 'd': + debug ++; + break; + + case '?': + default: + usage(); + } + } + + if (chdir(ATJOB_DIR) != 0) + perr("cannot change to " ATJOB_DIR); + + /* Main loop. Open spool directory for reading and look over all the + * files in there. If the filename indicates that the job should be run + * and the x bit is set, fork off a child which sets its user and group + * id to that of the files and exec a /bin/sh which executes the shell + * script. Unlink older files if they should no longer be run. For + * deletion, their r bit has to be turned on. + * + * Also, pick the oldest batch job to run, at most one per invocation of + * atrun. + */ + if ((spool = opendir(".")) == NULL) + perr("cannot read " ATJOB_DIR); + + now = time(NULL); + run_batch = 0; + batch_uid = (uid_t) -1; + batch_gid = (gid_t) -1; + + while ((dirent = readdir(spool)) != NULL) { + if (stat(dirent->d_name,&buf) != 0) + perr("cannot stat in " ATJOB_DIR); + + /* We don't want directories */ - DIR *spool; - struct dirent *dirent; - struct stat buf; - int older; - unsigned long ctm; - char queue; - - /* - * We don't need root privileges all the time; running under uid - * and gid daemon is fine. + if (!S_ISREG(buf.st_mode)) + continue; + + if (sscanf(dirent->d_name,"%c%5lx%8lx",&queue,&jobno,&ctm) != 3) + continue; + + run_time = (time_t) ctm*60; + + if ((S_IXUSR & buf.st_mode) && (run_time <=now)) { + if (isupper(queue) && (strcmp(batch_name,dirent->d_name) > 0)) { + run_batch = 1; + strncpy(batch_name, dirent->d_name, sizeof(batch_name)); + batch_uid = buf.st_uid; + batch_gid = buf.st_gid; + } + + /* The file is executable and old enough */ - - RELINQUISH_PRIVS_ROOT(0) /* it's setuid root */ - openlog("atrun", LOG_PID, LOG_CRON); - - namep = argv[0]; - if (chdir(_PATH_ATJOBS) != 0) - perr("Cannot change to " _PATH_ATJOBS); - - /* - * Main loop. Open spool directory for reading and look over all - * the files in there. If the filename indicates that the job - * should be run and the x bit is set, fork off a child which sets - * its user and group id to that of the files and exec a /bin/sh - * which executes the shell script. Unlink older files if they - * should no longer be run. For deletion, their r bit has to be - * turned on. + if (islower(queue)) + run_file(dirent->d_name, buf.st_uid, buf.st_gid); + } + /* Delete older files */ - if ((spool = opendir(".")) == NULL) - perr("Cannot read " _PATH_ATJOBS); - - while ((dirent = readdir(spool)) != NULL) { - double la; - - if (stat(dirent->d_name, &buf) != 0) - perr("Cannot stat in " _PATH_ATJOBS); - - /* We don't want directories */ - if (!S_ISREG(buf.st_mode)) - continue; - - if (sscanf(dirent->d_name, "%c%8lx", &queue, &ctm) != 2) - continue; - - if ((queue == 'b') && ((getloadavg(&la, 1) != 1) || - (la > ATRUN_MAXLOAD))) - continue; - - older = (time_t) ctm *60 <= time(NULL); - - /* The file is executable and old enough */ - if (older && (S_IXUSR & buf.st_mode)) { - /* - * Now we know we want to run the file, we can turn - * off the execute bit - */ - - PRIV_START - - if (chmod(dirent->d_name, S_IRUSR) != 0) - perr("Cannot change file permissions"); + if ((run_time < now) && !(S_IXUSR & buf.st_mode) && (S_IRUSR & buf.st_mode)) + unlink(dirent->d_name); + } + /* run the single batch file, if any + */ + if (run_batch && (getloadavg(&la, 1) == 1) && la < load_avg) + run_file(batch_name, batch_uid, batch_gid); + + closelog(); + exit(EXIT_SUCCESS); +} - PRIV_END +static void +usage(void) +{ + if (debug) + fprintf(stderr, "usage: atrun [-l load_avg] [-d]\n"); + else + syslog(LOG_ERR, "usage: atrun [-l load_avg] [-d]"); - run_file(dirent->d_name, buf.st_uid, buf.st_gid); - } - /* Delete older files */ - if (older && !(S_IXUSR & buf.st_mode) && - (S_IRUSR & buf.st_mode)) - unlink(dirent->d_name); - } - closelog(); - exit(EXIT_SUCCESS); + exit(EXIT_FAILURE); } diff --git a/atrun.tproj/atrun.h b/atrun.tproj/atrun.h index ef281f2..af24723 100644 --- a/atrun.tproj/atrun.h +++ b/atrun.tproj/atrun.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/atrun.tproj/com.apple.atrun.plist b/atrun.tproj/com.apple.atrun.plist new file mode 100644 index 0000000..34867ea --- /dev/null +++ b/atrun.tproj/com.apple.atrun.plist @@ -0,0 +1,16 @@ + + + + + Label + com.apple.atrun + ProgramArguments + + /usr/libexec/atrun + + StartInterval + 300 + Disabled + + + diff --git a/audit.tproj/Makefile b/audit.tproj/Makefile new file mode 100644 index 0000000..3ad050e --- /dev/null +++ b/audit.tproj/Makefile @@ -0,0 +1,50 @@ +# +# Generated by the Apple 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 = audit + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = audit.c + +OTHERSRCS = Makefile.preamble Makefile Makefile.postamble\ + auditd_control.defs audit.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/sbin +WINDOWS_INSTALLDIR = /Library/Executables +PDO_UNIX_INSTALLDIR = /bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + +HEADER_PATHS = -I../auditd.tproj + + +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 = $(JDKBINDIR)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/audit.tproj/Makefile.postamble b/audit.tproj/Makefile.postamble new file mode 100644 index 0000000..f093dff --- /dev/null +++ b/audit.tproj/Makefile.postamble @@ -0,0 +1,86 @@ +############################################################################### +# Makefile.postamble +# Copyright 2004, Apple Computer, Inc. +# +# Use this makefile, which is imported after all other makefiles, to +# override attributes for a project's Makefile environment. This allows you +# to take advantage of the environment set up by the other Makefiles. +# You can also define custom rules at the end of this file. +# +############################################################################### +# +# These variables are exported by the standard makefiles and can be +# used in any customizations you make. They are *outputs* of +# the Makefiles and should be used, not set. +# +# PRODUCTS: products to install. All of these products will be placed in +# the directory $(DSTROOT)$(INSTALLDIR) +# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. +# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. +# OFILE_DIR: Directory into which .o object files are generated. +# DERIVED_SRC_DIR: Directory used for all other derived files +# +# ALL_CFLAGS: flags to pass when compiling .c files +# ALL_MFLAGS: flags to pass when compiling .m files +# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files +# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files +# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files +# ALL_LDFLAGS: flags to pass when linking object files +# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files +# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files +# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files +# ALL_YFLAGS: flags to pass when processing .y (yacc) files +# ALL_LFLAGS: flags to pass when processing .l (lex) files +# +# NAME: name of application, bundle, subproject, palette, etc. +# LANGUAGES: langages in which the project is written (default "English") +# English_RESOURCES: localized resources (e.g. nib's, images) of project +# GLOBAL_RESOURCES: non-localized resources of project +# +# SRCROOT: base directory in which to place the new source files +# SRCPATH: relative path from SRCROOT to present subdirectory +# +# INSTALLDIR: Directory the product will be installed into by 'install' target +# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget +# to prefix this with DSTROOT when you use it. +# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget +# to prefix this with DSTROOT when you use it. +# +# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) +# +############################################################################### + +# Some compiler flags can be overridden here for certain build situations. +# +# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) +# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults +# to -g) +# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) +# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults +# to -O) +# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults +# to -pg -DPROFILE) +# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to +# the include path (defaults to -I.) +# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags +# passed to ld/libtool (defaults to nothing) + + +# Library and Framework projects only: +# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked +# against the framework will run against the correct version even if +# the current version of the framework changes. You may override this +# to "" as an alternative to using the DYLD_LIBRARY_PATH during your +# development cycle, but be sure to restore it before installing. +MIGFLAGS = +MIG = $(NEXT_ROOT)/usr/bin/mig + +auditd_control_user.c auditd_control.h: auditd_control.defs + cp $(SRCROOT)/auditd.tproj/auditd_control.defs $(SYM_DIR); + cd $(SYM_DIR) && \ + $(MIG) $(MIGFLAGS) -user auditd_control_user.c -header auditd_control.h \ + -server /dev/null -sheader /dev/null auditd_control.defs + + install-man-page: + install -d $(DSTROOT)/usr/share/man/man1 + install -c -m 444 audit.1 $(DSTROOT)/usr/share/man/man1/audit.1 diff --git a/audit.tproj/Makefile.preamble b/audit.tproj/Makefile.preamble new file mode 100644 index 0000000..e196000 --- /dev/null +++ b/audit.tproj/Makefile.preamble @@ -0,0 +1,19 @@ +############################################################################### +# Makefile.preamble +# Copyright 2004, Apple Computer, Inc. +# +# Use this makefile for configuring the standard application makefiles +# associated with ProjectBuilder. It is included before the main makefile. +# In Makefile.preamble you set attributes for a project, so they are available +# to the project's makefiles. In contrast, you typically write additional rules or +# override built-in behavior in the Makefile.postamble. +# +# Each directory in a project tree (main project plus subprojects) should +# have its own Makefile.preamble and Makefile.postamble. +############################################################################### +# +OTHER_GENERATED_OFILES = $(VERS_OFILE) +BEFORE_BUILD = auditd_control.h auditd_control_user.c +OTHER_OFILES = auditd_control_user.o +AFTER_INSTALL += install-man-page + diff --git a/audit.tproj/PB.project b/audit.tproj/PB.project new file mode 100644 index 0000000..e0c75af --- /dev/null +++ b/audit.tproj/PB.project @@ -0,0 +1,32 @@ +{ + "DYNAMIC_CODE_GEN" = YES; + FILESTABLE = { + FRAMEWORKS = (); + HEADERSEARCH = ("../auditd.tproj"); + "OTHER_LINKED" = ("audit.c"); + "OTHER_SOURCES" = ( + "Makefile.preamble", + Makefile, + "Makefile.postamble", + "auditd_control.defs", + "audit.1" + ); + }; + LANGUAGE = English; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + "NEXTSTEP_BUILDTOOL" = "/usr/bin/gnumake"; + "NEXTSTEP_INSTALLDIR" = "/usr/sbin"; + "NEXTSTEP_JAVA_COMPILER" = "/usr/bin/javac"; + "NEXTSTEP_OBJCPLUS_COMPILER" = "/usr/bin/cc"; + "PDO_UNIX_BUILDTOOL" = "$NEXT_ROOT/Developer/bin/make"; + "PDO_UNIX_INSTALLDIR" = "/bin"; + "PDO_UNIX_JAVA_COMPILER" = "$(JDKBINDIR)/javac"; + "PDO_UNIX_OBJCPLUS_COMPILER" = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = audit; + PROJECTTYPE = Tool; + PROJECTVERSION = "2.8"; + "WINDOWS_BUILDTOOL" = "$NEXT_ROOT/Developer/Executables/make"; + "WINDOWS_INSTALLDIR" = "/Library/Executables"; + "WINDOWS_JAVA_COMPILER" = "$(JDKBINDIR)/javac.exe"; + "WINDOWS_OBJCPLUS_COMPILER" = "$(DEVDIR)/gcc"; +} diff --git a/audit.tproj/audit.1 b/audit.tproj/audit.1 new file mode 100644 index 0000000..3b800a8 --- /dev/null +++ b/audit.tproj/audit.1 @@ -0,0 +1,43 @@ +.\" Copyright (c) 2004, Apple Computer, Inc. All rights reserved. +.\" +.Dd Jan 24, 2004 +.Dt AUDIT 1 +.Os "Mac OS X" +.Sh NAME +.Nm audit +.Nd audit management utility +.Sh SYNOPSIS +.Nm audit +.Op Fl nst +.Op Ar file +.Sh DESCRIPTION +The +.Nm +utility controls the state of auditing system. The optional +.Ar file +operand specifies the location of the audit control input file (default +/etc/security/audit_control). +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl n +Forces the audit system to close the existing audit log file and rotate to +a new log file in a location specified in the audit control file. +.It Fl s +Specifies that the audit system should [re]synchronize its +configuration from the audit control file. A new log file will be +created. +.It Fl t +Specifies that the audit system should terminate. Log files are closed +and renamed to indicate the time of the shutdown. +.El +.Sh NOTES +The auditd(8) daemon must already be running. +.Sh FILES +.Bl -tag -width "/etc/security/audit_control" -compact +.It Pa /etc/security/audit_control +Default audit policy file used to configure the auditing system. +.El +.Sh SEE ALSO +.Xr auditd 8 +.Xr audit_control 5 diff --git a/audit.tproj/audit.c b/audit.tproj/audit.c new file mode 100644 index 0000000..54b251f --- /dev/null +++ b/audit.tproj/audit.c @@ -0,0 +1,91 @@ +/* + * Program to trigger the audit daemon with a message that is either: + * - Open a new audit log file + * - Read the audit control file and take action on it + * - Close the audit log file and exit + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +mach_port_t serverPort; +mach_port_t bootstrapPort; + +void init(); +void process(int flags); + +/* + * Main routine to process command line options. + */ +int main(int argc, char **argv) +{ + char ch; + int flags = 0; + while ((ch = getopt(argc, argv, "nst")) != -1) { + switch(ch) { + + case 'n': + flags = OPEN_NEW; + break; + + case 's': + flags = READ_FILE; + break; + + case 't': + flags = CLOSE_AND_DIE; + break; + + case '?': + default: + (void)fprintf(stderr, + "usage: audit -n | -s | -t \n"); + exit(1); + } + } + init(); + process(flags); + return 0; +} + +/* + * Program initialization: + * Look up the server port and store it away. + */ +void init() +{ + if(host_get_audit_control_port(mach_host_self(), &serverPort) != KERN_SUCCESS) { + fprintf(stderr, "Cannot get auditd_control\n"); + exit(1); + } + + printf("Server port is %d\n", serverPort); +} + +/* + * Do all the real work. + * Send a message to the audit daemon and check the return code. + */ +void process(int flags) +{ + kern_return_t retcode; + retcode = auditd_control(serverPort, flags); + if(retcode != KERN_SUCCESS) { + mach_error("error doing IPC: ", retcode); + exit(1); + } + printf("Client call successful\n"); +} diff --git a/audit.tproj/auditd_control.defs b/audit.tproj/auditd_control.defs new file mode 100644 index 0000000..a4267ee --- /dev/null +++ b/audit.tproj/auditd_control.defs @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2004 Apple Computer, Inc. All Rights + * Reserved. This 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@ + */ + +#include "../auditd.tproj/auditd_control.defs" diff --git a/auditd.tproj/Makefile b/auditd.tproj/Makefile new file mode 100644 index 0000000..edb12d0 --- /dev/null +++ b/auditd.tproj/Makefile @@ -0,0 +1,52 @@ +# +# Generated by the Apple 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 = auditd + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +HFILES = auditd.h + +CFILES = audit_warn.c auditd.c + +OTHERSRCS = Makefile.preamble Makefile Makefile.postamble\ + audit_triggers.defs auditd_control.defs auditd.8 rc.audit + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/sbin +WINDOWS_INSTALLDIR = /Library/Executables +PDO_UNIX_INSTALLDIR = /usr/sbin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + +NEXTSTEP_PB_LDFLAGS = -lbsm + + +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 = $(JDKBINDIR)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/auditd.tproj/Makefile.postamble b/auditd.tproj/Makefile.postamble new file mode 100644 index 0000000..3b19087 --- /dev/null +++ b/auditd.tproj/Makefile.postamble @@ -0,0 +1,121 @@ +############################################################################### +# Makefile.postamble +# Copyright 1997, Apple Computer, Inc. +# +# Use this makefile, which is imported after all other makefiles, to +# override attributes for a project's Makefile environment. This allows you +# to take advantage of the environment set up by the other Makefiles. +# You can also define custom rules at the end of this file. +# +############################################################################### +# +# These variables are exported by the standard makefiles and can be +# used in any customizations you make. They are *outputs* of +# the Makefiles and should be used, not set. +# +# PRODUCTS: products to install. All of these products will be placed in +# the directory $(DSTROOT)$(INSTALLDIR) +# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. +# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. +# OFILE_DIR: Directory into which .o object files are generated. +# DERIVED_SRC_DIR: Directory used for all other derived files +# +# ALL_CFLAGS: flags to pass when compiling .c files +# ALL_MFLAGS: flags to pass when compiling .m files +# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files +# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files +# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files +# ALL_LDFLAGS: flags to pass when linking object files +# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files +# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files +# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files +# ALL_YFLAGS: flags to pass when processing .y (yacc) files +# ALL_LFLAGS: flags to pass when processing .l (lex) files +# +# NAME: name of application, bundle, subproject, palette, etc. +# LANGUAGES: langages in which the project is written (default "English") +# English_RESOURCES: localized resources (e.g. nib's, images) of project +# GLOBAL_RESOURCES: non-localized resources of project +# +# SRCROOT: base directory in which to place the new source files +# SRCPATH: relative path from SRCROOT to present subdirectory +# +# INSTALLDIR: Directory the product will be installed into by 'install' target +# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget +# to prefix this with DSTROOT when you use it. +# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget +# to prefix this with DSTROOT when you use it. +# +# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) +# +############################################################################### + +# Some compiler flags can be overridden here for certain build situations. +# +# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) +# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults +# to -g) +# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) +# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults +# to -O) +# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults +# to -pg -DPROFILE) +# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to +# the include path (defaults to -I.) +# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags +# passed to ld/libtool (defaults to nothing) + + +# Library and Framework projects only: +# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked +# against the framework will run against the correct version even if +# the current version of the framework changes. You may override this +# to "" as an alternative to using the DYLD_LIBRARY_PATH during your +# development cycle, but be sure to restore it before installing. + + +# Ownership and permissions of files installed by 'install' target + +#INSTALL_AS_USER = root + # User/group ownership +#INSTALL_AS_GROUP = wheel + # (probably want to set both of these) +#INSTALL_PERMISSIONS = + # If set, 'install' chmod's executable to this + + +# Options to strip. Note: -S strips debugging symbols (executables can be stripped +# down further with -x or, if they load no bundles, with no options at all). + +#STRIPFLAGS = -S + + +######################################################################### +# Put rules to extend the behavior of the standard Makefiles here. Include them in +# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. +# +# You should avoid redefining things like "install" or "app", as they are +# owned by the top-level Makefile API and no context has been set up for where +# derived files should go. +# +ETCDIR = $(DSTROOT)/private/etc +MIGFLAGS = -no-cpp-precomp -R -untyped -DNO_DIRECT_RPC +MIG = $(NEXT_ROOT)/usr/bin/mig + +auditd_control_server.c : auditd_control.defs + cp $(SRCROOT)/auditd.tproj/auditd_control.defs $(SYM_DIR); + cd $(SYM_DIR) && \ + $(MIG) $(MIGFLAGS) -user /dev/null -server auditd_control_server.c -sheader auditd_control_server.h auditd_control.defs + +audit_triggers_server.c: audit_triggers.defs + cp $(SRCROOT)/auditd.tproj/audit_triggers.defs $(SYM_DIR); + cd $(SYM_DIR) && \ + $(MIG) $(MIGFLAGS) -user /dev/null -server audit_triggers_server.c -sheader audit_triggers_server.h audit_triggers.defs + +install-startup: + install -d $(ETCDIR)/security + install -c -m 400 rc.audit $(ETCDIR)/security/rc.audit + +install-man-page: + install -d $(DSTROOT)/usr/share/man/man8 + install -c -m 444 auditd.8 $(DSTROOT)/usr/share/man/man8/auditd.8 diff --git a/auditd.tproj/Makefile.preamble b/auditd.tproj/Makefile.preamble new file mode 100644 index 0000000..162794a --- /dev/null +++ b/auditd.tproj/Makefile.preamble @@ -0,0 +1,18 @@ +############################################################################### +# Makefile.preamble +# Copyright 2004, Apple Computer, Inc. +# +# Use this makefile for configuring the standard application makefiles +# associated with ProjectBuilder. It is included before the main makefile. +# In Makefile.preamble you set attributes for a project, so they are available +# to the project's makefiles. In contrast, you typically write additional rules or +# override built-in behavior in the Makefile.postamble. +# +# Each directory in a project tree (main project plus subprojects) should +# have its own Makefile.preamble and Makefile.postamble. +############################################################################### +OTHER_GENERATED_OFILES = $(VERS_OFILE) +BEFORE_BUILD = auditd_control_server.c auditd_control_server.h \ + audit_triggers_server.c audit_triggers_server.h +OTHER_OFILES = auditd_control_server.o audit_triggers_server.o +AFTER_INSTALL += install-startup install-man-page diff --git a/auditd.tproj/PB.project b/auditd.tproj/PB.project new file mode 100644 index 0000000..f3df43c --- /dev/null +++ b/auditd.tproj/PB.project @@ -0,0 +1,38 @@ +{ + "DYNAMIC_CODE_GEN" = YES; + FILESTABLE = { + FRAMEWORKS = (); + "H_FILES" = ("auditd.h"); + "OTHER_LINKED" = ("audit_warn.c", "auditd.c"); + "OTHER_SOURCES" = ( + "Makefile.preamble", + Makefile, + "Makefile.postamble", + "audit_triggers.defs", + "auditd_control.defs", + "auditd.8", + "rc.audit" + ); + "PRECOMPILED_HEADERS" = (); + "PROJECT_HEADERS" = (); + "PUBLIC_HEADERS" = (); + }; + LANGUAGE = English; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + "NEXTSTEP_BUILDTOOL" = "/usr/bin/gnumake"; + "NEXTSTEP_INSTALLDIR" = "/usr/sbin"; + "NEXTSTEP_JAVA_COMPILER" = "/usr/bin/javac"; + "NEXTSTEP_LINKEROPTIONS" = "-lbsm"; + "NEXTSTEP_OBJCPLUS_COMPILER" = "/usr/bin/cc"; + "PDO_UNIX_BUILDTOOL" = "$NEXT_ROOT/Developer/bin/make"; + "PDO_UNIX_INSTALLDIR" = "/bin"; + "PDO_UNIX_JAVA_COMPILER" = "$(JDKBINDIR)/javac"; + "PDO_UNIX_OBJCPLUS_COMPILER" = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = auditd; + PROJECTTYPE = Tool; + PROJECTVERSION = "2.8"; + "WINDOWS_BUILDTOOL" = "$NEXT_ROOT/Developer/Executables/make"; + "WINDOWS_INSTALLDIR" = "/Library/Executables"; + "WINDOWS_JAVA_COMPILER" = "$(JDKBINDIR)/javac.exe"; + "WINDOWS_OBJCPLUS_COMPILER" = "$(DEVDIR)/gcc"; +} diff --git a/auditd.tproj/audit_triggers.defs b/auditd.tproj/audit_triggers.defs new file mode 100644 index 0000000..9fe2c35 --- /dev/null +++ b/auditd.tproj/audit_triggers.defs @@ -0,0 +1 @@ +#include diff --git a/auditd.tproj/audit_warn.c b/auditd.tproj/audit_warn.c new file mode 100644 index 0000000..22657a1 --- /dev/null +++ b/auditd.tproj/audit_warn.c @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2004 Apple Computer, Inc. All Rights + * Reserved. This 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@ + */ + +#include +#include +#include + +#include + +/* Write to the audit log. */ +static int auditwarnlog(char *args[]) +{ + char *loc_args[9]; + int i; + pid_t pid; + loc_args[0] = AUDITWARN_SCRIPT; + for (i = 0; args[i] != NULL && i < 8; i++) { + loc_args[i+1] = args[i]; + } + loc_args[i+1] = NULL; + + pid = fork(); + if (pid == 0) { + return execv(AUDITWARN_SCRIPT, loc_args); + /* not reached */ + exit(1); + } else if (pid == -1) { + return -1; + } else { + return 0; + } +} + +/* + * Indicates that the hard limit for all filesystems + * has been exceeded count times + */ +int audit_warn_allhard(int count) +{ + char intstr[12]; + char *args[3]; + + snprintf(intstr, 12, "%d", count); + + args[0] = HARDLIM_ALL_WARN; + args[1] = intstr; + args[2] = NULL; + + return auditwarnlog(args); +} + +/* + * Indicates that the soft limit for all filesystems + * has been exceeded + */ +int audit_warn_allsoft() +{ + char *args[2]; + + args[0] = SOFTLIM_ALL_WARN; + args[1] = NULL; + + return auditwarnlog(args); +} + +/* + * Indicates that someone other than the audit daemon + * turned off auditing + * XXX Its not clear at this point how this function will + * XXX be invoked + */ +int audit_warn_auditoff() +{ + char *args[2]; + + args[0] = AUDITOFF_WARN; + args[1] = NULL; + + return auditwarnlog(args); +} + +/* + * Indicates that the audit deammn is already running + */ +int audit_warn_ebusy() +{ + char *args[2]; + + args[0] = EBUSY_WARN; + args[1] = NULL; + + return auditwarnlog(args); + +} + +/* + * Indicates that there is a problem getting the directory + * from audit_control + * + * XXX Note that we take the filename instead of a count + * XXX as the argument here (different from BSM) + */ +int audit_warn_getacdir(char *filename) +{ + char *args[3]; + + args[0] = GETACDIR_WARN; + args[1] = filename; + args[2] = NULL; + + return auditwarnlog(args); +} + + +/* + * Indicates that the hard limit for this file has been + * exceeded + */ +int audit_warn_hard(char *filename) +{ + char *args[3]; + + args[0] = HARDLIM_WARN; + args[1] = filename; + args[2] = NULL; + + return auditwarnlog(args); + +} + +/* + * Indicates that auditing could not be started + */ +int audit_warn_nostart() +{ + char *args[2]; + + args[0] = NOSTART_WARN; + args[1] = NULL; + + return auditwarnlog(args); +} + +/* + * Indicaes that an error occrred during the orderly shutdown + * of the audit daemon + */ +int audit_warn_postsigterm() +{ + char *args[2]; + + args[0] = POSTSIGTERM_WARN; + args[1] = NULL; + + return auditwarnlog(args); +} + +/* + * Indicates that the soft limit for this file has been + * exceeded + */ +int audit_warn_soft(char *filename) +{ + char *args[3]; + + args[0] = SOFTLIM_WARN; + args[1] = filename; + args[2] = NULL; + + return auditwarnlog(args); + +} + +/* + * Indicates that the temporary audit file already exists + * indicating a fatal error + */ +int audit_warn_tmpfile() +{ + char *args[2]; + + args[0] = TMPFILE_WARN; + args[1] = NULL; + + return auditwarnlog(args); +} diff --git a/auditd.tproj/auditd.8 b/auditd.tproj/auditd.8 new file mode 100644 index 0000000..c5a9b15 --- /dev/null +++ b/auditd.tproj/auditd.8 @@ -0,0 +1,48 @@ +.\" Copyright (c) 2004, Apple Computer, Inc. All rights reserved. +.\" +.Dd Jan 24, 2004 +.Dt AUDITD 8 +.Os "Mac OS X" +.Sh NAME +.Nm auditd +.Nd audit log management daemon +.Sh SYNOPSIS +.Nm auditd +.Op Fl dhs +.Sh DESCRIPTION +The +.Nm +daemon responds to requests from the audit(1) utility and notifications +from the kernel. It manages the resulting audit log files and specified +log file locations. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl d +Starts the daemon in debug mode - it will not daemonize. +.It Fl h +Specifies that if auditing cannot be performed as specified, the system should +halt (panic). Normally, the system will attempt to proceed - although individual +processes may be stopped (see the -s option). +.It Fl s +Specifies that individual processes should stop rather than perform operations +that may cause audit records to be lost due to log file full conditions +.El +.Sh NOTE +.Pp +To assure uninterrupted audit support, the +.Nm auditd +daemon should not be started and stopped manually. Instead, the audit(1) command +should be used to inform the daemon to change state/configuration after altering +the audit_control file. +.Pp +Sending a SIGHUP to a running +.Nm auditd +daemon will force it to exit. +.Sh FILES +.Bl -tag -width "/var/audit" -compact +.It Pa /var/audit +Default directory for storing audit log files. +.El +.Sh SEE ALSO +.Xr audit 1 diff --git a/auditd.tproj/auditd.c b/auditd.tproj/auditd.c new file mode 100644 index 0000000..459bee3 --- /dev/null +++ b/auditd.tproj/auditd.c @@ -0,0 +1,791 @@ +/* + * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2004 Apple Computer, Inc. All Rights + * Reserved. This 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@ + */ + +#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 "auditd_control_server.h" +#include "audit_triggers_server.h" +#define NA_EVENT_STR_SIZE 25 + +static int ret, minval; +static char *lastfile = NULL; + +static int allhardcount = 0; + +mach_port_t bp = MACH_PORT_NULL; +mach_port_t control_port = MACH_PORT_NULL; +mach_port_t signal_port = MACH_PORT_NULL; +mach_port_t port_set = MACH_PORT_NULL; + +#ifndef __BSM_INTERNAL_NOTIFY_KEY +#define __BSM_INTERNAL_NOTIFY_KEY "com.apple.audit.change" +#endif /* __BSM_INTERNAL_NOTIFY_KEY */ + +TAILQ_HEAD(, dir_ent) dir_q; + + +/* Error starting auditd */ +void fail_exit() +{ + audit_warn_nostart(); + exit(1); +} + +/* + * Free our local list of directory names + */ +void free_dir_q() +{ + struct dir_ent *dirent; + + while ((dirent = TAILQ_FIRST(&dir_q))) { + TAILQ_REMOVE(&dir_q, dirent, dirs); + free(dirent->dirname); + free(dirent); + } +} + +/* + * generate the timestamp string + */ +int getTSstr(char *buf, int len) +{ + struct timeval ts; + struct timezone tzp; + time_t tt; + + if(gettimeofday(&ts, &tzp) != 0) { + return -1; + } + tt = (time_t)ts.tv_sec; + if(!strftime(buf, len, "%Y%m%d%H%M%S", gmtime(&tt))) { + return -1; + } + + return 0; +} + +/* + * Concat the directory name to the given file name + * XXX We should affix the hostname also + */ +char *affixdir(char *name, struct dir_ent *dirent) +{ + char *fn; + char *curdir; + const char *sep = "/"; + + curdir = dirent->dirname; + syslog(LOG_INFO, "dir = %s\n", dirent->dirname); + + fn = (char *) malloc (strlen(curdir) + strlen(sep) + + (2 * POSTFIX_LEN) + 1); + if(fn == NULL) { + return NULL; + } + strcpy(fn, curdir); + strcat(fn, sep); + strcat(fn, name); + + return fn; +} + +/* Close the previous audit trail file */ +int close_lastfile(char *TS) +{ + char *ptr; + char *oldname; + + if(lastfile != NULL) { + oldname = (char *)malloc(strlen(lastfile) + 1); + if(oldname == NULL) { + return -1; + } + strcpy(oldname, lastfile); + + /* rename the last file -- append timestamp */ + + if((ptr = strstr(lastfile, NOT_TERMINATED)) != NULL) { + *ptr = '.'; + strcpy(ptr+1, TS); + if(rename(oldname, lastfile) != 0) { + syslog(LOG_ERR, "Could not rename %s to %s \n", + oldname, lastfile); + } + else { + syslog(LOG_INFO, "renamed %s to %s \n", + oldname, lastfile); + } + } + + free(lastfile); + free(oldname); + + lastfile = NULL; + } + + return 0; +} + +/* + * Create the new file name, swap with existing audit file + */ +int swap_audit_file() +{ + char timestr[2 * POSTFIX_LEN]; + char *fn; + char TS[POSTFIX_LEN]; + struct dir_ent *dirent; + + if(getTSstr(TS, POSTFIX_LEN) != 0) { + return -1; + } + + strcpy(timestr, TS); + strcat(timestr, NOT_TERMINATED); + + /* try until we succeed */ + while((dirent = TAILQ_FIRST(&dir_q))) { + if((fn = affixdir(timestr, dirent)) == NULL) { + return -1; + } + + syslog(LOG_INFO, "New audit file is %s\n", fn); + if (open(fn, O_RDONLY | O_CREAT, S_IRUSR | S_IRGRP) < 0) { + perror("File open"); + } + else if (auditctl(fn) != 0) { + syslog(LOG_ERR, "auditctl failed! : %s\n", + strerror(errno)); + } + else { + /* Success */ + close_lastfile(TS); + lastfile = fn; + return 0; + } + + /* Tell the administrator about lack of permissions for dirent */ + audit_warn_getacdir(dirent->dirname); + + /* Try again with a different directory */ + TAILQ_REMOVE(&dir_q, dirent, dirs); + free(dirent->dirname); + free(dirent); + } + return -1; +} + +/* + * Read the audit_control file contents + */ +int read_control_file() +{ + char cur_dir[MAX_DIR_SIZE]; + struct dir_ent *dirent; + au_qctrl_t qctrl; + + /* Clear old values */ + free_dir_q(); + endac(); // force a re-read of the file the next time + + /* Post that the audit config changed */ + notify_post(__BSM_INTERNAL_NOTIFY_KEY); + + /* Read the list of directories into a local linked list */ + /* XXX We should use the reentrant interfaces once they are available */ + while(getacdir(cur_dir, MAX_DIR_SIZE) >= 0) { + dirent = (struct dir_ent *) malloc (sizeof(struct dir_ent)); + if(dirent == NULL) { + return -1; + } + + dirent->softlim = 0; + dirent->dirname = (char *) malloc (MAX_DIR_SIZE); + if(dirent->dirname == NULL) { + free(dirent); + return -1; + } + + strcpy(dirent->dirname, cur_dir); + TAILQ_INSERT_TAIL(&dir_q, dirent, dirs); + } + + allhardcount = 0; + + if(swap_audit_file() == -1) { + syslog(LOG_ERR, "Could not swap audit file\n"); + /* + * XXX Faulty directory listing? - user should be given + * XXX an opportunity to change the audit_control file + * XXX switch to a reduced mode of auditing? + */ + return -1; + } + + /* + * XXX There are synchronization problems here + * XXX what should we do if a trigger for the earlier limit + * XXX is generated here? + */ + if(0 == (ret = getacmin(&minval))) { + + syslog(LOG_INFO, "min free = %d\n", minval); + + if (auditon(A_GETQCTRL, &qctrl, sizeof(qctrl)) != 0) { + syslog(LOG_ERR, + "could not get audit queue settings\n"); + return -1; + } + qctrl.aq_minfree = minval; + if (auditon(A_SETQCTRL, &qctrl, sizeof(qctrl)) != 0) { + syslog(LOG_ERR, + "could not set audit queue settings\n"); + return -1; + } + } + + return 0; +} + +/* + * Close all log files, control files, and tell the audit system. + */ +int close_all() +{ + int err_ret = 0; + char TS[POSTFIX_LEN]; + int aufd; + token_t *tok; + + /* Generate an audit record */ + if((aufd = au_open()) == -1) { + syslog(LOG_ERR, "Could not create audit shutdown event.\n"); + } else { + + if((tok = au_to_text("auditd::Audit shutdown")) != NULL) { + au_write(aufd, tok); + } + + if(au_close(aufd, 1, AUE_audit_shutdown) == -1) { + syslog(LOG_ERR, "Could not close audit shutdown event.\n"); + } + } + + /* flush contents */ + err_ret = auditctl(NULL); + if (err_ret != 0) { + syslog(LOG_ERR, "auditctl failed! : %s\n", + strerror(errno)); + err_ret = 1; + } + if(getTSstr(TS, POSTFIX_LEN) == 0) { + close_lastfile(TS); + } + if(lastfile != NULL) + free(lastfile); + + free_dir_q(); + if((remove(AUDITD_PIDFILE) == -1) || err_ret) { + syslog(LOG_ERR, "Could not unregister\n"); + audit_warn_postsigterm(); + return (1); + } + endac(); + syslog(LOG_INFO, "Finished.\n"); + return (0); +} + +/* + * When we get a signal, we are often not at a clean point. + * So, little can be done in the signal handler itself. Instead, + * we send a message to the main servicing loop to do proper + * handling from a non-signal-handler context. + */ +static void +relay_signal(int signal) +{ + mach_msg_empty_send_t msg; + + msg.header.msgh_id = signal; + msg.header.msgh_remote_port = signal_port; + msg.header.msgh_local_port = MACH_PORT_NULL; + msg.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND, 0); + mach_msg(&(msg.header), MACH_SEND_MSG|MACH_SEND_TIMEOUT, sizeof(msg), + 0, MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); +} + +/* registering the daemon */ +int register_daemon() +{ + FILE * pidfile; + int fd; + pid_t pid; + + /* Set up the signal hander */ + if (signal(SIGTERM, relay_signal) == SIG_ERR) { + fail_exit(); + } + if (signal(SIGCHLD, relay_signal) == SIG_ERR) { + fail_exit(); + } + + if ((pidfile = fopen(AUDITD_PIDFILE, "a")) == NULL) { + audit_warn_tmpfile(); + return -1; + } + + /* attempt to lock the pid file; if a lock is present, exit */ + fd = fileno(pidfile); + if(flock(fd, LOCK_EX | LOCK_NB) < 0) { + syslog(LOG_ERR, "PID file is locked (is another auditd running?).\n"); + audit_warn_ebusy(); + return -1; + } + + pid = getpid(); + ftruncate(fd, 0); + if(fprintf(pidfile, "%u\n", pid) < 0) { + /* should not start the daemon */ + fail_exit(); + } + + fflush(pidfile); + return 0; +} + +/* + * React to input from the audit tool + */ +kern_return_t auditd_control(auditd_port, flags) + mach_port_t auditd_port; + int flags; +{ + int err_ret = 0; + + switch(flags) { + + case OPEN_NEW : + /* create a new file and swap with the one being used in kernel */ + if(swap_audit_file() == -1) { + syslog(LOG_ERR, "Error swapping audit file\n"); + } + break; + + case READ_FILE : + if(read_control_file() == -1) { + syslog(LOG_ERR, "Error in audit control file\n"); + } + break; + + case CLOSE_AND_DIE : + err_ret = close_all(); + exit (err_ret); + break; + + default : + break; + } + + return KERN_SUCCESS; +} + +/* + * Suppress duplicate messages within a 30 second interval. + * This should be enough to time to rotate log files without + * thrashing from soft warnings generated before the log is + * actually rotated. + */ +#define DUPLICATE_INTERVAL 30 +/* + * Implementation of the audit_triggers() MIG routine. + */ +kern_return_t audit_triggers(audit_port, flags) + mach_port_t audit_port; + int flags; +{ + static int last_flags; + static time_t last_time; + struct dir_ent *dirent; + + /* + * Suppres duplicate messages from the kernel within the specified interval + */ + struct timeval ts; + struct timezone tzp; + time_t tt; + + if(gettimeofday(&ts, &tzp) == 0) { + tt = (time_t)ts.tv_sec; + if ((flags == last_flags) && (tt < (last_time + DUPLICATE_INTERVAL))) { + return KERN_SUCCESS; + } + last_flags = flags; + last_time = tt; + } + + syslog(LOG_INFO, + "audit_triggers() called within auditd with flags = %d\n", + flags); + /* + * XXX Message processing is done here + */ + dirent = TAILQ_FIRST(&dir_q); + if(flags == AUDIT_TRIGGER_LOW_SPACE) { + if(dirent && (dirent->softlim != 1)) { + TAILQ_REMOVE(&dir_q, dirent, dirs); + /* add this node to the end of the list */ + TAILQ_INSERT_TAIL(&dir_q, dirent, dirs); + audit_warn_soft(dirent->dirname); + dirent->softlim = 1; + + if (TAILQ_NEXT(TAILQ_FIRST(&dir_q), dirs) != NULL && swap_audit_file() == -1) { + syslog(LOG_ERR, "Error swapping audit file\n"); + } + + /* + * check if the next dir has already reached its + * soft limit + */ + dirent = TAILQ_FIRST(&dir_q); + if(dirent->softlim == 1) { + /* all dirs have reached their soft limit */ + audit_warn_allsoft(); + } + } + else { + /* + * Continue auditing to the current file + * Also generate an allsoft warning + * XXX do we want to do this ? + */ + audit_warn_allsoft(); + } + } + else if (flags == AUDIT_TRIGGER_FILE_FULL) { + + /* delete current dir, go on to next */ + TAILQ_REMOVE(&dir_q, dirent, dirs); + audit_warn_hard(dirent->dirname); + free(dirent->dirname); + free(dirent); + + if(swap_audit_file() == -1) { + syslog(LOG_ERR, "Error swapping audit file in response to AUDIT_TRIGGER_FILE_FULL message\n"); + + /* Nowhere to write to */ + audit_warn_allhard(++allhardcount); + } + } + return KERN_SUCCESS; +} + +/* + * Reap our children. + */ +static void +reap_children(void) +{ + pid_t child; + int wstatus; + + while ((child = waitpid(-1, &wstatus, WNOHANG)) > 0) { + if (wstatus) { + syslog(LOG_INFO, "warn process [pid=%d] %s %d.\n", child, + ((WIFEXITED(wstatus)) ? + "exited with non-zero status" : + "exited as a result of signal"), + ((WIFEXITED(wstatus)) ? + WEXITSTATUS(wstatus) : + WTERMSIG(wstatus))); + } + } +} + +/* + * Handle an RPC call + */ +boolean_t auditd_combined_server( + mach_msg_header_t *InHeadP, + mach_msg_header_t *OutHeadP) +{ + mach_port_t local_port = InHeadP->msgh_local_port; + + if (local_port == signal_port) { + int signo = InHeadP->msgh_id; + int ret; + + if (SIGTERM == signo) { + ret = close_all(); + exit (ret); + } else if (SIGCHLD == signo) { + reap_children(); + return TRUE; + } else { + syslog(LOG_INFO, "Recevied signal %d.\n", signo); + return TRUE; + } + } else if (local_port == control_port) { + boolean_t result; + + result = audit_triggers_server(InHeadP, OutHeadP); + if (!result) + result = auditd_control_server(InHeadP, OutHeadP); + return result; + } + syslog(LOG_INFO, "Recevied msg on bad port 0x%x.\n", local_port); + return FALSE; +} + +void wait_on_audit_trigger(port_set) + mach_port_t port_set; +{ + kern_return_t result; + result = mach_msg_server(auditd_combined_server, 4096, port_set, MACH_MSG_OPTION_NONE); + syslog(LOG_ERR, "abnormal exit\n"); +} + +/* + * Configure the audit controls in the kernel: the event to class mapping, + * kernel preselection mask, etc. + */ +int config_audit_controls(long flags) +{ + au_event_ent_t *ev; + au_evclass_map_t evc_map; + au_mask_t aumask; + int ctr = 0; + char naeventstr[NA_EVENT_STR_SIZE]; + + /* Process the audit event file, obtaining a class mapping for each + * event, and send that mapping into the kernel. + * XXX There's a risk here that the BSM library will return NULL + * for an event when it can't properly map it to a class. In that + * case, we will not process any events beyond the one that failed, + * but should. We need a way to get a count of the events. + */ + + setauevent(); + while((ev = getauevent()) != NULL) { + evc_map.ec_number = ev->ae_number; + evc_map.ec_class = ev->ae_class; + if (auditon(A_SETCLASS, &evc_map, sizeof(au_evclass_map_t)) != 0) { + syslog(LOG_ERR, + "Failed to register class mapping for event %s", + ev->ae_name); + } else { + ctr++; + } + free(ev->ae_name); + free(ev->ae_desc); + free(ev); + } + endauevent(); + if (ctr == 0) + syslog(LOG_ERR, "No events to class mappings registered."); + else + syslog(LOG_INFO, "Registered %d event to class mappings.", ctr); + + /* Get the non-attributable event string and set the kernel mask + * from that. + */ + if ((getacna(naeventstr, NA_EVENT_STR_SIZE) == 0) + && ( getauditflagsbin(naeventstr, &aumask) == 0)) { + + if (auditon(A_SETKMASK, &aumask, sizeof(au_mask_t))){ + syslog(LOG_ERR, + "Failed to register non-attributable event mask."); + } else { + syslog(LOG_INFO, "Registered non-attributable event mask."); + } + + } else { + syslog(LOG_ERR,"Failed to obtain non-attributable event mask."); + } + + /* + * Set the audit policy flags based on passed in parameter values. + */ + if (auditon(A_SETPOLICY, &flags, sizeof(flags))) { + syslog(LOG_ERR, + "Failed to set audit policy."); + } + + return 0; +} + +void setup(long flags) +{ + mach_msg_type_name_t poly; + int aufd; + token_t *tok; + + /* Allocate a port set */ + if (mach_port_allocate(mach_task_self(), + MACH_PORT_RIGHT_PORT_SET, + &port_set) != KERN_SUCCESS) { + syslog(LOG_ERR, "allocation of port set failed\n"); + fail_exit(); + } + + /* Allocate a signal reflection port */ + if (mach_port_allocate(mach_task_self(), + MACH_PORT_RIGHT_RECEIVE, + &signal_port) != KERN_SUCCESS || + mach_port_move_member(mach_task_self(), + signal_port, + port_set) != KERN_SUCCESS) { + syslog(LOG_ERR, "allocation of signal port failed\n"); + fail_exit(); + } + + /* Allocate a trigger port */ + if (mach_port_allocate(mach_task_self(), + MACH_PORT_RIGHT_RECEIVE, + &control_port) != KERN_SUCCESS || + mach_port_move_member(mach_task_self(), + control_port, + port_set) != KERN_SUCCESS) { + syslog(LOG_ERR, "allocation of trigger port failed\n"); + fail_exit(); + } + + /* create a send right on our trigger port */ + mach_port_extract_right(mach_task_self(), control_port, + MACH_MSG_TYPE_MAKE_SEND, &control_port, &poly); + + TAILQ_INIT(&dir_q); + + /* register the trigger port with the kernel */ + if(host_set_audit_control_port(mach_host_self(), control_port) != KERN_SUCCESS) { + syslog(LOG_ERR, "Cannot set Mach control port\n"); + fail_exit(); + } + else { + syslog(LOG_ERR, "Mach control port registered\n"); + } + + if(read_control_file() == -1) { + syslog(LOG_ERR, "Error reading control file\n"); + fail_exit(); + } + + /* Generate an audit record */ + if((aufd = au_open()) == -1) { + syslog(LOG_ERR, "Could not create audit startup event.\n"); + } else { + + if((tok = au_to_text("auditd::Audit startup")) != NULL) { + au_write(aufd, tok); + } + + if(au_close(aufd, 1, AUE_audit_startup) == -1) { + syslog(LOG_ERR, "Could not close audit startup event.\n"); + } + } + + if (config_audit_controls(flags) == 0) + syslog(LOG_INFO, "Initialization successful\n"); + else + syslog(LOG_INFO, "Initialization failed\n"); +} + + +int main(int argc, char **argv) +{ + char ch; + long flags = AUDIT_CNT; + int debug = 0; + + while ((ch = getopt(argc, argv, "dhs")) != -1) { + switch(ch) { + + /* debug option */ + case 'd': + debug = 1; + break; + + /* fail-stop option */ + case 's': + flags &= ~(AUDIT_CNT); + break; + + /* halt-stop option */ + case 'h': + flags |= AUDIT_AHLT; + break; + + case '?': + default: + (void)fprintf(stderr, + "usage: auditd [-h | -s]\n"); + exit(1); + } + } + + openlog("auditd", LOG_CONS | LOG_PID, LOG_DAEMON); + syslog(LOG_INFO, "starting...\n"); + + if (debug == 0 && daemon(0, 0) == -1) { + syslog(LOG_ERR, "Failed to daemonize\n"); + exit(1); + } + + if(register_daemon() == -1) { + syslog(LOG_ERR, "Could not register as daemon\n"); + exit(1); + } + + setup(flags); + wait_on_audit_trigger(port_set); + syslog(LOG_INFO, "exiting.\n"); + + exit(1); +} diff --git a/auditd.tproj/auditd.h b/auditd.tproj/auditd.h new file mode 100644 index 0000000..5866377 --- /dev/null +++ b/auditd.tproj/auditd.h @@ -0,0 +1,51 @@ +#ifndef _AUDITD_H_ +#define _AUDITD_H_ + +#include +#include +#include + +#define MAX_DIR_SIZE 255 +#define AUDITD_NAME "auditd" + +#define POSTFIX_LEN 16 +#define NOT_TERMINATED ".not_terminated" + +struct dir_ent { + char *dirname; + char softlim; + TAILQ_ENTRY(dir_ent) dirs; +}; + +/* audit utility flags */ +#define OPEN_NEW 0x1 +#define READ_FILE 0x2 +#define CLOSE_AND_DIE 0x4 + +#define HARDLIM_ALL_WARN "allhard" +#define SOFTLIM_ALL_WARN "allsoft" +#define AUDITOFF_WARN "aditoff" +#define EBUSY_WARN "ebusy" +#define GETACDIR_WARN "getacdir" +#define HARDLIM_WARN "hard" +#define NOSTART_WARN "nostart" +#define POSTSIGTERM_WARN "postsigterm" +#define SOFTLIM_WARN "soft" +#define TMPFILE_WARN "tmpfile" + +#define AUDITWARN_SCRIPT "/etc/security/audit_warn" +#define AUDITD_PIDFILE "/var/run/auditd.pid" + +int audit_warn_allhard(int count); +int audit_warn_allsoft(); +int audit_warn_auditoff(); +int audit_warn_ebusy(); +int audit_warn_getacdir(char *filename); +int audit_warn_hard(char *filename); +int audit_warn_nostart(); +int audit_warn_postsigterm(); +int audit_warn_soft(char *filename); +int audit_warn_tmpfile(); + +#endif /* !_AUDITD_H_ */ + diff --git a/auditd.tproj/auditd_control.defs b/auditd.tproj/auditd_control.defs new file mode 100644 index 0000000..1cf8346 --- /dev/null +++ b/auditd.tproj/auditd_control.defs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2004 Apple Computer, Inc. All Rights + * Reserved. This 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@ + */ + +/* + * Exported client calls to the auditd facility. + */ + +subsystem + KernelUser + auditd_control 456; + +#include +#include + +simpleroutine auditd_control( + auditd_port : mach_port_t; + in flags : int); + diff --git a/auditd.tproj/rc.audit b/auditd.tproj/rc.audit new file mode 100644 index 0000000..799dc3c --- /dev/null +++ b/auditd.tproj/rc.audit @@ -0,0 +1,25 @@ +## +# Startup script for Common Criteria Auditing function. +## +# Copyright 2004 Apple Computer, Inc. +## + +. /etc/rc.common + +## +# Start the audit daemon (if present) +## +if [ "${AUDIT:=-NO-}" == "-YES-" ]; then + if [ -f /usr/sbin/auditd ]; then + /usr/sbin/auditd + fi +elif [ "${AUDIT:=-NO-}" == "-FAILSTOP-" ]; then + if [ -f /usr/sbin/auditd ]; then + /usr/sbin/auditd -s + fi +elif [ "${AUDIT:=-NO-}" == "-FAILHALT-" ]; then + if [ -f /usr/sbin/auditd ]; then + /usr/sbin/auditd -h + fi + +fi diff --git a/chkpasswd.tproj/Makefile b/chkpasswd.tproj/Makefile index 1d74f6a..236688c 100644 --- a/chkpasswd.tproj/Makefile +++ b/chkpasswd.tproj/Makefile @@ -17,7 +17,7 @@ HFILES = stringops.h CFILES = ds_passwd.c nis_passwd.c file_passwd.c netinfo_passwd.c passwd.c\ stringops.c -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble +OTHERSRCS = Makefile.preamble Makefile Makefile.postamble chkpasswd.8 MAKEFILEDIR = /System/Developer/Makefiles/project diff --git a/chkpasswd.tproj/Makefile.postamble b/chkpasswd.tproj/Makefile.postamble index 1518c3b..d309dcb 100644 --- a/chkpasswd.tproj/Makefile.postamble +++ b/chkpasswd.tproj/Makefile.postamble @@ -4,3 +4,7 @@ INSTALL_PERMISSIONS = 4555 #CHFLAGS = /usr/bin/chflags #after_install:: # $(CHFLAGS) schg $(DSTROOT)$(INSTALLDIR)/$(NAME) + +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 chkpasswd.8 $(DSTROOT)/usr/share/man/man8 diff --git a/chkpasswd.tproj/chkpasswd.8 b/chkpasswd.tproj/chkpasswd.8 new file mode 100644 index 0000000..96b9840 --- /dev/null +++ b/chkpasswd.tproj/chkpasswd.8 @@ -0,0 +1,53 @@ +.Dd July 20, 2004 +.Dt CHKPASSWD 8 +.Os Darwin +.Sh NAME +.Nm chkpasswd +.Nd verifies user password against various systems +.Sh SYNOPSIS +.Nm +.Op Fl i Ar infosystem +.Op Fl l Ar location +.Op Fl c +.Op Ar name +.Sh DESCRIPTION +.Nm +verifies a supplied username and password against NetInfo, file, NIS, or OpenDirectory backends. +.Pp +The options are as follows: +.Bl -tag -width Ds +.Fl i Ar infosystem +Specify the system against which to check the password (default is OpenDirectory). Valid systems: +.Pp +.Bl -tag -width "opendirectory" -compact +.It Cm netinfo +NetInfo database +.It Cm file +File-based passwords +.It Cm nis +NIS/YP authentication +.It Cm opendirectory +OpenDirectory (Directory Services) authentication +.El +.Fl l Ar location +Specify a location; varies based on info system type: +.Pp +.Bl -tag -width "opendirectory" -compact +.It Cm netinfo +Domain name or server/tag. +.It Cm file +Filename (default: /etc/passwd). +.It Cm nis +NIS domainname. +.It Cm opendirectory +Directory node name. +.El +.Fl c +The supplied password is compared verbatim without first being crypted. +.Ar name +Username +.El +.Sh SEE ALSO +.Xr nicl 1 , +.Xr passwd 5 , +.Xr dscl 1 diff --git a/chkpasswd.tproj/ds_passwd.c b/chkpasswd.tproj/ds_passwd.c index c01cc0b..29c18d9 100644 --- a/chkpasswd.tproj/ds_passwd.c +++ b/chkpasswd.tproj/ds_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/chkpasswd.tproj/file_passwd.c b/chkpasswd.tproj/file_passwd.c index 083c111..51fc8c1 100644 --- a/chkpasswd.tproj/file_passwd.c +++ b/chkpasswd.tproj/file_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/chkpasswd.tproj/netinfo_passwd.c b/chkpasswd.tproj/netinfo_passwd.c index e04f723..762f00d 100644 --- a/chkpasswd.tproj/netinfo_passwd.c +++ b/chkpasswd.tproj/netinfo_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/chkpasswd.tproj/nis_passwd.c b/chkpasswd.tproj/nis_passwd.c index a1227eb..89b0411 100644 --- a/chkpasswd.tproj/nis_passwd.c +++ b/chkpasswd.tproj/nis_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/chkpasswd.tproj/passwd.c b/chkpasswd.tproj/passwd.c index 6c201cb..2115573 100644 --- a/chkpasswd.tproj/passwd.c +++ b/chkpasswd.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/chkpasswd.tproj/stringops.c b/chkpasswd.tproj/stringops.c index a874a6f..a3621e3 100644 --- a/chkpasswd.tproj/stringops.c +++ b/chkpasswd.tproj/stringops.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/chkpasswd.tproj/stringops.h b/chkpasswd.tproj/stringops.h index f90163e..e0a679e 100644 --- a/chkpasswd.tproj/stringops.h +++ b/chkpasswd.tproj/stringops.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/chpass.tproj/chpass.c b/chpass.tproj/chpass.c index 4deeaa9..be23cf9 100644 --- a/chpass.tproj/chpass.c +++ b/chpass.tproj/chpass.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@ */ @@ -110,6 +109,7 @@ main(argc, argv) char *arg; #ifdef DIRECTORY_SERVICE struct passwd pworig; + char *task_argv[3] = { NULL }; #endif /* DIRECTORY_SERVICE */ op = EDITENTRY; @@ -269,11 +269,55 @@ main(argc, argv) pw_error((char *)NULL, 0, 1); #ifdef DIRECTORY_SERVICE } - system("/usr/sbin/lookupd -flushcache"); + task_argv[0] = "/usr/sbin/lookupd"; + task_argv[1] = "-flushcache"; + task_argv[2] = NULL; + LaunchTaskWithPipes( task_argv[0], task_argv, NULL, NULL ); #endif /* DIRECTORY_SERVICE */ exit(0); } +#ifdef DIRECTORY_SERVICE +// read from 0 +int LaunchTaskWithPipes(const char *path, char *const argv[], int *outPipe0, int *outPipe1) +{ + int outputPipe[2]; + pid_t pid; + + if (outPipe0 != NULL) + pipe(outputPipe); + + pid = fork(); + if (pid == -1) + return -1; + + /* Handle the child */ + if (pid == 0) + { + int result = -1; + + if (outPipe0 != NULL) + dup2(outputPipe[1], fileno(stdout)); + + result = execv(path, argv); + if (result == -1) { + _exit(1); + } + + /* This should never be reached */ + _exit(1); + } + + /* Now the parent */ + if ( outPipe0 != NULL ) + *outPipe0 = outputPipe[0]; + if ( outPipe1 != NULL ) + *outPipe1 = outputPipe[1]; + + return 0; +} +#endif /* DIRECTORY_SERVICE */ + void baduser() { diff --git a/chpass.tproj/chpass.h b/chpass.tproj/chpass.h index 1a59e75..6aab2a2 100644 --- a/chpass.tproj/chpass.h +++ b/chpass.tproj/chpass.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@ */ @@ -68,6 +67,8 @@ struct display { char *officephone; char *homephone; }; + +int LaunchTaskWithPipes(const char *path, char *const argv[], int *outPipe0, int *outPipe1); #endif /* DIRECTORY_SERVICE */ struct passwd; diff --git a/chpass.tproj/directory_service.c b/chpass.tproj/directory_service.c index 0bffe30..b857cf5 100644 --- a/chpass.tproj/directory_service.c +++ b/chpass.tproj/directory_service.c @@ -3,6 +3,10 @@ #include "directory_service.h" #include "chpass.h" #include +#include + +#include +extern int errno; #define CONFIGNAMELEN 14 #define GLOBALCONFIGLEN 20 @@ -16,7 +20,7 @@ /*--------------------------------------------------------------------------- * Global variables *---------------------------------------------------------------------------*/ -const char *DSPath = NULL; +char *DSPath = NULL; const char MasterPasswd[] = "/etc/master.passwd"; /*--------------------------------------------------------------------------- @@ -34,7 +38,6 @@ static char NetinfoRoot[] = "/NetInfo/root"; static char NiclPathFmt[] = "/users/%s"; static char NISPatFmt[] = "/usr/bin/ypcat passwd.byname | /usr/bin/grep -q '^%s:'"; static char RemoteNI[] = "/NetInfo/"; -static char PathSep[] = "/"; static char UserConfig[] = "User Configuration"; static unsigned char RestrictedFFRoot[] = { 0, /*E_LOGIN */ @@ -223,20 +226,23 @@ setrestricted(int where, struct passwd *pw) int i; ENTRY *ep; - switch(where) { - case WHERE_FILES: - restricted = uid ? RestrictedFFUser : RestrictedFFRoot; - break; - case WHERE_LOCALNI: - restricted = uid ? RestrictedLocalNIUser : RestrictedLocalNIRoot; - break; + switch(where) + { + case WHERE_FILES: + restricted = uid ? RestrictedFFUser : RestrictedFFRoot; + break; + case WHERE_LOCALNI: + restricted = uid ? RestrictedLocalNIUser : RestrictedLocalNIRoot; + break; + default: + return; } - + for (ep = list, i = NLIST; i > 0; i--) - (ep++)->restricted = *restricted++; - + (ep++)->restricted = *restricted++; + if (uid && !ok_shell(pw->pw_shell)) - list[E_SHELL].restricted = 1; + list[E_SHELL].restricted = 1; } /*--------------------------------------------------------------------------- @@ -323,170 +329,145 @@ whereDS(const char *name) *---------------------------------------------------------------*/ IF((status = dsFindDirNodes(dsRef, dataBuff, NULL, eDSAuthenticationSearchNodeName, &nodeCount, &context)) - == eDSNoErr) { - tDataListPtr nodeName; - if(nodeCount < 1) { - status = eDSNodeNotFound; - break; - } - nodeName = NULL; - IF((status = dsGetDirNodeName(dsRef, dataBuff, 1, - &nodeName)) == eDSNoErr) { - tDirNodeReference nodeRef; - - IF((status = dsOpenDirNode(dsRef, nodeName, &nodeRef)) - == eDSNoErr) { - tDataListPtr pRecType; - tDataListPtr pAttrType; - tDataListPtr pPattern; - unsigned long recCount; - tContextData context2 = NULL; - - /*--------------------------------------------------- - * Now search the search node for the given user name. - *---------------------------------------------------*/ - pRecType = dsBuildListFromStrings(dsRef, - kDSStdRecordTypeUsers, NULL); - pAttrType = dsBuildListFromStrings(dsRef, - kStandardSourceAlias, NULL); - pPattern = dsBuildListFromStrings(dsRef, name, NULL); - IF((status = dsGetRecordList(nodeRef, dataBuff, - pPattern, eDSExact, pRecType, pAttrType, 0, &recCount, - &context2)) == eDSNoErr) { - tAttributeListRef attrListRef; - tRecordEntry *pRecEntry; - - if(recCount < 1) { - status = E_NOTFOUND; + == eDSNoErr) + { + tDataListPtr nodeName; + if(nodeCount < 1) { + status = eDSNodeNotFound; break; - } - /*----------------------------------------------- - * Get the attributes for the first entry we find - *-----------------------------------------------*/ - IF((status = dsGetRecordEntry(nodeRef, - dataBuff, 1, &attrListRef, &pRecEntry)) == - eDSNoErr) { - tAttributeValueListRef valueRef; - tAttributeEntry *pAttrEntry; - - /*------------------------------------------- - * Get the first (only) attribute - *-------------------------------------------*/ - IF((status = dsGetAttributeEntry( nodeRef, - dataBuff, attrListRef, 1, &valueRef, - &pAttrEntry)) == eDSNoErr) { - tDataListPtr pPathList; - - /*--------------------------------------- - * Put the attribute values into a data - * list. - *---------------------------------------*/ - IF((pPathList = dsDataListAllocate(dsRef)) - != NULL) { - int k; - tAttributeValueEntry *pValueEntry; - - for(k = 1; k <= - pAttrEntry->fAttributeValueCount; - k++) { - IF((status = - dsGetAttributeValue(nodeRef, - dataBuff, k, valueRef, - &pValueEntry)) == eDSNoErr) { - if((status = - dsAppendStringToListAlloc( - dsRef, pPathList, - pValueEntry->fAttributeValueData.fBufferData)) - != eDSNoErr) { - k = pAttrEntry->fAttributeValueCount; - break; - } - } CLEANUP { - dsDeallocAttributeValueEntry( - dsRef, pValueEntry); - } ELSE { + } + nodeName = NULL; + IF((status = dsGetDirNodeName(dsRef, dataBuff, 1, &nodeName)) == eDSNoErr) + { + tDirNodeReference nodeRef; + + IF((status = dsOpenDirNode(dsRef, nodeName, &nodeRef)) == eDSNoErr) { + tDataListPtr pRecType; + tDataListPtr pAttrType; + tDataListPtr pPattern; + unsigned long recCount; + tContextData context2 = NULL; + + /*--------------------------------------------------- + * Now search the search node for the given user name. + *---------------------------------------------------*/ + pRecType = dsBuildListFromStrings(dsRef, + kDSStdRecordTypeUsers, NULL); + pAttrType = dsBuildListFromStrings(dsRef, + kDSNAttrMetaNodeLocation, NULL); + pPattern = dsBuildListFromStrings(dsRef, name, NULL); + IF((status = dsGetRecordList(nodeRef, dataBuff, + pPattern, eDSExact, pRecType, pAttrType, 0, &recCount, + &context2)) == eDSNoErr) { + tAttributeListRef attrListRef; + tRecordEntry *pRecEntry; + + if(recCount < 1) { + status = E_NOTFOUND; break; - } ENDIF - } - if(status != eDSNoErr) - break; - /*----------------------------------- - * Finally, build a path from the data - * list, and compare it to known paths. - *-----------------------------------*/ - if(DSPath) - free((void *)DSPath); - if((DSPath = dsGetPathFromList(dsRef, - pPathList, PathSep)) != NULL) { - if(strcmp(DSPath, LocalNI) == 0) { - status = WHERE_LOCALNI; - /*--------------------------- - * Translate to netinfo path - *---------------------------*/ - free((void *)DSPath); - DSPath = strdup("."); - } else if(strcmp(DSPath, DSFiles) - == 0) { - status = WHERE_FILES; - /*--------------------------- - * Translate to master.passwd - * path - *---------------------------*/ - free((void *)DSPath); - DSPath = strdup(MasterPasswd); - } else if(strncmp(DSPath, RemoteNI, - REMOTEINFOLEN) == 0) { - status = WHERE_REMOTENI; - /*--------------------------- - * Translate to netinfo path - *---------------------------*/ - if(strncmp(DSPath, NetinfoRoot, - NETINFOROOTLEN) == 0) { - if(DSPath[NETINFOROOTLEN] - == 0) { - free((void *)DSPath); - DSPath = strdup("/"); - } else { - char *tmp = - strdup(DSPath + - NETINFOROOTLEN); - free((void *)DSPath); - DSPath = tmp; - } } - } else - status = WHERE_DS; - } else - status = E_PATHOUTOFMEM; - } CLEANUP { - dsDataListDeallocate(dsRef, pPathList); - free(pPathList); - } ELSE { - status = E_DATALISTOUTOFMEM; - } ENDIF + /*----------------------------------------------- + * Get the attributes for the first entry we find + *-----------------------------------------------*/ + IF((status = dsGetRecordEntry(nodeRef, + dataBuff, 1, &attrListRef, &pRecEntry)) == + eDSNoErr) { + tAttributeValueListRef valueRef; + tAttributeEntry *pAttrEntry; + + /*------------------------------------------- + * Get the first (only) attribute + *-------------------------------------------*/ + IF((status = dsGetAttributeEntry( nodeRef, dataBuff, attrListRef, 1, &valueRef, + &pAttrEntry)) == eDSNoErr) + { + tAttributeValueEntry *pValueEntry; + + /*--------------------------------------- + * Put the attribute values into a data + * list. + *---------------------------------------*/ + + status = dsGetAttributeValue(nodeRef, dataBuff, 1, valueRef, &pValueEntry); + if ( status == eDSNoErr ) + { + DSPath = (char *) malloc( pValueEntry->fAttributeValueData.fBufferLength + 1 ); + if ( DSPath != NULL ) + strlcpy( DSPath, pValueEntry->fAttributeValueData.fBufferData, pValueEntry->fAttributeValueData.fBufferLength + 1 ); + + dsDeallocAttributeValueEntry(dsRef, pValueEntry); + } + + if(status != eDSNoErr) + break; + + if(strcmp(DSPath, LocalNI) == 0) + { + status = WHERE_LOCALNI; + /*--------------------------- + * Translate to netinfo path + *---------------------------*/ + free((void *)DSPath); + DSPath = strdup("."); + } + else if(strcmp(DSPath, DSFiles) == 0) + { + status = WHERE_FILES; + /*--------------------------- + * Translate to master.passwd + * path + *---------------------------*/ + free((void *)DSPath); + DSPath = strdup(MasterPasswd); + } + else if(strncmp(DSPath, RemoteNI, REMOTEINFOLEN) == 0) + { + status = WHERE_REMOTENI; + /*--------------------------- + * Translate to netinfo path + *---------------------------*/ + if(strncmp(DSPath, NetinfoRoot, + NETINFOROOTLEN) == 0) { + if(DSPath[NETINFOROOTLEN] + == 0) { + free((void *)DSPath); + DSPath = strdup("/"); + } else { + char *tmp = + strdup(DSPath + + NETINFOROOTLEN); + free((void *)DSPath); + DSPath = tmp; + } + } + } + else + { + status = WHERE_DS; + } + } CLEANUP { + dsCloseAttributeValueList(valueRef); + dsDeallocAttributeEntry(dsRef, pAttrEntry); + } ELSE { + } ENDIF + } CLEANUP { + dsCloseAttributeList(attrListRef); + dsDeallocRecordEntry(dsRef, pRecEntry); + } ENDIF + } CLEANUP { + if(context2) + dsReleaseContinueData(dsRef, context2); + } ENDIF + dsDataListDeallocate(dsRef, pRecType); + free(pRecType); + dsDataListDeallocate(dsRef, pAttrType); + free(pAttrType); + dsDataListDeallocate(dsRef, pPattern); + free(pPattern); } CLEANUP { - dsCloseAttributeValueList(valueRef); - dsDeallocAttributeEntry(dsRef, pAttrEntry); - } ELSE { + dsCloseDirNode(nodeRef); } ENDIF - } CLEANUP { - dsCloseAttributeList(attrListRef); - dsDeallocRecordEntry(dsRef, pRecEntry); - } ENDIF } CLEANUP { - if(context2) - dsReleaseContinueData(dsRef, context2); - } ENDIF - dsDataListDeallocate(dsRef, pRecType); - free(pRecType); - dsDataListDeallocate(dsRef, pAttrType); - free(pAttrType); - dsDataListDeallocate(dsRef, pPattern); - free(pPattern); - } CLEANUP { - dsCloseDirNode(nodeRef); - } ENDIF - } CLEANUP { dsDataListDeallocate(dsRef, nodeName); } ENDIF } CLEANUP { @@ -611,30 +592,66 @@ wherepwent(const char *name) char user[LINESIZE]; char *cp, *str; struct where *w; - FILE *fp = popen("/usr/sbin/lookupd -configuration", "r"); + FILE *fp = NULL; int status = 0; - - IF(fp != NULL) { + fd_set fdset; + struct timeval selectTimeout = { 2, 0 }; + int result; char order[LINESIZE], line[LINESIZE]; - + char *task_argv[3] = {NULL}; + int readPipe = -1; + int writePipe = -1; + /*------------------------------------------------------------------- * Save the first LookupOrder as the global setting. We make sure * that the first _config_name is Global Configuration. *-------------------------------------------------------------------*/ + + do + { + task_argv[0] = "/usr/sbin/lookupd"; + task_argv[1] = "-configuration"; + task_argv[2] = NULL; + + if ( LaunchTaskWithPipes(task_argv[0], task_argv, &readPipe, &writePipe) != 0 ) + return E_NOTFOUND; + + // close this pipe now so the forked process quits on completion + if ( writePipe != -1 ) + close( writePipe ); + + // wait for data (and skip signals) + FD_ZERO( &fdset ); + FD_SET( readPipe, &fdset ); + do { + result = select( FD_SETSIZE, &fdset, NULL, NULL, &selectTimeout ); + } + while ( result == -1 && errno == EINTR ); + if ( result == -1 || result == 0 ) { + status = E_NOTFOUND; + break; + } + + // now that the descriptor is ready, parse the configuration + fp = fdopen(readPipe, "r"); + if ( fp == NULL ) { + status = E_NOTFOUND; + break; + } *user = 0; - while(fgets(line, LINESIZE, fp)) { + while(fgets(line, LINESIZE, fp)) + { if(strncasecmp(line, LookupOrder, LOOKUPORDERLEN) == 0) { - if((cp = strchr(line, '\n')) != NULL) - *cp = 0; - strcpy(user, line + LOOKUPORDERLEN); - continue; + if((cp = strchr(line, '\n')) != NULL) + *cp = 0; + strcpy(user, line + LOOKUPORDERLEN); + continue; } if(strncasecmp(line, ConfigName, CONFIGNAMELEN) == 0) { - if(strncasecmp(line + CONFIGNAMELEN, GlobalConfig, - GLOBALCONFIGLEN) != 0) { - status = E_NOGLOBALCONFIG; - } - break; + if(strncasecmp(line + CONFIGNAMELEN, GlobalConfig, GLOBALCONFIGLEN) != 0) { + status = E_NOGLOBALCONFIG; + } + break; } } if(status < 0) @@ -644,7 +661,8 @@ wherepwent(const char *name) * Configuration. If found, replace the global order with this one. *-------------------------------------------------------------------*/ *order = 0; - while(fgets(line, LINESIZE, fp)) { + while(fgets(line, LINESIZE, fp)) + { if(strncasecmp(line, LookupOrder, LOOKUPORDERLEN) == 0) { if((cp = strchr(line, '\n')) != NULL) *cp = 0; @@ -652,10 +670,9 @@ wherepwent(const char *name) continue; } if(strncasecmp(line, ConfigName, CONFIGNAMELEN) == 0) { - if(strncasecmp(line + CONFIGNAMELEN, UserConfig, - USERCONFIGLEN) == 0) { + if(strncasecmp(line + CONFIGNAMELEN, UserConfig, USERCONFIGLEN) == 0) { if(*order) - strcpy(user, order); + strcpy(user, order); break; } *order = 0; @@ -665,15 +682,17 @@ wherepwent(const char *name) status = E_NOLOOKUPORDER; break; } - } CLEANUP { - pclose(fp); - } ELSE { - status = E_POPENFAILED; - } ENDIF - + } + while ( 0 ); + + if ( fp != NULL ) + fclose( fp ); + else if ( readPipe != -1 ) + close( readPipe ); + if(status < 0) return status; - + /*----------------------------------------------------------------------- * Now for each agent, call the corresponding where function. If the * return value is no E_NOTFOUND, then we either have found it or have diff --git a/chpass.tproj/directory_service.h b/chpass.tproj/directory_service.h index 7a3d6bc..4c5c606 100644 --- a/chpass.tproj/directory_service.h +++ b/chpass.tproj/directory_service.h @@ -61,7 +61,7 @@ enum { /*--------------------------------------------------------------------------- * Global variables *---------------------------------------------------------------------------*/ -extern const char *DSPath; +extern char *DSPath; extern const char MasterPasswd[]; /*--------------------------------------------------------------------------- diff --git a/chpass.tproj/ds_pw_util.c b/chpass.tproj/ds_pw_util.c index b0f86cd..1b76cad 100644 --- a/chpass.tproj/ds_pw_util.c +++ b/chpass.tproj/ds_pw_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/chpass.tproj/edit.c b/chpass.tproj/edit.c index ecdbe70..36454fa 100644 --- a/chpass.tproj/edit.c +++ b/chpass.tproj/edit.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/chpass.tproj/field.c b/chpass.tproj/field.c index c997892..bb3c062 100644 --- a/chpass.tproj/field.c +++ b/chpass.tproj/field.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/chpass.tproj/pathnames.h b/chpass.tproj/pathnames.h index 6f0a0bc..03c43a3 100644 --- a/chpass.tproj/pathnames.h +++ b/chpass.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/chpass.tproj/pw_copy.c b/chpass.tproj/pw_copy.c index d30b56f..64ddc9f 100644 --- a/chpass.tproj/pw_copy.c +++ b/chpass.tproj/pw_copy.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/chpass.tproj/pw_copy.h b/chpass.tproj/pw_copy.h index c71c067..4a742ac 100644 --- a/chpass.tproj/pw_copy.h +++ b/chpass.tproj/pw_copy.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/chpass.tproj/table.c b/chpass.tproj/table.c index b260e80..1cd169b 100644 --- a/chpass.tproj/table.c +++ b/chpass.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/chpass.tproj/util.c b/chpass.tproj/util.c index 74fd386..c4dd4d3 100644 --- a/chpass.tproj/util.c +++ b/chpass.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/dmesg.tproj/Makefile.postamble b/dmesg.tproj/Makefile.postamble index 2e4a713..adaa33e 100644 --- a/dmesg.tproj/Makefile.postamble +++ b/dmesg.tproj/Makefile.postamble @@ -1,2 +1,6 @@ INSTALL_AS_GROUP = kmem # (probably want to set both of these) INSTALL_PERMISSIONS = 2555 # If set, 'install' chmod's executable to this + +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 dmesg.8 $(DSTROOT)/usr/share/man/man8 diff --git a/dmesg.tproj/dmesg.c b/dmesg.tproj/dmesg.c index 321c40a..10d5cae 100644 --- a/dmesg.tproj/dmesg.c +++ b/dmesg.tproj/dmesg.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/dynamic_pager.tproj/dynamic_pager.8 b/dynamic_pager.tproj/dynamic_pager.8 index 2d5bb70..ad6a27f 100644 --- a/dynamic_pager.tproj/dynamic_pager.8 +++ b/dynamic_pager.tproj/dynamic_pager.8 @@ -8,6 +8,7 @@ .Nd dynamic pager external storage manager .Sh SYNOPSIS .Nm dynamic_pager +.Op Fl E .Op Fl F Ar filename .Op Fl S Ar filesize .Op Fl H Ar high-water-trigger @@ -25,6 +26,8 @@ daemon also provides a notification service for those applications which wish to receive notices when the external paging pool expands or contracts. .Sh OPTIONS .Bl -tag -width Ds +.It Fl E +Encrypt the data in the swap files. .It Fl F The base name of the .Ar filename diff --git a/dynamic_pager.tproj/dynamic_pager.c b/dynamic_pager.tproj/dynamic_pager.c index 0b20ab2..08a7d1a 100644 --- a/dynamic_pager.tproj/dynamic_pager.c +++ b/dynamic_pager.tproj/dynamic_pager.c @@ -10,7 +10,6 @@ #ifndef MACH_BSD #define MACH_BSD #endif -#include #include #include #include @@ -393,12 +392,13 @@ wait_on_paging_trigger(trigger_port) } void -paging_setup(flags, size, priority, low, high) +paging_setup(flags, size, priority, low, high, encrypted) int flags; int size; int priority; int low; int high; + boolean_t encrypted; { off_t filesize = size; char subfile[512]; @@ -427,6 +427,17 @@ paging_setup(flags, size, priority, low, high) exit(EXIT_FAILURE); } + if (macx_triggers(0, 0, + (encrypted + ? SWAP_ENCRYPT_ON + : SWAP_ENCRYPT_OFF), + MACH_PORT_NULL) != 0) { + fprintf(stderr, + "dynamic_pager: warning: " + "could not turn encrypted swap %s\n", + (encrypted ? "on" : "off")); + } + macx_swapon(subfile, flags, size, priority); if(hi_water) { @@ -464,6 +475,7 @@ main(int argc, char **argv) char default_filename[] = "/private/var/vm/swapfile"; int ch; int variable_sized = 1; + boolean_t encrypted_swap = FALSE; seteuid(getuid()); strcpy(fileroot, default_filename); @@ -475,9 +487,13 @@ main(int argc, char **argv) local_hi_water = 0; - while ((ch = getopt(argc, argv, "F:L:H:S:P:O:")) != EOF) { + while ((ch = getopt(argc, argv, "EF:L:H:S:P:O:")) != EOF) { switch((char)ch) { + case 'E': + encrypted_swap = TRUE; + break; + case 'F': strncpy(fileroot, optarg, 500); break; @@ -626,7 +642,8 @@ main(int argc, char **argv) argc -= optind; argv += optind; - paging_setup(0, limits[0].size, priority, limits[0].low_water, hi_water); + paging_setup(0, limits[0].size, priority, limits[0].low_water, hi_water, + encrypted_swap); return (0); } diff --git a/fs_usage.tproj/Makefile b/fs_usage.tproj/Makefile index 705acce..f636254 100644 --- a/fs_usage.tproj/Makefile +++ b/fs_usage.tproj/Makefile @@ -23,7 +23,6 @@ MAKEFILE = tool.make NEXTSTEP_INSTALLDIR = /usr/bin WINDOWS_INSTALLDIR = /Library/Executables PDO_UNIX_INSTALLDIR = /bin -LIBS = -lcurses DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) diff --git a/fs_usage.tproj/fs_usage.1 b/fs_usage.tproj/fs_usage.1 index ba3b3af..4479900 100644 --- a/fs_usage.tproj/fs_usage.1 +++ b/fs_usage.tproj/fs_usage.1 @@ -64,7 +64,7 @@ Only network related output is displayed. Only file system related output is displayed. .Pp .Pa cachehit -Exclude CACHE_HIT output from the displayed data. +In addition, display CACHE_HIT output. .It pid | cmd The sampled data can be limited to a list of process ids or commands. When a command name is given, all processes with that name will be sampled. diff --git a/fs_usage.tproj/fs_usage.c b/fs_usage.tproj/fs_usage.c index e0ffcbf..6f8b2f2 100644 --- a/fs_usage.tproj/fs_usage.c +++ b/fs_usage.tproj/fs_usage.c @@ -3,28 +3,27 @@ * * @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@ */ /* -cc -I. -DKERNEL_PRIVATE -O -o fs_usage fs_usage.c +cc -I. -DPRIVATE -D__APPLE_PRIVATE -O -o fs_usage fs_usage.c */ #define Default_DELAY 1 /* default delay interval */ @@ -57,6 +56,7 @@ cc -I. -DKERNEL_PRIVATE -O -o fs_usage fs_usage.c #include #include #import +#import #include extern int errno; @@ -126,11 +126,13 @@ int argmax = 0; * Network only or filesystem only output filter * Default of zero means report all activity - no filtering */ -#define FILESYS_FILTER 1 -#define NETWORK_FILTER 2 -#define CACHEHIT_FILTER 4 -#define DEFAULT_DO_NOT_FILTER 0 -int filter_mode = DEFAULT_DO_NOT_FILTER; +#define FILESYS_FILTER 0x01 +#define NETWORK_FILTER 0x02 +#define CACHEHIT_FILTER 0x04 +#define EXEC_FILTER 0x08 +#define DEFAULT_DO_NOT_FILTER 0x00 + +int filter_mode = CACHEHIT_FILTER; #define NFS_DEV -1 @@ -177,6 +179,11 @@ void init_arguments_buffer(); int get_real_command_name(int, char *, int); void create_map_entry(int, int, char *); +void enter_syscall(); +void exit_syscall(); +void extend_syscall(); +void kill_thread_map(); + #define TRACE_DATA_NEWTHREAD 0x07000004 #define TRACE_DATA_EXEC 0x07000008 #define TRACE_STRING_NEWTHREAD 0x07010004 @@ -250,6 +257,7 @@ void create_map_entry(int, int, char *); #define BSC_revoke 0x040C00E0 #define BSC_symlink 0x040C00E4 #define BSC_readlink 0x040C00E8 +#define BSC_execve 0x040C00EC #define BSC_chroot 0x040C00F4 #define BSC_dup2 0x040C0168 #define BSC_fsync 0x040C017C @@ -292,8 +300,26 @@ void create_map_entry(int, int, char *); #define BSC_searchfs 0x040C0384 #define BSC_delete 0x040C0388 #define BSC_copyfile 0x040C038C +#define BSC_getxattr 0x040C03A8 +#define BSC_fgetxattr 0x040C03AC +#define BSC_setxattr 0x040C03B0 +#define BSC_fsetxattr 0x040C03B4 +#define BSC_removexattr 0x040C03B8 +#define BSC_fremovexattr 0x040C03BC +#define BSC_listxattr 0x040C03C0 +#define BSC_flistxattr 0x040C03C4 #define BSC_fsctl 0x040C03C8 +#define BSC_open_extended 0x040C0454 +#define BSC_stat_extended 0x040C045C +#define BSC_lstat_extended 0x040C0460 +#define BSC_fstat_extended 0x040C0464 +#define BSC_chmod_extended 0x040C0468 +#define BSC_fchmod_extended 0x040C046C +#define BSC_access_extended 0x040C0470 +#define BSC_mkfifo_extended 0x040C048C +#define BSC_mkdir_extended 0x040C0490 #define BSC_load_shared_file 0x040C04A0 +#define BSC_lchown 0x040C05B0 // Carbon File Manager support #define FILEMGR_PBGETCATALOGINFO 0x1e000020 @@ -476,9 +502,11 @@ exit_usage(char *myname) { fprintf(stderr, " -e exclude the specified list of pids from the sample\n"); fprintf(stderr, " and exclude fs_usage by default\n"); fprintf(stderr, " -w force wider, detailed, output\n"); - fprintf(stderr, " -f Output is filtered based on the mode provided\n"); + fprintf(stderr, " -f Output is based on the mode provided\n"); fprintf(stderr, " mode = \"network\" Show only network related output\n"); - fprintf(stderr, " mode = \"filesys\" Show only file system related output\n"); + fprintf(stderr, " mode = \"filesys\" Show only file system related output\n"); + fprintf(stderr, " mode = \"exec\" Show only execs\n"); + fprintf(stderr, " mode = \"cachehit\" In addition, show cachehits\n"); fprintf(stderr, " pid selects process(s) to sample\n"); fprintf(stderr, " cmd selects process(s) matching command string to sample\n"); fprintf(stderr, "\n%s will handle a maximum list of %d pids.\n\n", myname, MAX_PIDS); @@ -537,7 +565,9 @@ main(argc, argv) else if (!strcmp(optarg, "filesys")) filter_mode |= FILESYS_FILTER; else if (!strcmp(optarg, "cachehit")) - filter_mode |= CACHEHIT_FILTER; /* turns off CACHE_HIT */ + filter_mode &= ~CACHEHIT_FILTER; /* turns on CACHE_HIT */ + else if (!strcmp(optarg, "exec")) + filter_mode |= EXEC_FILTER; break; default: @@ -634,7 +664,7 @@ main(argc, argv) /* main loop */ while (1) { - usleep(1000 * 25); + usleep(1000 * 20); sample_sc(); } @@ -887,7 +917,7 @@ sample_sc() count = needed; if (bufinfo.flags & KDBG_WRAPPED) { - fprintf(stderr, "buffer wrapped count = %d\n", count); + fprintf(stderr, "fs_usage: buffer overrun, events generated too quickly\n"); for (i = 0; i < cur_max; i++) { th_state[i].thread = 0; @@ -915,15 +945,12 @@ sample_sc() long curr_time; struct th_info *ti; struct diskio *dio; - void enter_syscall(); - void exit_syscall(); - void extend_syscall(); - void kill_thread_map(); + thread = kd[i].arg5; debugid = kd[i].debugid; type = kd[i].debugid & DBG_FUNC_MASK; - + now = kd[i].timestamp & KDBG_TIMESTAMP_MASK; if (i == 0) @@ -1030,6 +1057,7 @@ sample_sc() else { create_map_entry(thread, ti->pid, (char *)&kd[i].arg1); + if (ti == &th_state[cur_max - 1]) cur_max--; ti->thread = 0; @@ -1066,9 +1094,9 @@ sample_sc() handle. */ - if ((long *)sargptr >= (long *)&ti->pathname[PATHLENGTH]) - continue; - + if ((long *)sargptr >= (long *)&ti->pathname[PATHLENGTH]) { + continue; + } /* We need to detect consecutive vfslookup entries. So, if we get here and find a START entry, @@ -1076,11 +1104,10 @@ sample_sc() vfslookup entries. */ - if (debugid & DBG_FUNC_START) - { + if (debugid & DBG_FUNC_START) { (long *)ti->pathptr = (long *)&ti->pathname[PATHLENGTH]; continue; - } + } *sargptr++ = kd[i].arg1; *sargptr++ = kd[i].arg2; @@ -1381,10 +1408,34 @@ sample_sc() exit_syscall("socketpair", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; + case BSC_getxattr: + exit_syscall("getxattr", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + + case BSC_setxattr: + exit_syscall("setxattr", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + + case BSC_removexattr: + exit_syscall("removexattr", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + + case BSC_listxattr: + exit_syscall("listxattr", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + case BSC_stat: exit_syscall("stat", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; + case BSC_stat_extended: + exit_syscall("stat_extended", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + + case BSC_execve: + exit_syscall("execve", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + case BSC_load_shared_file: exit_syscall("load_sf", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; @@ -1393,6 +1444,10 @@ sample_sc() exit_syscall("open", thread, type, kd[i].arg1, kd[i].arg2, 2, 0, (double)now); break; + case BSC_open_extended: + exit_syscall("open_extended", thread, type, kd[i].arg1, kd[i].arg2, 2, 0, (double)now); + break; + case BSC_dup: exit_syscall("dup", thread, type, kd[i].arg1, kd[i].arg2, 2, 0, (double)now); break; @@ -1413,14 +1468,38 @@ sample_sc() exit_syscall("write", thread, type, kd[i].arg1, kd[i].arg2, 1, 1, (double)now); break; + case BSC_fgetxattr: + exit_syscall("fgetxattr", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now); + break; + + case BSC_fsetxattr: + exit_syscall("fsetxattr", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now); + break; + + case BSC_fremovexattr: + exit_syscall("fremovexattr", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now); + break; + + case BSC_flistxattr: + exit_syscall("flistxattr", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now); + break; + case BSC_fstat: exit_syscall("fstat", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now); break; + case BSC_fstat_extended: + exit_syscall("fstat_extended", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now); + break; + case BSC_lstat: exit_syscall("lstat", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; + case BSC_lstat_extended: + exit_syscall("lstat_extended", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + case BSC_link: exit_syscall("link", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; @@ -1437,14 +1516,26 @@ sample_sc() exit_syscall("chmod", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; + case BSC_chmod_extended: + exit_syscall("chmod_extended", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + case BSC_chown: exit_syscall("chown", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; + case BSC_lchown: + exit_syscall("lchown", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + case BSC_access: exit_syscall("access", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; + case BSC_access_extended: + exit_syscall("access_extended", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + case BSC_chdir: exit_syscall("chdir", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; @@ -1529,14 +1620,26 @@ sample_sc() exit_syscall("fchmod", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now); break; + case BSC_fchmod_extended: + exit_syscall("fchmod_extended", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now); + break; + case BSC_mkdir: exit_syscall("mkdir", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; + case BSC_mkdir_extended: + exit_syscall("mkdir_extended", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + case BSC_mkfifo: exit_syscall("mkfifo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; + case BSC_mkfifo_extended: + exit_syscall("mkfifo_extended", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); + break; + case BSC_rmdir: exit_syscall("rmdir", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now); break; @@ -1862,6 +1965,24 @@ enter_syscall(int thread, int type, kd_buf *kd, char *name, double now) case BSC_listen: case BSC_sendto: case BSC_socketpair: + case BSC_execve: + case BSC_getxattr: + case BSC_fgetxattr: + case BSC_setxattr: + case BSC_fsetxattr: + case BSC_removexattr: + case BSC_fremovexattr: + case BSC_listxattr: + case BSC_flistxattr: + case BSC_open_extended: + case BSC_stat_extended: + case BSC_lstat_extended: + case BSC_fstat_extended: + case BSC_chmod_extended: + case BSC_fchmod_extended: + case BSC_access_extended: + case BSC_mkfifo_extended: + case BSC_mkdir_extended: case BSC_stat: case BSC_load_shared_file: case BSC_open: @@ -1877,6 +1998,7 @@ enter_syscall(int thread, int type, kd_buf *kd, char *name, double now) case BSC_mknod: case BSC_chmod: case BSC_chown: + case BSC_lchown: case BSC_access: case BSC_chflags: case BSC_fchflags: @@ -1990,7 +2112,11 @@ enter_syscall(int thread, int type, kd_buf *kd, char *name, double now) case FILEMGR_PBLOCKRANGE: case FILEMGR_PBUNLOCKRANGE: - + if ((ti = find_thread(thread, BSC_execve))) { + if (ti->pathptr) { + exit_syscall("execve", thread, BSC_execve, 0, 0, 0, 0, (double)now); + } + } for (i = 0, ti = th_state; ti < &th_state[MAX_THREADS]; ti++, i++) { if (ti->thread == 0) break; @@ -2000,7 +2126,6 @@ enter_syscall(int thread, int type, kd_buf *kd, char *name, double now) if (i >= cur_max) cur_max = i + 1; - if ((type >> 24) == FILEMGR_CLASS) { ti->in_filemgr = 1; @@ -2336,19 +2461,11 @@ char *s; void getdivisor() { + struct mach_timebase_info mti; - unsigned int delta; - unsigned int abs_to_ns_num; - unsigned int abs_to_ns_denom; - unsigned int proc_to_abs_num; - unsigned int proc_to_abs_denom; + mach_timebase_info(&mti); - extern void MKGetTimeBaseInfo(unsigned int *, unsigned int *, unsigned int *, unsigned int *, unsigned int *); - - MKGetTimeBaseInfo (&delta, &abs_to_ns_num, &abs_to_ns_denom, - &proc_to_abs_num, &proc_to_abs_denom); - - divisor = ((double)abs_to_ns_denom / (double)abs_to_ns_num) * 1000; + divisor = ((double)mti.denom / (double)mti.numer) * 1000; } @@ -2390,7 +2507,7 @@ void read_command_map() } } - if (mapptr && (filter_mode != DEFAULT_DO_NOT_FILTER)) + if (mapptr && (filter_mode & (NETWORK_FILTER | FILESYS_FILTER))) { if (fdmapptr) { @@ -2455,7 +2572,7 @@ void create_map_entry(int thread, int pid, char *command) { map = &mapptr[i]; /* Reuse this entry, the thread has been * reassigned */ - if(filter_mode && fdmapptr) + if ((filter_mode & (NETWORK_FILTER | FILESYS_FILTER)) && fdmapptr) { fdmap = &fdmapptr[i]; if (fdmap->fd_thread != thread) /* This shouldn't happen */ @@ -2470,7 +2587,7 @@ void create_map_entry(int thread, int pid, char *command) { if (mapptr[i].valid == 0 ) map = &mapptr[i]; /* Reuse this invalid entry */ - if (filter_mode && fdmapptr) + if ((filter_mode & (NETWORK_FILTER | FILESYS_FILTER)) && fdmapptr) { fdmap = &fdmapptr[i]; } @@ -2489,7 +2606,7 @@ void create_map_entry(int thread, int pid, char *command) bzero(&mapptr[total_threads], total_threads*sizeof(kd_threadmap)); map = &mapptr[total_threads]; - if (filter_mode && fdmapptr) + if ((filter_mode & (NETWORK_FILTER | FILESYS_FILTER)) && fdmapptr) { fdmapptr = (fd_threadmap *)realloc(fdmapptr, n * sizeof(fd_threadmap)); bzero(&fdmapptr[total_threads], total_threads*sizeof(fd_threadmap)); @@ -2579,7 +2696,7 @@ kill_thread_map(int thread) map->command[0] = '\0'; } - if (filter_mode) + if ((filter_mode & (NETWORK_FILTER | FILESYS_FILTER))) { if ((fdmap = find_fd_thread_map(thread))) { @@ -3105,12 +3222,22 @@ check_filter_mode(struct th_info * ti, int type, int error, int retval, char *sc if (filter_mode == DEFAULT_DO_NOT_FILTER) return(1); - if (filter_mode & CACHEHIT_FILTER) + if (!strcmp (sc_name, "CACHE_HIT")) { + if (filter_mode & CACHEHIT_FILTER) + /* Do not print if cachehit filter is set */ + return(0); + return (1); + } + + if (filter_mode & EXEC_FILTER) { - /* Do not print if cachehit filter is set */ - if (!strcmp (sc_name, "CACHE_HIT")) - return(0); + if (!strcmp (sc_name, "execve")) + return(1); + return(0); } + if ( !(filter_mode & (FILESYS_FILTER | NETWORK_FILTER))) + return(1); + if (ti == (struct th_info *)0) { diff --git a/getconf.tproj/limits.gperf b/getconf.tproj/limits.gperf index 0a91be5..e395c1a 100644 --- a/getconf.tproj/limits.gperf +++ b/getconf.tproj/limits.gperf @@ -23,13 +23,12 @@ static const struct map *in_word_set(const char *str); %} struct map { const char *name; intmax_t value; int valid; }; %% -_POSIX_CLOCKRES_MIN, _POSIX_CLOCKRES_MIN _POSIX_AIO_LISTIO_MAX, _POSIX_AIO_LISTIO_MAX _POSIX_AIO_MAX, _POSIX_AIO_MAX _POSIX_ARG_MAX, _POSIX_ARG_MAX _POSIX_CHILD_MAX, _POSIX_CHILD_MAX +_POSIX_CLOCKRES_MIN, _POSIX_CLOCKRES_MIN _POSIX_DELAYTIMER_MAX, _POSIX_DELAYTIMER_MAX -_POSIX2_EXPR_NEST_MAX, _POSIX2_EXPR_NEST_MAX _POSIX_HOST_NAME_MAX, _POSIX_HOST_NAME_MAX _POSIX_LINK_MAX, _POSIX_LINK_MAX _POSIX_LOGIN_NAME_MAX, _POSIX_LOGIN_NAME_MAX @@ -68,7 +67,7 @@ _POSIX2_BC_SCALE_MAX, _POSIX2_BC_SCALE_MAX _POSIX2_BC_STRING_MAX, _POSIX2_BC_STRING_MAX _POSIX2_CHARCLASS_NAME_MAX, _POSIX2_CHARCLASS_NAME_MAX _POSIX2_COLL_WEIGHTS_MAX, _POSIX2_COLL_WEIGHTS_MAX -_POSIX2_EXPR_NEXT_MAX, _POSIX2_EXPR_NEST_MAX +_POSIX2_EXPR_NEST_MAX, _POSIX2_EXPR_NEST_MAX _POSIX2_LINE_MAX, _POSIX2_LINE_MAX _POSIX2_RE_DUP_MAX, _POSIX2_RE_DUP_MAX _XOPEN_IOV_MAX, _XOPEN_IOV_MAX diff --git a/getconf.tproj/pathconf.gperf b/getconf.tproj/pathconf.gperf index 19d011d..1b20649 100644 --- a/getconf.tproj/pathconf.gperf +++ b/getconf.tproj/pathconf.gperf @@ -41,12 +41,13 @@ TRUSTEDBSD_ACL_PATH_MAX, _PC_ACL_PATH_MAX TRUSTEDBSD_CAP_PRESENT, _PC_CAP_PRESENT TRUSTEDBSD_INF_PRESENT, _PC_INF_PRESENT TRUSTEDBSD_MAC_PRESENT, _PC_MAC_PRESENT +_POSIX_ASYNC_IO, _PC_ASYNC_IO _POSIX_CHOWN_RESTRICTED, _PC_CHOWN_RESTRICTED _POSIX_NO_TRUNC, _PC_NO_TRUNC -_POSIX_VDISABLE, _PC_VDISABLE -_POSIX_ASYNC_IO, _PC_ASYNC_IO +_POSIX_PATH_MAX, _PC_PATH_MAX _POSIX_PRIO_IO, _PC_PRIO_IO _POSIX_SYNC_IO, _PC_SYNC_IO +_POSIX_VDISABLE, _PC_VDISABLE %% int find_pathconf(const char *name, int *key) diff --git a/getconf.tproj/sysconf.gperf b/getconf.tproj/sysconf.gperf index ed96482..35c825e 100644 --- a/getconf.tproj/sysconf.gperf +++ b/getconf.tproj/sysconf.gperf @@ -73,9 +73,16 @@ _POSIX2_C_VERSION, _SC_2_C_VERSION _POSIX2_FORT_DEV, _SC_2_FORT_DEV _POSIX2_FORT_RUN, _SC_2_FORT_RUN _POSIX2_LOCALEDEF, _SC_2_LOCALEDEF +_POSIX2_PBS, _SC_PBS +_POSIX2_PBS_ACCOUNTING, _SC_PBS_ACCOUNTING, +_POSIX2_PBS_CHECKPOINT, _SC_PBS_CHECKPOINT +_POSIX2_PBS_LOCATE, _SC_PBS_LOCATE +_POSIX2_PBS_MESSAGE, _SC_PBS_MESSAGE +_POSIX2_PBS_TRACK, _SC_PBS_TRACK _POSIX2_SW_DEV, _SC_2_SW_DEV _POSIX2_UPE, _SC_2_UPE _POSIX2_VERSION, _SC_2_VERSION +_POSIX_ADVISORY_INFO, _SC_ADVISORY_INFO _POSIX_ASYNCHRONOUS_IO, _SC_ASYNCHRONOUS_IO _POSIX_BARRIERS, _SC_BARRIERS _POSIX_CLOCK_SELECTION, _SC_CLOCK_SELECTION @@ -92,6 +99,7 @@ _POSIX_MESSAGE_PASSING, _SC_MESSAGE_PASSING _POSIX_MONOTONIC_CLOCK, _SC_MONOTONIC_CLOCK _POSIX_PRIORITIZED_IO, _SC_PRIORITIZED_IO _POSIX_PRIORITY_SCHEDULING, _SC_PRIORITY_SCHEDULING +_POSIX_RAW_SOCKETS, _SC_RAW_SOCKETS _POSIX_READER_WRITER_LOCKS, _SC_READER_WRITER_LOCKS _POSIX_REALTIME_SIGNALS, _SC_REALTIME_SIGNALS _POSIX_REGEXP, _SC_REGEXP @@ -131,6 +139,7 @@ _XOPEN_LEGACY, _SC_XOPEN_LEGACY _XOPEN_REALTIME, _SC_XOPEN_REALTIME _XOPEN_REALTIME_THREADS, _SC_XOPEN_REALTIME_THREADS _XOPEN_SHM, _SC_XOPEN_SHM +_XOPEN_STREAMS, _SC_XOPEN_STREAMS _XOPEN_UNIX, _SC_XOPEN_UNIX _XOPEN_VERSION, _SC_XOPEN_VERSION _XOPEN_XCU_VERSION, _SC_XCU_VERSION diff --git a/getty.tproj/Makefile.postamble b/getty.tproj/Makefile.postamble index cb09ed6..03f6b6e 100644 --- a/getty.tproj/Makefile.postamble +++ b/getty.tproj/Makefile.postamble @@ -108,3 +108,9 @@ # 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/man5 + install -c -m 444 gettytab.5 $(DSTROOT)/usr/share/man/man5 + install -c -m 444 ttys.5 $(DSTROOT)/usr/share/man/man5 + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 getty.8 $(DSTROOT)/usr/share/man/man8 diff --git a/getty.tproj/extern.h b/getty.tproj/extern.h index 37241b8..f8e759a 100644 --- a/getty.tproj/extern.h +++ b/getty.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/getty.tproj/gettytab.h b/getty.tproj/gettytab.h index 0d869e2..2fcd79c 100644 --- a/getty.tproj/gettytab.h +++ b/getty.tproj/gettytab.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/getty.tproj/init.c b/getty.tproj/init.c index b5b6581..99c980a 100644 --- a/getty.tproj/init.c +++ b/getty.tproj/init.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/getty.tproj/main.c b/getty.tproj/main.c index 5b38228..3eaa6da 100644 --- a/getty.tproj/main.c +++ b/getty.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@ */ @@ -63,7 +62,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)main.c 8.1 (Berkeley) 6/20/93";*/ -static char rcsid[] = "$Id: main.c,v 1.2 2003/05/30 18:10:02 rbraun Exp $"; +static char rcsid[] = "$Id: main.c,v 1.3 2004/08/26 00:32:22 lindak Exp $"; #endif /* not lint */ #include @@ -101,7 +100,7 @@ int crmod, digit, lower, upper; char hostname[MAXHOSTNAMELEN]; struct utsname kerninfo; -char name[16]; +char name[MAXLOGNAME+1]; char dev[] = _PATH_DEV; char ttyn[32]; char *portselector(); @@ -395,7 +394,7 @@ getname() return (0); if (c == EOT) exit(1); - if (c == '\r' || c == '\n' || np >= &name[sizeof name]) { + if (c == '\r' || c == '\n' || np >= &name[sizeof name-1]) { putf("\r\n"); break; } diff --git a/getty.tproj/pathnames.h b/getty.tproj/pathnames.h index 1cf18ea..909042a 100644 --- a/getty.tproj/pathnames.h +++ b/getty.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/getty.tproj/subr.c b/getty.tproj/subr.c index cd9aca9..83fe9b4 100644 --- a/getty.tproj/subr.c +++ b/getty.tproj/subr.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,13 +56,13 @@ #ifndef lint /*static char sccsid[] = "from: @(#)subr.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$Id: subr.c,v 1.1.1.2 2000/01/11 02:10:15 wsanchez Exp $"; +static char rcsid[] = "$Id: subr.c,v 1.2 2004/09/30 22:57:04 lindak Exp $"; #endif /* not lint */ /* * Melbourne getty. */ -#define COMPAT_43 1 +#define COMPAT_43_TTY 1 #include #include #include diff --git a/hostinfo.tproj/hostinfo.c b/hostinfo.tproj/hostinfo.c index 33cfbfb..86c4e42 100644 --- a/hostinfo.tproj/hostinfo.c +++ b/hostinfo.tproj/hostinfo.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@ */ @@ -40,7 +39,6 @@ #include #include -#include #include #include #include diff --git a/iostat.tproj/iostat.c b/iostat.tproj/iostat.c index 3ea24b1..f6764e2 100644 --- a/iostat.tproj/iostat.c +++ b/iostat.tproj/iostat.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@ */ @@ -281,6 +280,11 @@ main(int argc, char **argv) Tflag = 1; } + /* + * TTY statistics are broken, disabling them. + */ + Tflag = 0; + /* * Figure out how many devices we should display if not given * an explicit value. diff --git a/kdump.tproj/Makefile b/kdump.tproj/Makefile index f09af30..23bdd7d 100644 --- a/kdump.tproj/Makefile +++ b/kdump.tproj/Makefile @@ -29,7 +29,7 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) -HEADER_PATHS = -I../ktrace.tproj +HEADER_PATHS = -I../ktrace.tproj -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders NEXTSTEP_PB_CFLAGS = -DMACH_USER_API WINDOWS_PB_CFLAGS = -DMACH_USER_API PDO_UNIX_PB_CFLAGS = -DMACH_USER_API diff --git a/kdump.tproj/kdump.c b/kdump.tproj/kdump.c index 822b118..bcb3698 100644 --- a/kdump.tproj/kdump.c +++ b/kdump.tproj/kdump.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@ */ @@ -54,25 +53,23 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ +#include #ifndef lint -static const char copyright[] = +__unused static const char copyright[] = "@(#) Copyright (c) 1988, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint #if 0 -static char sccsid[] = "@(#)kdump.c 8.1 (Berkeley) 6/6/93"; +__unused static char sccsid[] = "@(#)kdump.c 8.1 (Berkeley) 6/6/93"; #endif -static const char rcsid[] = +__unused static const char rcsid[] = "$FreeBSD: src/usr.bin/kdump/kdump.c,v 1.17 1999/12/29 05:05:33 peter Exp $"; #endif /* not lint */ -#define KERNEL -extern int errno; -#include -#undef KERNEL +#include #include #include #include @@ -89,18 +86,32 @@ extern int errno; #include #include "ktrace.h" +#define ERESTART -1 +#define EJUSTRETURN -2 int timestamp, decimal, fancy = 1, tail, maxdata; char *tracefile = DEF_TRACEFILE; struct ktr_header ktr_header; #define eqs(s1, s2) (strcmp((s1), (s2)) == 0) -main(argc, argv) - int argc; - char *argv[]; +/* Forward declarations */ +void usage(void); +int fread_tail(char *buf, int size, int num); +void dumpheader(struct ktr_header *kth); +void dumpheader(struct ktr_header *kth); +void ktrsyscall(struct ktr_syscall *ktr); +void ktrsysret(struct ktr_sysret *ktr); +void ktrnamei(char *cp, int len); +void ktrgenio(struct ktr_genio *ktr, int len); +void ktrpsig(struct ktr_psig *psig); +void ktrcsw(struct ktr_csw *cs); +void ktruser(int len, unsigned char *p); + +int +main(int argc, char *argv[]) { int ch, ktrlen, size; - register void *m; + void *m; int trpoints = ALL_POINTS; (void) setlocale(LC_CTYPE, ""); @@ -145,7 +156,7 @@ main(argc, argv) errx(1, "%s", strerror(ENOMEM)); if (!freopen(tracefile, "r", stdin)) err(1, "%s", tracefile); - while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) { + while (fread_tail((char *)&ktr_header, sizeof(struct ktr_header), 1)) { if (trpoints & (1<ktr_time, &prevtime); prevtime = temp; } - (void)printf("%ld.%06ld ", + (void)printf("%ld.%06d ", kth->ktr_time.tv_sec, kth->ktr_time.tv_usec); } (void)printf("%s ", type); @@ -256,13 +268,14 @@ static char *ptrace_ops[] = { "PT_TRACE_ME", "PT_READ_I", "PT_READ_D", "PT_READ_U", "PT_WRITE_I", "PT_WRITE_D", "PT_WRITE_U", "PT_CONTINUE", "PT_KILL", "PT_STEP", "PT_ATTACH", "PT_DETACH", + "PT_SIGEXC", "PT_THUPDATE", "PT_ATTACHEXC", }; -ktrsyscall(ktr) - register struct ktr_syscall *ktr; +void +ktrsyscall(struct ktr_syscall *ktr) { - register narg = ktr->ktr_narg; - register register_t *ip; + register_t narg = ktr->ktr_narg; + unsigned long long *ip; char *ioctlname(); if (ktr->ktr_code >= nsyscalls || ktr->ktr_code < 0) @@ -296,29 +309,17 @@ ktrsyscall(ktr) if (*ip < sizeof(ptrace_ops) / sizeof(ptrace_ops[0]) && *ip >= 0) (void)printf("(%s", ptrace_ops[*ip]); -#ifdef PT_GETREGS - else if (*ip == PT_GETREGS) - (void)printf("(%s", "PT_GETREGS"); -#endif -#ifdef PT_SETREGS - else if (*ip == PT_SETREGS) - (void)printf("(%s", "PT_SETREGS"); +#ifdef PT_FORCEQUOTA + else if (*ip == PT_FORCEQUOTA) + (void)printf("(%s", "PT_FORCEQUOTA"); #endif -#ifdef PT_GETFPREGS - else if (*ip == PT_GETFPREGS) - (void)printf("(%s", "PT_GETFPREGS"); +#ifdef PT_DENY_ATTACH + else if (*ip == PT_DENY_ATTACH) + (void)printf("(%s", "PT_DENY_ATTACH"); #endif -#ifdef PT_SETFPREGS - else if (*ip == PT_SETFPREGS) - (void)printf("(%s", "PT_SETFPREGS"); -#endif -#ifdef PT_GETDBREGS - else if (*ip == PT_GETDBREGS) - (void)printf("(%s", "PT_GETDBREGS"); -#endif -#ifdef PT_SETDBREGS - else if (*ip == PT_SETDBREGS) - (void)printf("(%s", "PT_SETDBREGS"); +#ifdef PT_FIRSTMACH + else if (*ip == PT_FIRSTMACH) + (void)printf("(%s", "PT_FIRSTMACH"); #endif else (void)printf("(%ld", (long)*ip); @@ -341,12 +342,12 @@ ktrsyscall(ktr) (void)putchar('\n'); } -ktrsysret(ktr) - struct ktr_sysret *ktr; +void +ktrsysret(struct ktr_sysret *ktr) { - register register_t ret = ktr->ktr_retval; - register int error = ktr->ktr_error; - register int code = ktr->ktr_code; + register_t ret = ktr->ktr_retval; + int error = ktr->ktr_error; + int code = ktr->ktr_code; if (code >= nsyscalls || code < 0) (void)printf("[%d] ", code); @@ -376,22 +377,22 @@ ktrsysret(ktr) (void)putchar('\n'); } -ktrnamei(cp, len) - char *cp; +void +ktrnamei(char *cp, int len) { (void)printf("\"%.*s\"\n", len, cp); } -ktrgenio(ktr, len) - struct ktr_genio *ktr; +void +ktrgenio(struct ktr_genio *ktr, int len) { - register int datalen = len - sizeof (struct ktr_genio); - register char *dp = (char *)ktr + sizeof (struct ktr_genio); - register char *cp; - register int col = 0; - register width; + int datalen = len - sizeof (struct ktr_genio); + char *dp = (char *)ktr + sizeof (struct ktr_genio); + char *cp; + int col = 0; + int width; char visbuf[5]; - static screenwidth = 0; + static int screenwidth = 0; if (screenwidth == 0) { struct winsize ws; @@ -446,16 +447,16 @@ ktrgenio(ktr, len) } char *signames[] = { - "NULL", "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", /* 1 - 6 */ + "NULL", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", /* 1 - 6 */ "EMT", "FPE", "KILL", "BUS", "SEGV", "SYS", /* 7 - 12 */ "PIPE", "ALRM", "TERM", "URG", "STOP", "TSTP", /* 13 - 18 */ "CONT", "CHLD", "TTIN", "TTOU", "IO", "XCPU", /* 19 - 24 */ - "XFSZ", "VTALRM", "PROF", "WINCH", "29", "USR1", /* 25 - 30 */ + "XFSZ", "VTALRM", "PROF", "WINCH", "INFO", "USR1", /* 25 - 30 */ "USR2", NULL, /* 31 - 32 */ }; -ktrpsig(psig) - struct ktr_psig *psig; +void +ktrpsig(struct ktr_psig *psig) { (void)printf("SIG%s ", signames[psig->signo]); if (psig->action == SIG_DFL) @@ -465,16 +466,15 @@ ktrpsig(psig) (u_long)psig->action, psig->mask, psig->code); } -ktrcsw(cs) - struct ktr_csw *cs; +void +ktrcsw(struct ktr_csw *cs) { (void)printf("%s %s\n", cs->out ? "stop" : "resume", cs->user ? "user" : "kernel"); } -ktruser(len, p) - int len; - unsigned char *p; +void +ktruser(int len, unsigned char *p) { (void)printf("%d ", len); while (len--) @@ -483,7 +483,8 @@ ktruser(len, p) } -usage() +void +usage(void) { (void)fprintf(stderr, "usage: kdump [-dnlRT] [-f trfile] [-m maxdata] [-t [cnisuw]]\n"); diff --git a/kdump.tproj/mkioctls b/kdump.tproj/mkioctls index 53c8afd..f98139a 100644 --- a/kdump.tproj/mkioctls +++ b/kdump.tproj/mkioctls @@ -35,7 +35,7 @@ ioctl_includes=` ` echo "/* XXX obnoxious prerequisites. */" -echo "#define COMPAT_43 1" +echo "#define COMPAT_43_TTY 1" echo "#include " echo "#include " echo "#include " @@ -76,10 +76,16 @@ BEGIN { break; ++i; # + if ($i == "SIOCADDRT" || $i == "SIOCDELRT") { + printf("#if 0\n"); + } if (use_switch) printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i); else printf("\tif (val == %s)\n\t\treturn(\"%s\");\n", $i, $i); + if ($i == "SIOCADDRT" || $i == "SIOCDELRT") { + printf("#endif\n"); + } } END { diff --git a/kdump.tproj/syscalls.c b/kdump.tproj/syscalls.c index 456f002..95ec073 100644 --- a/kdump.tproj/syscalls.c +++ b/kdump.tproj/syscalls.c @@ -1,378 +1,448 @@ /* - * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ + * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * + * @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. + * 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. * - * 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@ * - * @APPLE_LICENSE_HEADER_END@ + * + * System call switch table. + * + * DO NOT EDIT-- this file is automatically generated. + * created from syscalls.master */ -/* Copyright (c) 1992,1995-1999 Apple Computer, Inc. All rights resereved. */ -char *syscallnames[] = { - "syscall", /* 0 = syscall */ - "exit", /* 1 = exit */ - "fork", /* 2 = fork */ - "read", /* 3 = read */ - "write", /* 4 = write */ - "open", /* 5 = open */ - "close", /* 6 = close */ - "wait4", /* 7 = wait4 */ - "obs_creat", /* 8 = old creat */ - "link", /* 9 = link */ - "unlink", /* 10 = unlink */ - "obs_execv", /* 11 = obsolete execv */ - "chdir", /* 12 = chdir */ - "fchdir", /* 13 = fchdir */ - "mknod", /* 14 = mknod */ - "chmod", /* 15 = chmod */ - "chown", /* 16 = chown */ - "obs_break", /* 17 = obsolete break */ - "obs_getfsstat", /* 18 = obsolete getfsstat */ - "old_lseek", /* 19 = old lseek */ - "getpid", /* 20 = getpid */ - "obs_mount", /* 21 = obsolete mount */ - "obs_unmount", /* 22 = obsolete unmount */ - "setuid", /* 23 = setuid */ - "getuid", /* 24 = getuid */ - "geteuid", /* 25 = geteuid */ - "ptrace", /* 26 = ptrace */ - "recvmsg", /* 27 = recvmsg */ - "sendmsg", /* 28 = sendmsg */ - "recvfrom", /* 29 = recvfrom */ - "accept", /* 30 = accept */ - "getpeername", /* 31 = getpeername */ - "getsockname", /* 32 = getsockname */ - "access", /* 33 = access */ - "chflags", /* 34 = chflags */ - "fchflags", /* 35 = fchflags */ - "sync", /* 36 = sync */ - "kill", /* 37 = kill */ - "obs_stat", /* 38 = old stat */ - "getppid", /* 39 = getppid */ - "obs_lstat", /* 40 = old lstat */ - "dup", /* 41 = dup */ - "pipe", /* 42 = pipe */ - "getegid", /* 43 = getegid */ - "profil", /* 44 = profil */ - "ktrace", /* 45 = ktrace */ - "sigaction", /* 46 = sigaction */ - "getgid", /* 47 = getgid */ - "sigprocmask", /* 48 = sigprocmask */ - "getlogin", /* 49 = getlogin */ - "setlogin", /* 50 = setlogin */ - "acct", /* 51 = acct */ - "sigpending", /* 52 = sigpending */ - "sigaltstack", /* 53 = sigaltstack */ - "ioctl", /* 54 = ioctl */ - "reboot", /* 55 = reboot */ - "revoke", /* 56 = revoke */ - "symlink", /* 57 = symlink */ - "readlink", /* 58 = readlink */ - "execve", /* 59 = execve */ - "umask", /* 60 = umask */ - "chroot", /* 61 = chroot */ - "obs_fstat", /* 62 = old fstat */ - "#63", /* 63 = reserved */ - "obs_getpagesize", /* 64 = old getpagesize */ - "msync", /* 65 = msync */ - "vfork", /* 66 = vfork */ - "obs_vread", /* 67 = obsolete vread */ - "obs_vwrite", /* 68 = obsolete vwrite */ - "sbrk", /* 69 = sbrk */ - "sstk", /* 70 = sstk */ - "obs_mmap", /* 71 = old mmap */ - "obs_vadvise", /* 72 = obsolete vadvise */ - "munmap", /* 73 = munmap */ - "mprotect", /* 74 = mprotect */ - "madvise", /* 75 = madvise */ - "#76", /* 76 = obsolete vhangup */ - "#77", /* 77 = obsolete vlimit */ - "mincore", /* 78 = mincore */ - "getgroups", /* 79 = getgroups */ - "setgroups", /* 80 = setgroups */ - "getpgrp", /* 81 = getpgrp */ - "setpgid", /* 82 = setpgid */ - "setitimer", /* 83 = setitimer */ - "old_wait", /* 84 = old wait */ - "obs_swapon", /* 85 = swapon */ - "getitimer", /* 86 = getitimer */ - "obs_gethostname", /* 87 = old gethostname */ - "obs_sethostname", /* 88 = old sethostname */ - "getdtablesize", /* 89 = getdtablesize */ - "dup2", /* 90 = dup2 */ - "#91", /* 91 = getdopt */ - "fcntl", /* 92 = fcntl */ - "select", /* 93 = select */ - "#94", /* 94 = setdopt */ - "fsync", /* 95 = fsync */ - "setpriority", /* 96 = setpriority */ - "socket", /* 97 = socket */ - "connect", /* 98 = connect */ - "obs_accept", /* 99 = old accept */ - "getpriority", /* 100 = getpriority */ - "old_send", /* 101 = old send */ - "old_recv", /* 102 = old recv */ - "sigreturn", /* 103 = sigreturn */ - "bind", /* 104 = bind */ - "setsockopt", /* 105 = setsockopt */ - "listen", /* 106 = listen */ - "#107", /* 107 = obsolete vtimes */ - "obs_sigvec", /* 108 = old sigvec */ - "obs_sigblock", /* 109 = old sigblock */ - "obs_sigsetmask", /* 110 = old sigsetmask */ - "sigsuspend", /* 111 = sigsuspend */ - "obs_sigstack", /* 112 = old sigstack */ - "obs_recvmsg", /* 113 = old recvmsg */ - "obs_sendmsg", /* 114 = old sendmsg */ - "#115", /* 115 = obsolete vtrace */ - "gettimeofday", /* 116 = gettimeofday */ - "getrusage", /* 117 = getrusage */ - "getsockopt", /* 118 = getsockopt */ - "#119", /* 119 = nosys */ - "readv", /* 120 = readv */ - "writev", /* 121 = writev */ - "settimeofday", /* 122 = settimeofday */ - "fchown", /* 123 = fchown */ - "fchmod", /* 124 = fchmod */ - "obs_recvfrom", /* 125 = old recvfrom */ - "obs_setreuid", /* 126 = old setreuid */ - "obs_setregid", /* 127 = old setregid */ - "rename", /* 128 = rename */ - "obs_truncate", /* 129 = old truncate */ - "obs_ftruncate", /* 130 = old ftruncate */ - "flock", /* 131 = flock */ - "mkfifo", /* 132 = mkfifo */ - "sendto", /* 133 = sendto */ - "shutdown", /* 134 = shutdown */ - "socketpair", /* 135 = socketpair */ - "mkdir", /* 136 = mkdir */ - "rmdir", /* 137 = rmdir */ - "utimes", /* 138 = utimes */ - "futimes", /* 139 = futimes */ - "adjtime", /* 140 = adjtime */ - "obs_getpeername", /* 141 = old getpeername */ - "obs_gethostid", /* 142 = old gethostid */ - "#143", /* 143 = old sethostid */ - "obs_getrlimit", /* 144 = old getrlimit */ - "obs_setrlimit", /* 145 = old setrlimit */ - "obs_killpg", /* 146 = old killpg */ - "setsid", /* 147 = setsid */ - "#148", /* 148 = obsolete setquota */ - "#149", /* 149 = obsolete qquota */ - "obs_getsockname", /* 150 = old getsockname */ - "#151", /* 151 = nosys */ - "setprivexec", /* 152 = setprivexec */ - "pread", /* 153 = pread */ - "pwrite", /* 154 = pwrite */ - "nfssvc", /* 155 = nfssvc */ - "getdirentries", /* 156 =getdirentries */ - "statfs", /* 157 = statfs */ - "fstatfs", /* 158 = fstatfs */ - "unmount", /* 159 = unmount */ - "#160", /* 160 = obsolete async_daemon */ - "getfh", /* 161 = getfh */ - "obs_getdomainname",/* 162 = old getdomainname */ - "obs_setdomainname",/* 163 = old setdomainname */ - "#164", /* 164 */ - "quotactl", /* 165 = quotactl */ - "#166", /* 166 = obsolete exportfs */ - "mount", /* 167 = mount */ - "#168", /* 168 = obsolete ustat */ - "#169", /* 169 = nosys */ - "#170", /* 170 = obsolete table */ - "obs_wait3", /* 171 = old wait3 */ - "#172", /* 172 = obsolete rpause */ - "#173", /* 173 = nosys */ - "#174", /* 174 = obsolete getdents */ - "#175", /* 175 = nosys */ - "add_profil", /* 176 = add_profil */ /* NeXT */ - "#177", /* 177 = nosys */ - "#178", /* 178 = nosys */ - "#179", /* 179 = nosys */ - "kdebug_trace", /* 180 = kdebug_trace */ - "setgid", /* 181 = setgid */ - "setegid", /* 182 = setegid */ - "seteuid", /* 183 = seteuid */ - "#184", /* 184 = nosys */ - "#185", /* 185 = nosys */ - "#186", /* 186 = nosys */ - "#187", /* 187 = nosys */ - "stat", /* 188 = stat */ - "fstat", /* 189 = fstat */ - "lstat", /* 190 = lstat */ - "pathconf", /* 191 = pathconf */ - "fpathconf", /* 192 = fpathconf */ - "obs_getfsstat", /* 193 = old getfsstat */ - "getrlimit", /* 194 = getrlimit */ - "setrlimit", /* 195 = setrlimit */ - "getdirentries", /* 196 = getdirentries */ - "mmap", /* 197 = mmap */ - "#198", /* 198 = __syscall */ - "lseek", /* 199 = lseek */ - "truncate", /* 200 = truncate */ - "ftruncate", /* 201 = ftruncate */ - "__sysctl", /* 202 = __sysctl */ - "mlock", /* 203 = mlock */ - "munlock", /* 204 = munlock */ - "undelete", /* 205 = undelete */ - "ATsocket", /* 206 = ATsocket */ - "ATgetmsg", /* 207 = ATgetmsg */ - "ATputmsg", /* 208 = ATputmsg */ - "ATPsndreq", /* 209 = ATPsndreq */ - "ATPsndrsp", /* 210 = ATPsndrsp */ - "ATPgetreq", /* 211 = ATPgetreq */ - "ATPgetrsp", /* 212 = ATPgetrsp */ - "#213", /* 213 = Reserved for AppleTalk */ - "#214", /* 214 = Reserved for AppleTalk */ - "#215", /* 215 = Reserved for AppleTalk */ - "#216", /* 216 = Reserved */ - "#217", /* 217 = Reserved */ - "#218", /* 218 = Reserved */ - "#219", /* 219 = Reserved */ - "getattrlist", /* 220 = getattrlist */ - "setattrlist", /* 221 = setattrlist */ - "getdirentriesattr", /* 222 = getdirentriesattr */ - "exchangedata", /* 223 = exchangedata */ - "checkuseraccess", /* 224 - checkuseraccess */ - "searchfs", /* 225 = searchfs */ - "delete", /* 226 = private delete call */ - "copyfile", /* 227 = copyfile */ - "#228", /* 228 = nosys */ - "#229", /* 229 = nosys */ - "#230", /* 230 = reserved for AFS */ - "watchevent", /* 231 = watchevent */ - "waitevent", /* 232 = waitevent */ - "modwatch", /* 233 = modwatch */ - "#234", /* 234 = nosys */ - "#235", /* 235 = nosys */ - "#236", /* 236 = nosys */ - "#237", /* 237 = nosys */ - "#238", /* 238 = nosys */ - "#239", /* 239 = nosys */ - "#240", /* 240 = nosys */ - "#241", /* 241 = nosys */ - "fsctl", /* 242 = fsctl */ - "#243", /* 243 = nosys */ - "#244", /* 244 = nosys */ - "#245", /* 245 = nosys */ - "#246", /* 246 = nosys */ - "#247", /* 247 = nosys */ - "#248", /* 248 = nosys */ - "#249", /* 249 = nosys */ - "minherit", /* 250 = minherit */ - "semsys", /* 251 = semsys */ - "msgsys", /* 252 = msgsys */ - "shmsys", /* 253 = shmsys */ - "semctl", /* 254 = semctl */ - "semget", /* 255 = semget */ - "semop", /* 256 = semop */ - "semconfig", /* 257 = semconfig */ - "msgctl", /* 258 = msgctl */ - "msgget", /* 259 = msgget */ - "msgsnd", /* 260 = msgsnd */ - "msgrcv", /* 261 = msgrcv */ - "shmat", /* 262 = shmat */ - "shmctl", /* 263 = shmctl */ - "shmdt", /* 264 = shmdt */ - "shmget", /* 265 = shmget */ - "shm_open", /* 266 = shm_open */ - "shm_unlink", /* 267 = shm_unlink */ - "sem_open", /* 268 = sem_open */ - "sem_close", /* 269 = sem_close */ - "sem_unlink", /* 270 = sem_unlink */ - "sem_wait", /* 271 = sem_wait */ - "sem_trywait", /* 272 = sem_trywait */ - "sem_post", /* 273 = sem_post */ - "sem_getvalue", /* 274 = sem_getvalue */ - "sem_init", /* 275 = sem_init */ - "sem_destroy", /* 276 = sem_destroy */ - "#277", /* 277 = nosys */ - "#278", /* 278 = nosys */ - "#279", /* 279 = nosys */ - "#280", /* 280 = nosys */ - "#281", /* 281 = nosys */ - "#282", /* 282 = nosys */ - "#283", /* 283 = nosys */ - "#284", /* 284 = nosys */ - "#285", /* 285 = nosys */ - "#286", /* 286 = nosys */ - "#287", /* 287 = nosys */ - "#288", /* 288 = nosys */ - "#289", /* 289 = nosys */ - "#290", /* 290 = nosys */ - "#291", /* 291 = nosys */ - "#292", /* 292 = nosys */ - "#293", /* 293 = nosys */ - "#294", /* 294 = nosys */ - "#295", /* 295 = nosys */ - "load_shared_file", /* 296 = load_shared_file */ - "reset_shared_file", /* 297 = reset_shared_file */ - "new_system_shared_regions", /* 298 = new_system_shared_regions */ - "#299", /* 299 = nosys */ - "#300", /* 300 = modnext */ - "#301", /* 301 = modstat */ - "#302", /* 302 = modfnext */ - "#303", /* 303 = modfind */ - "#304", /* 304 = kldload */ - "#305", /* 305 = kldunload */ - "#306", /* 306 = kldfind */ - "#307", /* 307 = kldnext */ - "#308", /* 308 = kldstat */ - "#309", /* 309 = kldfirstmod */ - "#310", /* 310 = getsid */ - "#311", /* 311 = setresuid */ - "#312", /* 312 = setresgid */ - "#313", /* 313 = obsolete signanosleep */ - "#314", /* 314 = aio_return */ - "#315", /* 315 = aio_suspend */ - "#316", /* 316 = aio_cancel */ - "#317", /* 317 = aio_error */ - "#318", /* 318 = aio_read */ - "#319", /* 319 = aio_write */ - "#320", /* 320 = lio_listio */ - "#321", /* 321 = yield */ - "#322", /* 322 = thr_sleep */ - "#323", /* 323 = thr_wakeup */ - "mlockall", /* 324 = mlockall */ - "munlockall", /* 325 = munlockall */ - "#326", /* 326 */ - "issetugid", /* 327 = issetugid */ - "__pthread_kill", /* 328 = __pthread_kill */ - "pthread_sigmask", /* 329 = pthread_sigmask */ - "sigwait", /* 330 = sigwait */ - "#331", /* 331 */ - "#332", /* 332 */ - "#333", /* 333 */ - "#334", /* 334 */ - "utrace", /* 335 = utrace */ - "#336", /* 336 */ - "#337", /* 337 */ - "#338", /* 338 */ - "#339", /* 339 */ - "#340", /* 340 */ - "#341", /* 341 */ - "#342", /* 342 */ - "#343", /* 343 */ - "#344", /* 344 */ - "#345", /* 345 */ - "#346", /* 346 */ - "#347", /* 347 */ - "#348", /* 348 */ - "#349" /* 349 */ +const char *syscallnames[] = { + "syscall", /* 0 = syscall indirect syscall */ + "exit", /* 1 = exit */ + "fork", /* 2 = fork */ + "read", /* 3 = read */ + "write", /* 4 = write */ + "open", /* 5 = open */ + "close", /* 6 = close */ + "wait4", /* 7 = wait4 */ + "#8", /* 8 = old creat */ + "link", /* 9 = link */ + "unlink", /* 10 = unlink */ + "#11", /* 11 = old execv */ + "chdir", /* 12 = chdir */ + "fchdir", /* 13 = fchdir */ + "mknod", /* 14 = mknod */ + "chmod", /* 15 = chmod */ + "chown", /* 16 = chown */ + "obreak", /* 17 = obreak old break */ +#if COMPAT_GETFSSTAT + "ogetfsstat", /* 18 = ogetfsstat */ +#else + "getfsstat", /* 18 = getfsstat */ +#endif + "#19", /* 19 = old lseek */ + "getpid", /* 20 = getpid */ + "#21", /* 21 = old mount */ + "#22", /* 22 = old umount */ + "setuid", /* 23 = setuid */ + "getuid", /* 24 = getuid */ + "geteuid", /* 25 = geteuid */ + "ptrace", /* 26 = ptrace */ + "recvmsg", /* 27 = recvmsg */ + "sendmsg", /* 28 = sendmsg */ + "recvfrom", /* 29 = recvfrom */ + "accept", /* 30 = accept */ + "getpeername", /* 31 = getpeername */ + "getsockname", /* 32 = getsockname */ + "access", /* 33 = access */ + "chflags", /* 34 = chflags */ + "fchflags", /* 35 = fchflags */ + "sync", /* 36 = sync */ + "kill", /* 37 = kill */ + "#38", /* 38 = old stat */ + "getppid", /* 39 = getppid */ + "#40", /* 40 = old lstat */ + "dup", /* 41 = dup */ + "pipe", /* 42 = pipe */ + "getegid", /* 43 = getegid */ + "profil", /* 44 = profil */ + "ktrace", /* 45 = ktrace */ + "sigaction", /* 46 = sigaction */ + "getgid", /* 47 = getgid */ + "sigprocmask", /* 48 = sigprocmask */ + "getlogin", /* 49 = getlogin */ + "setlogin", /* 50 = setlogin */ + "acct", /* 51 = acct */ + "sigpending", /* 52 = sigpending */ + "sigaltstack", /* 53 = sigaltstack */ + "ioctl", /* 54 = ioctl */ + "reboot", /* 55 = reboot */ + "revoke", /* 56 = revoke */ + "symlink", /* 57 = symlink */ + "readlink", /* 58 = readlink */ + "execve", /* 59 = execve */ + "umask", /* 60 = umask */ + "chroot", /* 61 = chroot */ + "#62", /* 62 = old fstat */ + "#63", /* 63 = used internally , reserved */ + "#64", /* 64 = old getpagesize */ + "msync", /* 65 = msync */ + "vfork", /* 66 = vfork */ + "#67", /* 67 = old vread */ + "#68", /* 68 = old vwrite */ + "sbrk", /* 69 = sbrk */ + "sstk", /* 70 = sstk */ + "#71", /* 71 = old mmap */ + "ovadvise", /* 72 = ovadvise old vadvise */ + "munmap", /* 73 = munmap */ + "mprotect", /* 74 = mprotect */ + "madvise", /* 75 = madvise */ + "#76", /* 76 = old vhangup */ + "#77", /* 77 = old vlimit */ + "mincore", /* 78 = mincore */ + "getgroups", /* 79 = getgroups */ + "setgroups", /* 80 = setgroups */ + "getpgrp", /* 81 = getpgrp */ + "setpgid", /* 82 = setpgid */ + "setitimer", /* 83 = setitimer */ + "#84", /* 84 = old wait */ + "swapon", /* 85 = swapon */ + "getitimer", /* 86 = getitimer */ + "#87", /* 87 = old gethostname */ + "#88", /* 88 = old sethostname */ + "getdtablesize", /* 89 = getdtablesize */ + "dup2", /* 90 = dup2 */ + "#91", /* 91 = old getdopt */ + "fcntl", /* 92 = fcntl */ + "select", /* 93 = select */ + "#94", /* 94 = old setdopt */ + "fsync", /* 95 = fsync */ + "setpriority", /* 96 = setpriority */ + "socket", /* 97 = socket */ + "connect", /* 98 = connect */ + "#99", /* 99 = old accept */ + "getpriority", /* 100 = getpriority */ + "#101", /* 101 = old send */ + "#102", /* 102 = old recv */ +#ifdef __ppc__ + "#103", /* 103 = old sigreturn */ +#else + "sigreturn", /* 103 = sigreturn */ +#endif + "bind", /* 104 = bind */ + "setsockopt", /* 105 = setsockopt */ + "listen", /* 106 = listen */ + "#107", /* 107 = old vtimes */ + "#108", /* 108 = old sigvec */ + "#109", /* 109 = old sigblock */ + "#110", /* 110 = old sigsetmask */ + "sigsuspend", /* 111 = sigsuspend */ + "#112", /* 112 = old sigstack */ + "#113", /* 113 = old recvmsg */ + "#114", /* 114 = old sendmsg */ + "#115", /* 115 = old vtrace */ +#ifdef __ppc__ + "ppc_gettimeofday", /* 116 = ppc_gettimeofday */ +#else + "gettimeofday", /* 116 = gettimeofday */ +#endif + "getrusage", /* 117 = getrusage */ + "getsockopt", /* 118 = getsockopt */ + "#119", /* 119 = old resuba */ + "readv", /* 120 = readv */ + "writev", /* 121 = writev */ + "settimeofday", /* 122 = settimeofday */ + "fchown", /* 123 = fchown */ + "fchmod", /* 124 = fchmod */ + "#125", /* 125 = old recvfrom */ + "#126", /* 126 = old setreuid */ + "#127", /* 127 = old setregid */ + "rename", /* 128 = rename */ + "#129", /* 129 = old truncate */ + "#130", /* 130 = old ftruncate */ + "flock", /* 131 = flock */ + "mkfifo", /* 132 = mkfifo */ + "sendto", /* 133 = sendto */ + "shutdown", /* 134 = shutdown */ + "socketpair", /* 135 = socketpair */ + "mkdir", /* 136 = mkdir */ + "rmdir", /* 137 = rmdir */ + "utimes", /* 138 = utimes */ + "futimes", /* 139 = futimes */ + "adjtime", /* 140 = adjtime */ + "#141", /* 141 = old getpeername */ + "#142", /* 142 = old gethostid */ + "#143", /* 143 = old sethostid */ + "#144", /* 144 = old getrlimit */ + "#145", /* 145 = old setrlimit */ + "#146", /* 146 = old killpg */ + "setsid", /* 147 = setsid */ + "#148", /* 148 = old setquota */ + "#149", /* 149 = old qquota */ + "#150", /* 150 = old getsockname */ + "getpgid", /* 151 = getpgid */ + "setprivexec", /* 152 = setprivexec */ + "pread", /* 153 = pread */ + "pwrite", /* 154 = pwrite */ +#if NFSSERVER + "nfssvc", /* 155 = nfssvc */ +#else + "#155", /* 155 = */ +#endif + "#156", /* 156 = old getdirentries */ + "statfs", /* 157 = statfs */ + "fstatfs", /* 158 = fstatfs */ + "unmount", /* 159 = unmount */ + "#160", /* 160 = old async_daemon */ +#if NFSCLIENT + "getfh", /* 161 = getfh */ +#else + "#161", /* 161 = */ +#endif + "#162", /* 162 = old getdomainname */ + "#163", /* 163 = old setdomainname */ + "#164", /* 164 = */ + "quotactl", /* 165 = quotactl */ + "#166", /* 166 = old exportfs */ + "mount", /* 167 = mount */ + "#168", /* 168 = old ustat */ + "#169", /* 169 = */ + "table", /* 170 = table old table */ + "#171", /* 171 = old wait3 */ + "#172", /* 172 = old rpause */ + "waitid", /* 173 = waitid */ + "#174", /* 174 = old getdents */ + "#175", /* 175 = old gc_control */ + "add_profil", /* 176 = add_profil */ + "#177", /* 177 = */ + "#178", /* 178 = */ + "#179", /* 179 = */ + "kdebug_trace", /* 180 = kdebug_trace */ + "setgid", /* 181 = setgid */ + "setegid", /* 182 = setegid */ + "seteuid", /* 183 = seteuid */ +#ifdef __ppc__ + "sigreturn", /* 184 = sigreturn */ +#else + "#184", /* 184 = */ +#endif + "#185", /* 185 = */ + "#186", /* 186 = */ + "#187", /* 187 = */ + "stat", /* 188 = stat */ + "fstat", /* 189 = fstat */ + "lstat", /* 190 = lstat */ + "pathconf", /* 191 = pathconf */ + "fpathconf", /* 192 = fpathconf */ +#if COMPAT_GETFSSTAT + "getfsstat", /* 193 = getfsstat */ +#else + "#193", /* 193 = */ +#endif + "getrlimit", /* 194 = getrlimit */ + "setrlimit", /* 195 = setrlimit */ + "getdirentries", /* 196 = getdirentries */ + "mmap", /* 197 = mmap */ + "#198", /* 198 = __syscall */ + "lseek", /* 199 = lseek */ + "truncate", /* 200 = truncate */ + "ftruncate", /* 201 = ftruncate */ + "__sysctl", /* 202 = __sysctl */ + "mlock", /* 203 = mlock */ + "munlock", /* 204 = munlock */ + "undelete", /* 205 = undelete */ +#ifdef __ppc__ + "ATsocket", /* 206 = ATsocket */ + "ATgetmsg", /* 207 = ATgetmsg */ + "ATputmsg", /* 208 = ATputmsg */ + "ATPsndreq", /* 209 = ATPsndreq */ + "ATPsndrsp", /* 210 = ATPsndrsp */ + "ATPgetreq", /* 211 = ATPgetreq */ + "ATPgetrsp", /* 212 = ATPgetrsp */ + "#213", /* 213 = Reserved for AppleTalk */ +#else + "ATsocket", /* 206 = ATsocket */ + "ATgetmsg", /* 207 = ATgetmsg */ + "ATputmsg", /* 208 = ATputmsg */ + "ATPsndreq", /* 209 = ATPsndreq */ + "ATPsndrsp", /* 210 = ATPsndrsp */ + "ATPgetreq", /* 211 = ATPgetreq */ + "ATPgetrsp", /* 212 = ATPgetrsp */ + "#213", /* 213 = Reserved for AppleTalk */ +#endif /* __ppc__ */ + "kqueue_from_portset_np", /* 214 = kqueue_from_portset_np */ + "kqueue_portset_np", /* 215 = kqueue_portset_np */ + "mkcomplex", /* 216 = mkcomplex soon to be obsolete */ + "statv", /* 217 = statv soon to be obsolete */ + "lstatv", /* 218 = lstatv soon to be obsolete */ + "fstatv", /* 219 = fstatv soon to be obsolete */ + "getattrlist", /* 220 = getattrlist */ + "setattrlist", /* 221 = setattrlist */ + "getdirentriesattr", /* 222 = getdirentriesattr */ + "exchangedata", /* 223 = exchangedata */ +#ifdef __APPLE_API_OBSOLETE + "checkuseraccess", /* 224 = checkuseraccess */ +#else + "#224", /* 224 = HFS checkuseraccess check access to a file */ +#endif /* __APPLE_API_OBSOLETE */ + "searchfs", /* 225 = searchfs */ + "delete", /* 226 = delete private delete ( Carbon semantics ) */ + "copyfile", /* 227 = copyfile */ + "#228", /* 228 = */ + "#229", /* 229 = */ + "poll", /* 230 = poll */ + "watchevent", /* 231 = watchevent */ + "waitevent", /* 232 = waitevent */ + "modwatch", /* 233 = modwatch */ + "getxattr", /* 234 = getxattr */ + "fgetxattr", /* 235 = fgetxattr */ + "setxattr", /* 236 = setxattr */ + "fsetxattr", /* 237 = fsetxattr */ + "removexattr", /* 238 = removexattr */ + "fremovexattr", /* 239 = fremovexattr */ + "listxattr", /* 240 = listxattr */ + "flistxattr", /* 241 = flistxattr */ + "fsctl", /* 242 = fsctl */ + "#243", /* 243 = */ + "#244", /* 244 = */ + "#245", /* 245 = */ + "#246", /* 246 = */ +#if NFSCLIENT + "nfsclnt", /* 247 = nfsclnt */ + "fhopen", /* 248 = fhopen */ +#else + "#247", /* 247 = */ + "#248", /* 248 = */ +#endif + "#249", /* 249 = */ + "minherit", /* 250 = minherit */ + "semsys", /* 251 = semsys */ + "msgsys", /* 252 = msgsys */ + "shmsys", /* 253 = shmsys */ + "semctl", /* 254 = semctl */ + "semget", /* 255 = semget */ + "semop", /* 256 = semop */ + "semconfig", /* 257 = semconfig */ + "msgctl", /* 258 = msgctl */ + "msgget", /* 259 = msgget */ + "msgsnd", /* 260 = msgsnd */ + "msgrcv", /* 261 = msgrcv */ + "shmat", /* 262 = shmat */ + "shmctl", /* 263 = shmctl */ + "shmdt", /* 264 = shmdt */ + "shmget", /* 265 = shmget */ + "shm_open", /* 266 = shm_open */ + "shm_unlink", /* 267 = shm_unlink */ + "sem_open", /* 268 = sem_open */ + "sem_close", /* 269 = sem_close */ + "sem_unlink", /* 270 = sem_unlink */ + "sem_wait", /* 271 = sem_wait */ + "sem_trywait", /* 272 = sem_trywait */ + "sem_post", /* 273 = sem_post */ + "sem_getvalue", /* 274 = sem_getvalue */ + "sem_init", /* 275 = sem_init */ + "sem_destroy", /* 276 = sem_destroy */ + "open_extended", /* 277 = open_extended */ + "umask_extended", /* 278 = umask_extended */ + "stat_extended", /* 279 = stat_extended */ + "lstat_extended", /* 280 = lstat_extended */ + "fstat_extended", /* 281 = fstat_extended */ + "chmod_extended", /* 282 = chmod_extended */ + "fchmod_extended", /* 283 = fchmod_extended */ + "access_extended", /* 284 = access_extended */ + "settid", /* 285 = settid */ + "gettid", /* 286 = gettid */ + "setsgroups", /* 287 = setsgroups */ + "getsgroups", /* 288 = getsgroups */ + "setwgroups", /* 289 = setwgroups */ + "getwgroups", /* 290 = getwgroups */ + "mkfifo_extended", /* 291 = mkfifo_extended */ + "mkdir_extended", /* 292 = mkdir_extended */ + "identitysvc", /* 293 = identitysvc */ + "#294", /* 294 = */ + "#295", /* 295 = */ + "load_shared_file", /* 296 = load_shared_file */ + "reset_shared_file", /* 297 = reset_shared_file */ + "new_system_shared_regions", /* 298 = new_system_shared_regions */ + "shared_region_map_file_np", /* 299 = shared_region_map_file_np */ + "shared_region_make_private_np", /* 300 = shared_region_make_private_np */ + "#301", /* 301 = */ + "#302", /* 302 = */ + "#303", /* 303 = */ + "#304", /* 304 = */ + "#305", /* 305 = */ + "#306", /* 306 = */ + "#307", /* 307 = */ + "#308", /* 308 = */ + "#309", /* 309 = */ + "getsid", /* 310 = getsid */ + "#311", /* 311 = */ + "#312", /* 312 = */ + "aio_fsync", /* 313 = aio_fsync */ + "aio_return", /* 314 = aio_return */ + "aio_suspend", /* 315 = aio_suspend */ + "aio_cancel", /* 316 = aio_cancel */ + "aio_error", /* 317 = aio_error */ + "aio_read", /* 318 = aio_read */ + "aio_write", /* 319 = aio_write */ + "lio_listio", /* 320 = lio_listio */ + "#321", /* 321 = */ + "#322", /* 322 = */ + "#323", /* 323 = */ + "mlockall", /* 324 = mlockall */ + "munlockall", /* 325 = munlockall */ + "#326", /* 326 = */ + "issetugid", /* 327 = issetugid */ + "__pthread_kill", /* 328 = __pthread_kill */ + "pthread_sigmask", /* 329 = pthread_sigmask */ + "sigwait", /* 330 = sigwait */ + "__disable_threadsignal", /* 331 = __disable_threadsignal */ + "__pthread_markcancel", /* 332 = __pthread_markcancel */ + "__pthread_canceled", /* 333 = __pthread_canceled */ + "__semwait_signal", /* 334 = __semwait_signal */ + "utrace", /* 335 = utrace */ + "#336", /* 336 = */ + "#337", /* 337 = */ + "#338", /* 338 = */ + "#339", /* 339 = */ + "#340", /* 340 = */ + "#341", /* 341 = */ + "#342", /* 342 = */ + "#343", /* 343 = */ + "#344", /* 344 = */ + "#345", /* 345 = */ + "#346", /* 346 = */ + "#347", /* 347 = */ + "#348", /* 348 = */ + "#349", /* 349 = */ + "audit", /* 350 = audit */ + "auditon", /* 351 = auditon */ + "#352", /* 352 = */ + "getauid", /* 353 = getauid */ + "setauid", /* 354 = setauid */ + "getaudit", /* 355 = getaudit */ + "setaudit", /* 356 = setaudit */ + "getaudit_addr", /* 357 = getaudit_addr */ + "setaudit_addr", /* 358 = setaudit_addr */ + "auditctl", /* 359 = auditctl */ + "#360", /* 360 = */ + "#361", /* 361 = */ + "kqueue", /* 362 = kqueue */ + "kevent", /* 363 = kevent */ + "lchown", /* 364 = lchown */ + "#365", /* 365 = */ + "#366", /* 366 = */ + "#367", /* 367 = */ + "#368", /* 368 = */ + "#369", /* 369 = */ }; diff --git a/kgmon.tproj/Makefile.postamble b/kgmon.tproj/Makefile.postamble index c2d2690..069e5cc 100644 --- a/kgmon.tproj/Makefile.postamble +++ b/kgmon.tproj/Makefile.postamble @@ -111,3 +111,7 @@ # 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: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 kgmon.8 $(DSTROOT)/usr/share/man/man8 diff --git a/kgmon.tproj/kgmon.c b/kgmon.tproj/kgmon.c index 3039a89..47161c0 100644 --- a/kgmon.tproj/kgmon.c +++ b/kgmon.tproj/kgmon.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/ktrace.tproj/Makefile b/ktrace.tproj/Makefile index 254b43a..5991b29 100644 --- a/ktrace.tproj/Makefile +++ b/ktrace.tproj/Makefile @@ -18,6 +18,7 @@ CFILES = ktrace.c subr.c OTHERSRCS = Makefile.preamble Makefile Makefile.postamble ktrace.1 +HEADER_PATHS = -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles CODE_GEN_STYLE = DYNAMIC diff --git a/ktrace.tproj/ktrace.c b/ktrace.tproj/ktrace.c index 74484ce..50e3b2f 100644 --- a/ktrace.tproj/ktrace.c +++ b/ktrace.tproj/ktrace.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@ */ @@ -55,17 +54,19 @@ * SUCH DAMAGE. */ +#include + #ifndef lint -static char copyright[] = +__unused static char copyright[] = "@(#) Copyright (c) 1988, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint #if 0 -static char sccsid[] = "@(#)ktrace.c 8.1 (Berkeley) 6/6/93"; +__unused static char sccsid[] = "@(#)ktrace.c 8.1 (Berkeley) 6/6/93"; #endif -static const char rcsid[] = +__unused static const char rcsid[] = "$FreeBSD: src/usr.bin/ktrace/ktrace.c,v 1.12.2.3 2001/07/11 00:29:27 mikeh Exp $"; #endif /* not lint */ @@ -79,19 +80,27 @@ static const char rcsid[] = #include #include +#include #include #include "ktrace.h" void no_ktrace __P((int)); void usage __P((void)); +int rpid(char *p); -main(argc, argv) - int argc; - char **argv; +int +main(int argc, char *argv[]) { enum { NOTSET, CLEAR, CLEARALL } clear; - int append, ch, fd, inherit, ops, pid, pidset, trpoints; + int append; + int ch; + int fd; + int inherit; + int ops; + int pid = 1; /* protected by pidset */ + int pidset; + int trpoints; char *tracefile; mode_t omask; struct stat sb; @@ -190,8 +199,8 @@ main(argc, argv) exit(0); } -rpid(p) - char *p; +int +rpid(char *p) { static int first; @@ -207,7 +216,7 @@ rpid(p) } void -usage() +usage(void) { (void)fprintf(stderr, "%s\n%s\n", "usage: ktrace [-aCcdi] [-f trfile] [-g pgrp | -p pid] [-t cnisuw]", @@ -216,8 +225,7 @@ usage() } void -no_ktrace(sig) - int sig; +no_ktrace(int sig) { (void)fprintf(stderr, "error:\tktrace() system call not supported in the running kernel\n\tre-compile kernel with 'options KTRACE'\n"); diff --git a/ktrace.tproj/ktrace.h b/ktrace.tproj/ktrace.h index 9f6431a..2d96f7e 100644 --- a/ktrace.tproj/ktrace.h +++ b/ktrace.tproj/ktrace.h @@ -39,3 +39,12 @@ #define ALL_POINTS (DEF_POINTS | KTRFAC_CSW) #define DEF_TRACEFILE "ktrace.out" + +/* + * External function declarations + */ +/* subr.c */ +int getpoints(char *s); +void timevaladd(struct timeval *t1, struct timeval *t2); +void timevalsub(struct timeval *t1, struct timeval *t2); +void timevalfix(struct timeval *t1); diff --git a/ktrace.tproj/subr.c b/ktrace.tproj/subr.c index e5186dd..be7da68 100644 --- a/ktrace.tproj/subr.c +++ b/ktrace.tproj/subr.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@ */ @@ -74,8 +73,8 @@ static const char rcsid[] = #include "ktrace.h" -getpoints(s) - char *s; +int +getpoints(char *s) { int facs = 0; @@ -110,24 +109,24 @@ getpoints(s) return (facs); } -timevaladd(t1, t2) - struct timeval *t1, *t2; +void +timevaladd(struct timeval *t1, struct timeval *t2) { t1->tv_sec += t2->tv_sec; t1->tv_usec += t2->tv_usec; timevalfix(t1); } -timevalsub(t1, t2) - struct timeval *t1, *t2; +void +timevalsub(struct timeval *t1, struct timeval *t2) { t1->tv_sec -= t2->tv_sec; t1->tv_usec -= t2->tv_usec; timevalfix(t1); } -timevalfix(t1) - struct timeval *t1; +void +timevalfix(struct timeval *t1) { if (t1->tv_usec < 0) { t1->tv_sec--; diff --git a/latency.tproj/latency.c b/latency.tproj/latency.c index 0244241..3682b85 100644 --- a/latency.tproj/latency.c +++ b/latency.tproj/latency.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@ */ @@ -712,7 +711,6 @@ char *argv[]; void init_code_file(); void do_kernel_nm(); void open_logfile(); - void mk_wait_until(); my_policy = THREAD_STANDARD_POLICY; policy_name = "TIMESHARE"; @@ -898,7 +896,7 @@ char *argv[]; timestamp1 = mach_absolute_time(); adeadline = timestamp1 + adelay; - mk_wait_until(adeadline); + mach_wait_until(adeadline); timestamp2 = mach_absolute_time(); start = timestamp1; diff --git a/login.tproj/Makefile b/login.tproj/Makefile index 66d930a..5784e64 100644 --- a/login.tproj/Makefile +++ b/login.tproj/Makefile @@ -25,7 +25,7 @@ MAKEFILE = tool.make NEXTSTEP_INSTALLDIR = /usr/bin WINDOWS_INSTALLDIR = /usr/bin PDO_UNIX_INSTALLDIR = /usr/bin -LIBS = -lpam -lpam_misc +LIBS = -lbsm -lpam -lpam_misc DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) diff --git a/login.tproj/PB.project b/login.tproj/PB.project index 5ee51ca..04af4a8 100644 --- a/login.tproj/PB.project +++ b/login.tproj/PB.project @@ -3,7 +3,7 @@ FILESTABLE = { C_FILES = (); H_FILES = (pathnames.h); - OTHER_LIBS = (); + OTHER_LIBS = (bsm, pam, "pam_misc"); OTHER_LINKED = (klogin.c, login.c); OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, login.1); SUBPROJECTS = (); diff --git a/login.tproj/klogin.c b/login.tproj/klogin.c index ed9444d..3426d9c 100644 --- a/login.tproj/klogin.c +++ b/login.tproj/klogin.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/login.tproj/login.c b/login.tproj/login.c index 291b760..09909c9 100644 --- a/login.tproj/login.c +++ b/login.tproj/login.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@ */ @@ -55,10 +54,10 @@ * SUCH DAMAGE. */ -#ifndef lint +#if 0 static char copyright[] = "@(#) Copyright (c) Apple Computer, Inc. 1997\n\n"; -#endif /* not lint */ +#endif /* * login [ name ] @@ -88,6 +87,15 @@ static char copyright[] = #include #include +#include +#include +#include +#include +#include + +#include +#include + #ifdef USE_PAM #include #include @@ -108,10 +116,17 @@ void timedout __P((int)); #ifdef KERBEROS int klogin __P((struct passwd *, char *, char *, char *)); #endif +void au_success(); +void au_fail(char *, int); + extern void login __P((struct utmp *)); +static void bail(int, int); +static void refused(const char *, const char *, int); #define TTYGRPNAME "tty" /* name of group to own ttys */ +#define NO_SLEEP_EXIT 0 +#define SLEEP_EXIT 5 /* * This bounds the time given to login. Not a define so it can @@ -129,6 +144,18 @@ int authok; struct passwd *pwd; int failures; char term[64], *hostname, *username = NULL, *tty; +#ifdef USE_PAM +static pam_handle_t *pamh = NULL; +static struct pam_conv conv = { misc_conv, NULL }; +static int pam_err; +static int pam_silent = PAM_SILENT; +static int pam_cred_established; +static int pam_session_established; +#endif /* USE_PAM */ +int hflag; + +#define NA_EVENT_STR_SIZE 25 +au_tid_t tid; int main(argc, argv) @@ -138,22 +165,24 @@ main(argc, argv) extern char **environ; struct group *gr; struct stat st; - struct timeval tp; struct utmp utmp; - int ask, ch, cnt, oflag = 0, fflag, hflag, pflag, quietlog, rootlogin = 0, rval; + int ask, ch, cnt, oflag = 0, fflag, pflag, quietlog, rootlogin = 0; uid_t uid; uid_t euid; gid_t egid; - char *domain, *p, *salt, *ttyn; + char *domain, *p, *ttyn; char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10]; char localhost[MAXHOSTNAMELEN]; #ifdef USE_PAM - pam_handle_t *pamh = NULL; - struct pam_conv conv = { misc_conv, NULL }; char **pmenv; pid_t pid; +#else + int rval; + char *salt; #endif + char auditsuccess = 1; + (void)signal(SIGALRM, timedout); (void)alarm(timeout); (void)signal(SIGQUIT, SIG_IGN); @@ -229,27 +258,44 @@ main(argc, argv) else tty = ttyn; + /* Set the terminal id */ + audit_set_terminal_id(&tid); + if (fstat(STDIN_FILENO, &st) < 0) { + fprintf(stderr, "login: Unable to stat terminal\n"); + au_fail("Unable to stat terminal", 1); + exit(-1); + } + if (S_ISCHR(st.st_mode)) { + tid.port = st.st_rdev; + } else { + tid.port = 0; + } + #ifdef USE_PAM - rval = pam_start("login", username, &conv, &pamh); - if( rval != PAM_SUCCESS ) { - fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, rval)); + pam_err = pam_start("login", username, &conv, &pamh); + if( pam_err != PAM_SUCCESS ) { + fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, pam_err)); + au_fail("PAM Error", 1); exit(1); } - rval = pam_set_item(pamh, PAM_TTY, tty); - if( rval != PAM_SUCCESS ) { - fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, rval)); + pam_err = pam_set_item(pamh, PAM_TTY, tty); + if( pam_err != PAM_SUCCESS ) { + fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, pam_err)); + au_fail("PAM Error", 1); exit(1); } - rval = pam_set_item(pamh, PAM_RHOST, hostname); - if( rval != PAM_SUCCESS ) { - fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, rval)); + pam_err = pam_set_item(pamh, PAM_RHOST, hostname); + if( pam_err != PAM_SUCCESS ) { + fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, pam_err)); + au_fail("PAM Error", 1); exit(1); } - rval = pam_set_item(pamh, PAM_USER_PROMPT, "login: "); - if( rval != PAM_SUCCESS ) { - fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, rval)); + pam_err = pam_set_item(pamh, PAM_USER_PROMPT, "login: "); + if( pam_err != PAM_SUCCESS ) { + fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, pam_err)); + au_fail("PAM Error", 1); exit(1); } @@ -261,14 +307,20 @@ main(argc, argv) rootlogin = 1; if( (pwd != NULL) && fflag && ((uid == 0) || (uid == pwd->pw_uid)) ){ - rval = 0; + pam_err = 0; + auditsuccess = 0; /* we've simply opened a terminal window */ } else { - rval = pam_authenticate(pamh, 0); - while( (!oflag) && (cnt++ < 10) && ((rval == PAM_AUTH_ERR) || - (rval == PAM_USER_UNKNOWN) || - (rval == PAM_CRED_INSUFFICIENT) || - (rval == PAM_AUTHINFO_UNAVAIL))) { + pam_err = pam_authenticate(pamh, 0); + while( (!oflag) && (cnt++ < 10) && ((pam_err == PAM_AUTH_ERR) || + (pam_err == PAM_USER_UNKNOWN) || + (pam_err == PAM_CRED_INSUFFICIENT) || + (pam_err == PAM_AUTHINFO_UNAVAIL))) { + /* + * we are not exiting here, but this corresponds to + * a failed login event, so set exitstatus to 1 + */ + au_fail("Login incorrect", 1); badlogin(username); printf("Login incorrect\n"); rootlogin = 0; @@ -277,39 +329,43 @@ main(argc, argv) if( (pwd != NULL) && (pwd->pw_uid == 0) ) rootlogin = 1; pam_set_item(pamh, PAM_USER, username); - rval = pam_authenticate(pamh, 0); + pam_err = pam_authenticate(pamh, 0); } - if( rval != PAM_SUCCESS ) { + if( pam_err != PAM_SUCCESS ) { pam_get_item(pamh, PAM_USER, (void *)&username); badlogin(username); printf("Login incorrect\n"); + au_fail("Login incorrect", 1); exit(1); } - rval = pam_acct_mgmt(pamh, 0); - if( rval == PAM_NEW_AUTHTOK_REQD ) { - rval = pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK); + pam_err = pam_acct_mgmt(pamh, 0); + if( pam_err == PAM_NEW_AUTHTOK_REQD ) { + pam_err = pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK); } - if( rval != PAM_SUCCESS ) { - fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, rval)); + if( pam_err != PAM_SUCCESS ) { + fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, pam_err)); + au_fail("PAM error", 1); exit(1); } } - rval = pam_get_item(pamh, PAM_USER, (void *)&username); - if( (rval == PAM_SUCCESS) && username && *username) + pam_err = pam_get_item(pamh, PAM_USER, (void *)&username); + if( (pam_err == PAM_SUCCESS) && username && *username) pwd = getpwnam(username); - rval = pam_open_session(pamh, 0); - if( rval != PAM_SUCCESS ) { - fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, rval)); + pam_err = pam_open_session(pamh, 0); + if( pam_err != PAM_SUCCESS ) { + fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, pam_err)); + au_fail("PAM error", 1); exit(1); } - rval = pam_setcred(pamh, PAM_ESTABLISH_CRED); - if( rval != PAM_SUCCESS ) { - fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, rval)); + pam_err = pam_setcred(pamh, PAM_ESTABLISH_CRED); + if( pam_err != PAM_SUCCESS ) { + fprintf(stderr, "login: PAM Error: %s\n", pam_strerror(pamh, pam_err)); + au_fail("PAM error", 1); exit(1); } @@ -337,8 +393,9 @@ main(argc, argv) * for nonexistent name (mistyped username). */ if (failures && strcmp(tbuf, username)) { - if (failures > (pwd ? 0 : 1)) + if (failures > (pwd ? 0 : 1)) { badlogin(tbuf); + } failures = 0; } (void)strcpy(tbuf, username); @@ -401,6 +458,7 @@ main(argc, argv) syslog(LOG_NOTICE, "LOGIN %s REFUSED ON TTY %s", pwd->pw_name, tty); + au_fail("Login refused on terminal", 0); continue; } @@ -413,8 +471,10 @@ main(argc, argv) if (++cnt > 3) { if (cnt >= 10) { badlogin(username); + au_fail("Login incorrect", 1); sleepexit(1); } + au_fail("Login incorrect", 1); sleep((u_int)((cnt - 3) * 5)); } } @@ -429,18 +489,27 @@ main(argc, argv) if (!rootlogin) checknologin(); + /* Audit successful login */ + if (auditsuccess) + au_success(); + setegid(pwd->pw_gid); seteuid(rootlogin ? 0 : pwd->pw_uid); /* First do a stat in case the homedir is automounted */ - stat(pwd->pw_dir,&st); + stat(pwd->pw_dir,&st); - if (chdir(pwd->pw_dir) < 0) { - (void)printf("No home directory %s!\n", pwd->pw_dir); - if (chdir("/")) - exit(0); - pwd->pw_dir = "/"; - (void)printf("Logging in with home = \"/\".\n"); + if (!*pwd->pw_dir || chdir(pwd->pw_dir) < 0) { + printf("No home directory %s!\n", pwd->pw_dir); + if (chdir("/")) { + refused("Cannot find root directory", "HOMEDIR", 1); + } + pwd->pw_dir = strdup("/"); + if (pwd->pw_dir == NULL) { + syslog(LOG_NOTICE, "strdup(): %m"); + bail(SLEEP_EXIT, 1); + } + printf("Logging in with home = \"/\".\n"); } seteuid(euid); setegid(egid); @@ -463,10 +532,15 @@ main(argc, argv) (void)chmod(ttyn, 0620); (void)setgid(pwd->pw_gid); - initgroups(username, pwd->pw_gid); + if (initgroups(username, pwd->pw_gid) == -1) + syslog(LOG_ERR, "login: initgroups() failed"); if (*pwd->pw_shell == '\0') - pwd->pw_shell = _PATH_BSHELL; + pwd->pw_shell = strdup(_PATH_BSHELL); + if (pwd->pw_shell == NULL) { + syslog(LOG_NOTICE, "strdup(): %m"); + bail(SLEEP_EXIT, 1); + } /* Destroy environment unless user has requested its preservation. */ if (!pflag) { @@ -497,8 +571,8 @@ main(argc, argv) } else if( pid != 0 ) { waitpid(pid, NULL, 0); pam_setcred(pamh, PAM_DELETE_CRED); - rval = pam_close_session(pamh, 0); - pam_end(pamh,rval); + pam_err = pam_close_session(pamh, 0); + pam_end(pamh,pam_err); chown(ttyn, 0, 0); chmod(ttyn, 0666); exit(0); @@ -559,6 +633,142 @@ main(argc, argv) #define NBUFSIZ (MAXLOGNAME + 1) #endif +/* + * The following tokens are included in the audit record for successful login attempts + * header + * subject + * return + */ +void au_success() +{ + token_t *tok; + int aufd; + au_mask_t aumask; + auditinfo_t auinfo; + uid_t uid = pwd->pw_uid; + gid_t gid = pwd->pw_gid; + pid_t pid = getpid(); + long au_cond; + + /* If we are not auditing, don't cut an audit record; just return */ + if (auditon(A_GETCOND, &au_cond, sizeof(long)) < 0) { + fprintf(stderr, "login: Could not determine audit condition\n"); + exit(1); + } + if (au_cond == AUC_NOAUDIT) + return; + + /* Compute and Set the user's preselection mask */ + if(au_user_mask(pwd->pw_name, &aumask) == -1) { + fprintf(stderr, "login: Could not set audit mask\n"); + exit(1); + } + + /* Set the audit info for the user */ + auinfo.ai_auid = uid; + auinfo.ai_asid = pid; + bcopy(&tid, &auinfo.ai_termid, sizeof(auinfo.ai_termid)); + bcopy(&aumask, &auinfo.ai_mask, sizeof(auinfo.ai_mask)); + if(setaudit(&auinfo) != 0) { + fprintf(stderr, "login: setaudit failed: %s\n", strerror(errno)); + exit(1); + } + + if((aufd = au_open()) == -1) { + fprintf(stderr, "login: Audit Error: au_open() failed\n"); + exit(1); + } + + /* The subject that is created (euid, egid of the current process) */ + if((tok = au_to_subject32(uid, geteuid(), getegid(), + uid, gid, pid, pid, &tid)) == NULL) { + fprintf(stderr, "login: Audit Error: au_to_subject32() failed\n"); + exit(1); + } + au_write(aufd, tok); + + if((tok = au_to_return32(0, 0)) == NULL) { + fprintf(stderr, "login: Audit Error: au_to_return32() failed\n"); + exit(1); + } + au_write(aufd, tok); + + if(au_close(aufd, 1, AUE_login) == -1) { + fprintf(stderr, "login: Audit Record was not committed.\n"); + exit(1); + } +} + +/* + * The following tokens are included in the audit record for successful login attempts + * header + * subject + * text + * return + */ +void au_fail(char *errmsg, int na) +{ + token_t *tok; + int aufd; + long au_cond; + uid_t uid; + gid_t gid; + pid_t pid = getpid(); + + /* If we are not auditing, don't cut an audit record; just return */ + if (auditon(A_GETCOND, &au_cond, sizeof(long)) < 0) { + fprintf(stderr, "login: Could not determine audit condition\n"); + exit(1); + } + if (au_cond == AUC_NOAUDIT) + return; + + if((aufd = au_open()) == -1) { + fprintf(stderr, "login: Audit Error: au_open() failed\n"); + exit(1); + } + + if(na) { + /* Non attributable event */ + /* Assuming that login is not called within a users' session => auid,asid == -1 */ + if((tok = au_to_subject32(-1, geteuid(), getegid(), -1, -1, + pid, -1, &tid)) == NULL) { + + fprintf(stderr, "login: Audit Error: au_to_subject32() failed\n"); + exit(1); + } + } + else { + /* we know the subject -- so use its value instead */ + uid = pwd->pw_uid; + gid = pwd->pw_gid; + if((tok = au_to_subject32(uid, geteuid(), getegid(), + uid, gid, pid, pid, &tid)) == NULL) { + fprintf(stderr, "login: Audit Error: au_to_subject32() failed\n"); + exit(1); + } + } + au_write(aufd, tok); + + /* Include the error message */ + if((tok = au_to_text(errmsg)) == NULL) { + fprintf(stderr, "login: Audit Error: au_to_text() failed\n"); + exit(1); + } + au_write(aufd, tok); + + if((tok = au_to_return32(1, errno)) == NULL) { + fprintf(stderr, "login: Audit Error: au_to_return32() failed\n"); + exit(1); + } + au_write(aufd, tok); + + if(au_close(aufd, 1, AUE_login) == -1) { + fprintf(stderr, "login: Audit Error: au_close() was not committed\n"); + exit(1); + } +} + void getloginname() { @@ -645,6 +855,7 @@ checknologin() if ((fd = open(_PATH_NOLOGIN, O_RDONLY, 0)) >= 0) { while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) (void)write(fileno(stdout), tbuf, nchars); + au_fail("No login", 0); sleepexit(0); } } @@ -736,3 +947,66 @@ sleepexit(eval) (void)sleep(5); exit(eval); } + +static void +refused(const char *msg, const char *rtype, int lout) +{ + + if (msg != NULL) + printf("%s.\n", msg); + if (hflag) + syslog(LOG_NOTICE, "LOGIN %s REFUSED (%s) FROM %s ON TTY %s", + pwd->pw_name, rtype, hostname, tty); + else + syslog(LOG_NOTICE, "LOGIN %s REFUSED (%s) ON TTY %s", + pwd->pw_name, rtype, tty); + if (lout) + bail(SLEEP_EXIT, 1); +} + +#ifdef USE_PAM +/* + * Log a PAM error + */ +static void +pam_syslog(const char *msg) +{ + syslog(LOG_ERR, "%s: %s", msg, pam_strerror(pamh, pam_err)); +} + +/* + * Shut down PAM + */ +static void +pam_cleanup() +{ + + if (pamh != NULL) { + if (pam_session_established) { + pam_err = pam_close_session(pamh, 0); + if (pam_err != PAM_SUCCESS) + pam_syslog("pam_close_session()"); + } + pam_session_established = 0; + if (pam_cred_established) { + pam_err = pam_setcred(pamh, pam_silent|PAM_DELETE_CRED); + if (pam_err != PAM_SUCCESS) + pam_syslog("pam_setcred()"); + } + pam_cred_established = 0; + pam_end(pamh, pam_err); + pamh = NULL; + } +} +#endif /* USE_PAM */ +/* + * Exit, optionally after sleeping a few seconds + */ +void +bail(int sec, int eval) +{ + + pam_cleanup(); + (void)sleep(sec); + exit(eval); +} diff --git a/login.tproj/pathnames.h b/login.tproj/pathnames.h index ffdde6d..b83bb9b 100644 --- a/login.tproj/pathnames.h +++ b/login.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/makekey.tproj/Makefile.postamble b/makekey.tproj/Makefile.postamble index cb09ed6..b42299c 100644 --- a/makekey.tproj/Makefile.postamble +++ b/makekey.tproj/Makefile.postamble @@ -108,3 +108,6 @@ # 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 makekey.8 $(DSTROOT)/usr/share/man/man8 diff --git a/makekey.tproj/makekey.c b/makekey.tproj/makekey.c index 557bcfc..487cfaa 100644 --- a/makekey.tproj/makekey.c +++ b/makekey.tproj/makekey.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/mkfile.tproj/mkfile.c b/mkfile.tproj/mkfile.c index 5f70877..4aff548 100644 --- a/mkfile.tproj/mkfile.c +++ b/mkfile.tproj/mkfile.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/nvram.tproj/nvram.c b/nvram.tproj/nvram.c index 9fbbe4d..b9a6db9 100644 --- a/nvram.tproj/nvram.c +++ b/nvram.tproj/nvram.c @@ -1,25 +1,22 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2005 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 + * + * 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, 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@ */ /* @@ -293,7 +290,7 @@ static void ParseFile(char *fileName) // SetOrGetOFVariable(str) // -// Parse the input string the set or get the specified +// Parse the input string, then set or get the specified // Open Firmware variable. // static void SetOrGetOFVariable(char *str) @@ -348,9 +345,9 @@ static kern_return_t GetOFVariable(char *name, CFStringRef *nameRef, CFTypeRef *valueRef) { *nameRef = CFStringCreateWithCString(kCFAllocatorDefault, name, - kCFStringEncodingMacRoman); + kCFStringEncodingUTF8); if (*nameRef == 0) { - FatalError(-1, "Error CFString for key %s", (long)name); + FatalError(-1, "Error (-1) creating CFString for key %s", (long)name); } *valueRef = IORegistryEntryCreateCFProperty(gOptionsRef, *nameRef, 0, 0); @@ -372,7 +369,7 @@ static kern_return_t SetOFVariable(char *name, char *value) kern_return_t result; nameRef = CFStringCreateWithCString(kCFAllocatorDefault, name, - kCFStringEncodingMacRoman); + kCFStringEncodingUTF8); if (nameRef == 0) { FatalError(-1, "Error (-1) creating CFString for key %s", (long)name); } @@ -462,22 +459,33 @@ static void PrintOFVariables() static void PrintOFVariable(const void *key, const void *value, void *context) { long cnt, cnt2; + CFIndex nameLen; + char *nameBuffer = 0; const char *nameString; char numberBuffer[10]; const uint8_t *dataPtr; uint8_t dataChar; char *dataBuffer = 0; + CFIndex valueLen; + char *valueBuffer = 0; const char *valueString = 0; uint32_t number, length; CFTypeID typeID; // Get the OF variable's name. - nameString = CFStringGetCStringPtr(key, kCFStringEncodingMacRoman); + nameLen = CFStringGetLength(key) + 1; + nameBuffer = malloc(nameLen); + if( nameBuffer && CFStringGetCString(key, nameBuffer, nameLen, kCFStringEncodingUTF8) ) + nameString = nameBuffer; + else { + Error("Error (-1) Unable to convert property name to C string", 0); + nameString = ""; + } // Get the OF variable's type. typeID = CFGetTypeID(value); - if (typeID == CFBooleanGetTypeID()) { + if (typeID == CFBooleanGetTypeID()) { if (CFBooleanGetValue(value)) valueString = "true"; else valueString = "false"; } else if (typeID == CFNumberGetTypeID()) { @@ -487,7 +495,14 @@ static void PrintOFVariable(const void *key, const void *value, void *context) else sprintf(numberBuffer, "0x%x", number); valueString = numberBuffer; } else if (typeID == CFStringGetTypeID()) { - valueString = CFStringGetCStringPtr(value, kCFStringEncodingMacRoman); + valueLen = CFStringGetLength(value) + 1; + valueBuffer = malloc(valueLen + 1); + if ( valueBuffer && CFStringGetCString(value, valueBuffer, valueLen, kCFStringEncodingUTF8) ) + valueString = valueBuffer; + else { + Error("Error (-1) Unable to convert value to C string", 0); + valueString = ""; + } } else if (typeID == CFDataGetTypeID()) { length = CFDataGetLength(value); if (length == 0) valueString = ""; @@ -507,12 +522,16 @@ static void PrintOFVariable(const void *key, const void *value, void *context) valueString = dataBuffer; } } - } else return; + } else { + valueString=""; + } if ((nameString != 0) && (valueString != 0)) printf("%s\t%s\n", nameString, valueString); if (dataBuffer != 0) free(dataBuffer); + if (nameBuffer != 0) free(nameBuffer); + if (valueBuffer != 0) free(valueBuffer); } @@ -535,7 +554,7 @@ static CFTypeRef ConvertValueToCFTypeRef(CFTypeID typeID, char *value) &number); } else if (typeID == CFStringGetTypeID()) { valueRef = CFStringCreateWithCString(kCFAllocatorDefault, value, - kCFStringEncodingMacRoman); + kCFStringEncodingUTF8); } else if (typeID == CFDataGetTypeID()) { length = strlen(value); for (cnt = cnt2 = 0; cnt < length; cnt++, cnt2++) { diff --git a/pagesize.tproj/Makefile.postamble b/pagesize.tproj/Makefile.postamble index 89cd0ea..42cbf76 100644 --- a/pagesize.tproj/Makefile.postamble +++ b/pagesize.tproj/Makefile.postamble @@ -127,3 +127,5 @@ pagesize: pagesize.sh after_install:: $(CP) -p ${SYM_DIR}/pagesize $(DSTROOT)$(INSTALLDIR)/pagesize $(CHMOD) 555 $(DSTROOT)$(INSTALLDIR)/pagesize + mkdir -p $(DSTROOT)/usr/share/man/man1 + install -c -m 444 pagesize.1 $(DSTROOT)/usr/share/man/man1 diff --git a/passwd.tproj/ds_passwd.c b/passwd.tproj/ds_passwd.c index e8da6ae..38f21c9 100644 --- a/passwd.tproj/ds_passwd.c +++ b/passwd.tproj/ds_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@ */ @@ -144,13 +143,21 @@ ds_passwd(char *uname, char *locn) int wasroot = 0; char *loginUser = NULL; int changePassOnSelf = 1; + const char *errMsgStr = NULL; + struct passwd *userRec = NULL; if (uname == NULL) return -1; - loginUser = getlogin(); - if ( loginUser != NULL ) - changePassOnSelf = ( strcmp( loginUser, uname ) == 0 ); + /* getlogin() is the wrong thing to use here. Use getpwuid(getuid()); */ + /* sns 5 Jan 2005 */ + + userRec = getpwuid( getuid() ); + if ( userRec != NULL ) { + loginUser = userRec->pw_name; + if ( loginUser != NULL ) + changePassOnSelf = (strcmp(loginUser, uname) == 0); + } status = dsOpenDirService( &dsRef ); if (status != eDSNoErr) @@ -258,6 +265,11 @@ ds_passwd(char *uname, char *locn) } } + if ( pUserLocation == NULL || pUserName == NULL ) { + status = eDSAuthInvalidUserName; + break; + } + pUserNode = dsBuildFromPath( dsRef, pUserLocation, "/" ); status = dsOpenDirNode( dsRef, pUserNode, &userNodeRef ); if ( status != eDSNoErr ) break; @@ -319,6 +331,7 @@ ds_passwd(char *uname, char *locn) status = dsDoDirNodeAuth( userNodeRef, pAuthType, 1, tDataBuff, pStepBuff, NULL ); } else + if ( loginUser != NULL ) { pAuthType = dsDataNodeAllocateString( dsRef, kDSStdAuthSetPasswd ); uiCurr = 0; @@ -355,6 +368,10 @@ ds_passwd(char *uname, char *locn) status = dsDoDirNodeAuth( userNodeRef, pAuthType, 1, tDataBuff, pStepBuff, NULL ); } + else + { + status = eDSAuthFailed; + } } while ( isroot == 1 && status != eDSNoErr ); @@ -405,7 +422,28 @@ ds_passwd(char *uname, char *locn) if ( status != eDSNoErr ) { errno = EACCES; - fprintf(stderr, "Sorry\n"); + switch( status ) + { + case eDSAuthPasswordTooShort: + errMsgStr = "The new password is too short."; + break; + + case eDSAuthPasswordTooLong: + errMsgStr = "The new password is too long."; + break; + + case eDSAuthPasswordNeedsLetter: + errMsgStr = "The new password must contain a letter."; + break; + + case eDSAuthPasswordNeedsDigit: + errMsgStr = "The new password must contain a number."; + break; + + default: + errMsgStr = "Sorry"; + } + fprintf(stderr, "%s\n", errMsgStr); exit(1); } diff --git a/passwd.tproj/file_passwd.c b/passwd.tproj/file_passwd.c index 67278c5..7f1eb81 100644 --- a/passwd.tproj/file_passwd.c +++ b/passwd.tproj/file_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@ */ @@ -39,7 +38,7 @@ extern void getpasswd(char *, int, int, int, int, char *, char **, char**, char **); -static int do_compat = 1; +//static int do_compat = 1; (unused) char * getline(FILE *fp) @@ -198,8 +197,8 @@ rewrite_file(char *pwname, FILE *fp, struct passwd *newpw) if (cfp != NULL) fprintf(cfp, "%s\n", line); continue; } - - fprintf(tfp, "%s:%s:%d:%d:%s:%d:%d:%s:%s:%s\n", + + fprintf(tfp, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n", newpw->pw_name, newpw->pw_passwd, newpw->pw_uid, newpw->pw_gid, newpw->pw_class, newpw->pw_change, newpw->pw_expire, newpw->pw_gecos, newpw->pw_dir, newpw->pw_shell); diff --git a/passwd.tproj/netinfo_passwd.c b/passwd.tproj/netinfo_passwd.c index e86a25b..29f56d7 100644 --- a/passwd.tproj/netinfo_passwd.c +++ b/passwd.tproj/netinfo_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@ */ @@ -49,7 +48,7 @@ sys_ismyaddress(unsigned long addr) int offset; int sock; struct sockaddr_in *sin; - int i, len; + //int i, len; (unused) if (addr == htonl(INADDR_LOOPBACK)) return 1; diff --git a/passwd.tproj/nis_passwd.c b/passwd.tproj/nis_passwd.c index 8be2044..9043e92 100644 --- a/passwd.tproj/nis_passwd.c +++ b/passwd.tproj/nis_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/passwd.tproj/passwd.1 b/passwd.tproj/passwd.1 index 39e96f9..367dde6 100644 --- a/passwd.tproj/passwd.1 +++ b/passwd.tproj/passwd.1 @@ -67,16 +67,17 @@ the authenticating host. This option specifies where the password update should be applied. Under Mac OS X 10.3, supported infosystems are: .Bl -tag -width flag -.It Ar netinfo +.It Ar opendirectory (default) +A system conforming to opendirectory APIs and supporting updates (including LDAP, netinfo, etc). +If no -l option is specified, the search node is used. +.It Ar netinfo The netinfo database containing the user's password. If no -l option is specified, the local netinfo database is assumed. .It Ar file The local flat-files (included for legacy configurations). .It Ar nis A remote NIS server containing the user's password. -.It Ar opendirectory -A system conforming to opendirectory APIs and supporting updates (including LDAP, netinfo, etc). .El .It Fl l Ar location This option causes the password to be updated in the given location of the choosen infosystem. diff --git a/passwd.tproj/passwd.c b/passwd.tproj/passwd.c index 3d2b19d..c0c8c33 100644 --- a/passwd.tproj/passwd.c +++ b/passwd.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@ */ @@ -179,6 +178,7 @@ main(int argc, char *argv[]) { char *user, *locn; int i, infosystem; + int free_user = 0; /* since DS works for most infosystems, make it the default */ //infosystem = INFO_NETINFO; @@ -227,11 +227,22 @@ main(int argc, char *argv[]) if (user == NULL) { - /* + /* * Verify that the login name exists. * lukeh 24 Dec 1997 */ - if ((user = getlogin()) == NULL) + + /* getlogin() is the wrong thing to use here because it returns the wrong user after su */ + /* sns 5 Jan 2005 */ + + struct passwd * userRec = getpwuid(getuid()); + if (userRec != NULL && userRec->pw_name != NULL) { + /* global static mem is volatile; must strdup */ + user = strdup(userRec->pw_name); + free_user = 1; + } + + if (user == NULL) { fprintf(stderr, "you don't have a login name\n"); exit(1); @@ -253,7 +264,10 @@ main(int argc, char *argv[]) ds_passwd(user, locn); break; } - + + if (free_user == 1) + free(user); + exit(0); } diff --git a/passwd.tproj/stringops.c b/passwd.tproj/stringops.c index a874a6f..a3621e3 100644 --- a/passwd.tproj/stringops.c +++ b/passwd.tproj/stringops.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/passwd.tproj/stringops.h b/passwd.tproj/stringops.h index f90163e..e0a679e 100644 --- a/passwd.tproj/stringops.h +++ b/passwd.tproj/stringops.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/pt_chown.tproj/Makefile b/pt_chown.tproj/Makefile new file mode 100644 index 0000000..9503386 --- /dev/null +++ b/pt_chown.tproj/Makefile @@ -0,0 +1,46 @@ +# +# 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 = pt_chown + +PROJECTVERSION = 1.1 +PROJECT_TYPE = Tool + +CFILES = pt_chown.c + +OTHERSRCS = Makefile.preamble Makefile Makefile.postamble + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/libexec +WINDOWS_INSTALLDIR = /usr/libexec +PDO_UNIX_INSTALLDIR = /usr/libexec +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/pt_chown.tproj/Makefile.postamble b/pt_chown.tproj/Makefile.postamble new file mode 100644 index 0000000..401ddbc --- /dev/null +++ b/pt_chown.tproj/Makefile.postamble @@ -0,0 +1,2 @@ +after_install: + chmod 4511 $(DSTROOT)/usr/libexec/pt_chown diff --git a/pt_chown.tproj/Makefile.preamble b/pt_chown.tproj/Makefile.preamble new file mode 100644 index 0000000..ecc3ec7 --- /dev/null +++ b/pt_chown.tproj/Makefile.preamble @@ -0,0 +1 @@ +OTHER_CFLAGS = -D__FBSDID=__RCSID diff --git a/pt_chown.tproj/PB.project b/pt_chown.tproj/PB.project new file mode 100644 index 0000000..ec106d6 --- /dev/null +++ b/pt_chown.tproj/PB.project @@ -0,0 +1,37 @@ +{ + FILESTABLE = { + FRAMEWORKS = (); + OTHER_LINKED = (pt_chown.c); + OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.dist); + PRECOMPILED_HEADERS = (); + PROJECT_HEADERS = (); + PUBLIC_HEADERS = (); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + NEXTSTEP_BUILDDIR = ""; + NEXTSTEP_BUILDTOOL = /bin/make; + NEXTSTEP_COMPILEROPTIONS = ""; + NEXTSTEP_INSTALLDIR = /usr/libexec; + 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/libexec; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_LINKEROPTIONS = ""; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = pt_chown; + PROJECTTYPE = Tool; + PROJECTVERSION = 1.1; + WINDOWS_BUILDDIR = ""; + WINDOWS_BUILDTOOL = /bin/make; + WINDOWS_COMPILEROPTIONS = ""; + WINDOWS_INSTALLDIR = /usr/libexec; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_LINKEROPTIONS = ""; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/pt_chown.tproj/pt_chown.c b/pt_chown.tproj/pt_chown.c new file mode 100644 index 0000000..4ac16f3 --- /dev/null +++ b/pt_chown.tproj/pt_chown.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2002 The FreeBSD Project, Inc. + * All rights reserved. + * + * This software includes code contributed to the FreeBSD Project + * by Ryan Younce of North Carolina State University. + * + * 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 FreeBSD Project nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR ITS 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 +__FBSDID("$FreeBSD: /repoman/r/ncvs/src/libexec/pt_chown/pt_chown.c,v 1.1 2003/01/02 20:44:41 jmallett Exp $"); +#endif /* not lint */ + +#include + +#include +#include +#include +#include + +/* + * pt_chown + * Utility support routine for grantpt(3). + * + * According to IEEE Std 1003.1-2001, grantpt(3) changes ownership and + * permission bits of a slave pseudo-terminal device associated with a + * master. + * + * Since doing this if we are not the owner of the slave (which would + * rarely happen) cannot be done by conventional methods, grantpt(3) + * has to rely on this support program, which is setuid root, to change + * the slave's owner, group, and permission mode attributes. It's + * a rather undesirable approach, but Digital Unix and Solaris also seem + * to rely on this approach to pull this off. + * + * This program hangs around long enough to do just these things upon + * its standard input (which is set up by grantpt(3) to be the master's + * descriptor, the one passed to it). The rationale behind this + * approach not allowing somebody to modify ownership of another active + * pseudo terminal is: + * + * 1) This program only operates on its standard input. If STDIN_FILENO + * is not open or is not a pseudo-terminal master, no action is + * taken and the program exits (ptsname() is called for a non-NULL + * return). + * 2) Only one active file description for a pseudo-terminal master + * can exist at a time (attempting to open an active PTY returns with + * EIO - I/O Error). Thus, if the pseudo-terminal is already in + * use by somebody else, it could not have been opened to begin + * with, and thus this program would be useless in such situations. + */ +int +main(int argc, char *argv[]) +{ + int retcode; + char *slave; + gid_t gid; + struct group *grp; + + retcode = EX_OK; + + if ((slave = ptsname(STDIN_FILENO)) == NULL) + retcode = EX_USAGE; + else { + gid = (grp = getgrnam("tty")) ? grp->gr_gid : -1; + if (chown(slave, getuid(), gid) == 0 && + chmod(slave, S_IRUSR | S_IWUSR | S_IWGRP) == 0) + retcode = 0; + else + retcode = EX_NOPERM; + } + + /* + * grantpt(3) checks the retcode for being either zero or + * nonzero. Any nonzero return results in errno being set + * to EACCES. + */ + exit(retcode); +} diff --git a/pwd_mkdb.tproj/pw_scan.h b/pwd_mkdb.tproj/pw_scan.h index f7ec9c4..51c9a44 100644 --- a/pwd_mkdb.tproj/pw_scan.h +++ b/pwd_mkdb.tproj/pw_scan.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/reboot.tproj/Makefile.postamble b/reboot.tproj/Makefile.postamble index 8dbc6d6..4424c4c 100644 --- a/reboot.tproj/Makefile.postamble +++ b/reboot.tproj/Makefile.postamble @@ -1,4 +1,5 @@ after_install:: $(LN) $(INSTALLED_PRODUCTS) $(DSTROOT)$(INSTALLDIR)/halt mkdir -p $(DSTROOT)/usr/share/man/man8 - cp reboot.8 $(DSTROOT)/usr/share/man/man8/ + install -c -m 444 reboot.8 $(DSTROOT)/usr/share/man/man8/ + ln $(DSTROOT)/usr/share/man/man8/reboot.8 $(DSTROOT)/usr/share/man/man8/halt.8 diff --git a/reboot.tproj/reboot.c b/reboot.tproj/reboot.c index f2f0eef..61b6e38 100644 --- a/reboot.tproj/reboot.c +++ b/reboot.tproj/reboot.c @@ -83,18 +83,18 @@ main(int argc, char *argv[]) #ifndef __APPLE__ while ((ch = getopt(argc, argv, "dk:lnpq")) != -1) #else - while ((ch = getopt(argc, argv, "k:lnq")) != -1) + while ((ch = getopt(argc, argv, "lnq")) != -1) #endif switch(ch) { #ifndef __APPLE__ case 'd': howto |= RB_DUMP; break; -#endif case 'k': kflag = 1; kernel = optarg; break; +#endif case 'l': lflag = 1; break; @@ -133,6 +133,7 @@ main(int argc, char *argv[]) err(1, NULL); } +#ifndef __APPLE__ if (kflag) { fd = open("/boot/nextboot.conf", O_WRONLY | O_CREAT, 0444); if (fd > -1) { @@ -143,6 +144,7 @@ main(int argc, char *argv[]) close(fd); } } +#endif /* Log the reboot. */ if (!lflag) { @@ -224,7 +226,11 @@ restart: void usage() { +#ifndef __APPLE__ (void)fprintf(stderr, "usage: %s [-dnpq] [-k kernel]\n", +#else + (void)fprintf(stderr, "usage: %s [-lnq]\n", +#endif dohalt ? "halt" : "reboot"); exit(1); } diff --git a/sa.tproj/Makefile b/sa.tproj/Makefile new file mode 100644 index 0000000..21ee968 --- /dev/null +++ b/sa.tproj/Makefile @@ -0,0 +1,51 @@ +# +# Generated by the Apple 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 = sa + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = main.c pdb.c usrdb.c + +OTHERSRCS = Makefile.preamble Makefile Makefile.postamble extern.h pathnames.h \ + sa.8 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/sbin +WINDOWS_INSTALLDIR = /Library/Executables +PDO_UNIX_INSTALLDIR = /bin +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + +HEADER_PATHS = -I$(NEXT_ROOT)/System/Library/System.framework/\ + -I$(NEXT_ROOT)/System/Library/Frameworks/System.framework/PrivateHeaders\ + -I$(NEXT_ROOT)/System/Library/Frameworks/System.framework/PrivateHeaders/bsd\ + -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/bsd + +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 = $(JDKBINDIR)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/sa.tproj/Makefile.postamble b/sa.tproj/Makefile.postamble new file mode 100644 index 0000000..864cfa1 --- /dev/null +++ b/sa.tproj/Makefile.postamble @@ -0,0 +1,104 @@ +############################################################################### +# Makefile.postamble +# Copyright 1997, Apple Computer, Inc. +# +# Use this makefile, which is imported after all other makefiles, to +# override attributes for a project's Makefile environment. This allows you +# to take advantage of the environment set up by the other Makefiles. +# You can also define custom rules at the end of this file. +# +############################################################################### +# +# These variables are exported by the standard makefiles and can be +# used in any customizations you make. They are *outputs* of +# the Makefiles and should be used, not set. +# +# PRODUCTS: products to install. All of these products will be placed in +# the directory $(DSTROOT)$(INSTALLDIR) +# GLOBAL_RESOURCE_DIR: The directory to which resources are copied. +# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied. +# OFILE_DIR: Directory into which .o object files are generated. +# DERIVED_SRC_DIR: Directory used for all other derived files +# +# ALL_CFLAGS: flags to pass when compiling .c files +# ALL_MFLAGS: flags to pass when compiling .m files +# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files +# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files +# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files +# ALL_LDFLAGS: flags to pass when linking object files +# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files +# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files +# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files +# ALL_YFLAGS: flags to pass when processing .y (yacc) files +# ALL_LFLAGS: flags to pass when processing .l (lex) files +# +# NAME: name of application, bundle, subproject, palette, etc. +# LANGUAGES: langages in which the project is written (default "English") +# English_RESOURCES: localized resources (e.g. nib's, images) of project +# GLOBAL_RESOURCES: non-localized resources of project +# +# SRCROOT: base directory in which to place the new source files +# SRCPATH: relative path from SRCROOT to present subdirectory +# +# INSTALLDIR: Directory the product will be installed into by 'install' target +# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget +# to prefix this with DSTROOT when you use it. +# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget +# to prefix this with DSTROOT when you use it. +# +# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows) +# +############################################################################### + +# Some compiler flags can be overridden here for certain build situations. +# +# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost) +# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults +# to -g) +# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG) +# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults +# to -O) +# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults +# to -pg -DPROFILE) +# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to +# the include path (defaults to -I.) +# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags +# passed to ld/libtool (defaults to nothing) + + +# Library and Framework projects only: +# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked +# against the framework will run against the correct version even if +# the current version of the framework changes. You may override this +# to "" as an alternative to using the DYLD_LIBRARY_PATH during your +# development cycle, but be sure to restore it before installing. + + +# Ownership and permissions of files installed by 'install' target + +#INSTALL_AS_USER = root + # User/group ownership +#INSTALL_AS_GROUP = wheel + # (probably want to set both of these) +#INSTALL_PERMISSIONS = 4555 + # If set, 'install' chmod's executable to this + + +# Options to strip. Note: -S strips debugging symbols (executables can be stripped +# down further with -x or, if they load no bundles, with no options at all). + +#STRIPFLAGS = -S + + +######################################################################### +# Put rules to extend the behavior of the standard Makefiles here. Include them in +# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble. +# +# You should avoid redefining things like "install" or "app", as they are +# owned by the top-level Makefile API and no context has been set up for where +# derived files should go. +# + +install-man-page: + install -d $(DSTROOT)/usr/share/man/man8 + install -c -m 444 sa.8 $(DSTROOT)/usr/share/man/man8/sa.8 diff --git a/sa.tproj/Makefile.preamble b/sa.tproj/Makefile.preamble new file mode 100644 index 0000000..a4606c6 --- /dev/null +++ b/sa.tproj/Makefile.preamble @@ -0,0 +1,140 @@ +############################################################################### +# Makefile.preamble +# Copyright 1997, Apple Computer, Inc. +# +# Use this makefile for configuring the standard application makefiles +# associated with ProjectBuilder. It is included before the main makefile. +# In Makefile.preamble you set attributes for a project, so they are available +# to the project's makefiles. In contrast, you typically write additional rules or +# override built-in behavior in the Makefile.postamble. +# +# Each directory in a project tree (main project plus subprojects) should +# have its own Makefile.preamble and Makefile.postamble. +############################################################################### +# +# Before the main makefile is included for this project, you may set: +# +# MAKEFILEDIR: Directory in which to find $(MAKEFILE) +# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make) + +# Compiler/linker flags added to the defaults: The OTHER_* variables will be +# inherited by all nested sub-projects, but the LOCAL_ versions of the same +# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's +# Build Attributes inspector if at all possible. To override the default flags +# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The +# variables below are *inputs* to the build process and distinct from the override +# settings done (less often) in the Makefile.postamble. +# +# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler +# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m, +# .cc, .cxx, .C, and .M files. There is no need to respecify the +# flags in OTHER_MFLAGS, etc. +# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files +# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files +# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files +# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when +# precompiling header files +# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool +# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap +# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen +# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc +# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex + +# These variables provide hooks enabling you to add behavior at almost every +# stage of the make: +# +# BEFORE_PREBUILD: targets to build before installing headers for a subproject +# AFTER_PREBUILD: targets to build after installing headers for a subproject +# BEFORE_BUILD_RECURSION: targets to make before building subprojects +# BEFORE_BUILD: targets to make before a build, but after subprojects +# AFTER_BUILD: targets to make after a build +# +# BEFORE_INSTALL: targets to build before installing the product +# AFTER_INSTALL: targets to build after installing the product +# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject +# AFTER_POSTINSTALL: targts to build after postinstalling every subproject +# +# BEFORE_INSTALLHDRS: targets to build before installing headers for a +# subproject +# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject +# BEFORE_INSTALLSRC: targets to build before installing source for a subproject +# AFTER_INSTALLSRC: targets to build after installing source for a subproject +# +# BEFORE_DEPEND: targets to build before building dependencies for a +# subproject +# AFTER_DEPEND: targets to build after building dependencies for a +# subproject +# +# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is +# updated every time the project is built. If NO, the dependency +# file is only built when the depend target is invoked. + +# Framework-related variables: +# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates +# where to put the framework's DLL. This variable defaults to +# $(INSTALLDIR)/../Executables + +# Library-related variables: +# PUBLIC_HEADER_DIR: Determines where public exported header files +# should be installed. Do not include $(DSTROOT) in this value -- +# it is prefixed automatically. For library projects you should +# set this to something like /Developer/Headers/$(NAME). Do not set +# this variable for framework projects unless you do not want the +# header files included in the framework. +# PRIVATE_HEADER_DIR: Determines where private exported header files +# should be installed. Do not include $(DSTROOT) in this value -- +# it is prefixed automatically. +# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines +# whether the libraries produced are statically linked when they +# are used or if they are dynamically loadable. This defaults to +# DYNAMIC. +# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates +# where to put the library's DLL. This variable defaults to +# $(INSTALLDIR)/../Executables +# +# INSTALL_AS_USER: owner of the intalled products (default root) +# INSTALL_AS_GROUP: group of the installed products (default wheel) +# INSTALL_PERMISSIONS: permissions of the installed product (default o+rX) +# +# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be +# passed on the command line to recursive invocations of make. Note that +# the values in OTHER_*FLAGS are inherited by subprojects automatically -- +# you do not have to (and shouldn't) add OTHER_*FLAGS to +# OTHER_RECURSIVE_VARIABLES. + +# Additional headers to export beyond those in the PB.project: +# OTHER_PUBLIC_HEADERS +# OTHER_PROJECT_HEADERS +# OTHER_PRIVATE_HEADERS + +# Additional files for the project's product: <> +# OTHER_RESOURCES: (non-localized) resources for this project +# OTHER_OFILES: relocatables to be linked into this project +# OTHER_LIBS: more libraries to link against +# OTHER_PRODUCT_DEPENDS: other dependencies of this project +# OTHER_SOURCEFILES: other source files maintained by .pre/postamble +# OTHER_GARBAGE: additional files to be removed by `make clean' + +# Set this to YES if you don't want a final libtool call for a library/framework. +# BUILD_OFILES_LIST_ONLY + +# 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) + +# This definition will suppress stripping of debug symbols when an executable +# is installed. By default it is YES. +# STRIP_ON_INSTALL = NO + +# Uncomment to suppress generation of a KeyValueCoding index when installing +# frameworks (This index is used by WOB and IB to determine keys available +# for an object). Set to YES by default. +# PREINDEX_FRAMEWORK = NO + +# Change this definition to install projects somewhere other than the +# standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems +# and "" on other systems. +DSTROOT = $(HOME) + +AFTER_INSTALL += install-man-page + diff --git a/sa.tproj/PB.project b/sa.tproj/PB.project new file mode 100644 index 0000000..0158f5a --- /dev/null +++ b/sa.tproj/PB.project @@ -0,0 +1,26 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + HEADERSEARCH = ("$(NEXT_ROOT)/System/Library/Frameworks/System.framework/PrivateHeaders/bsd"); + OTHER_LINKED = (main.c, pdb.c, usrdb.c); + OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, sa.8, extern.h, pathnames.h); + }; + LANGUAGE = English; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_COMPILEROPTIONS = "-DKERNEL_PRIVATE"; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_INSTALLDIR = /bin; + PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = sa; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_INSTALLDIR = /Library/Executables; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/sa.tproj/extern.h b/sa.tproj/extern.h new file mode 100644 index 0000000..f77282b --- /dev/null +++ b/sa.tproj/extern.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 1994 Christopher G. Demetriou + * 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 Christopher G. Demetriou. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/usr.sbin/sa/extern.h,v 1.5 2002/07/11 22:11:20 alfred Exp $ + */ + +#include +#include +#include + +/* structures */ + +struct cmdinfo { + char ci_comm[MAXCOMLEN+2]; /* command name (+ '*') */ + u_long ci_uid; /* user id */ + u_quad_t ci_calls; /* number of calls */ + u_quad_t ci_etime; /* elapsed time */ + u_quad_t ci_utime; /* user time */ + u_quad_t ci_stime; /* system time */ + u_quad_t ci_mem; /* memory use */ + u_quad_t ci_io; /* number of disk i/o ops */ + u_int ci_flags; /* flags; see below */ +}; +#define CI_UNPRINTABLE 0x0001 /* unprintable chars in name */ + +struct userinfo { + u_long ui_uid; /* user id; for consistency */ + u_quad_t ui_calls; /* number of invocations */ + u_quad_t ui_utime; /* user time */ + u_quad_t ui_stime; /* system time */ + u_quad_t ui_mem; /* memory use */ + u_quad_t ui_io; /* number of disk i/o ops */ +}; + +/* typedefs */ + +typedef int (*cmpf_t)(const DBT *, const DBT *); + +/* external functions in pdb.c */ +int pacct_init(void); +void pacct_destroy(void); +int pacct_add(const struct cmdinfo *); +int pacct_update(void); +void pacct_print(void); + +/* external functions in usrdb.c */ +int usracct_init(void); +void usracct_destroy(void); +int usracct_add(const struct cmdinfo *); +int usracct_update(void); +void usracct_print(void); + +/* variables */ + +extern int aflag, bflag, cflag, dflag, Dflag, fflag, iflag, jflag, kflag; +extern int Kflag, lflag, mflag, qflag, rflag, sflag, tflag, uflag, vflag; +extern u_quad_t cutoff; +extern cmpf_t sa_cmp; + +/* some #defines to help with db's stupidity */ + +#define DB_CLOSE(db) \ + ((*(db)->close)(db)) +#define DB_GET(db, key, data, flags) \ + ((*(db)->get)((db), (key), (data), (flags))) +#define DB_PUT(db, key, data, flags) \ + ((*(db)->put)((db), (key), (data), (flags))) +#define DB_SYNC(db, flags) \ + ((*(db)->sync)((db), (flags))) +#define DB_SEQ(db, key, data, flags) \ + ((*(db)->seq)((db), (key), (data), (flags))) diff --git a/sa.tproj/main.c b/sa.tproj/main.c new file mode 100644 index 0000000..4bc068d --- /dev/null +++ b/sa.tproj/main.c @@ -0,0 +1,556 @@ +/* + * Copyright (c) 1994 Christopher G. Demetriou + * 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 Christopher G. Demetriou. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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) 1994 Christopher G. Demetriou\n\ + All rights reserved.\n"; +#endif + +#ifndef lint +static const char rcsid[] = + "$FreeBSD: src/usr.sbin/sa/main.c,v 1.12 2002/07/15 16:05:15 des Exp $"; +#endif /* not lint */ + +/* + * sa: system accounting + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "extern.h" +#include "pathnames.h" + +static int acct_load(char *, int); +static u_quad_t decode_comp_t(comp_t); +static int cmp_comm(const char *, const char *); +static int cmp_usrsys(const DBT *, const DBT *); +static int cmp_avgusrsys(const DBT *, const DBT *); +static int cmp_dkio(const DBT *, const DBT *); +static int cmp_avgdkio(const DBT *, const DBT *); +static int cmp_cpumem(const DBT *, const DBT *); +static int cmp_avgcpumem(const DBT *, const DBT *); +static int cmp_calls(const DBT *, const DBT *); +static void usage(void); + +int aflag, bflag, cflag, dflag, Dflag, fflag, iflag, jflag, kflag; +int Kflag, lflag, mflag, qflag, rflag, sflag, tflag, uflag, vflag; +u_quad_t cutoff = 1; + +static char *dfltargv[] = { NULL }; +static int dfltargc = (sizeof dfltargv/sizeof(char *)); + +/* default to comparing by sum of user + system time */ +cmpf_t sa_cmp = cmp_usrsys; + +int +main(int argc, char **argv) +{ + char ch; + char pathacct[] = _PATH_ACCT; + int error = 0; + + dfltargv[0] = pathacct; + + while ((ch = getopt(argc, argv, "abcdDfijkKlmnqrstuv:")) != -1) + switch (ch) { + case 'a': + /* print all commands */ + aflag = 1; + break; + case 'b': + /* sort by per-call user/system time average */ + bflag = 1; + sa_cmp = cmp_avgusrsys; + break; + case 'c': + /* print percentage total time */ + cflag = 1; + break; + case 'd': + /* sort by averge number of disk I/O ops */ + dflag = 1; + sa_cmp = cmp_avgdkio; + break; + case 'D': + /* print and sort by total disk I/O ops */ + Dflag = 1; + sa_cmp = cmp_dkio; + break; + case 'f': + /* force no interactive threshold comprison */ + fflag = 1; + break; + case 'i': + /* do not read in summary file */ + iflag = 1; + break; + case 'j': + /* instead of total minutes, give sec/call */ + jflag = 1; + break; + case 'k': + /* sort by cpu-time average memory usage */ + kflag = 1; + sa_cmp = cmp_avgcpumem; + break; + case 'K': + /* print and sort by cpu-storage integral */ + sa_cmp = cmp_cpumem; + Kflag = 1; + break; + case 'l': + /* separate system and user time */ + lflag = 1; + break; + case 'm': + /* print procs and time per-user */ + mflag = 1; + break; + case 'n': + /* sort by number of calls */ + sa_cmp = cmp_calls; + break; + case 'q': + /* quiet; error messages only */ + qflag = 1; + break; + case 'r': + /* reverse order of sort */ + rflag = 1; + break; + case 's': + /* merge accounting file into summaries */ + sflag = 1; + break; + case 't': + /* report ratio of user and system times */ + tflag = 1; + break; + case 'u': + /* first, print uid and command name */ + uflag = 1; + break; + case 'v': + /* cull junk */ + vflag = 1; + cutoff = atoi(optarg); + break; + case '?': + default: + usage(); + } + + argc -= optind; + argv += optind; + + /* various argument checking */ + if (fflag && !vflag) + errx(1, "only one of -f requires -v"); + if (fflag && aflag) + errx(1, "only one of -a and -v may be specified"); + /* XXX need more argument checking */ + + if (!uflag) { + /* initialize tables */ + if ((sflag || (!mflag && !qflag)) && pacct_init() != 0) + errx(1, "process accounting initialization failed"); + if ((sflag || (mflag && !qflag)) && usracct_init() != 0) + errx(1, "user accounting initialization failed"); + } + + if (argc == 0) { + argc = dfltargc; + argv = dfltargv; + } + + /* for each file specified */ + for (; argc > 0; argc--, argv++) { + int fd; + + /* + * load the accounting data from the file. + * if it fails, go on to the next file. + */ + fd = acct_load(argv[0], sflag); + if (fd < 0) + continue; + + if (!uflag && sflag) { +#ifndef DEBUG + sigset_t nmask, omask; + int unmask = 1; + + /* + * block most signals so we aren't interrupted during + * the update. + */ + if (sigfillset(&nmask) == -1) { + warn("sigfillset"); + unmask = 0; + error = 1; + } + if (unmask && + (sigprocmask(SIG_BLOCK, &nmask, &omask) == -1)) { + warn("couldn't set signal mask"); + unmask = 0; + error = 1; + } +#endif /* DEBUG */ + + /* + * truncate the accounting data file ASAP, to avoid + * losing data. don't worry about errors in updating + * the saved stats; better to underbill than overbill, + * but we want every accounting record intact. + */ + if (ftruncate(fd, 0) == -1) { + warn("couldn't truncate %s", *argv); + error = 1; + } + + /* + * update saved user and process accounting data. + * note errors for later. + */ + if (pacct_update() != 0 || usracct_update() != 0) + error = 1; + +#ifndef DEBUG + /* + * restore signals + */ + if (unmask && + (sigprocmask(SIG_SETMASK, &omask, NULL) == -1)) { + warn("couldn't restore signal mask"); + error = 1; + } +#endif /* DEBUG */ + } + + /* + * close the opened accounting file + */ + if (close(fd) == -1) { + warn("close %s", *argv); + error = 1; + } + } + + if (!uflag && !qflag) { + /* print any results we may have obtained. */ + if (!mflag) + pacct_print(); + else + usracct_print(); + } + + if (!uflag) { + /* finally, deallocate databases */ + if (sflag || (!mflag && !qflag)) + pacct_destroy(); + if (sflag || (mflag && !qflag)) + usracct_destroy(); + } + + exit(error); +} + +static void +usage() +{ + (void)fprintf(stderr, + "usage: sa [-abcdDfijkKlmnqrstu] [-v cutoff] [file ...]\n"); + exit(1); +} + +static int +acct_load(pn, wr) + char *pn; + int wr; +{ + struct acct ac; + struct cmdinfo ci; + ssize_t rv; + int fd, i; + + /* + * open the file + */ + fd = open(pn, wr ? O_RDWR : O_RDONLY, 0); + if (fd == -1) { + warn("open %s %s", pn, wr ? "for read/write" : "read-only"); + return (-1); + } + + /* + * read all we can; don't stat and open because more processes + * could exit, and we'd miss them + */ + while (1) { + /* get one accounting entry and punt if there's an error */ + rv = read(fd, &ac, sizeof(struct acct)); + if (rv == -1) + warn("error reading %s", pn); + else if (rv > 0 && rv < (int)sizeof(struct acct)) + warnx("short read of accounting data in %s", pn); + if (rv != sizeof(struct acct)) + break; + + /* decode it */ + ci.ci_calls = 1; + for (i = 0; i < (int)sizeof ac.ac_comm && ac.ac_comm[i] != '\0'; + i++) { + char c = ac.ac_comm[i]; + + if (!isascii(c) || iscntrl(c)) { + ci.ci_comm[i] = '?'; + ci.ci_flags |= CI_UNPRINTABLE; + } else + ci.ci_comm[i] = c; + } + if (ac.ac_flag & AFORK) + ci.ci_comm[i++] = '*'; + ci.ci_comm[i++] = '\0'; + ci.ci_etime = decode_comp_t(ac.ac_etime); + ci.ci_utime = decode_comp_t(ac.ac_utime); + ci.ci_stime = decode_comp_t(ac.ac_stime); + ci.ci_uid = ac.ac_uid; + ci.ci_mem = ac.ac_mem; + ci.ci_io = decode_comp_t(ac.ac_io) / AHZ; + + if (!uflag) { + /* and enter it into the usracct and pacct databases */ + if (sflag || (!mflag && !qflag)) + pacct_add(&ci); + if (sflag || (mflag && !qflag)) + usracct_add(&ci); + } else if (!qflag) + printf("%6lu %12.2f cpu %12juk mem %12ju io %s\n", + ci.ci_uid, + (ci.ci_utime + ci.ci_stime) / (double) AHZ, + (uintmax_t)ci.ci_mem, (uintmax_t)ci.ci_io, + ci.ci_comm); + } + + /* finally, return the file descriptor for possible truncation */ + return (fd); +} + +static u_quad_t +decode_comp_t(comp) + comp_t comp; +{ + u_quad_t rv; + + /* + * for more info on the comp_t format, see: + * /usr/src/sys/kern/kern_acct.c + * /usr/src/sys/sys/acct.h + * /usr/src/usr.bin/lastcomm/lastcomm.c + */ + rv = comp & 0x1fff; /* 13 bit fraction */ + comp >>= 13; /* 3 bit base-8 exponent */ + while (comp--) + rv <<= 3; + + return (rv); +} + +/* sort commands, doing the right thing in terms of reversals */ +static int +cmp_comm(s1, s2) + const char *s1, *s2; +{ + int rv; + + rv = strcmp(s1, s2); + if (rv == 0) + rv = -1; + return (rflag ? rv : -rv); +} + +/* sort by total user and system time */ +static int +cmp_usrsys(d1, d2) + const DBT *d1, *d2; +{ + struct cmdinfo c1, c2; + u_quad_t t1, t2; + + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); + + t1 = c1.ci_utime + c1.ci_stime; + t2 = c2.ci_utime + c2.ci_stime; + + if (t1 < t2) + return -1; + else if (t1 == t2) + return (cmp_comm(c1.ci_comm, c2.ci_comm)); + else + return 1; +} + +/* sort by average user and system time */ +static int +cmp_avgusrsys(d1, d2) + const DBT *d1, *d2; +{ + struct cmdinfo c1, c2; + double t1, t2; + + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); + + t1 = c1.ci_utime + c1.ci_stime; + t1 /= (double) (c1.ci_calls ? c1.ci_calls : 1); + + t2 = c2.ci_utime + c2.ci_stime; + t2 /= (double) (c2.ci_calls ? c2.ci_calls : 1); + + if (t1 < t2) + return -1; + else if (t1 == t2) + return (cmp_comm(c1.ci_comm, c2.ci_comm)); + else + return 1; +} + +/* sort by total number of disk I/O operations */ +static int +cmp_dkio(d1, d2) + const DBT *d1, *d2; +{ + struct cmdinfo c1, c2; + + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); + + if (c1.ci_io < c2.ci_io) + return -1; + else if (c1.ci_io == c2.ci_io) + return (cmp_comm(c1.ci_comm, c2.ci_comm)); + else + return 1; +} + +/* sort by average number of disk I/O operations */ +static int +cmp_avgdkio(d1, d2) + const DBT *d1, *d2; +{ + struct cmdinfo c1, c2; + double n1, n2; + + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); + + n1 = (double) c1.ci_io / (double) (c1.ci_calls ? c1.ci_calls : 1); + n2 = (double) c2.ci_io / (double) (c2.ci_calls ? c2.ci_calls : 1); + + if (n1 < n2) + return -1; + else if (n1 == n2) + return (cmp_comm(c1.ci_comm, c2.ci_comm)); + else + return 1; +} + +/* sort by the cpu-storage integral */ +static int +cmp_cpumem(d1, d2) + const DBT *d1, *d2; +{ + struct cmdinfo c1, c2; + + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); + + if (c1.ci_mem < c2.ci_mem) + return -1; + else if (c1.ci_mem == c2.ci_mem) + return (cmp_comm(c1.ci_comm, c2.ci_comm)); + else + return 1; +} + +/* sort by the cpu-time average memory usage */ +static int +cmp_avgcpumem(d1, d2) + const DBT *d1, *d2; +{ + struct cmdinfo c1, c2; + u_quad_t t1, t2; + double n1, n2; + + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); + + t1 = c1.ci_utime + c1.ci_stime; + t2 = c2.ci_utime + c2.ci_stime; + + n1 = (double) c1.ci_mem / (double) (t1 ? t1 : 1); + n2 = (double) c2.ci_mem / (double) (t2 ? t2 : 1); + + if (n1 < n2) + return -1; + else if (n1 == n2) + return (cmp_comm(c1.ci_comm, c2.ci_comm)); + else + return 1; +} + +/* sort by the number of invocations */ +static int +cmp_calls(d1, d2) + const DBT *d1, *d2; +{ + struct cmdinfo c1, c2; + + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); + + if (c1.ci_calls < c2.ci_calls) + return -1; + else if (c1.ci_calls == c2.ci_calls) + return (cmp_comm(c1.ci_comm, c2.ci_comm)); + else + return 1; +} diff --git a/sa.tproj/pathnames.h b/sa.tproj/pathnames.h new file mode 100644 index 0000000..8cb7f44 --- /dev/null +++ b/sa.tproj/pathnames.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 1994 Christopher G. Demetriou + * 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 Christopher G. Demetriou. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/usr.sbin/sa/pathnames.h,v 1.4 1999/08/28 01:19:52 peter Exp $ + */ + +#define _PATH_ACCT "/var/account/acct" +#define _PATH_SAVACCT "/var/account/savacct" +#define _PATH_USRACCT "/var/account/usracct" diff --git a/sa.tproj/pdb.c b/sa.tproj/pdb.c new file mode 100644 index 0000000..f0dd48b --- /dev/null +++ b/sa.tproj/pdb.c @@ -0,0 +1,424 @@ +/* + * Copyright (c) 1994 Christopher G. Demetriou + * 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 Christopher G. Demetriou. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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[] = + "$FreeBSD: src/usr.sbin/sa/pdb.c,v 1.9 2002/07/15 16:05:15 des Exp $"; +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "extern.h" +#include "pathnames.h" + +static int check_junk __P((struct cmdinfo *)); +static void add_ci __P((const struct cmdinfo *, struct cmdinfo *)); +static void print_ci __P((const struct cmdinfo *, const struct cmdinfo *)); + +static DB *pacct_db; + +int +pacct_init() +{ + DB *saved_pacct_db; + int error; + + pacct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL); + if (pacct_db == NULL) + return (-1); + + error = 0; + if (!iflag) { + DBT key, data; + int serr, nerr; + + saved_pacct_db = dbopen(_PATH_SAVACCT, O_RDONLY, 0, DB_BTREE, + NULL); + if (saved_pacct_db == NULL) { + error = errno == ENOENT ? 0 : -1; + if (error) + warn("retrieving process accounting summary"); + goto out; + } + + serr = DB_SEQ(saved_pacct_db, &key, &data, R_FIRST); + if (serr < 0) { + warn("retrieving process accounting summary"); + error = -1; + goto closeout; + } + while (serr == 0) { + nerr = DB_PUT(pacct_db, &key, &data, 0); + if (nerr < 0) { + warn("initializing process accounting stats"); + error = -1; + break; + } + + serr = DB_SEQ(saved_pacct_db, &key, &data, R_NEXT); + if (serr < 0) { + warn("retrieving process accounting summary"); + error = -1; + break; + } + } + +closeout: if (DB_CLOSE(saved_pacct_db) < 0) { + warn("closing process accounting summary"); + error = -1; + } + } + +out: if (error != 0) + pacct_destroy(); + return (error); +} + +void +pacct_destroy() +{ + if (DB_CLOSE(pacct_db) < 0) + warn("destroying process accounting stats"); +} + +int +pacct_add(ci) + const struct cmdinfo *ci; +{ + DBT key, data; + struct cmdinfo newci; + char keydata[sizeof ci->ci_comm]; + int rv; + + bcopy(ci->ci_comm, &keydata, sizeof keydata); + key.data = &keydata; + key.size = strlen(keydata); + + rv = DB_GET(pacct_db, &key, &data, 0); + if (rv < 0) { + warn("get key %s from process accounting stats", ci->ci_comm); + return (-1); + } else if (rv == 0) { /* it's there; copy whole thing */ + /* XXX compare size if paranoid */ + /* add the old data to the new data */ + bcopy(data.data, &newci, data.size); + } else { /* it's not there; zero it and copy the key */ + bzero(&newci, sizeof newci); + bcopy(key.data, newci.ci_comm, key.size); + } + + add_ci(ci, &newci); + + data.data = &newci; + data.size = sizeof newci; + rv = DB_PUT(pacct_db, &key, &data, 0); + if (rv < 0) { + warn("add key %s to process accounting stats", ci->ci_comm); + return (-1); + } else if (rv == 1) { + warnx("duplicate key %s in process accounting stats", + ci->ci_comm); + return (-1); + } + + return (0); +} + +int +pacct_update() +{ + DB *saved_pacct_db; + DBT key, data; + int error, serr, nerr; + + saved_pacct_db = dbopen(_PATH_SAVACCT, O_RDWR|O_CREAT|O_TRUNC, 0644, + DB_BTREE, NULL); + if (saved_pacct_db == NULL) { + warn("creating process accounting summary"); + return (-1); + } + + error = 0; + + serr = DB_SEQ(pacct_db, &key, &data, R_FIRST); + if (serr < 0) { + warn("retrieving process accounting stats"); + error = -1; + } + while (serr == 0) { + nerr = DB_PUT(saved_pacct_db, &key, &data, 0); + if (nerr < 0) { + warn("saving process accounting summary"); + error = -1; + break; + } + + serr = DB_SEQ(pacct_db, &key, &data, R_NEXT); + if (serr < 0) { + warn("retrieving process accounting stats"); + error = -1; + break; + } + } + + if (DB_SYNC(saved_pacct_db, 0) < 0) { + warn("syncing process accounting summary"); + error = -1; + } + if (DB_CLOSE(saved_pacct_db) < 0) { + warn("closing process accounting summary"); + error = -1; + } + return error; +} + +void +pacct_print() +{ + BTREEINFO bti; + DBT key, data, ndata; + DB *output_pacct_db; + struct cmdinfo *cip, ci, ci_total, ci_other, ci_junk; + int rv; + + bzero(&ci_total, sizeof ci_total); + strcpy(ci_total.ci_comm, ""); + bzero(&ci_other, sizeof ci_other); + strcpy(ci_other.ci_comm, "***other"); + bzero(&ci_junk, sizeof ci_junk); + strcpy(ci_junk.ci_comm, "**junk**"); + + /* + * Retrieve them into new DB, sorted by appropriate key. + * At the same time, cull 'other' and 'junk' + */ + bzero(&bti, sizeof bti); + bti.compare = sa_cmp; + output_pacct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, &bti); + if (output_pacct_db == NULL) { + warn("couldn't sort process accounting stats"); + return; + } + + ndata.data = NULL; + ndata.size = 0; + rv = DB_SEQ(pacct_db, &key, &data, R_FIRST); + if (rv < 0) + warn("retrieving process accounting stats"); + while (rv == 0) { + cip = (struct cmdinfo *) data.data; + bcopy(cip, &ci, sizeof ci); + + /* add to total */ + add_ci(&ci, &ci_total); + + if (vflag && ci.ci_calls <= cutoff && + (fflag || check_junk(&ci))) { + /* put it into **junk** */ + add_ci(&ci, &ci_junk); + goto next; + } + if (!aflag && + ((ci.ci_flags & CI_UNPRINTABLE) != 0 || ci.ci_calls <= 1)) { + /* put into ***other */ + add_ci(&ci, &ci_other); + goto next; + } + rv = DB_PUT(output_pacct_db, &data, &ndata, 0); + if (rv < 0) + warn("sorting process accounting stats"); + +next: rv = DB_SEQ(pacct_db, &key, &data, R_NEXT); + if (rv < 0) + warn("retrieving process accounting stats"); + } + + /* insert **junk** and ***other */ + if (ci_junk.ci_calls != 0) { + data.data = &ci_junk; + data.size = sizeof ci_junk; + rv = DB_PUT(output_pacct_db, &data, &ndata, 0); + if (rv < 0) + warn("sorting process accounting stats"); + } + if (ci_other.ci_calls != 0) { + data.data = &ci_other; + data.size = sizeof ci_other; + rv = DB_PUT(output_pacct_db, &data, &ndata, 0); + if (rv < 0) + warn("sorting process accounting stats"); + } + + /* print out the total */ + print_ci(&ci_total, &ci_total); + + /* print out; if reversed, print first (smallest) first */ + rv = DB_SEQ(output_pacct_db, &data, &ndata, rflag ? R_FIRST : R_LAST); + if (rv < 0) + warn("retrieving process accounting report"); + while (rv == 0) { + cip = (struct cmdinfo *) data.data; + bcopy(cip, &ci, sizeof ci); + + print_ci(&ci, &ci_total); + + rv = DB_SEQ(output_pacct_db, &data, &ndata, + rflag ? R_NEXT : R_PREV); + if (rv < 0) + warn("retrieving process accounting report"); + } + DB_CLOSE(output_pacct_db); +} + +static int +check_junk(cip) + struct cmdinfo *cip; +{ + char *cp; + size_t len; + + fprintf(stderr, "%s (%ju) -- ", cip->ci_comm, (uintmax_t)cip->ci_calls); + cp = fgetln(stdin, &len); + + return (cp && (cp[0] == 'y' || cp[0] == 'Y')) ? 1 : 0; +} + +static void +add_ci(fromcip, tocip) + const struct cmdinfo *fromcip; + struct cmdinfo *tocip; +{ + tocip->ci_calls += fromcip->ci_calls; + tocip->ci_etime += fromcip->ci_etime; + tocip->ci_utime += fromcip->ci_utime; + tocip->ci_stime += fromcip->ci_stime; + tocip->ci_mem += fromcip->ci_mem; + tocip->ci_io += fromcip->ci_io; +} + +static void +print_ci(cip, totalcip) + const struct cmdinfo *cip, *totalcip; +{ + double t, c; + int uflow; + + c = cip->ci_calls ? cip->ci_calls : 1; + t = (cip->ci_utime + cip->ci_stime) / (double) AHZ; + if (t < 0.01) { + t = 0.01; + uflow = 1; + } else + uflow = 0; + + printf("%8ju ", (uintmax_t)cip->ci_calls); + if (cflag) { + if (cip != totalcip) + printf(" %4.2f%% ", + cip->ci_calls / (double) totalcip->ci_calls); + else + printf(" %4s ", ""); + } + + if (jflag) + printf("%11.2fre ", cip->ci_etime / (double) (AHZ * c)); + else + printf("%11.2fre ", cip->ci_etime / (60.0 * AHZ)); + if (cflag) { + if (cip != totalcip) + printf(" %4.2f%% ", + cip->ci_etime / (double) totalcip->ci_etime); + else + printf(" %4s ", ""); + } + + if (!lflag) { + if (jflag) + printf("%11.2fcp ", t / (double) cip->ci_calls); + else + printf("%11.2fcp ", t / 60.0); + if (cflag) { + if (cip != totalcip) + printf(" %4.2f%% ", + (cip->ci_utime + cip->ci_stime) / (double) + (totalcip->ci_utime + totalcip->ci_stime)); + else + printf(" %4s ", ""); + } + } else { + if (jflag) + printf("%11.2fu ", cip->ci_utime / (double) (AHZ * c)); + else + printf("%11.2fu ", cip->ci_utime / (60.0 * AHZ)); + if (cflag) { + if (cip != totalcip) + printf(" %4.2f%% ", cip->ci_utime / (double) totalcip->ci_utime); + else + printf(" %4s ", ""); + } + if (jflag) + printf("%11.2fs ", cip->ci_stime / (double) (AHZ * c)); + else + printf("%11.2fs ", cip->ci_stime / (60.0 * AHZ)); + if (cflag) { + if (cip != totalcip) + printf(" %4.2f%% ", cip->ci_stime / (double) totalcip->ci_stime); + else + printf(" %4s ", ""); + } + } + + if (tflag) { + if (!uflow) + printf("%8.2fre/cp ", + cip->ci_etime / + (double) (cip->ci_utime + cip->ci_stime)); + else + printf("*ignore* "); + } + + if (Dflag) + printf("%10jutio ", (uintmax_t)cip->ci_io); + else + printf("%8.0favio ", cip->ci_io / c); + + if (Kflag) + printf("%10juk*sec ", (uintmax_t)cip->ci_mem); + else + printf("%8.0fk ", cip->ci_mem / t); + + printf(" %s\n", cip->ci_comm); +} diff --git a/sa.tproj/sa.8 b/sa.tproj/sa.8 new file mode 100644 index 0000000..4ba9503 --- /dev/null +++ b/sa.tproj/sa.8 @@ -0,0 +1,237 @@ +.\" +.\" Copyright (c) 1994 Christopher G. Demetriou +.\" 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 Christopher G. Demetriou. +.\" 3. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/usr.sbin/sa/sa.8,v 1.15 2002/07/14 14:46:01 charnier Exp $ +.\" +.Dd February 25, 1994 +.Dt SA 8 +.Os +.Sh NAME +.Nm sa +.Nd print system accounting statistics +.Sh SYNOPSIS +.Nm +.Op Fl abcdDfijkKlmnqrstu +.Op Fl v Ar cutoff +.Op Ar +.Sh DESCRIPTION +The +.Nm +utility reports on, cleans up, +and generally maintains system +accounting files. +.Pp +The +.Nm +utility is able to condense the information in +.Pa /var/account/acct +into the summary files +.Pa /var/account/savacct +and +.Pa /var/account/usracct , +which contain system statistics according +to command name and login id, respectively. +This condensation is desirable because on a +large system, +.Pa /var/account/acct +can grow by hundreds of blocks per day. +The summary files are normally read before +the accounting file, so that reports include +all available information. +.Pp +If file names are supplied, they are read instead of +.Pa /var/account/acct . +After each file is read, if the summary +files are being updated, an updated summary will +be saved to disk. Only one report is printed, +after the last file is processed. +.Pp +The labels used in the output indicate the following, except +where otherwise specified by individual options: +.Bl -tag -width k*sec +.It Dv avio +Average number of I/O operations per execution +.It Dv cp +Sum of user and system time, in minutes +.It Dv cpu +Same as +.Dv cp +.It Dv k +CPU-time averaged core usage, in 1k units +.It Dv k*sec +CPU storage integral, in 1k-core seconds +.It Dv re +Real time, in minutes +.It Dv s +System time, in minutes +.It Dv tio +Total number of I/O operations +.It Dv u +User time, in minutes +.El +.Pp +The options to +.Nm +are: +.Bl -tag -width Ds +.It Fl a +List all command names, including those containing unprintable +characters and those used only once. By default, +.Nm +places all names containing unprintable characters and +those used only once under the name ``***other''. +.It Fl b +If printing command statistics, sort output by the sum of user and system +time divided by number of calls. +.It Fl c +In addition to the number of calls and the user, system and real times +for each command, print their percentage of the total over all commands. +.It Fl d +If printing command statistics, sort by the average number of disk +I/O operations. If printing user statistics, print the average number of +disk I/O operations per user. +.It Fl D +If printing command statistics, sort and print by the total number +of disk I/O operations. +.It Fl f +Force no interactive threshold comparison with the +.Fl v +option. +.It Fl i +Do not read in the summary files. +.It Fl j +Instead of the total minutes per category, give seconds per call. +.It Fl k +If printing command statistics, sort by the cpu-time average memory +usage. If printing user statistics, print the cpu-time average +memory usage. +.It Fl K +If printing command statistics, print and sort by the cpu-storage integral. +.It Fl l +Separate system and user time; normally they are combined. +.It Fl m +Print per-user statistics rather than per-command statistics. +.It Fl n +Sort by number of calls. +.It Fl q +Create no output other than error messages. +.It Fl r +Reverse order of sort. +.It Fl s +Truncate the accounting files when done and merge their data +into the summary files. +.It Fl t +For each command, report the ratio of real time to the sum +of user and system cpu times. +If the cpu time is too small to report, ``*ignore*'' appears in +this field. +.It Fl u +Superseding all other flags, for each entry +in the accounting file, print the user ID, total seconds of cpu usage, +total memory usage, number of I/O operations performed, and +command name. +.It Fl v Ar cutoff +For each command used +.Ar cutoff +times or fewer, print the command name and await a reply +from the terminal. If the reply begins with ``y'', add +the command to the category ``**junk**''. This flag is +used to strip garbage from the report. +.El +.Pp +By default, per-command statistics will be printed. The number of +calls, the total elapsed time in minutes, total cpu and user time +in minutes, average number of I/O operations, and CPU-time +averaged core usage will be printed. If the +.Fl m +option is specified, per-user statistics will be printed, including +the user name, the number of commands invoked, total cpu time used +(in minutes), total number of I/O operations, and CPU storage integral +for each user. If the +.Fl u +option is specified, the uid, user and system time (in seconds), +CPU storage integral, I/O usage, and command name will be printed +for each entry in the accounting data file. +.Pp +If the +.Fl u +flag is specified, all flags other than +.Fl q +are ignored. If the +.Fl m +flag is specified, only the +.Fl b , +.Fl d , +.Fl i , +.Fl k , +.Fl q , +and +.Fl s +flags are honored. +.Sh DIAGNOSTICS +.Ex -std +.Sh FILES +.Bl -tag -width /var/account/usracct -compact +.It Pa /var/account/acct +raw accounting data file +.It Pa /var/account/savacct +per-command accounting summary database +.It Pa /var/account/usracct +per-user accounting summary database +.El +.Sh SEE ALSO +.Xr lastcomm 1 , +.Xr acct 5 , +.Xr ac 8 , +.Xr accton 8 +.Sh BUGS +The number of options to this program is absurd, especially considering +that there's not much logic behind their lettering. +.Pp +The field labels should be more consistent. +.Pp +The VM system does not record the CPU storage integral. +.Sh CAVEATS +While the behavior of the options in this version of +.Nm +was modeled after the original version, there are some intentional +differences and undoubtedly some unintentional ones as well. In +particular, the +.Fl q +option has been added, and the +.Fl m +option now understands more options than it used to. +.Pp +The formats of the summary files created by this version of +.Nm +are very different from the those used by the original version. +This is not considered a problem, however, because the accounting record +format has changed as well (since user ids are now 32 bits). +.Sh AUTHORS +.An Chris G. Demetriou Aq cgd@postgres.berkeley.edu diff --git a/sa.tproj/usrdb.c b/sa.tproj/usrdb.c new file mode 100644 index 0000000..dda96ae --- /dev/null +++ b/sa.tproj/usrdb.c @@ -0,0 +1,288 @@ +/* + * Copyright (c) 1994 Christopher G. Demetriou + * 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 Christopher G. Demetriou. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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[] = + "$FreeBSD: src/usr.sbin/sa/usrdb.c,v 1.12 2002/07/15 16:05:15 des Exp $"; +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "extern.h" +#include "pathnames.h" + +static int uid_compare __P((const DBT *, const DBT *)); + +static DB *usracct_db; + +int +usracct_init() +{ + DB *saved_usracct_db; + BTREEINFO bti; + int error; + + bzero(&bti, sizeof bti); + bti.compare = uid_compare; + + usracct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, &bti); + if (usracct_db == NULL) + return (-1); + + error = 0; + if (!iflag) { + DBT key, data; + int serr, nerr; + + saved_usracct_db = dbopen(_PATH_USRACCT, O_RDONLY, 0, DB_BTREE, + &bti); + if (saved_usracct_db == NULL) { + error = (errno == ENOENT) ? 0 : -1; + if (error) + warn("retrieving user accounting summary"); + goto out; + } + + serr = DB_SEQ(saved_usracct_db, &key, &data, R_FIRST); + if (serr < 0) { + warn("retrieving user accounting summary"); + error = -1; + goto closeout; + } + while (serr == 0) { + nerr = DB_PUT(usracct_db, &key, &data, 0); + if (nerr < 0) { + warn("initializing user accounting stats"); + error = -1; + break; + } + + serr = DB_SEQ(saved_usracct_db, &key, &data, R_NEXT); + if (serr < 0) { + warn("retrieving user accounting summary"); + error = -1; + break; + } + } + +closeout: + if (DB_CLOSE(saved_usracct_db) < 0) { + warn("closing user accounting summary"); + error = -1; + } + } + +out: + if (error != 0) + usracct_destroy(); + return (error); +} + +void +usracct_destroy() +{ + if (DB_CLOSE(usracct_db) < 0) + warn("destroying user accounting stats"); +} + +int +usracct_add(ci) + const struct cmdinfo *ci; +{ + DBT key, data; + struct userinfo newui; + u_long uid; + int rv; + + uid = ci->ci_uid; + key.data = &uid; + key.size = sizeof uid; + + rv = DB_GET(usracct_db, &key, &data, 0); + if (rv < 0) { + warn("get key %lu from user accounting stats", uid); + return (-1); + } else if (rv == 0) { /* it's there; copy whole thing */ + /* add the old data to the new data */ + bcopy(data.data, &newui, data.size); + if (newui.ui_uid != uid) { + warnx("key %lu != expected record number %lu", + newui.ui_uid, uid); + warnx("inconsistent user accounting stats"); + return (-1); + } + } else { /* it's not there; zero it and copy the key */ + bzero(&newui, sizeof newui); + newui.ui_uid = ci->ci_uid; + } + + newui.ui_calls += ci->ci_calls; + newui.ui_utime += ci->ci_utime; + newui.ui_stime += ci->ci_stime; + newui.ui_mem += ci->ci_mem; + newui.ui_io += ci->ci_io; + + data.data = &newui; + data.size = sizeof newui; + rv = DB_PUT(usracct_db, &key, &data, 0); + if (rv < 0) { + warn("add key %lu to user accounting stats", uid); + return (-1); + } else if (rv != 0) { + warnx("DB_PUT returned 1"); + return (-1); + } + + return (0); +} + +int +usracct_update() +{ + DB *saved_usracct_db; + DBT key, data; + BTREEINFO bti; + int error, serr, nerr; + + bzero(&bti, sizeof bti); + bti.compare = uid_compare; + + saved_usracct_db = dbopen(_PATH_USRACCT, O_RDWR|O_CREAT|O_TRUNC, 0644, + DB_BTREE, &bti); + if (saved_usracct_db == NULL) { + warn("creating user accounting summary"); + return (-1); + } + + error = 0; + + serr = DB_SEQ(usracct_db, &key, &data, R_FIRST); + if (serr < 0) { + warn("retrieving user accounting stats"); + error = -1; + } + while (serr == 0) { + nerr = DB_PUT(saved_usracct_db, &key, &data, 0); + if (nerr < 0) { + warn("saving user accounting summary"); + error = -1; + break; + } + + serr = DB_SEQ(usracct_db, &key, &data, R_NEXT); + if (serr < 0) { + warn("retrieving user accounting stats"); + error = -1; + break; + } + } + + if (DB_SYNC(saved_usracct_db, 0) < 0) { + warn("syncing process accounting summary"); + error = -1; + } + if (DB_CLOSE(saved_usracct_db) < 0) { + warn("closing process accounting summary"); + error = -1; + } + return error; +} + +void +usracct_print() +{ + DBT key, data; + struct userinfo uistore, *ui = &uistore; + double t; + int rv; + + rv = DB_SEQ(usracct_db, &key, &data, R_FIRST); + if (rv < 0) + warn("retrieving user accounting stats"); + + while (rv == 0) { + memcpy(ui, data.data, sizeof(struct userinfo)); + + printf("%-*s %9ju ", MAXLOGNAME - 1, + user_from_uid(ui->ui_uid, 0), (uintmax_t)ui->ui_calls); + + t = (double) (ui->ui_utime + ui->ui_stime) / + (double) AHZ; + if (t < 0.0001) /* kill divide by zero */ + t = 0.0001; + + printf("%12.2f%s ", t / 60.0, "cpu"); + + /* ui->ui_calls is always != 0 */ + if (dflag) + printf("%12ju%s", + (uintmax_t)(ui->ui_io / ui->ui_calls), "avio"); + else + printf("%12ju%s", (uintmax_t)ui->ui_io, "tio"); + + /* t is always >= 0.0001; see above */ + if (kflag) + printf("%12.0f%s", ui->ui_mem / t, "k"); + else + printf("%12ju%s", (uintmax_t)ui->ui_mem, "k*sec"); + + printf("\n"); + + rv = DB_SEQ(usracct_db, &key, &data, R_NEXT); + if (rv < 0) + warn("retrieving user accounting stats"); + } +} + +static int +uid_compare(k1, k2) + const DBT *k1, *k2; +{ + u_long d1, d2; + + bcopy(k1->data, &d1, sizeof d1); + bcopy(k2->data, &d2, sizeof d2); + + if (d1 < d2) + return -1; + else if (d1 == d2) + return 0; + else + return 1; +} diff --git a/sadc.tproj/sadc.c b/sadc.tproj/sadc.c index 8b67b3f..bbbe829 100644 --- a/sadc.tproj/sadc.c +++ b/sadc.tproj/sadc.c @@ -42,6 +42,7 @@ #include #include #include +#include #include @@ -79,10 +80,6 @@ int dp_count = 0; struct netstats *ns_table = NULL; int ns_count = 0; -static kvm_t *kvmd; -static struct nlist nlist_net[2]; -int kvm_init_failed = 0; - static uid_t realuid; int network_mode = 0; @@ -99,8 +96,6 @@ static int get_ndrives(); static int record_device(io_registry_entry_t, struct drivestats *, int ndrives); static int check_device_path (char *name, char *path, int ndrives); static void get_netstat_sample(int pppflag); -static int kvm_init(); -static int kread(u_long addr, void *buf, size_t nbytes); int main(argc, argv) @@ -816,68 +811,6 @@ check_device_path (char *name, char *path, int ndrives) } -/* - * success - returns 1 - * failure - returns 0 - */ -static int -kvm_init() -{ - int retval = 1; - char errbuf[_POSIX2_LINE_MAX]; - - - /* - * Initialize the kvm descriptor and get the location of _ifnet in - * preparation for gathering network statistics. - * - * We become root again momentarily so that we have permission to - * open /dev/kmem. - */ - if (seteuid(0)) - { - fprintf(stderr, "sar: root privleges denied\n"); - retval = 0; - goto RETURN; - } - kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); - setuid(realuid); - - if (kvmd == NULL) { - fprintf(stderr, "sar: error in kvm_openfiles(): %s", errbuf); - retval = 0; - goto RETURN; - } - nlist_net[0].n_name = "_ifnet"; - nlist_net[1].n_name = NULL; - if (kvm_nlist(kvmd, nlist_net) < 0) { - fprintf(stderr,"sar: error in kvm_nlist(): %s", kvm_geterr(kvmd)); - retval = 0; - goto RETURN; - } - if (nlist_net[0].n_type == N_UNDF) { - fprintf(stderr, "sadc: No nlist for _ifnet"); - retval = 0; - goto RETURN; - } - RETURN: - return (retval); -} - -/* Read data from kernel memory. */ -static int -kread(u_long addr, void *buf, size_t nbytes) -{ - int retval = 0; - - if (kvm_read(kvmd, addr, buf, nbytes) != (ssize_t)nbytes) { - fprintf(stderr, "sadc: error in kvm_read(): %s\n", kvm_geterr(kvmd)); - retval = 1; - } - - return (retval); -} - /* * Thus far, only the networking stats take an optional flag @@ -893,22 +826,10 @@ get_netstat_sample(int mode) int n; int ns_index = 0; - struct ifnet ifnet; - struct ifnethead ifnethead; - u_long off; char tname[MAX_TNAME_SIZE + 1]; char name[MAX_TNAME_UNIT_SIZE + 1]; + struct ifaddrs *ifa_list, *ifa; - if (ns_table == NULL) - { - /* this is our first sample -- do some init */ - - /* if kvm_init fails, we don't retry */ - if (kvm_init_failed || !kvm_init()) - { - kvm_init_failed = 1; - return; - } /* * Set the starting table size to 100 entries @@ -922,24 +843,19 @@ get_netstat_sample(int mode) fprintf(stderr, "sadc: malloc netstat table failed\n"); return; } - } bzero(ns_table, ns_count * sizeof(struct netstats)); - if (nlist_net[0].n_value != 0 - && kread(nlist_net[0].n_value, &ifnethead, sizeof(ifnethead)) == 0) - { - for (ns_index = 0, off = (u_long)ifnethead.tqh_first; - off != 0; - off = (u_long)ifnet.if_link.tqe_next) + if (getifaddrs(&ifa_list) == -1) + return; + + for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) { - if (kread(off, &ifnet, sizeof(ifnet))) - { - break; - } - if (kread((u_long)ifnet.if_name, tname, sizeof(tname))) - { - break; - } + struct if_data *if_data = (struct if_data *)ifa->ifa_data; + + if (AF_LINK != ifa->ifa_addr->sa_family) + continue; + if (ifa->ifa_data == 0) + continue; tname[MAX_TNAME_SIZE] = '\0'; if (!(network_mode & NET_PPP_MODE)) { @@ -947,10 +863,10 @@ get_netstat_sample(int mode) * If the flag is set, include PPP connections. * By default this collection is turned off */ - if(!strncmp(tname, "ppp", 3)) + if(!strncmp(ifa->ifa_name, "ppp", 3)) continue; } - snprintf(name, MAX_TNAME_UNIT_SIZE, "%s%d", tname, ifnet.if_unit); + snprintf(name, MAX_TNAME_UNIT_SIZE, "%s", ifa->ifa_name); name[MAX_TNAME_UNIT_SIZE] = '\0'; if (ns_index == ns_count) @@ -962,7 +878,6 @@ get_netstat_sample(int mode) ns_count = n; } - /* * As a means of helping to identify when interface unit numbers * are reused, a generation counter may eventually be implemented. @@ -974,16 +889,16 @@ get_netstat_sample(int mode) strncpy(ns_table[ns_index].tname_unit, name, MAX_TNAME_UNIT_SIZE); ns_table[ns_index].tname_unit[MAX_TNAME_UNIT_SIZE] = '\0'; - ns_table[ns_index].net_ipackets = ifnet.if_ipackets; - ns_table[ns_index].net_ierrors = ifnet.if_ierrors; - ns_table[ns_index].net_opackets = ifnet.if_opackets; - ns_table[ns_index].net_oerrors = ifnet.if_oerrors; - ns_table[ns_index].net_collisions = ifnet.if_collisions; - ns_table[ns_index].net_ibytes = ifnet.if_ibytes; - ns_table[ns_index].net_obytes = ifnet.if_obytes; - ns_table[ns_index].net_imcasts = ifnet.if_imcasts; - ns_table[ns_index].net_omcasts = ifnet.if_omcasts; - ns_table[ns_index].net_drops = ifnet.if_snd.ifq_drops; + ns_table[ns_index].net_ipackets = if_data->ifi_ipackets; + ns_table[ns_index].net_ierrors = if_data->ifi_ierrors; + ns_table[ns_index].net_opackets = if_data->ifi_opackets; + ns_table[ns_index].net_oerrors = if_data->ifi_oerrors; + ns_table[ns_index].net_collisions = if_data->ifi_collisions; + ns_table[ns_index].net_ibytes = if_data->ifi_ibytes; + ns_table[ns_index].net_obytes = if_data->ifi_obytes; + ns_table[ns_index].net_imcasts = if_data->ifi_imcasts; + ns_table[ns_index].net_omcasts = if_data->ifi_omcasts; + ns_table[ns_index].net_drops = if_data->ifi_iqdrops; ns_index++; } /* end for */ @@ -991,6 +906,5 @@ get_netstat_sample(int mode) netstats_record.rec_size = sizeof(struct netstats); write_record_hdr(&netstats_record); write_record_data((char *)ns_table, (ns_index * sizeof(struct netstats))); - } /* end if */ return; } diff --git a/sar.tproj/Makefile b/sar.tproj/Makefile index ffad6cd..e35a96a 100644 --- a/sar.tproj/Makefile +++ b/sar.tproj/Makefile @@ -31,7 +31,6 @@ PROF_LIBS = $(LIBS) HEADER_PATHS = -I. -FRAMEWORKS = -framework Foundation NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc diff --git a/sc_usage.tproj/sc_usage.c b/sc_usage.tproj/sc_usage.c index 6808993..da3c078 100644 --- a/sc_usage.tproj/sc_usage.c +++ b/sc_usage.tproj/sc_usage.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/sc_usage.tproj/trace.codes b/sc_usage.tproj/trace.codes index d8af9df..fb043d5 100644 --- a/sc_usage.tproj/trace.codes +++ b/sc_usage.tproj/trace.codes @@ -1,4 +1,4 @@ -917 +991 0x1f000000 DYLD_initialize 0x1f010000 DYLD_CALL_image_init_routine 0x1f010004 DYLD_CALL_dependent_init_routine @@ -47,15 +47,17 @@ 0x1f040010 DYLD_map_bundle_image 0x1f040014 DYLD_load_dependent_libraries 0x1f040018 DYLD_notify_prebinding_agent +0x21060000 LAUNCH_CPSTraceLineNum +0x21060004 LAUNCH_CPSLaunch +0x21060008 LAUNCH_CPSRegisterwithServer +0x2106000c LAUNCH_CPSCheckInNewProcess +0x21060010 LAUNCH_CPSServerSideLaunch +0x21060014 LAUNCH_CPSExecProcess 0x21070000 LAUNCH_LSOpen 0x21070004 LAUNCH_LSRegisterItem 0x21070008 LAUNCH_LSGetApplicationAndFlagsForInfo 0x1fff0000 LAUNCH_START_FINDER 0x1fff0100 LAUNCH_START_DOCK -0x1fff0300 LAUNCH_CPSLaunch -0x1fff0304 LAUNCH_CPSRegisterwithServer -0x1fff0308 LAUNCH_CGSCheckInNewProcess -0x1fff030c LAUNCH_CPSExecProcess 0x1fff0310 LAUNCH_APP_EnterEventLoop 0x1fff0314 LAUNCH_APP_WillOpenUntitled 0x1fff031c LAUNCH_APP_DidOpenUntitled @@ -65,6 +67,7 @@ 0xff000118 MSG_mach_notify_no_senders 0xff00011c MSG_mach_notify_send_once 0xff000120 MSG_mach_notify_dead_name +0xff0001ec MSG_audit_triggers 0xff000320 MSG_host_info 0xff000324 MSG_host_kernel_version 0xff000328 MSG_host_page_size @@ -83,6 +86,7 @@ 0xff00035c MSG_mach_memory_object_memory_entry_64 0xff000360 MSG_host_statistics 0xff000364 MSG_host_request_notification +0xff000368 MSG_host_lockgroup_info 0xff000640 MSG_host_get_boot_info 0xff000644 MSG_host_reboot 0xff000648 MSG_host_priv_statistics @@ -101,7 +105,7 @@ 0xff00067c MSG_host_get_exception_ports 0xff000680 MSG_host_swap_exception_ports 0xff000684 MSG_host_load_symbol_table -0xff000688 MSG_task_swappable +0xff000688 MSG_mach_vm_wire 0xff00068c MSG_host_processor_sets 0xff000690 MSG_host_processor_set_priv 0xff000694 MSG_set_dp_control_port @@ -148,6 +152,7 @@ 0xff0023a8 MSG_default_pager_backing_store_info 0xff0023ac MSG_default_pager_add_file 0xff0023b0 MSG_default_pager_triggers +0xff0023b4 MSG_default_pager_info_64 0xff0023dc MSG_default_pager_space_alert 0xff002584 MSG_exception_raise 0xff002588 MSG_exception_raise_state @@ -212,6 +217,8 @@ 0xff002ca4 MSG_io_service_get_matching_services_ool 0xff002ca8 MSG_io_service_match_property_table_ool 0xff002cac MSG_io_service_add_notification_ool +0xff002cb0 MSG_io_object_get_superclass +0xff002cb4 MSG_io_object_get_bundle_identifier 0xff002ee0 MSG_processor_start 0xff002ee4 MSG_processor_exit 0xff002ee8 MSG_processor_info @@ -273,7 +280,6 @@ 0xff003584 MSG_task_get_emulation_vector 0xff003588 MSG_task_set_emulation_vector 0xff00358c MSG_task_set_ras_pc -0xff003590 MSG_kernel_task_create 0xff003594 MSG_task_assign 0xff003598 MSG_task_assign_default 0xff00359c MSG_task_get_assignment @@ -323,7 +329,6 @@ 0xff003ba4 MSG_vm_map_page_query 0xff003ba8 MSG_mach_vm_region_info 0xff003bac MSG_vm_mapped_pages_info -0xff003bb0 MSG_vm_region_object_create 0xff003bb4 MSG_vm_region_recurse 0xff003bb8 MSG_vm_region_recurse_64 0xff003bbc MSG_mach_vm_region_info_64 @@ -331,8 +336,6 @@ 0xff003bc4 MSG_mach_make_memory_entry_64 0xff003bc8 MSG_vm_map_64 0xff003bcc MSG_vm_map_get_upl -0xff003bd0 MSG_vm_upl_map -0xff003bd4 MSG_vm_upl_unmap 0xff003bd8 MSG_vm_purgable_control 0xff003e80 MSG_processor_set_statistics 0xff003e84 MSG_processor_set_destroy @@ -344,6 +347,24 @@ 0xff003e9c MSG_processor_set_policy_control 0xff003ea0 MSG_processor_set_stack_usage 0xff003ea4 MSG_processor_set_info +0xff004b00 MSG_mach_vm_allocate +0xff004b04 MSG_mach_vm_deallocate +0xff004b08 MSG_mach_vm_protect +0xff004b0c MSG_mach_vm_inherit +0xff004b10 MSG_mach_vm_read +0xff004b14 MSG_mach_vm_read_list +0xff004b18 MSG_mach_vm_write +0xff004b1c MSG_mach_vm_copy +0xff004b20 MSG_mach_vm_read_overwrite +0xff004b24 MSG_mach_vm_msync +0xff004b28 MSG_mach_vm_behavior_set +0xff004b2c MSG_mach_vm_map +0xff004b30 MSG_mach_vm_machine_attribute +0xff004b34 MSG_mach_vm_remap +0xff004b38 MSG_mach_vm_page_query +0xff004b3c MSG_mach_vm_region_recurse +0xff004b40 MSG_mach_vm_region +0xff004b44 MSG__mach_make_memory_entry 0xff004e20 MSG_ledger_create 0xff004e24 MSG_ledger_terminate 0xff004e28 MSG_ledger_transfer @@ -375,8 +396,14 @@ 0x1300000 MACH_vmfault 0x1300004 MACH_Pageout 0x1400000 MACH_SCHED +0x1400004 MACH_STKATTACH 0x1400008 MACH_STKHANDOFF +0x140000c MACH_CALLCONT +0x1400010 MACH_CALLOUT +0x1400014 MACH_ServiceT 0x1400018 MACH_MKRUNNABLE +0x140001c MACH_PROMOTE +0x1400020 MACH_DEMOTE 0x1500000 MACH_MSGID_INVALID 0x1090000 DecrTrap 0x1090004 DecrSet @@ -625,10 +652,10 @@ 0x40c0160 BSC_obs_sethostname 0x40c0164 BSC_getdtablesize 0x40c0168 BSC_dup2 -0x40c016c BSC_#91 +0x40c016c BSC_obs_getdopt 0x40c0170 BSC_fcntl 0x40c0174 BSC_select -0x40c0178 BSC_#94 +0x40c0178 BSC_obs_setdopt 0x40c017c BSC_fsync 0x40c0180 BSC_setpriority 0x40c0184 BSC_socket @@ -641,7 +668,7 @@ 0x40c01a0 BSC_bind 0x40c01a4 BSC_setsockopt 0x40c01a8 BSC_listen -0x40c01ac BSC_#107 +0x40c01ac BSC_obs_vtimes 0x40c01b0 BSC_obs_sigvec 0x40c01b4 BSC_obs_sigblock 0x40c01b8 BSC_obs_sigsetmask @@ -649,11 +676,11 @@ 0x40c01c0 BSC_obs_sigstack 0x40c01c4 BSC_obs_recvmsg 0x40c01c8 BSC_obs_sendmsg -0x40c01cc BSC_#115 +0x40c01cc BSC_obs_vtrace 0x40c01d0 BSC_gettimeofday 0x40c01d4 BSC_getrusage 0x40c01d8 BSC_getsockopt -0x40c01dc BSC_#119 +0x40c01dc BSC_obs_resuba 0x40c01e0 BSC_readv 0x40c01e4 BSC_writev 0x40c01e8 BSC_settimeofday @@ -677,13 +704,13 @@ 0x40c0230 BSC_adjtime 0x40c0234 BSC_obs_getpeername 0x40c0238 BSC_obs_gethostid -0x40c023c BSC_#143 +0x40c023c BSC_obs_sethostid 0x40c0240 BSC_obs_getrlimit 0x40c0244 BSC_obs_setrlimit 0x40c0248 BSC_obs_killpg 0x40c024c BSC_setsid -0x40c0250 BSC_#148 -0x40c0254 BSC_#149 +0x40c0250 BSC_obs_setquota +0x40c0254 BSC_obs_qquota 0x40c0258 BSC_obs_getsockname 0x40c025c BSC_getpgid 0x40c0260 BSC_setprivexec @@ -696,22 +723,22 @@ 0x40c0274 BSC_statfs 0x40c0278 BSC_fstatfs 0x40c027c BSC_unmount -0x40c0280 BSC_#160 +0x40c0280 BSC_obs_async_daemon 0x40c0284 BSC_getfh 0x40c0288 BSC_obs_getdomainname 0x40c028c BSC_obs_setdomainname 0x40c0290 BSC_#164 0x40c0294 BSC_quotactl -0x40c0298 BSC_#166 +0x40c0298 BSC_obs_exportfs 0x40c029c BSC_mount -0x40c02a0 BSC_#168 +0x40c02a0 BSC_obs_ustat 0x40c02a4 BSC_#169 -0x40c02a8 BSC_#170 +0x40c02a8 BSC_table 0x40c02ac BSC_obs_wait3 -0x40c02b0 BSC_#172 -0x40c02b4 BSC_#173 -0x40c02b8 BSC_#174 -0x40c02bc BSC_#175 +0x40c02b0 BSC_obs_rpause +0x40c02b4 BSC_waitid +0x40c02b8 BSC_obs_getdents +0x40c02bc BSC_obs_gc_control 0x40c02c0 BSC_add_profil 0x40c02c4 BSC_#177 0x40c02c8 BSC_#178 @@ -734,7 +761,7 @@ 0x40c030c BSC_setrlimit 0x40c0310 BSC_getdirentries 0x40c0314 BSC_mmap -0x40c0318 BSC_#198 +0x40c0318 BSC__syscall 0x40c031c BSC_lseek 0x40c0320 BSC_truncate 0x40c0324 BSC_ftruncate @@ -766,18 +793,18 @@ 0x40c038c BSC_copyfile 0x40c0390 BSC_#228 0x40c0394 BSC_#229 -0x40c0398 BSC_#230 +0x40c0398 BSC_poll 0x40c039c BSC_watchevent 0x40c03a0 BSC_waitevent 0x40c03a4 BSC_modwatch -0x40c03a8 BSC_#234 -0x40c03ac BSC_#235 -0x40c03b0 BSC_#236 -0x40c03b4 BSC_#237 -0x40c03b8 BSC_#238 -0x40c03bc BSC_#239 -0x40c03c0 BSC_#240 -0x40c03c4 BSC_#241 +0x40c03a8 BSC_getxattr +0x40c03ac BSC_fgetxattr +0x40c03b0 BSC_setxattr +0x40c03b4 BSC_fsetxattr +0x40c03b8 BSC_removexattr +0x40c03bc BSC_fremovexattr +0x40c03c0 BSC_listxattr +0x40c03c4 BSC_flistxattr 0x40c03c8 BSC_fsctl 0x40c03cc BSC_#243 0x40c03d0 BSC_#244 @@ -813,30 +840,30 @@ 0x40c0448 BSC_sem_getvalue 0x40c044c BSC_sem_init 0x40c0450 BSC_sem_destroy -0x40c0454 BSC_#277 -0x40c0458 BSC_#278 -0x40c045c BSC_#279 -0x40c0460 BSC_#280 -0x40c0464 BSC_#281 -0x40c0468 BSC_#282 -0x40c046c BSC_#283 -0x40c0470 BSC_#284 -0x40c0474 BSC_#285 -0x40c0478 BSC_#286 -0x40c047c BSC_#287 -0x40c0480 BSC_#288 -0x40c0484 BSC_#289 -0x40c0488 BSC_#290 -0x40c048c BSC_#291 -0x40c0490 BSC_#292 -0x40c0494 BSC_#293 +0x40c0454 BSC_open_extended +0x40c0458 BSC_umask_extended +0x40c045c BSC_stat_extended +0x40c0460 BSC_lstat_extended +0x40c0464 BSC_fstat_extended +0x40c0468 BSC_chmod_extended +0x40c046c BSC_fchmod_extended +0x40c0470 BSC_access_extended +0x40c0474 BSC_settid +0x40c0478 BSC_gettid +0x40c047c BSC_setsgroups +0x40c0480 BSC_getsgroups +0x40c0484 BSC_setwgroups +0x40c0488 BSC_getwgroups +0x40c048c BSC_mkfifo_extended +0x40c0490 BSC_mkdir_extended +0x40c0494 BSC_identifysvc 0x40c0498 BSC_#294 0x40c049c BSC_#295 0x40c04a0 BSC_load_shared_file 0x40c04a4 BSC_reset_shared_file 0x40c04a8 BSC_new_system_shared_regions -0x40c04ac BSC_#299 -0x40c04b0 BSC_#300 +0x40c04ac BSC_shared_region_map_file_np +0x40c04b0 BSC_shared_region_make_private_np 0x40c04b4 BSC_#301 0x40c04b8 BSC_#302 0x40c04bc BSC_#303 @@ -867,10 +894,10 @@ 0x40c0520 BSC_pthread_kill 0x40c0524 BSC_pthread_sigmask 0x40c0528 BSC_sigwait -0x40c052c BSC_#331 -0x40c0530 BSC_#332 -0x40c0534 BSC_#333 -0x40c0538 BSC_#334 +0x40c052c BSC_disable_threadsignal +0x40c0530 BSC_pthread_markcancel +0x40c0534 BSC_pthread_canceled +0x40c0538 BSC_semwait_signal 0x40c053c BSC_utrace 0x40c0540 BSC_#336 0x40c0544 BSC_#337 @@ -888,7 +915,7 @@ 0x40c0574 BSC_#349 0x40c0578 BSC_audit 0x40c057c BSC_auditon -0x40c0580 BSC_auditsvc +0x40c0580 BSC_#352 0x40c0584 BSC_getauid 0x40c0588 BSC_setauid 0x40c058c BSC_getaudit @@ -900,7 +927,7 @@ 0x40c05a4 BSC_#361 0x40c05a8 BSC_kqueue 0x40c05ac BSC_kevent -0x40c05b0 BSC_#364 +0x40c05b0 BSC_lchown 0x40c05b4 BSC_#365 0x40c05b8 BSC_#366 0x40c05bc BSC_#367 @@ -910,6 +937,55 @@ 0x50b001c IES_filter 0x50c0010 TES_action 0x50d0018 CQ_action +0x5100004 PM_SetParent +0x5100008 PM_AddChild +0x510000c PM_RemoveChild +0x5100010 PM_CtrlDriver +0x5100014 PM_CtrlDrvrE1 +0x5100018 PM_CtrlDrvrE2 +0x510001c PM_CtrlDrvrE3 +0x5100020 PM_CtrlDrvrE4 +0x5100024 PM_IntDriver +0x5100028 PM_AckE1 +0x510002c PM_ChildAck +0x5100030 PM_DriverAck +0x5100034 PM_AckE2 +0x5100038 PM_AckE3 +0x510003c PM_AckE4 +0x5100040 PM_DrvrAckSPwr +0x5100044 PM_WillChange +0x5100048 PM_DidChange +0x510004c PM_ReqstDomain +0x5100050 PM_MakeUsable +0x5100054 PM_ChangeTo +0x5100058 PM_ChngeToPriv +0x510005c PM_SetAggrssvs +0x5100060 PM_CritclTemp +0x5100064 PM_OverrideOn +0x5100068 PM_OverrideOff +0x510006c PM_EnqueueErr +0x5100070 PM_CollapseQ +0x5100074 PM_ChangeDone +0x5100078 PM_CtrlDrvTrdy +0x510007c PM_IntDrvrTrdy +0x5100080 PM_StartAckTmr +0x5100084 PM_ParentChnge +0x5100088 PM_AmndPrnChng +0x510008c PM_DeviceChnge +0x5100090 PM_ReqDenied +0x5100094 PM_CtrlDrvrE45 +0x5100098 PM_PrgrmHrdwre +0x510009c PM_InfDrvrPre +0x51000a0 PM_InfDrvrPost +0x51000a4 PM_RemoveDrivr +0x51000a8 PM_IdlTimerPrd +0x51000ac PM_SystemWake +0x51000b0 PM_AckE5 +0x51000b4 PM_ClientAck +0x51000b8 PM_ClientTardy +0x51000bc PM_ClientCancl +0x51000c0 PM_ClientNotfy +0x51000c4 PM_AppNotify 0x7000004 TRACE_DATA_NEWTHREAD 0x7010004 TRACE_STRING_NEWTHREAD 0x7010008 TRACE_STRING_EXEC diff --git a/shutdown.tproj/Makefile b/shutdown.tproj/Makefile index 73d25a8..a257e8c 100644 --- a/shutdown.tproj/Makefile +++ b/shutdown.tproj/Makefile @@ -26,7 +26,7 @@ MAKEFILE = tool.make NEXTSTEP_INSTALLDIR = /sbin WINDOWS_INSTALLDIR = /sbin PDO_UNIX_INSTALLDIR = /sbin -LIBS = +LIBS = -lbsm DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) diff --git a/shutdown.tproj/Makefile.postamble b/shutdown.tproj/Makefile.postamble index 42bdd1f..3e4dc90 100644 --- a/shutdown.tproj/Makefile.postamble +++ b/shutdown.tproj/Makefile.postamble @@ -1,2 +1,6 @@ INSTALL_AS_GROUP = operator # (probably want to set both of these) INSTALL_PERMISSIONS = 0555 # If set, 'install' chmod's executable to this + +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 shutdown.8 $(DSTROOT)/usr/share/man/man8 diff --git a/shutdown.tproj/PB.project b/shutdown.tproj/PB.project index 87cbc03..a6190ce 100644 --- a/shutdown.tproj/PB.project +++ b/shutdown.tproj/PB.project @@ -4,7 +4,7 @@ FRAMEWORKS = (); H_FILES = (pathnames.h); M_FILES = (); - OTHER_LIBS = (); + OTHER_LIBS = (bsm); OTHER_LINKED = (shutdown.c); OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, Makefile.dist, shutdown.8); PRECOMPILED_HEADERS = (); diff --git a/shutdown.tproj/pathnames.h b/shutdown.tproj/pathnames.h index 4056ffe..2bb5f01 100644 --- a/shutdown.tproj/pathnames.h +++ b/shutdown.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/shutdown.tproj/shutdown.c b/shutdown.tproj/shutdown.c index 532649e..dcef480 100644 --- a/shutdown.tproj/shutdown.c +++ b/shutdown.tproj/shutdown.c @@ -61,6 +61,11 @@ static const char rcsid[] = #include #include +#include +#include +#include + + #include "pathnames.h" #ifdef __APPLE__ @@ -114,6 +119,7 @@ void nolog(void); void timeout(int); void timewarn(int); void usage(const char *); +int audit_shutdown(int); int main(argc, argv) @@ -227,6 +233,7 @@ main(argc, argv) whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???"; #ifdef DEBUG + audit_shutdown(0); (void)putc('\n', stdout); #else (void)setpriority(PRIO_PROCESS, 0, PRIO_MIN); @@ -234,11 +241,15 @@ main(argc, argv) int forkpid; forkpid = fork(); - if (forkpid == -1) + if (forkpid == -1) { + audit_shutdown(1); err(1, "fork"); - if (forkpid) + } + if (forkpid) { errx(0, "[pid %d]", forkpid); + } } + audit_shutdown(0); setsid(); #endif openlog("shutdown", LOG_CONS, LOG_AUTH); @@ -396,6 +407,16 @@ die_you_gravy_sucking_pig_dog() (void)printf(" no sync"); (void)printf("\nkill -HUP 1\n"); #else +#ifdef __APPLE__ + { + int ws = 0; + int fp = fork(); + if (fp == 0) + execl(_PATH_BSHELL, _PATH_BSHELL, "/etc/rc.shutdown", NULL); + else if (fp > 0) + waitpid(fp, &ws, 0); + } +#endif if (!oflag) { (void)kill(1, doreboot ? SIGINT : /* reboot */ dohalt ? SIGUSR1 : /* halt */ @@ -571,3 +592,49 @@ usage(cp) " time [warning-message ...]\n"); exit(1); } + +/* + * The following tokens are included in the audit record for shutdown + * header + * subject + * return + */ +int audit_shutdown(int exitstatus) +{ + int aufd; + token_t *tok; + long au_cond; + + /* If we are not auditing, don't cut an audit record; just return */ + if (auditon(A_GETCOND, &au_cond, sizeof(long)) < 0) { + fprintf(stderr, "shutdown: Could not determine audit condition\n"); + return 0; + } + if (au_cond == AUC_NOAUDIT) + return 0; + + if((aufd = au_open()) == -1) { + fprintf(stderr, "shutdown: Audit Error: au_open() failed\n"); + exit(1); + } + + /* The subject that performed the operation */ + if((tok = au_to_me()) == NULL) { + fprintf(stderr, "shutdown: Audit Error: au_to_me() failed\n"); + exit(1); + } + au_write(aufd, tok); + + /* success and failure status */ + if((tok = au_to_return32(exitstatus, errno)) == NULL) { + fprintf(stderr, "shutdown: Audit Error: au_to_return32() failed\n"); + exit(1); + } + au_write(aufd, tok); + + if(au_close(aufd, 1, AUE_shutdown) == -1) { + fprintf(stderr, "shutdown: Audit Error: au_close() failed\n"); + exit(1); + } + return 1; +} diff --git a/sync.tproj/Makefile b/sync.tproj/Makefile index ea9c493..9d45673 100644 --- a/sync.tproj/Makefile +++ b/sync.tproj/Makefile @@ -14,7 +14,7 @@ PROJECT_TYPE = Tool CFILES = sync.c -OTHERSRCS = Makefile.preamble Makefile Makefile.dist sync.8 +OTHERSRCS = Makefile.preamble Makefile Makefile.dist sync.8 Makefile.postamble MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/sync.tproj/Makefile.postamble b/sync.tproj/Makefile.postamble new file mode 100644 index 0000000..1ad0185 --- /dev/null +++ b/sync.tproj/Makefile.postamble @@ -0,0 +1,3 @@ +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 sync.8 $(DSTROOT)/usr/share/man/man8 diff --git a/sync.tproj/sync.c b/sync.tproj/sync.c index b61e1ba..9a242f3 100644 --- a/sync.tproj/sync.c +++ b/sync.tproj/sync.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/sysctl.tproj/sysctl.8 b/sysctl.tproj/sysctl.8 index eac32d6..5261f6b 100644 --- a/sysctl.tproj/sysctl.8 +++ b/sysctl.tproj/sysctl.8 @@ -142,6 +142,7 @@ privilege can change the value. .It kern.vdisable integer no .It kern.boottime struct no .It vm.loadavg struct no +.It vm.swapusage struct no .It machdep.console_device dev_t no .It net.inet.ip.forwarding integer yes .It net.inet.ip.redirect integer yes @@ -214,10 +215,15 @@ Information about the system clock rate may be obtained with: sysctl kern.clockrate .Ed .Pp -Information about the load average history may be obtained with +Information about the load average history may be obtained with: .Bd -literal -offset indent -compact sysctl vm.loadavg .Ed +.Pp +Information about the system's swap space usage may be obtained with: +.Bd -literal -offset indent -compact +sysctl vm.swapusage +.Ed .Sh FILES .Bl -tag -width -compact .It Pa diff --git a/sysctl.tproj/sysctl.c b/sysctl.tproj/sysctl.c index 7e09d52..631ad40 100644 --- a/sysctl.tproj/sysctl.c +++ b/sysctl.tproj/sysctl.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@ */ @@ -111,7 +110,6 @@ static char sccsid[] = "@(#)sysctl.c 8.5 (Berkeley) 5/9/95"; #else #include #endif /* __APPLE__ */ -#include #include #include @@ -351,7 +349,8 @@ old_parse(string, flags) break; case CTL_VM: - if (mib[1] == VM_LOADAVG) { /* XXX this is bogus */ + switch (mib[1]) { + case VM_LOADAVG: { /* XXX this is bogus */ double loads[3]; getloadavg(loads, 3); @@ -361,6 +360,33 @@ old_parse(string, flags) loads[0], loads[1], loads[2]); return; } + case VM_SWAPUSAGE: { + struct xsw_usage xsu; + int saved_errno; + + size = sizeof (xsu); + if (sysctl(mib, 2, &xsu, &size, NULL, 0) != 0) { + if (flags == 0) + return; + saved_errno = errno; + if (!nflag) + fprintf(stderr, "%s: ", string); + fprintf(stderr, "sysctl(VM_SWAPUSAGE): %s\n", + strerror(saved_errno)); + return; + } + + if (!nflag) + fprintf(stdout, "%s: ", string); + fprintf(stdout, + "total = %.2fM used = %.2fM free = %.2fM %s\n", + ((double) xsu.xsu_total) / (1024.0 * 1024.0), + ((double) xsu.xsu_used) / (1024.0 * 1024.0), + ((double) xsu.xsu_avail) / (1024.0 * 1024.0), + xsu.xsu_encrypted ? "(encrypted)" : ""); + return; + } + } if (flags == 0) return; fprintf(stderr, @@ -723,8 +749,7 @@ parse(char *string, int flags) case CTLTYPE_STRING: break; case CTLTYPE_QUAD: - break; - sscanf(newval, "%qd", &quadval); + quadval = strtoq(newval, NULL, 0); newval = &quadval; newsize = sizeof quadval; break; diff --git a/update.tproj/disk_power.h b/update.tproj/disk_power.h index 62f6f16..141cb94 100644 --- a/update.tproj/disk_power.h +++ b/update.tproj/disk_power.h @@ -2,30 +2,11 @@ #define __SPINDOWN_H__ +#include +#include #include #include -/* --- -*/ - -/* Public types */ - -/* ATA power states, from lowest to highest power usage */ -// This is taken from the IOATABlockStorage project, IOATAStorageDefines.h -enum IOATAPowerState -{ - kIOATAPowerStateSystemSleep = 0, - kIOATAPowerStateSleep = 1, - kIOATAPowerStateStandby = 2, - kIOATAPowerStateIdle = 3, - kIOATAPowerStateActive = 4, - - kNumIOATAPowerStates -}; - -typedef enum IOATAPowerState IOATAPowerState; - /* IOATAPowerStates */ struct IOATAPowerStates diff --git a/update.tproj/update.c b/update.tproj/update.c index 821bb3d..8e2638d 100644 --- a/update.tproj/update.c +++ b/update.tproj/update.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/utmp_update.tproj/Makefile b/utmp_update.tproj/Makefile new file mode 100644 index 0000000..bcb031d --- /dev/null +++ b/utmp_update.tproj/Makefile @@ -0,0 +1,46 @@ +# +# 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 = utmp_update + +PROJECTVERSION = 1.1 +PROJECT_TYPE = Tool + +CFILES = utmp_update.c + +OTHERSRCS = Makefile Makefile.postamble + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/libexec +WINDOWS_INSTALLDIR = /usr/libexec +PDO_UNIX_INSTALLDIR = /usr/libexec +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/utmp_update.tproj/Makefile.postamble b/utmp_update.tproj/Makefile.postamble new file mode 100644 index 0000000..f11cc67 --- /dev/null +++ b/utmp_update.tproj/Makefile.postamble @@ -0,0 +1,2 @@ +after_install: + chmod 4511 $(DSTROOT)/usr/libexec/utmp_update diff --git a/utmp_update.tproj/PB.project b/utmp_update.tproj/PB.project new file mode 100644 index 0000000..068e4df --- /dev/null +++ b/utmp_update.tproj/PB.project @@ -0,0 +1,37 @@ +{ + FILESTABLE = { + FRAMEWORKS = (); + OTHER_LINKED = (utmp_update.c); + OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); + PRECOMPILED_HEADERS = (); + PROJECT_HEADERS = (); + PUBLIC_HEADERS = (); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + NEXTSTEP_BUILDDIR = ""; + NEXTSTEP_BUILDTOOL = /bin/make; + NEXTSTEP_COMPILEROPTIONS = ""; + NEXTSTEP_INSTALLDIR = /usr/libexec; + 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/libexec; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_LINKEROPTIONS = ""; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = utmp_update; + PROJECTTYPE = Tool; + PROJECTVERSION = 1.1; + WINDOWS_BUILDDIR = ""; + WINDOWS_BUILDTOOL = /bin/make; + WINDOWS_COMPILEROPTIONS = ""; + WINDOWS_INSTALLDIR = /usr/libexec; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_LINKEROPTIONS = ""; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/utmp_update.tproj/utmp_update.c b/utmp_update.tproj/utmp_update.c new file mode 100644 index 0000000..733c649 --- /dev/null +++ b/utmp_update.tproj/utmp_update.c @@ -0,0 +1,147 @@ +/* $NetBSD: utmp_update.c,v 1.6 2003/02/26 18:16:50 christos Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 + +__RCSID("$NetBSD: utmp_update.c,v 1.6 2003/02/26 18:16:50 christos Exp $"); + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int, char *[]); + +int +main(int argc, char *argv[]) +{ + struct utmpx *utx; + size_t len; + struct passwd *pwd; + struct stat st; + int fd; + uid_t euid, ruid; + char tty[MAXPATHLEN]; + + euid = geteuid(); + ruid = getuid(); + if (seteuid(ruid) == -1) + err(1, "seteuid"); + + if (argc != 2) { + (void)fprintf(stderr, "Usage: %s \n", + getprogname()); + exit(1); + } + + len = strlen(argv[1]); + + // arg string can't be greater the 4x the size of struct utmpx + // nor less that the size of struct utmpx + if (len > sizeof(*utx) * 4 || len < sizeof(*utx)) + errx(1, "Bad argument"); + + // need an extra byte because strunvis will null terminate + if ((utx = malloc(len + 1)) == NULL) + err(1, NULL); + + if (strunvis((char *)utx, argv[1]) != sizeof(*utx)) + errx(1, "Decoding error"); + + switch (utx->ut_type) { + case USER_PROCESS: + case DEAD_PROCESS: + break; + default: + errx(1, "Invalid utmpx type %d", (int)utx->ut_type); + } + + if (ruid != 0) { + if ((pwd = getpwuid(ruid)) == NULL) + errx(1, "User %lu does not exist in password database", + (long)ruid); + + if (strcmp(pwd->pw_name, utx->ut_user) != 0) + errx(1, "Current user `%s' does not match " + "`%s' in utmpx entry", pwd->pw_name, utx->ut_user); + } + + (void)snprintf(tty, sizeof(tty), "%s%s", _PATH_DEV, utx->ut_line); + fd = open(tty, O_RDONLY, 0); + if (fd != -1) { + if (fstat(fd, &st) == -1) + err(1, "Cannot stat `%s'", tty); + if (ruid != 0 && st.st_uid != ruid) + errx(1, "%s: Is not owned by you", tty); + if (!isatty(fd)) + errx(1, "%s: Not a tty device", tty); + (void)close(fd); + if (access(tty, W_OK|R_OK) == -1) + err(1, "%s", tty); + } else { + struct utmpx utold, *utoldp; + /* + * A daemon like ftpd that does not use a tty line? + * We only allow it to kill its own existing entries + */ + if (utx->ut_type != DEAD_PROCESS) + err(1, "Cannot open `%s'", tty); + + (void)memcpy(utold.ut_line, utx->ut_line, sizeof(utx->ut_line)); + if ((utoldp = getutxline(&utold)) == NULL) + err(1, "Cannot find existing entry for `%s'", + utx->ut_line); + if (utoldp->ut_pid != getppid()) + err(1, "Cannot modify entry for `%s'", tty); + } + + (void)seteuid(euid); + if (pututxline(utx) == NULL) + err(1, "Cannot update utmp entry"); + + return 0; +} diff --git a/vipw.tproj/pw_util.c b/vipw.tproj/pw_util.c index b6a1277..d22d94c 100644 --- a/vipw.tproj/pw_util.c +++ b/vipw.tproj/pw_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/vipw.tproj/pw_util.h b/vipw.tproj/pw_util.h index bd59553..b5811b0 100644 --- a/vipw.tproj/pw_util.h +++ b/vipw.tproj/pw_util.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/vipw.tproj/vipw.c b/vipw.tproj/vipw.c index 9301626..d15932b 100644 --- a/vipw.tproj/vipw.c +++ b/vipw.tproj/vipw.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/vm_stat.tproj/vm_stat.c b/vm_stat.tproj/vm_stat.c index c0c0f45..01d9a62 100644 --- a/vm_stat.tproj/vm_stat.c +++ b/vm_stat.tproj/vm_stat.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/zdump.tproj/Makefile.postamble b/zdump.tproj/Makefile.postamble index 590f9a6..566ba1b 100644 --- a/zdump.tproj/Makefile.postamble +++ b/zdump.tproj/Makefile.postamble @@ -122,4 +122,8 @@ # for generated tools should use $(EXECUTABLE_EXT) on the end. -VPATH += :../zic.tproj \ No newline at end of file +VPATH += :../zic.tproj + +after_install: + mkdir -p $(DSTROOT)/usr/share/man/man8 + install -c -m 444 zdump.8 $(DSTROOT)/usr/share/man/man8 diff --git a/zdump.tproj/zdump.8 b/zdump.tproj/zdump.8 index 7126d4e..065a1d6 100644 --- a/zdump.tproj/zdump.8 +++ b/zdump.tproj/zdump.8 @@ -1,25 +1,33 @@ -.\" $OpenBSD: zdump.8,v 1.3 1997/01/14 03:16:54 millert Exp $ -.TH ZDUMP 8 -.SH NAME -zdump \- time zone dumper -.SH SYNOPSIS -.B zdump -[ -.B \-v -] [ -.B \-c -cutoffyear ] [ zonename ... ] -.SH DESCRIPTION -.I Zdump -prints the current time in each -.I zonename +.\" +.\" @(#)zdump.8 7.3 +.\" $FreeBSD: src/usr.sbin/zic/zdump.8,v 1.10 2004/06/20 21:41:11 stefanf Exp $ +.\" +.Dd June 20, 2004 +.Dt ZDUMP 8 +.Os +.Sh NAME +.Nm zdump +.Nd timezone dumper +.Sh SYNOPSIS +.Nm +.Op Fl -version +.Op Fl v +.Op Fl c Ar cutoffyear +.Op Ar zonename ... +.Sh DESCRIPTION +The +.Nm +utility prints the current time in each +.Ar zonename named on the command line. -.PP -These options are available: -.TP -.B \-v +.Pp +The following options are available: +.Bl -tag -width indent +.It Fl -version +Output version information and exit. +.It Fl v For each -.I zonename +.Ar zonename on the command line, print the time at the lowest possible time value, the time one day after the lowest possible time value, @@ -28,13 +36,14 @@ each detected time discontinuity, the time at one day less than the highest possible time value, and the time at the highest possible time value, Each line ends with -.B isdst=1 +.Em isdst=1 if the given time is Daylight Saving Time or -.B isdst=0 +.Em isdst=0 otherwise. -.TP -.BI "\-c " cutoffyear +.It Fl c Ar cutoffyear Cut off the verbose output near the start of the given year. -.SH "SEE ALSO" -ctime(3), tzfile(5), zic(8) -.\" @(#)zdump.8 7.3 +.El +.Sh "SEE ALSO" +.Xr ctime 3 , +.Xr tzfile 5 , +.Xr zic 8 diff --git a/zdump.tproj/zdump.c b/zdump.tproj/zdump.c index 5c8cd68..f98d117 100644 --- a/zdump.tproj/zdump.c +++ b/zdump.tproj/zdump.c @@ -1,34 +1,9 @@ -/* - * 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@ - */ -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char elsieid[] = "@(#)zdump.c 7.24"; -#else -static char rcsid[] = "$OpenBSD: zdump.c,v 1.5 1997/01/21 04:52:45 millert Exp $"; -#endif -#endif /* LIBC_SCCS and not lint */ +static const char elsieid[] = "@(#)zdump.c 7.31"; + +#ifndef lint +static const char rcsid[] = + "$FreeBSD: src/usr.sbin/zic/zdump.c,v 1.9 2004/06/20 21:41:11 stefanf Exp $"; +#endif /* not lint */ /* ** This code has been made independent of the rest of the time @@ -36,11 +11,13 @@ static char rcsid[] = "$OpenBSD: zdump.c,v 1.5 1997/01/21 04:52:45 millert Exp $ ** You can use this code to help in verifying other implementations. */ -#include "stdio.h" /* for stdout, stderr, perror */ -#include "string.h" /* for strcpy */ -#include "sys/types.h" /* for time_t */ -#include "time.h" /* for struct tm */ -#include "stdlib.h" /* for exit, malloc, atoi */ +#include +#include /* for stdout, stderr */ +#include /* for exit, malloc, atoi */ +#include /* for strcpy */ +#include /* for time_t */ +#include /* for struct tm */ +#include #ifndef MAX_STRING_LENGTH #define MAX_STRING_LENGTH 1024 @@ -137,19 +114,24 @@ static char rcsid[] = "$OpenBSD: zdump.c,v 1.5 1997/01/21 04:52:45 millert Exp $ #define TZ_DOMAIN "tz" #endif /* !defined TZ_DOMAIN */ +#ifndef P +#ifdef __STDC__ +#define P(x) x +#endif /* defined __STDC__ */ +#ifndef __STDC__ +#define P(x) () +#endif /* !defined __STDC__ */ +#endif /* !defined P */ + extern char ** environ; -extern int getopt(); -extern char * optarg; -extern int optind; -extern time_t time(); extern char * tzname[2]; -static char * abbr(); -static long delta(); -static time_t hunt(); -static int longest; -static char * progname; -static void show(); +static char * abbr P((struct tm * tmp)); +static long delta P((struct tm * newp, struct tm * oldp)); +static time_t hunt P((char * name, time_t lot, time_t hit)); +static size_t longest; +static void show P((char * zone, time_t t, int v)); +static void usage(void); int main(argc, argv) @@ -178,19 +160,19 @@ char * argv[]; #endif /* defined(TEXTDOMAINDIR) */ (void) textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT - 0 */ - progname = argv[0]; + for (i = 1; i < argc; ++i) + if (strcmp(argv[i], "--version") == 0) { + errx(EXIT_SUCCESS, "%s", elsieid); + } vflag = 0; cutoff = NULL; while ((c = getopt(argc, argv, "c:v")) == 'c' || c == 'v') if (c == 'v') vflag = 1; else cutoff = optarg; - if (c != EOF || + if ((c != EOF && c != -1) || (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) { - (void) fprintf(stderr, -_("%s: usage is %s [ -v ] [ -c cutoff ] zonename ...\n"), - argv[0], argv[0]); - (void) exit(EXIT_FAILURE); + usage(); } if (cutoff != NULL) { int y; @@ -218,10 +200,9 @@ _("%s: usage is %s [ -v ] [ -c cutoff ] zonename ...\n"), sizeof *fakeenv)); if (fakeenv == NULL || (fakeenv[0] = (char *) malloc((size_t) (longest + - 4))) == NULL) { - (void) perror(progname); - (void) exit(EXIT_FAILURE); - } + 4))) == NULL) + errx(EXIT_FAILURE, + _("malloc() failed")); to = 0; (void) strcpy(fakeenv[to++], "TZ="); for (from = 0; environ[from] != NULL; ++from) @@ -234,9 +215,10 @@ _("%s: usage is %s [ -v ] [ -c cutoff ] zonename ...\n"), static char buf[MAX_STRING_LENGTH]; (void) strcpy(&fakeenv[0][3], argv[i]); - show(argv[i], now, FALSE); - if (!vflag) + if (!vflag) { + show(argv[i], now, FALSE); continue; + } /* ** Get lowest value of t. */ @@ -279,12 +261,8 @@ _("%s: usage is %s [ -v ] [ -c cutoff ] zonename ...\n"), t += SECSPERHOUR * HOURSPERDAY; show(argv[i], t, TRUE); } - if (fflush(stdout) || ferror(stdout)) { - (void) fprintf(stderr, _("%s: Error writing standard output "), - argv[0]); - (void) perror(_("standard output")); - (void) exit(EXIT_FAILURE); - } + if (fflush(stdout) || ferror(stdout)) + errx(EXIT_FAILURE, _("error writing standard output")); exit(EXIT_SUCCESS); /* gcc -Wall pacifier */ @@ -292,6 +270,14 @@ _("%s: usage is %s [ -v ] [ -c cutoff ] zonename ...\n"), continue; } +static void +usage(void) +{ + fprintf(stderr, +_("usage: zdump [--version] [-v] [-c cutoff] zonename ...\n")); + exit(EXIT_FAILURE); +} + static time_t hunt(name, lot, hit) char * name; @@ -305,7 +291,6 @@ time_t hit; lotm = *localtime(&lot); (void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1); - loab[(sizeof loab) - 1] = '\0'; while ((hit - lot) >= 2) { t = lot / 2 + hit / 2; if (t <= lot) @@ -352,8 +337,6 @@ struct tm * oldp; return result; } -extern struct tm * localtime(); - static void show(zone, t, v) char * zone; @@ -362,9 +345,9 @@ int v; { struct tm * tmp; - (void) printf("%-*s ", longest, zone); + (void) printf("%-*s ", (int) longest, zone); if (v) - (void) printf("%.24s GMT = ", asctime(gmtime(&t))); + (void) printf("%.24s UTC = ", asctime(gmtime(&t))); tmp = localtime(&t); (void) printf("%.24s", asctime(tmp)); if (*abbr(tmp) != '\0') diff --git a/zic.tproj/Makefile b/zic.tproj/Makefile index 7b908e2..0c7fbce 100644 --- a/zic.tproj/Makefile +++ b/zic.tproj/Makefile @@ -12,7 +12,7 @@ NAME = zic PROJECTVERSION = 2.8 PROJECT_TYPE = Tool -HFILES = private.h tzfile.h +HFILES = private.h CFILES = ialloc.c scheck.c zic.c diff --git a/zic.tproj/Makefile.postamble b/zic.tproj/Makefile.postamble index ead4ca7..be0f925 100644 --- a/zic.tproj/Makefile.postamble +++ b/zic.tproj/Makefile.postamble @@ -150,8 +150,9 @@ POSIXRULES= US/Pacific YEARISTYPE= datfiles/yearistype.sh YEARISTYPECOPY= ${SYM_DIR}/yearistypecopy +# pacificnew is obsolete and was removed from YDATA YDATA= africa antarctica asia australasia \ - europe northamerica southamerica pacificnew etcetera factory \ + europe northamerica southamerica etcetera factory \ backward NDATA= systemv SDATA= solar87 solar88 solar89 @@ -159,7 +160,7 @@ TDATA= $(YDATA) $(NDATA) $(SDATA) DATA= $(YDATA) $(NDATA) $(SDATA) leapseconds # yearistype.sh USNO= usno1988 usno1989 -ZIC=zic +ZIC=${DSTROOT}/usr/sbin/zic ${YEARISTYPECOPY}: cp ${YEARISTYPE} ${YEARISTYPECOPY} @@ -192,16 +193,25 @@ right_posix: right_only other_two #since we are not doing native builds ... hack hack hack -ZONE_FILES = africa antarctica asia australasia europe northamerica southamerica pacificnew etcetera factory backward systemv solar87 solar88 solar89 +# pacificnew is obsolete and was removed from ZONE_FILES +ZONE_FILES = africa antarctica asia australasia europe northamerica southamerica etcetera factory backward systemv solar87 solar88 solar89 +ZONEINFO = ${DSTROOT}/usr/share/zoneinfo after_install:: -mkdir -p ${DSTROOT}/usr/share - -rm -rf ${DSTROOT}/usr/share/zoneinfo - mkdir -p ${DSTROOT}/usr/share/zoneinfo - for tz in $(ZONE_FILES); do \ - zic -L /dev/null -d ${DSTROOT}/usr/share/zoneinfo -y datfiles/yearistype.sh datfiles/$${tz}; \ + -rm -rf ${ZONEINFO} + mkdir -p ${ZONEINFO} + for tz in ${ZONE_FILES}; do \ + if [[ $${tz} = "northamerica" ]]; then \ + ${ZIC} -p America/New_York -L /dev/null -d ${ZONEINFO} -y datfiles/yearistype.sh datfiles/$${tz}; \ + else \ + ${ZIC} -L /dev/null -d ${ZONEINFO} -y datfiles/yearistype.sh datfiles/$${tz}; \ + fi \ done - chmod -R og-w ${DSTROOT}/usr/share/zoneinfo + chmod -R og-w ${ZONEINFO} + install -c -m 444 datfiles/zone.tab ${ZONEINFO} -mkdir -p ${DSTROOT}/private/etc -rm -f ${DSTROOT}/private/etc/localtime ln -fs /usr/share/zoneinfo/${LOCALTIME} ${DSTROOT}/private/etc/localtime + mkdir -p ${DSTROOT}/usr/share/man/man8 + install -c -m 444 zic.8 ${DSTROOT}/usr/share/man/man8 diff --git a/zic.tproj/datfiles/Theory b/zic.tproj/datfiles/Theory new file mode 100644 index 0000000..6d5efa0 --- /dev/null +++ b/zic.tproj/datfiles/Theory @@ -0,0 +1,506 @@ +@(#)Theory 7.13 + + +----- Outline ----- + + Time and date functions + Names of time zone regions + Time zone abbreviations + Calendrical issues + + +----- Time and date functions ----- + +These time and date functions are upwards compatible with POSIX.1, +an international standard for Unix-like systems. +As of this writing, the current edition of POSIX.1 is: + + Information technology --Portable Operating System Interface (POSIX (R)) + -- Part 1: System Application Program Interface (API) [C Language] + ISO/IEC 9945-1:1996 + ANSI/IEEE Std 1003.1, 1996 Edition + 1996-07-12 + +POSIX.1 has the following properties and limitations. + +* In POSIX.1, time display in a process is controlled by the + environment variable TZ. Unfortunately, the POSIX.1 TZ string takes + a form that is hard to describe and is error-prone in practice. + Also, POSIX.1 TZ strings can't deal with other (for example, Israeli) + daylight saving time rules, or situations where more than two + time zone abbreviations are used in an area. + + The POSIX.1 TZ string takes the following form: + + stdoffset[dst[offset],date[/time],date[/time]] + + where: + + std and dst + are 3 or more characters specifying the standard + and daylight saving time (DST) zone names. + offset + is of the form `[-]hh:[mm[:ss]]' and specifies the + offset west of UTC. The default DST offset is one hour + ahead of standard time. + date[/time],date[/time] + specifies the beginning and end of DST. If this is absent, + the system supplies its own rules for DST, and these can + differ from year to year; typically US DST rules are used. + time + takes the form `hh:[mm[:ss]]' and defaults to 02:00. + date + takes one of the following forms: + Jn (1<=n<=365) + origin-1 day number not counting February 29 + n (0<=n<=365) + origin-0 day number counting February 29 if present + Mm.n.d (0[Sunday]<=d<=6[Saturday], 1<=n<=5, 1<=m<=12) + for the dth day of week n of month m of the year, + where week 1 is the first week in which day d appears, + and `5' stands for the last week in which day d appears + (which may be either the 4th or 5th week). + +* In POSIX.1, when a TZ value like "EST5EDT" is parsed, + typically the current US DST rules are used, + but this means that the US DST rules are compiled into each program + that does time conversion. This means that when US time conversion + rules change (as in the United States in 1987), all programs that + do time conversion must be recompiled to ensure proper results. + +* In POSIX.1, there's no tamper-proof way for a process to learn the + system's best idea of local wall clock. (This is important for + applications that an administrator wants used only at certain times-- + without regard to whether the user has fiddled the "TZ" environment + variable. While an administrator can "do everything in UTC" to get + around the problem, doing so is inconvenient and precludes handling + daylight saving time shifts--as might be required to limit phone + calls to off-peak hours.) + +* POSIX.1 requires that systems ignore leap seconds. + +These are the extensions that have been made to the POSIX.1 functions: + +* The "TZ" environment variable is used in generating the name of a file + from which time zone information is read (or is interpreted a la + POSIX); "TZ" is no longer constrained to be a three-letter time zone + name followed by a number of hours and an optional three-letter + daylight time zone name. The daylight saving time rules to be used + for a particular time zone are encoded in the time zone file; + the format of the file allows U.S., Australian, and other rules to be + encoded, and allows for situations where more than two time zone + abbreviations are used. + + It was recognized that allowing the "TZ" environment variable to + take on values such as "America/New_York" might cause "old" programs + (that expect "TZ" to have a certain form) to operate incorrectly; + consideration was given to using some other environment variable + (for example, "TIMEZONE") to hold the string used to generate the + time zone information file name. In the end, however, it was decided + to continue using "TZ": it is widely used for time zone purposes; + separately maintaining both "TZ" and "TIMEZONE" seemed a nuisance; + and systems where "new" forms of "TZ" might cause problems can simply + use TZ values such as "EST5EDT" which can be used both by + "new" programs (a la POSIX) and "old" programs (as zone names and + offsets). + +* To handle places where more than two time zone abbreviations are used, + the functions "localtime" and "gmtime" set tzname[tmp->tm_isdst] + (where "tmp" is the value the function returns) to the time zone + abbreviation to be used. This differs from POSIX.1, where the elements + of tzname are only changed as a result of calls to tzset. + +* Since the "TZ" environment variable can now be used to control time + conversion, the "daylight" and "timezone" variables are no longer + needed. (These variables are defined and set by "tzset"; however, their + values will not be used by "localtime.") + +* The "localtime" function has been set up to deliver correct results + for near-minimum or near-maximum time_t values. (A comment in the + source code tells how to get compatibly wrong results). + +* A function "tzsetwall" has been added to arrange for the system's + best approximation to local wall clock time to be delivered by + subsequent calls to "localtime." Source code for portable + applications that "must" run on local wall clock time should call + "tzsetwall();" if such code is moved to "old" systems that don't + provide tzsetwall, you won't be able to generate an executable program. + (These time zone functions also arrange for local wall clock time to be + used if tzset is called--directly or indirectly--and there's no "TZ" + environment variable; portable applications should not, however, rely + on this behavior since it's not the way SVR2 systems behave.) + +* These functions can account for leap seconds, thanks to Bradley White + (bww@k.cs.cmu.edu). + +Points of interest to folks with other systems: + +* This package is already part of many POSIX-compliant hosts, + including BSD, HP, Linux, Network Appliance, SCO, SGI, and Sun. + On such hosts, the primary use of this package + is to update obsolete time zone rule tables. + To do this, you may need to compile the time zone compiler + `zic' supplied with this package instead of using the system `zic', + since the format of zic's input changed slightly in late 1994, + and many vendors still do not support the new input format. + +* The Unix Version 7 "timezone" function is not present in this package; + it's impossible to reliably map timezone's arguments (a "minutes west + of GMT" value and a "daylight saving time in effect" flag) to a + time zone abbreviation, and we refuse to guess. + Programs that in the past used the timezone function may now examine + tzname[localtime(&clock)->tm_isdst] to learn the correct time + zone abbreviation to use. Alternatively, use + localtime(&clock)->tm_zone if this has been enabled. + +* The 4.2BSD gettimeofday function is not used in this package. + This formerly let users obtain the current UTC offset and DST flag, + but this functionality was removed in later versions of BSD. + +* In SVR2, time conversion fails for near-minimum or near-maximum + time_t values when doing conversions for places that don't use UTC. + This package takes care to do these conversions correctly. + +The functions that are conditionally compiled if STD_INSPIRED is defined +should, at this point, be looked on primarily as food for thought. They are +not in any sense "standard compatible"--some are not, in fact, specified in +*any* standard. They do, however, represent responses of various authors to +standardization proposals. + +Other time conversion proposals, in particular the one developed by folks at +Hewlett Packard, offer a wider selection of functions that provide capabilities +beyond those provided here. The absence of such functions from this package +is not meant to discourage the development, standardization, or use of such +functions. Rather, their absence reflects the decision to make this package +contain valid extensions to POSIX.1, to ensure its broad +acceptability. If more powerful time conversion functions can be standardized, +so much the better. + + +----- Names of time zone rule files ----- + +The time zone rule file naming conventions attempt to strike a balance +among the following goals: + + * Uniquely identify every national region where clocks have all + agreed since 1970. This is essential for the intended use: static + clocks keeping local civil time. + + * Indicate to humans as to where that region is. This simplifes use. + + * Be robust in the presence of political changes. This reduces the + number of updates and backward-compatibility hacks. For example, + names of countries are ordinarily not used, to avoid + incompatibilities when countries change their name + (e.g. Zaire->Congo) or when locations change countries + (e.g. Hong Kong from UK colony to China). + + * Be portable to a wide variety of implementations. + This promotes use of the technology. + + * Use a consistent naming convention over the entire world. + This simplifies both use and maintenance. + +This naming convention is not intended for use by inexperienced users +to select TZ values by themselves (though they can of course examine +and reuse existing settings). Distributors should provide +documentation and/or a simple selection interface that explains the +names; see the 'tzselect' program supplied with this distribution for +one example. + +Names normally have the form AREA/LOCATION, where AREA is the name +of a continent or ocean, and LOCATION is the name of a specific +location within that region. North and South America share the same +area, `America'. Typical names are `Africa/Cairo', `America/New_York', +and `Pacific/Honolulu'. + +Here are the general rules used for choosing location names, +in decreasing order of importance: + + Use only valid POSIX file name components (i.e., the parts of + names other than `/'). Within a file name component, + use only ASCII letters, `.', `-' and `_'. Do not use + digits, as that might create an ambiguity with POSIX + TZ strings. A file name component must not exceed 14 + characters or start with `-'. E.g., prefer `Brunei' + to `Bandar_Seri_Begawan'. + Include at least one location per time zone rule set per country. + One such location is enough. Use ISO 3166 (see the file + iso3166.tab) to help decide whether something is a country. + If all the clocks in a country's region have agreed since 1970, + don't bother to include more than one location + even if subregions' clocks disagreed before 1970. + Otherwise these tables would become annoyingly large. + If a name is ambiguous, use a less ambiguous alternative; + e.g. many cities are named San Jose and Georgetown, so + prefer `Costa_Rica' to `San_Jose' and `Guyana' to `Georgetown'. + Keep locations compact. Use cities or small islands, not countries + or regions, so that any future time zone changes do not split + locations into different time zones. E.g. prefer `Paris' + to `France', since France has had multiple time zones. + Use mainstream English spelling, e.g. prefer `Rome' to `Roma', and + prefer `Athens' to the true name (which uses Greek letters). + The POSIX file name restrictions encourage this rule. + Use the most populous among locations in a country's time zone, + e.g. prefer `Shanghai' to `Beijing'. Among locations with + similar populations, pick the best-known location, + e.g. prefer `Rome' to `Milan'. + Use the singular form, e.g. prefer `Canary' to `Canaries'. + Omit common suffixes like `_Islands' and `_City', unless that + would lead to ambiguity. E.g. prefer `Cayman' to + `Cayman_Islands' and `Guatemala' to `Guatemala_City', + but prefer `Mexico_City' to `Mexico' because the country + of Mexico has several time zones. + Use `_' to represent a space. + Omit `.' from abbreviations in names, e.g. prefer `St_Helena' + to `St._Helena'. + Do not change established names if they only marginally + violate the above rules. For example, don't change + the existing name `Rome' to `Milan' merely because + Milan's population has grown to be somewhat greater + than Rome's. + If a name is changed, put its old spelling in the `backward' file. + +The file `zone.tab' lists the geographical locations used to name +time zone rule files. + +Older versions of this package used a different naming scheme, +and these older names are still supported. +See the file `backward' for most of these older names +(e.g. `US/Eastern' instead of `America/New_York'). +The other old-fashioned names still supported are +`WET', `CET', `MET', `EET' (see the file `europe'), +and `Factory' (see the file `factory'). + + +----- Time zone abbreviations ----- + +When this package is installed, it generates time zone abbreviations +like `EST' to be compatible with human tradition and POSIX.1. +Here are the general rules used for choosing time zone abbreviations, +in decreasing order of importance: + + Use abbreviations that consist of three or more ASCII letters. + Previous editions of this database also used characters like + ' ' and '?', but these characters have a special meaning to + the shell and cause commands like + set `date` + to have unexpected effects. + Previous editions of this rule required upper-case letters, + but the Congressman who introduced Chamorro Standard Time + preferred "ChST", so the rule has been relaxed. + + This rule guarantees that all abbreviations could have + been specified by a POSIX.1 TZ string. POSIX.1 + requires at least three characters for an + abbreviation. POSIX.1-1996 says that an abbreviation + cannot start with ':', and cannot contain ',', '-', + '+', NUL, or a digit. Draft 7 of POSIX 1003.1-200x + changes this rule to say that an abbreviation can + contain only '-', '+', and alphanumeric characters in + the current locale. To be portable to both sets of + rules, an abbreviation must therefore use only ASCII + letters, as these are the only letters that are + alphabetic in all locales. + + Use abbreviations that are in common use among English-speakers, + e.g. `EST' for Eastern Standard Time in North America. + We assume that applications translate them to other languages + as part of the normal localization process; for example, + a French application might translate `EST' to `HNE'. + + For zones whose times are taken from a city's longitude, use the + traditional xMT notation, e.g. `PMT' for Paris Mean Time. + The only name like this in current use is `GMT'. + + If there is no common English abbreviation, abbreviate the English + translation of the usual phrase used by native speakers. + If this is not available or is a phrase mentioning the country + (e.g. ``Cape Verde Time''), then: + + When a country has a single or principal time zone region, + append `T' to the country's ISO code, e.g. `CVT' for + Cape Verde Time. For summer time append `ST'; + for double summer time append `DST'; etc. + When a country has multiple time zones, take the first three + letters of an English place name identifying each zone + and then append `T', `ST', etc. as before; + e.g. `VLAST' for VLAdivostok Summer Time. + + Use "zzz" for locations while uninhabited. The mnemonic is that + these locations are, in some sense, asleep. + +Application writers should note that these abbreviations are ambiguous +in practice: e.g. `EST' has a different meaning in Australia than +it does in the United States. In new applications, it's often better +to use numeric UTC offsets like `-0500' instead of time zone +abbreviations like `EST'; this avoids the ambiguity. + + +----- Calendrical issues ----- + +Calendrical issues are a bit out of scope for a time zone database, +but they indicate the sort of problems that we would run into if we +extended the time zone database further into the past. An excellent +resource in this area is Nachum Dershowitz and Edward M. Reingold, + +Calendrical Calculations +, Cambridge University Press (1997). Other information and +sources are given below. They sometimes disagree. + + +France + +Gregorian calendar adopted 1582-12-20. +French Revolutionary calendar used 1793-11-24 through 1805-12-31, +and (in Paris only) 1871-05-06 through 1871-05-23. + + +Russia + +From Chris Carrier <72157.3334@CompuServe.COM> (1996-12-02): +On 1929-10-01 the Soviet Union instituted an ``Eternal Calendar'' +with 30-day months plus 5 holidays, with a 5-day week. +On 1931-12-01 it changed to a 6-day week; in 1934 it reverted to the +Gregorian calendar while retaining the 6-day week; on 1940-06-27 it +reverted to the 7-day week. With the 6-day week the usual days +off were the 6th, 12th, 18th, 24th and 30th of the month. +(Source: Evitiar Zerubavel, _The Seven Day Circle_) + + +Mark Brader reported a similar story in "The Book of Calendars", edited +by Frank Parise (1982, Facts on File, ISBN 0-8719-6467-8), page 377. But: + +From: Petteri Sulonen (via Usenet) +Date: 14 Jan 1999 00:00:00 GMT +Message-ID: + +If your source is correct, how come documents between 1929 -- 1940 were +still dated using the conventional, Gregorian calendar? + +I can post a scan of a document dated December 1, 1934, signed by +Yenukidze, the secretary, on behalf of Kalinin, the President of the +Executive Committee of the Supreme Soviet, if you like. + + + +Sweden (and Finland) + +From: msb@sq.com (Mark Brader) + +Subject: Re: Gregorian reform -- a part of locale? + +Date: 1996-07-06 + +In 1700, Denmark made the transition from Julian to Gregorian. Sweden +decided to *start* a transition in 1700 as well, but rather than have one of +those unsightly calendar gaps :-), they simply decreed that the next leap +year after 1696 would be in 1744 -- putting the whole country on a calendar +different from both Julian and Gregorian for a period of 40 years. + +However, in 1704 something went wrong and the plan was not carried through; +they did, after all, have a leap year that year. And one in 1708. In 1712 +they gave it up and went back to Julian, putting 30 days in February that +year!... + +Then in 1753, Sweden made the transition to Gregorian in the usual manner, +getting there only 13 years behind the original schedule. + +(A previous posting of this story was challenged, and Swedish readers +produced the following references to support it: "Tiderakning och historia" +by Natanael Beckman (1924) and "Tid, en bok om tiderakning och +kalendervasen" by Lars-Olof Lode'n (no date was given).) + + +Grotefend's data + +From: "Michael Palmer" [with one obvious typo fixed] +Subject: Re: Gregorian Calendar (was Re: Another FHC related question +Newsgroups: soc.genealogy.german +Date: Tue, 9 Feb 1999 02:32:48 -800 +Message-ID: <199902091032.CAA09644@netcom10.netcom.com> + +The following is a(n incomplete) listing, arranged chronologically, of +European states, with the date they converted from the Julian to the +Gregorian calendar: + +04/15 Oct 1582 - Italy (with exceptions), Spain, Portugal, Poland (Roman + Catholics and Danzig only) +09/20 Dec 1582 - France, Lorraine + +21 Dec 1582/ + 01 Jan 1583 - Holland, Brabant, Flanders, Hennegau +10/21 Feb 1583 - bishopric of Liege (L"uttich) +13/24 Feb 1583 - bishopric of Augsburg +04/15 Oct 1583 - electorate of Trier +05/16 Oct 1583 - Bavaria, bishoprics of Freising, Eichstedt, Regensburg, + Salzburg, Brixen +13/24 Oct 1583 - Austrian Oberelsass and Breisgau +20/31 Oct 1583 - bishopric of Basel +02/13 Nov 1583 - duchy of J"ulich-Berg +02/13 Nov 1583 - electorate and city of K"oln +04/15 Nov 1583 - bishopric of W"urzburg +11/22 Nov 1583 - electorate of Mainz +16/27 Nov 1583 - bishopric of Strassburg and the margraviate of Baden +17/28 Nov 1583 - bishopric of M"unster and duchy of Cleve +14/25 Dec 1583 - Steiermark + +06/17 Jan 1584 - Austria and Bohemia +11/22 Jan 1584 - Luzern, Uri, Schwyz, Zug, Freiburg, Solothurn +12/23 Jan 1584 - Silesia and the Lausitz +22 Jan/ + 02 Feb 1584 - Hungary (legally on 21 Oct 1587) + Jun 1584 - Unterwalden +01/12 Jul 1584 - duchy of Westfalen + +16/27 Jun 1585 - bishopric of Paderborn + +14/25 Dec 1590 - Transylvania + +22 Aug/ + 02 Sep 1612 - duchy of Prussia + +13/24 Dec 1614 - Pfalz-Neuburg + + 1617 - duchy of Kurland (reverted to the Julian calendar in + 1796) + + 1624 - bishopric of Osnabr"uck + + 1630 - bishopric of Minden + +15/26 Mar 1631 - bishopric of Hildesheim + + 1655 - Kanton Wallis + +05/16 Feb 1682 - city of Strassburg + +18 Feb/ + 01 Mar 1700 - Protestant Germany (including Swedish possessions in + Germany), Denmark, Norway +30 Jun/ + 12 Jul 1700 - Gelderland, Zutphen +10 Nov/ + 12 Dec 1700 - Utrecht, Overijssel + +31 Dec 1700/ + 12 Jan 1701 - Friesland, Groningen, Z"urich, Bern, Basel, Geneva, + Turgau, and Schaffhausen + + 1724 - Glarus, Appenzell, and the city of St. Gallen + +01 Jan 1750 - Pisa and Florence + +02/14 Sep 1752 - Great Britain + +17 Feb/ + 01 Mar 1753 - Sweden + +1760-1812 - Graub"unden + +The Russian empire (including Finland and the Baltic states) did not +convert to the Gregorian calendar until the Soviet revolution of 1917. + +Source: H. Grotefend, _Taschenbuch der Zeitrechnung des deutschen +Mittelalters und der Neuzeit_, herausgegeben von Dr. O. Grotefend +(Hannover: Hahnsche Buchhandlung, 1941), pp. 26-28. diff --git a/zic.tproj/datfiles/asia b/zic.tproj/datfiles/asia index 92a9aa1..3c2c1a1 100644 --- a/zic.tproj/datfiles/asia +++ b/zic.tproj/datfiles/asia @@ -1,4 +1,4 @@ -# @(#)asia 7.71 +# @(#)asia 7.77 # This data is by no means authoritative; if you think you know better, # go ahead and edit the file (and please send any changes to @@ -335,6 +335,16 @@ Link Asia/Nicosia Europe/Nicosia # Instead of putting back clocks at the end of October, Georgia # will stay on daylight savings time this winter to save energy, # President Eduard Shevardnadze decreed Wednesday. +# +# From the BBC via Joseph S. Myers (2004-06-27): +# +# Georgia moved closer to Western Europe on Sunday... The former Soviet +# republic has changed its time zone back to that of Moscow. As a result it +# is now just four hours ahead of Greenwich Mean Time, rather than five hours +# ahead. The switch was decreed by the pro-Western president of Georgia, +# Mikhail Saakashvili, who said the change was partly prompted by the process +# of integration into Europe. + # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone Asia/Tbilisi 2:59:16 - LMT 1880 2:59:16 - TBMT 1924 May 2 # Tbilisi Mean Time @@ -345,7 +355,8 @@ Zone Asia/Tbilisi 2:59:16 - LMT 1880 3:00 E-EurAsia GE%sT 1994 Sep lastSun 4:00 E-EurAsia GE%sT 1996 Oct lastSun 4:00 1:00 GEST 1997 Mar lastSun - 4:00 E-EurAsia GE%sT + 4:00 E-EurAsia GE%sT 2004 Jun 27 + 3:00 RussiaAsia GE%sT # East Timor @@ -380,7 +391,7 @@ Zone Asia/Dili 8:22:20 - LMT 1912 # India # Zone NAME GMTOFF RULES FORMAT [UNTIL] -Zone Asia/Calcutta 5:53:28 - LMT 1880 +Zone Asia/Calcutta 5:53:28 - LMT 1880 # Kolkata 5:53:20 - HMT 1941 Oct # Howrah Mean Time? 6:30 - BURT 1942 May 15 # Burma Time 5:30 - IST 1942 Sep @@ -736,44 +747,39 @@ Zone Asia/Jerusalem 2:20:56 - LMT 1880 2:20:40 - JMT 1918 # Jerusalem Mean Time? 2:00 Zion I%sT -# From Ephraim Silverberg (2002-07-07): -# -# The Israeli government today adopted a proposal by Minister of Interior -# Eli Yishai to shorten the period of Daylight Savings Time for the year -# 2002 (only -- the dates for 2003 and 2004 are, so far, unaffected). -# -# The proposed date to Daylight Savings Time is September 13, 2002 instead -# of the current date: October 7, 2002. The hour of changeover has not -# yet been decided. -# -# (2002-07-10): -# While today the Knesset passed the initial proposal to reduce DST by -# some three weeks, a new compromise is being worked out between -# Minister of Justice Meir Sheetrit and Minister of Interior Eli -# Yishai to revert to standard time for a period of 48-96 _hours_ -# (sic) around the Yom Kippur fast day (September 15-16) and then go -# *back* to DST until the end of October. The details of the proposal -# have yet to be worked out, but the second and final readings of the -# bill have until July 24 to pass. -# -# (2002-07-25): -# Thanks go to Yitschak Goldberg from E&M for bringing this (Hebrew) article -# to my attention: -# -# http://www.ynet.co.il/articles/0,7340,L-2019315,00.html -# -# Hence, the proposal to shorten DST was withdrawn yesterday and the timezone -# files that have been in effect since July 2000 are still valid for all of -# 2002. -# -# Please note that the article mentions that the Shas MK's intend to -# bring up their amendment for future years (2003 and beyond). What this -# means exactly is anyone's guess since there are no set dates yet beyond -# 2004 and the end day set for 2003 and 2004 is already the 7th of Tishrei -# (i.e. before the fast of Yom Kippur). The only thing they may want to -# change is the start date of DST in 2003 from Mar.28.03 (24th of Adar II) -# to Apr.18.03 (16th of Nisan) so that the Passover Seder will take place -# during Standard Time. The start date for 2004 is already Nisan 16th. +# From Ephraim Silverberg (2003-03-23): +# +# Minister of Interior Poraz has announced that he will respect the law +# passed in July 2000 (proposed at the time jointly by himself and +# then-MK David Azulai [Shas]) fixing the dates for 2000-2004. Hence, +# the dates for 2003 and 2004 remain unchanged.... +# +# As far as 2005 and beyond, no dates have been set. However, the +# minister has mentioned that he wishes to propose to move Israel's +# timezone in 2005 from GMT+2 to GMT+3 and upon that have DST during +# the summer months (i.e. GMT+4). However, no legislation in this +# direction is expected until the latter part of 2004 which is a long +# time off in terms of Israeli politics. + +# (2004-09-20): +# The latest rumour, however, is that in 2005, when the clock changes to +# Daylight Saving Time (date as yet unknown), the move will be a two-hour leap +# forward (from UTC+0200 to UTC+0400) and then, in the fall, the clock will +# move back only an hour to UTC+0300 thus effectively moving Israel's timezone +# from UTC+0200 to UTC+0300. However, no actual draft has been put before the +# Knesset (Israel's Parliament) though the intention is to do so this +# month [2004-09]. + +# (2004-09-26): +# Even though the draft law for the above did pass the Ministerial Committee +# for Legislative Matters three months ago, it was voted down in today's +# Cabinet meeting. The current suggestion is to keep the current timezone at +# UTC+0200 but have an extended period of Daylight Saving Time (UTC+0300) from +# the beginning of Passover holiday in the spring to after the Tabernacle +# holiday in the fall (i.e. the dates of which are governed by the Hebrew +# calendar but this means at least 184 days of DST). However, this is only a +# suggestion that was raised in today's cabinet meeting and has not yet been +# drafted. @@ -926,7 +932,7 @@ Zone Asia/Aqtau 3:21:04 - LMT 1924 May 2 6:00 - SHET 1982 Apr 1 5:00 RussiaAsia SHE%sT 1991 5:00 - SHET 1991 Dec 16 # independence - 5:00 RussiaAsia AQT%sT 1995 Sep lastSun # Aqtau Time + 5:00 RussiaAsia AQT%sT 1995 Mar lastSun 2:00 # Aqtau Time 4:00 RussiaAsia AQT%sT # West Kazakhstan Zone Asia/Oral 3:25:24 - LMT 1924 May 2 # or Ural'sk @@ -1036,22 +1042,29 @@ Zone Asia/Beirut 2:22:00 - LMT 1880 Rule NBorneo 1935 1941 - Sep 14 0:00 0:20 TS # one-Third Summer Rule NBorneo 1935 1941 - Dec 14 0:00 0 - # -# Zone NAME GMTOFF RULES FORMAT [UNTIL] # peninsular Malaysia -Zone Asia/Kuala_Lumpur 6:46:48 - LMT 1880 - 6:55:24 - SMT 1905 Jun # Singapore Mean Time - 7:00 - MALT 1933 # Malaya Time - 7:20 - MALT 1942 Feb 15 - 9:00 - JST 1945 Sep 2 - 7:20 - MALT 1950 - 7:30 - MALT 1982 May +# The data here are taken from Mok Ly Yng (2003-10-30) +# . +# Zone NAME GMTOFF RULES FORMAT [UNTIL] +Zone Asia/Kuala_Lumpur 6:46:46 - LMT 1901 Jan 1 + 6:55:25 - SMT 1905 Jun 1 # Singapore M.T. + 7:00 - MALT 1933 Jan 1 # Malaya Time + 7:00 0:20 MALST 1936 Jan 1 + 7:20 - MALT 1941 Sep 1 + 7:30 - MALT 1942 Feb 16 + 9:00 - JST 1945 Sep 12 + 7:30 - MALT 1982 Jan 1 8:00 - MYT # Malaysia Time # Sabah & Sarawak +# From Paul Eggert (2003-11-01): +# The data here are mostly from Shanks, but the 1942, 1945 and 1982 +# transition dates are from Mok Ly Yng. +# Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone Asia/Kuching 7:21:20 - LMT 1926 Mar 7:30 - BORT 1933 # Borneo Time - 8:00 NBorneo BOR%sT 1942 - 9:00 - JST 1945 Sep 2 - 8:00 - BORT 1982 May + 8:00 NBorneo BOR%sT 1942 Feb 16 + 9:00 - JST 1945 Sep 12 + 8:00 - BORT 1982 Jan 1 8:00 - MYT # Maldives @@ -1103,6 +1116,15 @@ Zone Indian/Maldives 4:54:00 - LMT 1880 # Male # # [The province of Selenge is omitted from the above lists.] +# From Ganbold Ts., Ulaanbaatar (2004-04-17): +# Daylight saving occurs at 02:00 local time last Saturday of March. +# It will change back to normal at 02:00 local time last Saturday of +# September.... As I remember this rule was changed in 2001. +# +# From Paul Eggert (2004-04-17): +# For now, assume Rives McDow's informant got confused about Friday vs +# Saturday, and that his 2001 dates should have 1 added to them. + # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S Rule Mongol 1983 1984 - Apr 1 0:00 1:00 S Rule Mongol 1983 only - Oct 1 0:00 0 - @@ -1112,8 +1134,9 @@ Rule Mongol 1983 only - Oct 1 0:00 0 - Rule Mongol 1985 1998 - Mar lastSun 2:00s 1:00 S Rule Mongol 1984 1998 - Sep lastSun 2:00s 0 - # IATA SSIM (1999-09) says Mongolia no longer observes DST. -Rule Mongol 2001 only - Apr 27 2:00s 1:00 S -Rule Mongol 2001 only - Sep 28 2:00s 0 - +Rule Mongol 2001 only - Apr lastSat 2:00 1:00 S +Rule Mongol 2001 max - Sep lastSat 2:00 0 - +Rule Mongol 2002 max - Mar lastSat 2:00 1:00 S # Zone NAME GMTOFF RULES FORMAT [UNTIL] # Hovd, a.k.a. Chovd, Dund-Us, Dzhargalant, Khovd, Jirgalanta @@ -1320,15 +1343,18 @@ Zone Asia/Riyadh 3:06:52 - LMT 1950 3:00 - AST # Singapore +# The data here are taken from Mok Ly Yng (2003-10-30) +# . # Zone NAME GMTOFF RULES FORMAT [UNTIL] -Zone Asia/Singapore 6:55:24 - LMT 1880 - 6:55:24 - SMT 1905 Jun # Singapore Mean Time - 7:00 - MALT 1933 # Malaya Time - 7:20 - MALT 1942 Feb 15 - 9:00 - JST 1945 Sep 2 - 7:20 - MALT 1950 +Zone Asia/Singapore 6:55:25 - LMT 1901 Jan 1 + 6:55:25 - SMT 1905 Jun 1 # Singapore M.T. + 7:00 - MALT 1933 Jan 1 # Malaya Time + 7:00 0:20 MALST 1936 Jan 1 + 7:20 - MALT 1941 Sep 1 + 7:30 - MALT 1942 Feb 16 + 9:00 - JST 1945 Sep 12 7:30 - MALT 1965 Aug 9 # independence - 7:30 - SGT 1982 May # Singapore Time + 7:30 - SGT 1982 Jan 1 # Singapore Time 8:00 - SGT # Spratly Is diff --git a/zic.tproj/datfiles/australasia b/zic.tproj/datfiles/australasia index 5fc7b1b..d8a8e36 100644 --- a/zic.tproj/datfiles/australasia +++ b/zic.tproj/datfiles/australasia @@ -1,4 +1,4 @@ -# @(#)australasia 7.68 +# @(#)australasia 7.69 # This file also includes Pacific islands. # Notes are at the end of this file @@ -297,45 +297,37 @@ Zone Pacific/Noumea 11:05:48 - LMT 1912 Jan 13 ############################################################################### # New Zealand -# -# From Paul Eggert (2002-10-23): -# The Department of Internal Affairs (DIA) maintains a brief history; -# see tz-link.htm for the full reference. -# -# Shanks gives 1868 for the introduction of standard time; go with the -# DIA's more-precise 1868-11-02. The DIA says that clocks were -# advanced by half an hour in 1941; go with Shanks's more-precise -# 1940-09-29 02:00. The DIA says that starting in 1933 DST began the -# first Sunday in September; go with Shanks's last Sunday starting in -# 1934. # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S -# Shanks gives 1927 Nov 6 - 1928 Mar 4, 1928 Oct 14 - 1929 Mar 17, -# 1929 Oct 13 - 1930 Mar 16; go with Whitman. -Rule NZ 1927 only - Nov 26 2:00 0:30 HD -Rule NZ 1928 1929 - Mar Sun>=1 2:00 0 S -Rule NZ 1928 only - Nov 4 2:00 0:30 HD -Rule NZ 1929 only - Oct 30 2:00 0:30 HD -Rule NZ 1930 1933 - Mar Sun>=15 2:00 0 S -Rule NZ 1930 1933 - Oct Sun>=8 2:00 0:30 HD -# Whitman says DST went on and off during war years, and the base UT offset -# didn't change until 1945 Apr 30; go with Shanks. -Rule NZ 1934 1940 - Apr lastSun 2:00 0 S -Rule NZ 1934 1939 - Sep lastSun 2:00 0:30 HD +Rule NZ 1927 only - Nov 6 2:00 1:00 S +Rule NZ 1928 only - Mar 4 2:00 0 M +Rule NZ 1928 1933 - Oct Sun>=8 2:00 0:30 S +Rule NZ 1929 1933 - Mar Sun>=15 2:00 0 M +Rule NZ 1934 1940 - Apr lastSun 2:00 0 M +Rule NZ 1934 1940 - Sep lastSun 2:00 0:30 S +Rule NZ 1946 only - Jan 1 0:00 0 S +# Since 1957 Chatham has been 45 minutes ahead of NZ, but there's no +# convenient notation for this so we must duplicate the Rule lines. Rule NZ 1974 only - Nov Sun>=1 2:00s 1:00 D +Rule Chatham 1974 only - Nov Sun>=1 2:45s 1:00 D Rule NZ 1975 only - Feb lastSun 2:00s 0 S +Rule Chatham 1975 only - Feb lastSun 2:45s 0 S Rule NZ 1975 1988 - Oct lastSun 2:00s 1:00 D +Rule Chatham 1975 1988 - Oct lastSun 2:45s 1:00 D Rule NZ 1976 1989 - Mar Sun>=1 2:00s 0 S +Rule Chatham 1976 1989 - Mar Sun>=1 2:45s 0 S Rule NZ 1989 only - Oct Sun>=8 2:00s 1:00 D +Rule Chatham 1989 only - Oct Sun>=8 2:45s 1:00 D Rule NZ 1990 max - Oct Sun>=1 2:00s 1:00 D -Rule NZ 1990 max - Mar Sun>=15 2:00s 0 S Rule Chatham 1990 max - Oct Sun>=1 2:45s 1:00 D -Rule Chatham 1991 max - Mar Sun>=15 2:45s 0 S +Rule NZ 1990 max - Mar Sun>=15 2:00s 0 S +Rule Chatham 1990 max - Mar Sun>=15 2:45s 0 S # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone Pacific/Auckland 11:39:04 - LMT 1868 Nov 2 - 11:30 NZ NZ%sT 1940 Sep 29 2:00 + 11:30 NZ NZ%sT 1946 Jan 1 12:00 NZ NZ%sT -Zone Pacific/Chatham 12:45 Chatham CHA%sT +Zone Pacific/Chatham 12:13:48 - LMT 1957 Jan 1 + 12:45 Chatham CHA%sT # Auckland Is @@ -443,6 +435,8 @@ Zone Pacific/Johnston -10:00 - HST # Midway Zone Pacific/Midway -11:49:28 - LMT 1901 + -11:00 - NST 1956 Jun 3 + -11:00 1:00 NDT 1956 Sep 2 -11:00 - NST 1967 Apr # N=Nome -11:00 - BST 1983 Nov 30 # B=Bering -11:00 - SST # S=Samoa @@ -513,7 +507,8 @@ Zone Pacific/Wallis 12:15:20 - LMT 1901 # 10:00 EST EST Eastern Australia # 10:00 ChST Chamorro # 10:30 LHST LHST Lord Howe* -# 12:00 NZST NZDT New Zealand +# 11:30 NZMT NZST New Zealand through 1945 +# 12:00 NZST NZDT New Zealand 1946-present # 12:45 CHAST CHADT Chatham* # -11:00 SST Samoa # -10:00 HST Hawaii @@ -1067,11 +1062,14 @@ Zone Pacific/Wallis 12:15:20 - LMT 1901 # time on both the first Sunday in October and the third Sunday in March. # As with Australia, we'll assume the tradition is 2:00s, not 2:00. # -# From Paul Eggert (1999-10-29): -# Shanks gives no time data for Chatham; usno1989 says it's +12:45, -# usno1995 says it's +12:45/+13:45, and IATA SSIM (1991/1999) -# gives the NZ rules but with transitions at 2:45 local standard time. -# Guess that they have been in lock-step with NZ since 1990. +# From Paul Eggert (2003-05-26): +# The Department of Internal Affairs (DIA) maintains a brief history, +# as does Carol Squires; see tz-link.htm for the full references. +# Use these sources in preference to Shanks. +# +# For Chatham, IATA SSIM (1991/1999) gives the NZ rules but with +# transitions at 2:45 local standard time; this confirms that Chatham +# is always exactly 45 minutes ahead of Auckland. ############################################################################### @@ -1154,6 +1152,23 @@ Zone Pacific/Wallis 12:15:20 - LMT 1901 # We don't know when Kosrae switched from UTC+12; assume January 1 for now. +# Midway + +# From Charles T O'Connor, KMTH DJ (1956), +# quoted in the KTMH section of the Radio Heritage Collection +# (2002-12-31): +# For the past two months we've been on what is known as Daylight +# Saving Time. This time has put us on air at 5am in the morning, +# your time down there in New Zealand. Starting September 2, 1956 +# we'll again go back to Standard Time. This'll mean that we'll go to +# air at 6am your time. +# +# From Paul Eggert (2003-03-23): +# We don't know the date of that quote, but we'll guess they +# started DST on June 3. Possibly DST was observed other years +# in Midway, but we have no record of it. + + # Pitcairn # From Rives McDow (1999-11-08): @@ -1277,6 +1292,24 @@ Zone Pacific/Wallis 12:15:20 - LMT 1901 # From Pulu 'Anau (2002-11-05): # The law was for 3 years, supposedly to get renewed. It wasn't. + +# Wake + +# From Vernice Anderson, Personal Secretary to Philip Jessup, +# US Ambassador At Large (oral history interview, 1971-02-02): +# +# Saturday, the 14th [of October, 1950] -- ... The time was all the +# more confusing at that point, because we had crossed the +# International Date Line, thus getting two Sundays. Furthermore, we +# discovered that Wake Island had two hours of daylight saving time +# making calculation of time in Washington difficult if not almost +# impossible. +# +# http://www.trumanlibrary.org/wake/meeting.htm + +# From Paul Eggert (2003-03-23): +# We have no other report of DST in Wake Island, so omit this info for now. + ############################################################################### # The International Date Line diff --git a/zic.tproj/datfiles/backward b/zic.tproj/datfiles/backward index eace5ab..6e118c2 100644 --- a/zic.tproj/datfiles/backward +++ b/zic.tproj/datfiles/backward @@ -1,12 +1,17 @@ -# @(#)backward 7.23 +# @(#)backward 7.26 # This file provides links between current names for time zones # and their old names. Many names changed in late 1993. Link America/Adak America/Atka +Link America/Argentina/Buenos_Aires America/Buenos_Aires +Link America/Argentina/Catamarca America/Catamarca +Link America/Argentina/Cordoba America/Cordoba Link America/Tijuana America/Ensenada Link America/Indianapolis America/Fort_Wayne +Link America/Argentina/Jujuy America/Jujuy Link America/Indiana/Knox America/Knox_IN +Link America/Argentina/Mendoza America/Mendoza Link America/Rio_Branco America/Porto_Acre Link America/Cordoba America/Rosario Link America/St_Thomas America/Virgin @@ -36,7 +41,7 @@ Link America/Manaus Brazil/West Link America/Halifax Canada/Atlantic Link America/Winnipeg Canada/Central Link America/Regina Canada/East-Saskatchewan -Link America/Montreal Canada/Eastern +Link America/Toronto Canada/Eastern Link America/Edmonton Canada/Mountain Link America/St_Johns Canada/Newfoundland Link America/Vancouver Canada/Pacific @@ -65,7 +70,7 @@ Link Africa/Tripoli Libya Link America/Tijuana Mexico/BajaNorte Link America/Mazatlan Mexico/BajaSur Link America/Mexico_City Mexico/General -Link America/Denver Navajo +Link America/Shiprock Navajo Link Pacific/Auckland NZ Link Pacific/Chatham NZ-CHAT Link Pacific/Pago_Pago Pacific/Samoa diff --git a/zic.tproj/datfiles/europe b/zic.tproj/datfiles/europe index 50fe876..eeb114f 100644 --- a/zic.tproj/datfiles/europe +++ b/zic.tproj/datfiles/europe @@ -1,4 +1,4 @@ -# @(#)europe 7.83 +# @(#)europe 7.88 # This data is by no means authoritative; if you think you know better, # go ahead and edit the file (and please send any changes to @@ -24,6 +24,10 @@ # Whitman Publishing Co, 2 Niagara Av, Ealing, London (undated), # which I found in the UCLA library. # +# +# William Willett, The Waste of Daylight, 19th edition +# (1914-03) +# # Brazil's Departamento Servico da Hora (DSH), # # History of Summer Time @@ -125,7 +129,7 @@ # transition date for London, namely 1847-12-01. We don't know as much # about Dublin, so we use 1880-08-02, the legal transition time. -# From Paul Eggert (1999-01-30): +# From Paul Eggert (2003-09-27): # Summer Time was first seriously proposed by William Willett (1857-1915), # a London builder and member of the Royal Astronomical Society # who circulated a pamphlet ``The Waste of Daylight'' (1907) @@ -133,14 +137,24 @@ # and retarding them by the same amount on four Sundays in September. # A bill was drafted in 1909 and introduced in Parliament several times, # but it met with ridicule and opposition, especially from farming interests. -# One-hour Summer Time was eventually adopted as a wartime measure in 1916. -# See: -# -# Summer Time Arrives Early, The Times (2000-05-18) -# -# A monument was erected in 1927 to Willett, in an open space in a 45-acre wood -# near Chiselhurst, Kent that was purchased by popular subscription and open -# to the public. +# Later editions of the pamphlet proposed one-hour summer time, and +# it was eventually adopted as a wartime measure in 1916. +# See: Summer Time Arrives Early, The Times (2000-05-18). +# A monument to Willett was unveiled on 1927-05-21, in an open space in +# a 45-acre wood near Chislehurst, Kent that was purchased by popular +# subscription and open to the public. On the south face of the monolith, +# designed by G. W. Miller, is the the William Willett Memorial Sundial, +# which is permanently set to Summer Time. + +# From Winston Churchill (1934-04-28): +# It is one of the paradoxes of history that we should owe the boon of +# summer time, which gives every year to the people of this country +# between 160 and 170 hours more daylight leisure, to a war which +# plunged Europe into darkness for four years, and shook the +# foundations of civilization throughout the world. +# -- +# "A Silent Toast to William Willett", Pictorial Weekly +# # From Paul Eggert (1996-09-03): # The OED Supplement says that the English originally said ``Daylight Saving'' @@ -693,6 +707,9 @@ Zone Europe/Sofia 1:33:16 - LMT 1880 # Croatia # see Serbia and Montenegro +# Cyprus +# See the `asia' file. + # Czech Republic # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S Rule Czech 1945 only - Apr 8 2:00s 1:00 S @@ -904,6 +921,10 @@ Zone Europe/Helsinki 1:39:52 - LMT 1878 May 31 2:00 Finland EE%sT 1981 Mar 29 2:00 2:00 EU EE%sT +# Aaland Is +Link Europe/Helsinki Europe/Mariehamn + + # France # From Ciro Discepolo (2000-12-20): @@ -1323,7 +1344,7 @@ Zone Europe/Riga 1:36:24 - LMT 1880 2:00 1:00 EEST 1989 Sep lastSun 2:00s 2:00 Latvia EE%sT 1997 Jan 21 2:00 EU EE%sT 2000 Feb 29 - 2:00 - EET 2001 + 2:00 - EET 2001 Jan 2 2:00 EU EE%sT # Liechtenstein @@ -1750,8 +1771,10 @@ Rule Port 1980 only - Mar lastSun 0:00s 1:00 S Rule Port 1981 1982 - Mar lastSun 1:00s 1:00 S Rule Port 1983 only - Mar lastSun 2:00s 1:00 S # Zone NAME GMTOFF RULES FORMAT [UNTIL] +# Shanks says that the transition from LMT to WET occurred 1911-05-24; +# Willett says 1912-01-01. Go with Willett. Zone Europe/Lisbon -0:36:32 - LMT 1884 - -0:36:32 - LMT 1911 May 24 # Lisbon Mean Time + -0:36:32 - LMT 1912 Jan 1 # Lisbon Mean Time 0:00 Port WE%sT 1966 Apr 3 2:00 1:00 - CET 1976 Sep 26 1:00 0:00 Port WE%sT 1983 Sep 25 1:00s @@ -1815,7 +1838,7 @@ Zone Europe/Bucharest 1:44:24 - LMT 1891 Oct # # From Andrey A. Chernov (1996-10-04): # `MSK' and `MSD' were born and used initially on Moscow computers with -# Unix-like OSes by several developer groups (e.g. Demos group, Kiae group).... +# UNIX-like OSes by several developer groups (e.g. Demos group, Kiae group).... # The next step was the UUCP network, the Relcom predecessor # (used mainly for mail), and MSK/MSD was actively used there. # @@ -1936,28 +1959,26 @@ Zone Asia/Irkutsk 6:57:20 - LMT 1880 7:00 Russia IRK%sT 1992 Jan 19 2:00s 8:00 Russia IRK%sT # -# From Oscar van Vlijmen (2001-08-25): [This region consists of] +# From Oscar van Vlijmen (2003-10-18): [This region consists of] # Aginskij Buryatskij avtonomnyj okrug, Amurskaya oblast', # [parts of] Respublika Sakha (Yakutiya), Chitinskaya oblast'. -# -# From Alan Pritchard (2001-08-24): [The Sakha districts are:] -# Aldansky, Amginsky, Anabarsky, Bulunsky, Churapchinsky, -# Eveno-Bytantaisky, Gorny, Khangalassky, Kobyaisky, Lensky, -# Megino-Kangalassky, Mirninsky, Namsky, Nyurbinsky, Olenyoksky, -# Olyokminsky, Srednekolymsky, Suntarsky, Tattinsky, Ust-Aldansky, -# Verkhnekolymsky, Verkhnevilyuisky, Vilyuisky, Zhigansky. +# The Sakha districts are: Aldanskij, Amginskij, Anabarskij, +# Bulunskij, Verkhnekolymskij, Verkhnevilyujskij, Vilyujskij, Gornyj, +# Zhiganskij, Kobyajskij, Lenskij, Megino-Kangalasskij, Mirninskij, +# Namskij, Nyurbinskij, Olenekskij, Olekminskij, Srednekolymskij, +# Suntarskij, Tattinskij, Ust'-Aldanskij, Khangalasskij, +# Churapchinskij, Eveno-Bytantajskij. Zone Asia/Yakutsk 8:38:40 - LMT 1919 Dec 15 8:00 - YAKT 1930 Jun 21 # Yakutsk Time 9:00 Russia YAK%sT 1991 Mar 31 2:00s 8:00 Russia YAK%sT 1992 Jan 19 2:00s 9:00 Russia YAK%sT # -# From Oscar van Vlijmen (2001-08-25): [This region consists of] +# From Oscar van Vlijmen (2003-10-18): [This region consists of] # Evrejskaya avtonomnaya oblast', Khabarovskij kraj, Primorskij kraj, # [parts of] Respublika Sakha (Yakutiya). -# -# From Alan Pritchard (2001-08-24): [The Sakha districts are:] -# Tomponsky, Ust-Maisky, Ust-Yansky, Verkhoyansky. +# The Sakha districts are: Verkhoyanskij, Tomponskij, Ust'-Majskij, +# Ust'-Yanskij. Zone Asia/Vladivostok 8:47:44 - LMT 1922 Nov 15 9:00 - VLAT 1930 Jun 21 # Vladivostok Time 10:00 Russia VLA%sT 1991 Mar 31 2:00s @@ -1974,11 +1995,11 @@ Zone Asia/Sakhalin 9:30:48 - LMT 1905 Aug 23 11:00 Russia SAK%sT 1997 Mar lastSun 2:00s 10:00 Russia SAK%sT # -# From Oscar van Vlijmen (2001-08-25): [This region consists of] +# From Oscar van Vlijmen (2003-10-18): [This region consists of] # Magadanskaya oblast', Respublika Sakha (Yakutiya). -# -# From Alan Pritchard (2001-08-24): [The Sakha districts are:] -# Abyisky, Allaikhovsky, Momsky, Nizhnekolymsky, Oimyakonsky. +# Probably also: Kuril Islands. +# The Sakha districts are: Abyjskij, Allaikhovskij, Momskij, +# Nizhnekolymskij, Ojmyakonskij. Zone Asia/Magadan 10:03:12 - LMT 1924 May 2 10:00 - MAGT 1930 Jun 21 # Magadan Time 11:00 Russia MAG%sT 1991 Mar 31 2:00s diff --git a/zic.tproj/datfiles/leapseconds b/zic.tproj/datfiles/leapseconds index c5306a6..7add330 100644 --- a/zic.tproj/datfiles/leapseconds +++ b/zic.tproj/datfiles/leapseconds @@ -1,4 +1,4 @@ -# @(#)leapseconds 7.15 +# @(#)leapseconds 7.17 # Allowance for leapseconds added to each timezone file. @@ -44,37 +44,38 @@ Leap 1995 Dec 31 23:59:60 + S Leap 1997 Jun 30 23:59:60 + S Leap 1998 Dec 31 23:59:60 + S -# INTERNATIONAL EARTH ROTATION SERVICE (IERS) -# SERVICE INTERNATIONAL DE LA ROTATION TERRESTRE +# INTERNATIONAL EARTH ROTATION AND REFERENCE SYSTEMS SERVICE (IERS) +# +# SERVICE INTERNATIONAL DE LA ROTATION TERRESTRE ET DES SYSTEMES DE REFERENCE # # SERVICE DE LA ROTATION TERRESTRE # OBSERVATOIRE DE PARIS # 61, Av. de l'Observatoire 75014 PARIS (France) # Tel. : 33 (0) 1 40 51 22 26 # FAX : 33 (0) 1 40 51 22 91 -# Internet : iers@obspm.fr +# Internet : services.iers@obspm.fr +# +# Paris, 15 January 2004 # -# Paris, 14 January 2002 +# Bulletin C 27 # -# Bulletin C 23 +# To authorities responsible +# for the measurement and +# distribution of time # -# To authorities responsible -# for the measurement and -# distribution of time +# INFORMATION ON UTC - TAI # -# INFORMATION ON UTC - TAI +# NO positive leap second will be introduced at the end of June 2004. +# The difference between UTC and the International Atomic Time TAI is: # -# NO positive leap second will be introduced at the end of June 2002. -# The difference between UTC and the International Atomic Time TAI is : -# -# from 1999 January 1, 0h UTC, until further notice : UTC-TAI = -32 s +# from 1999 January 1, 0h UTC, until further notice : UTC-TAI = -32 s # # Leap seconds can be introduced in UTC at the end of the months of December -# or June, depending on the evolution of UT1-TAI. Bulletin C is mailed every +# or June, depending on the evolution of UT1-TAI. Bulletin C is mailed every # six months, either to announce a time step in UTC, or to confirm that there # will be no time step at the next possible date. # -# Daniel GAMBIS -# Director -# Earth Orientation Center of IERS -# Observatoire de Paris, France +# Daniel GAMBIS +# Director +# Earth Orientation Center of IERS +# Observatoire de Paris, France diff --git a/zic.tproj/datfiles/northamerica b/zic.tproj/datfiles/northamerica index ff36fe4..6e755b0 100644 --- a/zic.tproj/datfiles/northamerica +++ b/zic.tproj/datfiles/northamerica @@ -1,4 +1,4 @@ -# @(#)northamerica 7.62 +# @(#)northamerica 7.69 # also includes Central America and the Caribbean # This data is by no means authoritative; if you think you know better, @@ -193,10 +193,6 @@ Rule US 1987 max - Apr Sun>=1 2:00 1:00 D # Samoa standard time # The law doesn't give abbreviations. # -# From Paul Eggert (1995-12-19): -# Shanks uses 1983-10-30, not 1983-11-30, for the 1983 transitions. -# Go with Shanks. -# # From Paul Eggert (2000-01-08), following a heads-up from Rives McDow: # Public law 106-564 (2000-12-23) introduced the abbreviation # "Chamorro Standard Time" for time in Guam and the Northern Marianas. @@ -228,7 +224,9 @@ Zone America/New_York -4:56:02 - LMT 1883 Nov 18 12:00 # US central time, represented by Chicago -# Alabama, Arkansas, Florida panhandle, Illinois, western Indiana +# Alabama, Arkansas, Florida panhandle (Bay, Calhoun, Escambia, +# Gulf, Holmes, Jackson, Okaloosa, Santa Rosa, Walton, and +# Washington counties), Illinois, western Indiana # (Gibson, Jasper, Lake, LaPorte, Newton, Porter, Posey, Spencer, # Vanderburgh, and Warrick counties), Iowa, most of Kansas, western # Kentucky, Louisiana, Minnesota, Mississippi, Missouri, eastern @@ -258,7 +256,7 @@ Zone America/North_Dakota/Center -6:45:12 - LMT 1883 Nov 18 12:00 # US mountain time, represented by Denver # -# Colorado, southern Idaho, far western Kansas, Montana, western +# Colorado, far western Kansas, Montana, western # Nebraska, Nevada border (Jackpot, Owyhee, and Mountain City), # New Mexico, southwestern North Dakota, far eastern Oregon, # western South Dakota, far western Texas (El Paso County, Hudspeth County, @@ -280,7 +278,9 @@ Zone America/Denver -6:59:56 - LMT 1883 Nov 18 12:00 # US Pacific time, represented by Los Angeles # -# California, northern Idaho, most of Nevada, most of Oregon, and Washington +# California, northern Idaho (Benewah, Bonner, Boundary, Clearwater, +# Idaho, Kootenai, Latah, Lewis, Nez Perce, and Shoshone counties), +# most of Nevada, most of Oregon, and Washington # # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER Rule CA 1948 only - Mar 14 2:00 1:00 D @@ -319,13 +319,14 @@ Zone America/Juneau 15:02:19 - LMT 1867 Oct 18 -8:00 US P%sT 1946 -8:00 - PST 1969 -8:00 US P%sT 1983 Oct 30 2:00 + -9:00 US Y%sT 1983 Nov 30 -9:00 US AK%sT Zone America/Yakutat 14:41:05 - LMT 1867 Oct 18 -9:18:55 - LMT 1900 Aug 20 12:00 -9:00 - YST 1942 -9:00 US Y%sT 1946 -9:00 - YST 1969 - -9:00 US Y%sT 1983 Oct 30 2:00 + -9:00 US Y%sT 1983 Nov 30 -9:00 US AK%sT Zone America/Anchorage 14:00:24 - LMT 1867 Oct 18 -9:59:36 - LMT 1900 Aug 20 12:00 @@ -334,6 +335,7 @@ Zone America/Anchorage 14:00:24 - LMT 1867 Oct 18 -10:00 - CAT 1967 Apr -10:00 - AHST 1969 -10:00 US AH%sT 1983 Oct 30 2:00 + -9:00 US Y%sT 1983 Nov 30 -9:00 US AK%sT Zone America/Nome 12:58:21 - LMT 1867 Oct 18 -11:01:38 - LMT 1900 Aug 20 12:00 @@ -342,6 +344,7 @@ Zone America/Nome 12:58:21 - LMT 1867 Oct 18 -11:00 - NST 1967 Apr -11:00 - BST 1969 -11:00 US B%sT 1983 Oct 30 2:00 + -9:00 US Y%sT 1983 Nov 30 -9:00 US AK%sT Zone America/Adak 12:13:21 - LMT 1867 Oct 18 -11:46:38 - LMT 1900 Aug 20 12:00 @@ -350,6 +353,7 @@ Zone America/Adak 12:13:21 - LMT 1867 Oct 18 -11:00 - NST 1967 Apr -11:00 - BST 1969 -11:00 US B%sT 1983 Oct 30 2:00 + -10:00 US AH%sT 1983 Nov 30 -10:00 US HA%sT # Shanks writes that part of southwest Alaska (e.g. Aniak) # switched from -11:00 to -10:00 on 1968-09-22 at 02:00, @@ -405,14 +409,20 @@ Zone America/Phoenix -7:28:18 - LMT 1883 Nov 18 12:00 -7:00 - MST # From Arthur David Olson (1988-02-13): # A writer from the Inter Tribal Council of Arizona, Inc., -# notes in private correspondence dated 12/28/87 that "Presently, only the +# notes in private correspondence dated 1987-12-28 that "Presently, only the # Navajo Nation participates in the Daylight Saving Time policy, due to its # large size and location in three states." (The "only" means that other # tribal nations don't use DST.) Link America/Denver America/Shiprock -# Southern Idaho and eastern Oregon switched four weeks late in 1974. +# Southern Idaho (Ada, Adams, Bannock, Bear Lake, Bingham, Blaine, +# Boise, Bonneville, Butte, Camas, Canyon, Caribou, Cassia, Clark, +# Custer, Elmore, Franklin, Fremont, Gem, Gooding, Jefferson, Jerome, +# Lemhi, Lincoln, Madison, Minidoka, Oneida, Owyhee, Payette, Power, +# Teton, Twin Falls, Valley, Washington counties) and eastern Oregon +# switched four weeks late in 1974. +# # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone America/Boise -7:44:49 - LMT 1883 Nov 18 12:00 -8:00 US P%sT 1923 May 13 2:00 @@ -685,9 +695,15 @@ Link Pacific/Honolulu HST # Except where otherwise noted, Shanks is the source for entries through 1990, # and IATA SSIM is the source for entries after 1990. # -# Another source occasionally used is Edward W. Whitman, World Time Differences, -# Whitman Publishing Co, 2 Niagara Av, Ealing, London (undated), which -# I found in the UCLA library. +# Other sources occasionally used include: +# +# Edward W. Whitman, World Time Differences, +# Whitman Publishing Co, 2 Niagara Av, Ealing, London (undated), +# which I found in the UCLA library. +# +# +# William Willett, The Waste of Daylight, 19th edition +# (1914-03) # # See the `europe' file for Greenland. @@ -743,7 +759,8 @@ Link Pacific/Honolulu HST # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S Rule Canada 1918 only - Apr 14 2:00 1:00 D Rule Canada 1918 only - Oct 31 2:00 0 S -Rule Canada 1942 only - Feb 9 2:00 1:00 W +Rule Canada 1942 only - Feb 9 2:00 1:00 W # War +Rule Canada 1945 only - Aug 14 23:00u 1:00 P # Peace Rule Canada 1945 only - Sep 30 2:00 0 S Rule Canada 1974 1986 - Apr lastSun 2:00 1:00 D Rule Canada 1974 max - Oct lastSun 2:00 0 S @@ -759,27 +776,20 @@ Rule Canada 1987 max - Apr Sun>=1 2:00 1:00 D # but excluding, say, Black Tickle. # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S -Rule StJohns 1917 1918 - Apr Sun>=8 2:00 1:00 D +Rule StJohns 1917 only - Apr 8 2:00 1:00 D Rule StJohns 1917 only - Sep 17 2:00 0 S -Rule StJohns 1918 only - Oct 31 2:00 0 S # Whitman gives 1919 Apr 5 and 1920 Apr 5; go with Shanks. Rule StJohns 1919 only - May 5 23:00 1:00 D Rule StJohns 1919 only - Aug 12 23:00 0 S # For 1931-1935 Whitman gives Apr same date; go with Shanks. Rule StJohns 1920 1935 - May Sun>=1 23:00 1:00 D Rule StJohns 1920 1935 - Oct lastSun 23:00 0 S -# For 1936-1941 Shanks gives May Mon>=9 and Oct Mon>=2; go with Whitman. -Rule StJohns 1936 1941 - May Sun>=8 0:00 1:00 D -Rule StJohns 1936 1941 - Oct Sun>=1 0:00 0 S -# Shanks gives 1942 May 11 - 1945 Sep 30; go with Whitman. -Rule StJohns 1942 only - Mar 1 0:00 1:00 W -Rule StJohns 1942 only - Dec 31 0:00 0 S -Rule StJohns 1943 only - May 30 0:00 1:00 W -Rule StJohns 1943 only - Sep 5 0:00 0 S -Rule StJohns 1944 only - Jul 10 0:00 1:00 W -Rule StJohns 1944 only - Sep 2 0:00 0 S -Rule StJohns 1945 only - Jan 1 0:00 1:00 W -Rule StJohns 1945 only - Oct 7 2:00 0 S +# For 1936-1941 Whitman gives May Sun>=8 and Oct Sun>=1; go with Shanks. +Rule StJohns 1936 1941 - May Mon>=9 0:00 1:00 D +Rule StJohns 1936 1941 - Oct Mon>=2 0:00 0 S +# Whitman gives the following transitions: +# 1942 03-01/12-31, 1943 05-30/09-05, 1944 07-10/09-02, 1945 01-01/10-07 +# but go with Shanks and assume they used Canadian rules. # For 1946-9 Whitman gives May 5,4,9,1 - Oct 1,5,3,2, and for 1950 he gives # Apr 30 - Sep 24; go with Shanks. Rule StJohns 1946 1950 - May Sun>=8 2:00 1:00 D @@ -797,18 +807,24 @@ Rule StJohns 1989 max - Apr Sun>=1 0:01 1:00 D # St John's has an apostrophe, but Posix file names can't have apostrophes. # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone America/St_Johns -3:30:52 - LMT 1884 + -3:30:52 StJohns N%sT 1918 + -3:30:52 Canada N%sT 1919 -3:30:52 StJohns N%sT 1935 Mar 30 + -3:30 StJohns N%sT 1942 May 11 + -3:30 Canada N%sT 1946 -3:30 StJohns N%sT - # most of east Labrador # The name `Happy Valley-Goose Bay' is too long; use `Goose Bay'. # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone America/Goose_Bay -4:01:40 - LMT 1884 # Happy Valley-Goose Bay - -3:30:52 StJohns NST 1919 + -3:30:52 - NST 1918 + -3:30:52 Canada N%sT 1919 -3:30:52 - NST 1935 Mar 30 -3:30 - NST 1936 + -3:30 StJohns N%sT 1942 May 11 + -3:30 Canada N%sT 1946 -3:30 StJohns N%sT 1966 Mar 15 2:00 -4:00 StJohns A%sT @@ -830,8 +846,6 @@ Zone America/Goose_Bay -4:01:40 - LMT 1884 # Happy Valley-Goose Bay # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S Rule Halifax 1916 only - Apr 1 0:00 1:00 D Rule Halifax 1916 only - Oct 1 0:00 0 S -Rule Halifax 1918 only - Apr 14 2:00 1:00 D -Rule Halifax 1918 only - Oct 31 2:00 0 S Rule Halifax 1920 only - May 9 0:00 1:00 D Rule Halifax 1920 only - Aug 29 0:00 0 S Rule Halifax 1921 only - May 6 0:00 1:00 D @@ -850,6 +864,7 @@ Rule Halifax 1928 only - Sep 9 0:00 0 S Rule Halifax 1929 only - Sep 3 0:00 0 S Rule Halifax 1930 only - Sep 15 0:00 0 S Rule Halifax 1931 1932 - Sep Mon>=24 0:00 0 S +Rule Halifax 1932 only - May 1 0:00 1:00 D Rule Halifax 1933 only - Apr 30 0:00 1:00 D Rule Halifax 1933 only - Oct 2 0:00 0 S Rule Halifax 1934 only - May 20 0:00 1:00 D @@ -862,33 +877,55 @@ Rule Halifax 1937 1938 - May Sun>=1 0:00 1:00 D Rule Halifax 1937 1941 - Sep Mon>=24 0:00 0 S Rule Halifax 1939 only - May 28 0:00 1:00 D Rule Halifax 1940 1941 - May Sun>=1 0:00 1:00 D -Rule Halifax 1942 only - Feb 9 2:00 1:00 W -Rule Halifax 1945 1959 - Sep lastSun 2:00 0 S -Rule Halifax 1946 1959 - Apr lastSun 2:00 1:00 D -Rule Halifax 1962 1986 - Apr lastSun 2:00 1:00 D -Rule Halifax 1962 max - Oct lastSun 2:00 0 S -Rule Halifax 1987 max - Apr Sun>=1 2:00 1:00 D +Rule Halifax 1946 1949 - Sep lastSun 2:00 0 S +Rule Halifax 1946 1949 - Apr lastSun 2:00 1:00 D +Rule Halifax 1951 1954 - Sep lastSun 2:00 0 S +Rule Halifax 1951 1954 - Apr lastSun 2:00 1:00 D +Rule Halifax 1956 1959 - Sep lastSun 2:00 0 S +Rule Halifax 1956 1959 - Apr lastSun 2:00 1:00 D +Rule Halifax 1962 1973 - Apr lastSun 2:00 1:00 D +Rule Halifax 1962 1973 - Oct lastSun 2:00 0 S # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone America/Halifax -4:14:24 - LMT 1902 Jun 15 - -4:00 Halifax A%sT + -4:00 Halifax A%sT 1918 + -4:00 Canada A%sT 1919 + -4:00 Halifax A%sT 1942 Feb 9 2:00s + -4:00 Canada A%sT 1946 + -4:00 Halifax A%sT 1974 + -4:00 Canada A%sT Zone America/Glace_Bay -3:59:48 - LMT 1902 Jun 15 -4:00 Canada A%sT 1953 -4:00 Halifax A%sT 1954 -4:00 - AST 1972 - -4:00 Halifax A%sT + -4:00 Halifax A%sT 1974 + -4:00 Canada A%sT # Ontario, Quebec # From Paul Eggert (1996-06-12): -# Shanks writes that since 1970 most of this region has been like Montreal. +# Shanks writes that since 1970 most of Ontario has been like Toronto, +# and most of Quebec has been like Montreal. # Thunder Bay skipped DST in 1973. # Many smaller locales did not observe peacetime DST until 1974; # Nipigon (EST) and Rainy River (CST) are the largest that we know of. # Far west Ontario is like Winnipeg; far east Quebec is like Halifax. +# From Mark Brader (2003-07-26): +# [According to the Toronto Star] Orillia, Ontario, adopted DST +# effective Saturday, 1912-06-22, 22:00; the article mentions that +# Port Arthur (now part of Thunder Bay, Ontario) as well as Moose Jaw +# have already done so. In Orillia DST was to run until Saturday, +# 1912-08-31 (no time mentioned), but it was met with considerable +# hostility from certain segments of the public, and was revoked after +# only two weeks -- I copied it as Saturday, 1912-07-07, 22:00, but +# presumably that should be -07-06. (1912-06-19, -07-12; also letters +# earlier in June). +# +# Kenora, Ontario, was to abandon DST on 1914-06-01 (-05-21). + # From Paul Eggert (1997-10-17): -# msb@sq.com writes that an article in the 1997-10-14 Toronto Star +# Mark Brader writes that an article in the 1997-10-14 Toronto Star # says that Atikokan, Ontario currently does not observe DST, # but will vote on 11-10 whether to use EST/EDT. # He also writes that the @@ -915,43 +952,115 @@ Zone America/Glace_Bay -3:59:48 - LMT 1902 Jun 15 # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S Rule Mont 1917 only - Mar 25 2:00 1:00 D Rule Mont 1917 only - Apr 24 0:00 0 S -Rule Mont 1918 only - Apr 14 2:00 1:00 D -Rule Mont 1918 only - Oct 31 2:00 0 S Rule Mont 1919 only - Mar 31 2:30 1:00 D Rule Mont 1919 only - Oct 25 2:30 0 S Rule Mont 1920 only - May 2 2:30 1:00 D -Rule Mont 1920 only - Oct 3 2:30 0 S +Rule Mont 1920 1922 - Oct Sun>=1 2:30 0 S Rule Mont 1921 only - May 1 2:00 1:00 D -Rule Mont 1921 only - Oct 2 2:30 0 S Rule Mont 1922 only - Apr 30 2:00 1:00 D -Rule Mont 1922 only - Oct 1 2:30 0 S Rule Mont 1924 only - May 17 2:00 1:00 D Rule Mont 1924 1926 - Sep lastSun 2:30 0 S Rule Mont 1925 1926 - May Sun>=1 2:00 1:00 D -Rule Mont 1927 only - May 1 0:00 1:00 D -Rule Mont 1927 1932 - Sep Sun>=25 0:00 0 S -Rule Mont 1928 1931 - Apr Sun>=25 0:00 1:00 D -Rule Mont 1932 only - May 1 0:00 1:00 D -Rule Mont 1933 1940 - Apr Sun>=24 0:00 1:00 D -Rule Mont 1933 only - Oct 1 0:00 0 S -Rule Mont 1934 1939 - Sep Sun>=24 0:00 0 S +# The 1927-to-1937 rules can be expressed more simply as +# Rule Mont 1927 1937 - Apr lastSat 24:00 1:00 D +# Rule Mont 1927 1937 - Sep lastSat 24:00 0 S +# The rules below avoid use of 24:00 +# (which pre-1998 versions of zic cannot handle). +Rule Mont 1927 only - May 1 0:00 1:00 D +Rule Mont 1927 1932 - Sep lastSun 0:00 0 S +Rule Mont 1928 1931 - Apr lastSun 0:00 1:00 D +Rule Mont 1932 only - May 1 0:00 1:00 D +Rule Mont 1933 1940 - Apr lastSun 0:00 1:00 D +Rule Mont 1933 only - Oct 1 0:00 0 S +Rule Mont 1934 1939 - Sep lastSun 0:00 0 S +Rule Mont 1946 1973 - Apr lastSun 2:00 1:00 D Rule Mont 1945 1948 - Sep lastSun 2:00 0 S -Rule Mont 1946 1986 - Apr lastSun 2:00 1:00 D Rule Mont 1949 1950 - Oct lastSun 2:00 0 S Rule Mont 1951 1956 - Sep lastSun 2:00 0 S -Rule Mont 1957 max - Oct lastSun 2:00 0 S -Rule Mont 1987 max - Apr Sun>=1 2:00 1:00 D +Rule Mont 1957 1973 - Oct lastSun 2:00 0 S + +Rule Toronto 1919 only - Mar 30 23:30 1:00 D +Rule Toronto 1919 only - Oct 26 0:00 0 S +Rule Toronto 1920 only - May 2 2:00 1:00 D +Rule Toronto 1920 only - Sep 26 0:00 0 S +Rule Toronto 1921 only - May 15 2:00 1:00 D +Rule Toronto 1921 only - Sep 15 2:00 0 S +Rule Toronto 1922 1923 - May Sun>=8 2:00 1:00 D +# Shanks says 1923-09-19; assume it's a typo and that "-16" was meant. +Rule Toronto 1922 1926 - Sep Sun>=15 2:00 0 S +Rule Toronto 1924 1927 - May Sun>=1 2:00 1:00 D +# The 1927-to-1939 rules can be expressed more simply as +# Rule Toronto 1927 1937 - Sep Sun>=25 2:00 0 S +# Rule Toronto 1928 1937 - Apr Sun>=25 2:00 1:00 D +# Rule Toronto 1938 1940 - Apr lastSun 2:00 1:00 D +# Rule Toronto 1938 1939 - Sep lastSun 2:00 0 S +# The rules below avoid use of Sun>=25 +# (which pre-2004 versions of zic cannot handle). +Rule Toronto 1927 1932 - Sep lastSun 2:00 0 S +Rule Toronto 1928 1931 - Apr lastSun 2:00 1:00 D +Rule Toronto 1932 only - May 1 2:00 1:00 D +Rule Toronto 1933 1940 - Apr lastSun 2:00 1:00 D +Rule Toronto 1933 only - Oct 1 2:00 0 S +Rule Toronto 1934 1939 - Sep lastSun 2:00 0 S +Rule Toronto 1945 1946 - Sep lastSun 2:00 0 S +Rule Toronto 1946 only - Apr lastSun 2:00 1:00 D +Rule Toronto 1947 1949 - Apr lastSun 0:00 1:00 D +Rule Toronto 1947 1948 - Sep lastSun 0:00 0 S +Rule Toronto 1949 only - Nov lastSun 0:00 0 S +Rule Toronto 1950 1973 - Apr lastSun 2:00 1:00 D +Rule Toronto 1950 only - Nov lastSun 2:00 0 S +Rule Toronto 1951 1956 - Sep lastSun 2:00 0 S +# Shanks says Toronto ended DST a week early in 1971, namely on 1971-10-24, +# but Mark Brader wrote (2003-05-31) that he checked the 1971-10-30 issue +# of the Toronto Star, and it said that DST ended 1971-10-31 as usual. +Rule Toronto 1957 1973 - Oct lastSun 2:00 0 S + +# From Paul Eggert (2003-07-27): +# Willett (1914-03) writes (p. 17) "In the Cities of Fort William, and +# Port Arthur, Ontario, the principle of the Bill has been in +# operation for the past three years, and in the City of Moose Jaw, +# Saskatchewan, for one year." + +# From David Bryan via Tory Tronrud, Director/Curator, +# Thunder Bay Museum (2003-11-12): +# There is some suggestion, however, that, by-law or not, daylight +# savings time was being practiced in Fort William and Port Arthur +# before 1909.... [I]n 1910, the line between the Eastern and Central +# Time Zones was permanently moved about two hundred miles west to +# include the Thunder Bay area.... When Canada adopted daylight +# savings time in 1916, Fort William and Port Arthur, having done so +# already, did not change their clocks.... During the Second World +# War,... [t]he cities agreed to implement DST during the summer +# months for the remainder of the war years. + # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone America/Montreal -4:54:16 - LMT 1884 - -5:00 Mont E%sT + -5:00 Mont E%sT 1918 + -5:00 Canada E%sT 1919 + -5:00 Mont E%sT 1942 Feb 9 2:00s + -5:00 Canada E%sT 1946 + -5:00 Mont E%sT 1974 + -5:00 Canada E%sT +Zone America/Toronto -5:17:32 - LMT 1895 + -5:00 Canada E%sT 1919 + -5:00 Toronto E%sT 1942 Feb 9 2:00s + -5:00 Canada E%sT 1946 + -5:00 Toronto E%sT 1974 + -5:00 Canada E%sT Zone America/Thunder_Bay -5:57:00 - LMT 1895 + -6:00 - CST 1910 + -5:00 - EST 1942 -5:00 Canada E%sT 1970 -5:00 Mont E%sT 1973 -5:00 - EST 1974 -5:00 Canada E%sT Zone America/Nipigon -5:53:04 - LMT 1895 + -5:00 Canada E%sT 1940 Sep 29 + -5:00 1:00 EDT 1942 Feb 9 2:00s -5:00 Canada E%sT Zone America/Rainy_River -6:17:56 - LMT 1895 + -6:00 Canada C%sT 1940 Sep 29 + -6:00 1:00 CDT 1942 Feb 9 2:00s -6:00 Canada C%sT @@ -964,7 +1073,8 @@ Rule Winn 1918 only - Apr 14 2:00 1:00 D Rule Winn 1918 only - Oct 31 2:00 0 S Rule Winn 1937 only - May 16 2:00 1:00 D Rule Winn 1937 only - Sep 26 2:00 0 S -Rule Winn 1942 only - Feb 9 2:00 1:00 W +Rule Winn 1942 only - Feb 9 2:00 1:00 W # War +Rule Winn 1945 only - Aug 14 23:00u 1:00 P # Peace Rule Winn 1945 only - Sep lastSun 2:00 0 S Rule Winn 1946 only - May 12 2:00 1:00 D Rule Winn 1946 only - Oct 13 2:00 0 S @@ -992,6 +1102,20 @@ Zone America/Winnipeg -6:28:36 - LMT 1887 Jul 16 # Saskatchewan +# From Mark Brader (2003-07-26): +# The first actual adoption of DST in Canada was at the municipal +# level. As the [Toronto] Star put it (1912-06-07), "While people +# elsewhere have long been talking of legislation to save daylight, +# the city of Moose Jaw [Saskatchewan] has acted on its own hook." +# DST in Moose Jaw began on Saturday, 1912-06-01 (no time mentioned: +# presumably late evening, as below), and would run until "the end of +# the summer". The discrepancy between municipal time and railroad +# time was noted. + +# From Paul Eggert (2003-07-27): +# Willett (1914-03) notes that DST "has been in operation ... in the +# City of Moose Jaw, Saskatchewan, for one year." + # From Paul Eggert (2000-10-02): # Shanks writes that since 1970 most of this region has been like Regina. # Some western towns (e.g. Swift Current) switched from MST/MDT to CST in 1972. @@ -1034,12 +1158,14 @@ Rule Regina 1937 1941 - Apr Sun>=8 0:00 1:00 D Rule Regina 1937 only - Oct Sun>=8 0:00 0 S Rule Regina 1938 only - Oct Sun>=1 0:00 0 S Rule Regina 1939 1941 - Oct Sun>=8 0:00 0 S -Rule Regina 1942 only - Feb 9 2:00 1:00 W +Rule Regina 1942 only - Feb 9 2:00 1:00 W # War +Rule Regina 1945 only - Aug 14 23:00u 1:00 P # Peace Rule Regina 1945 only - Sep lastSun 2:00 0 S Rule Regina 1946 only - Apr Sun>=8 2:00 1:00 D Rule Regina 1946 only - Oct Sun>=8 2:00 0 S -Rule Regina 1947 1959 - Apr lastSun 2:00 1:00 D -Rule Regina 1947 1958 - Sep lastSun 2:00 0 S +Rule Regina 1947 1957 - Apr lastSun 2:00 1:00 D +Rule Regina 1947 1957 - Sep lastSun 2:00 0 S +Rule Regina 1959 only - Apr lastSun 2:00 1:00 D Rule Regina 1959 only - Oct lastSun 2:00 0 S # Rule Swift 1957 only - Apr lastSun 2:00 1:00 D @@ -1067,7 +1193,8 @@ Rule Edm 1919 only - May 27 2:00 0 S Rule Edm 1920 1923 - Apr lastSun 2:00 1:00 D Rule Edm 1920 only - Oct lastSun 2:00 0 S Rule Edm 1921 1923 - Sep lastSun 2:00 0 S -Rule Edm 1942 only - Feb 9 2:00 1:00 W +Rule Edm 1942 only - Feb 9 2:00 1:00 W # War +Rule Edm 1945 only - Aug 14 23:00u 1:00 P # Peace Rule Edm 1945 only - Sep lastSun 2:00 0 S Rule Edm 1947 only - Apr lastSun 2:00 1:00 D Rule Edm 1947 only - Sep lastSun 2:00 0 S @@ -1093,7 +1220,8 @@ Zone America/Edmonton -7:33:52 - LMT 1906 Sep # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S Rule Vanc 1918 only - Apr 14 2:00 1:00 D Rule Vanc 1918 only - Oct 31 2:00 0 S -Rule Vanc 1942 only - Feb 9 2:00 1:00 W +Rule Vanc 1942 only - Feb 9 2:00 1:00 W # War +Rule Vanc 1945 only - Aug 14 23:00u 1:00 P # Peace Rule Vanc 1945 only - Sep 30 2:00 0 S Rule Vanc 1946 1986 - Apr lastSun 2:00 1:00 D Rule Vanc 1946 only - Oct 13 2:00 0 S @@ -1219,7 +1347,8 @@ Rule NT_YK 1918 only - Apr 14 2:00 1:00 D Rule NT_YK 1918 only - Oct 27 2:00 0 S Rule NT_YK 1919 only - May 25 2:00 1:00 D Rule NT_YK 1919 only - Nov 1 0:00 0 S -Rule NT_YK 1942 only - Feb 9 2:00 1:00 W +Rule NT_YK 1942 only - Feb 9 2:00 1:00 W # War +Rule NT_YK 1945 only - Aug 14 23:00u 1:00 P # Peace Rule NT_YK 1945 only - Sep 30 2:00 0 S Rule NT_YK 1965 only - Apr lastSun 0:00 2:00 DD Rule NT_YK 1965 only - Oct lastSun 2:00 0 S @@ -1412,7 +1541,7 @@ Rule Mexico 1939 only - Feb 5 0:00 1:00 D Rule Mexico 1939 only - Jun 25 0:00 0 S Rule Mexico 1940 only - Dec 9 0:00 1:00 D Rule Mexico 1941 only - Apr 1 0:00 0 S -Rule Mexico 1943 only - Dec 16 0:00 1:00 W +Rule Mexico 1943 only - Dec 16 0:00 1:00 W # War Rule Mexico 1944 only - May 1 0:00 0 S Rule Mexico 1950 only - Feb 12 0:00 1:00 D Rule Mexico 1950 only - Jul 30 0:00 0 S @@ -1682,7 +1811,8 @@ Zone America/Santo_Domingo -4:39:36 - LMT 1890 # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S Rule Salv 1987 1988 - May Sun>=1 0:00 1:00 D Rule Salv 1987 1988 - Sep lastSun 0:00 0 S -# There are too many San Salvadors elsewhere, so we'll use `El Salvador'. +# There are too many San Salvadors elsewhere, so use America/El_Salvador +# instead of America/San_Salvador. # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone America/El_Salvador -5:56:48 - LMT 1921 # San Salvador -6:00 Salv C%sT @@ -1812,7 +1942,8 @@ Zone America/St_Lucia -4:04:00 - LMT 1890 # Castries # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone America/Miquelon -3:44:40 - LMT 1911 May 15 # St Pierre -4:00 - AST 1980 May - -3:00 Mont PM%sT # Pierre & Miquelon Time + -3:00 - PMST 1987 # Pierre & Miquelon Time + -3:00 Canada PM%sT # St Vincent and the Grenadines # Zone NAME GMTOFF RULES FORMAT [UNTIL] diff --git a/zic.tproj/datfiles/southamerica b/zic.tproj/datfiles/southamerica index 3210556..9124910 100644 --- a/zic.tproj/datfiles/southamerica +++ b/zic.tproj/datfiles/southamerica @@ -1,4 +1,4 @@ -# @(#)southamerica 7.46 +# @(#)southamerica 7.54 # This data is by no means authoritative; if you think you know better, # go ahead and edit the file (and please send any changes to @@ -141,6 +141,13 @@ Rule Arg 2000 only - Mar Sun>=1 0:00 0 - # This kind of things had always been done this way in Argentina. # We are still -03:00 all year round in all of the country. # +# From Mariano Absatz (2004-05-21): +# Today it was officially published that the Province of Mendoza is changing +# its timezone this winter... starting tomorrow night.... +# http://www.gobernac.mendoza.gov.ar/boletin/pdf/20040521-27158-normas.pdf +# From Paul Eggert (2004-05-24): +# It's Law No. 7,210. This change is due to a public power emergency, so for +# now we'll assume it's for this year only. # # From Paul Eggert (2002-01-22): # @@ -148,17 +155,61 @@ Rule Arg 2000 only - Mar Sun>=1 0:00 0 - # says that standard time in Argentina from 1894-10-31 # to 1920-05-01 was -4:16:48.25. Go with this more-precise value # over Shanks. +# +# From Mariano Absatz (2004-06-05): +# These media articles from a major newspaper mostly cover the current state: +# http://www.lanacion.com.ar/04/05/27/de_604825.asp +# http://www.lanacion.com.ar/04/05/28/de_605203.asp +# +# The following eight (8) provinces pulled clocks back to UTC-04:00 at +# midnight Monday May 31st. (that is, the night between 05/31 and 06/01). +# Apparently, all nine provinces would go back to UTC-03:00 at the same +# time in October 17th. +# +# Catamarca, Chubut, La Rioja, San Juan, San Luis, Santa Cruz, +# Tierra del Fuego, Tucuman. +# +# From Mariano Absatz (2004-06-14): +# ... this weekend, the Province of Tucuman decided it'd go back to UTC-03:00 +# yesterday midnight (that is, at 24:00 Saturday 12th), since the people's +# annoyance with the change is much higher than the power savings obtained.... +# +# From Gwillim Law (2004-06-14): +# http://www.lanacion.com.ar/04/06/10/de_609078.asp ... +# "The time change in Tierra del Fuego was a conflicted decision from +# the start. The government had decreed that the measure would take +# effect on June 1, but a normative error forced the new time to begin +# three days earlier, from a Saturday to a Sunday.... +# Our understanding was that the change was originally scheduled to take place +# on June 1 at 00:00 in Chubut, Santa Cruz, Tierra del Fuego (and some other +# provinces). Sunday was May 30, only two days earlier. So the article +# contains a contradiction. I would give more credence to the Saturday/Sunday +# date than the "three days earlier" phrase, and conclude that Tierra del +# Fuego set its clocks back at 2004-05-30 00:00. +# +# From Steffen Thorsen (2004-10-05): +# The previous law 7210 which changed the province of Mendoza's time zone +# back in May have been modified slightly in a new law 7277, which set the +# new end date to 2004-09-26 (original date was 2004-10-17). +# http://www.gobernac.mendoza.gov.ar/boletin/pdf/20040924-27244-normas.pdf +# +# From Mariano Absatz (2004-10-05): +# San Juan changed from UTC-03:00 to UTC-04:00 at midnight between +# Sunday, May 30th and Monday, May 31st. It changed back to UTC-03:00 +# at midnight between Saturday, July 24th and Sunday, July 25th.... +# http://www.sanjuan.gov.ar/prensa/archivo/000329.html +# http://www.sanjuan.gov.ar/prensa/archivo/000426.html +# http://www.sanjuan.gov.ar/prensa/archivo/000441.html # Unless otherwise specified, data are from Shanks through 1992, from # the IATA otherwise. As noted below, Shanks says that -# America/Cordoba split into 7 subregions during 1991/1992, but we +# America/Cordoba split into 6 subregions during 1991/1992, but we # haven't verified this yet so for now we'll keep it a single region. # # Zone NAME GMTOFF RULES FORMAT [UNTIL] # -# Buenos Aires (BA), Capital Federal (CF), Santa Cruz (SC), -# Tierra del Fuego, Antartida e Islas del Atlantico Sur (TF) -Zone America/Buenos_Aires -3:53:48 - LMT 1894 Oct 31 +# Buenos Aires (BA), Capital Federal (CF), +Zone America/Argentina/Buenos_Aires -3:53:48 - LMT 1894 Oct 31 -4:16:48 - CMT 1920 May # Cordoba Mean Time -4:00 - ART 1930 Dec -4:00 Arg AR%sT 1969 Oct 5 @@ -167,24 +218,30 @@ Zone America/Buenos_Aires -3:53:48 - LMT 1894 Oct 31 -3:00 - ART # # Santa Fe (SF), Entre Rios (ER), Corrientes (CN), Misiones (MN), Chaco (CC), -# Formosa (FM), Salta (SA), Tucuman (TM), Santiago del Estero (SE), -# Cordoba (CB), La Rioja (LR), San Juan (SJ), San Luis (SL), La Pampa (LP), -# Neuquen (NQ), Rio Negro (RN), Chubut (CH) +# Formosa (FM), Salta (SA), Santiago del Estero (SE), Cordoba (CB), +# San Luis (SL), La Pampa (LP), Neuquen (NQ), Rio Negro (RN) # # Shanks also makes the following claims, which we haven't verified: # - Formosa switched to -3:00 on 1991-01-07. -# - La Rioja and San Juan switched to -4:00 on 1991-03-01 -# and then to -3:00 on 1991-05-07. # - Misiones switched to -3:00 on 1990-12-29. # - Chaco switched to -3:00 on 1991-01-04. # - San Luis switched to -4:00 on 1990-03-14, then to -3:00 on 1990-10-15, # then to -4:00 on 1991-03-01, then to -3:00 on 1991-06-01. # - Santiago del Estero switched to -4:00 on 1991-04-01, # then to -3:00 on 1991-04-26. -# If we need to add Zones for these areas, we may need to have a subdirectory -# for Argentina, as e.g. "America/San_Luis" is too ambiguious. # -Zone America/Cordoba -4:16:48 - LMT 1894 Oct 31 +Zone America/Argentina/Cordoba -4:16:48 - LMT 1894 Oct 31 + -4:16:48 - CMT 1920 May + -4:00 - ART 1930 Dec + -4:00 Arg AR%sT 1969 Oct 5 + -3:00 Arg AR%sT 1991 Mar 3 + -4:00 - WART 1991 Oct 20 + -3:00 Arg AR%sT 1999 Oct 3 + -4:00 Arg AR%sT 2000 Mar 3 + -3:00 - ART +# +# Tucuman (TM) +Zone America/Argentina/Tucuman -4:20:52 - LMT 1894 Oct 31 -4:16:48 - CMT 1920 May -4:00 - ART 1930 Dec -4:00 Arg AR%sT 1969 Oct 5 @@ -192,10 +249,38 @@ Zone America/Cordoba -4:16:48 - LMT 1894 Oct 31 -4:00 - WART 1991 Oct 20 -3:00 Arg AR%sT 1999 Oct 3 -4:00 Arg AR%sT 2000 Mar 3 + -3:00 - ART 2004 Jun 1 + -4:00 - WART 2004 Jun 13 + -3:00 - ART +# +# La Rioja (LR) +Zone America/Argentina/La_Rioja -4:27:24 - LMT 1894 Oct 31 + -4:16:48 - CMT 1920 May + -4:00 - ART 1930 Dec + -4:00 Arg AR%sT 1969 Oct 5 + -3:00 Arg AR%sT 1991 Mar 1 + -4:00 - WART 1991 May 7 + -3:00 Arg AR%sT 1999 Oct 3 + -4:00 Arg AR%sT 2000 Mar 3 + -3:00 - ART 2004 Jun 1 + -4:00 - WART 2004 Jun 20 + -3:00 - ART +# +# San Juan (SJ) +Zone America/Argentina/San_Juan -4:34:04 - LMT 1894 Oct 31 + -4:16:48 - CMT 1920 May + -4:00 - ART 1930 Dec + -4:00 Arg AR%sT 1969 Oct 5 + -3:00 Arg AR%sT 1991 Mar 1 + -4:00 - WART 1991 May 7 + -3:00 Arg AR%sT 1999 Oct 3 + -4:00 Arg AR%sT 2000 Mar 3 + -3:00 - ART 2004 May 31 + -4:00 - WART 2004 Jul 25 -3:00 - ART # # Jujuy (JY) -Zone America/Jujuy -4:21:12 - LMT 1894 Oct 31 +Zone America/Argentina/Jujuy -4:21:12 - LMT 1894 Oct 31 -4:16:48 - CMT 1920 May -4:00 - ART 1930 Dec -4:00 Arg AR%sT 1969 Oct 5 @@ -209,7 +294,7 @@ Zone America/Jujuy -4:21:12 - LMT 1894 Oct 31 -3:00 - ART # # Catamarca (CT) -Zone America/Catamarca -4:23:08 - LMT 1894 Oct 31 +Zone America/Argentina/Catamarca -4:23:08 - LMT 1894 Oct 31 -4:16:48 - CMT 1920 May -4:00 - ART 1930 Dec -4:00 Arg AR%sT 1969 Oct 5 @@ -217,10 +302,12 @@ Zone America/Catamarca -4:23:08 - LMT 1894 Oct 31 -4:00 - WART 1991 Oct 20 -3:00 Arg AR%sT 1999 Oct 3 -4:00 Arg AR%sT 2000 Mar 3 + -3:00 - ART 2004 Jun 1 + -4:00 - WART 2004 Jun 20 -3:00 - ART # # Mendoza (MZ) -Zone America/Mendoza -4:35:16 - LMT 1894 Oct 31 +Zone America/Argentina/Mendoza -4:35:16 - LMT 1894 Oct 31 -4:16:48 - CMT 1920 May -4:00 - ART 1930 Dec -4:00 Arg AR%sT 1969 Oct 5 @@ -232,6 +319,44 @@ Zone America/Mendoza -4:35:16 - LMT 1894 Oct 31 -4:00 - WART 1992 Oct 18 -3:00 Arg AR%sT 1999 Oct 3 -4:00 Arg AR%sT 2000 Mar 3 + -3:00 - ART 2004 May 23 + -4:00 - WART 2004 Sep 26 + -3:00 - ART +# +# Chubut (CH) +# The name "Comodoro Rivadavia" exceeds the 14-byte POSIX limit. +Zone America/Argentina/ComodRivadavia -4:30:00 - LMT 1894 Oct 31 + -4:16:48 - CMT 1920 May + -4:00 - ART 1930 Dec + -4:00 Arg AR%sT 1969 Oct 5 + -3:00 Arg AR%sT 1991 Mar 3 + -4:00 - WART 1991 Oct 20 + -3:00 Arg AR%sT 1999 Oct 3 + -4:00 Arg AR%sT 2000 Mar 3 + -3:00 - ART 2004 Jun 1 + -4:00 - WART 2004 Jun 20 + -3:00 - ART +# +# Santa Cruz (SC) +Zone America/Argentina/Rio_Gallegos -4:36:52 - LMT 1894 Oct 31 + -4:16:48 - CMT 1920 May # Cordoba Mean Time + -4:00 - ART 1930 Dec + -4:00 Arg AR%sT 1969 Oct 5 + -3:00 Arg AR%sT 1999 Oct 3 + -4:00 Arg AR%sT 2000 Mar 3 + -3:00 - ART 2004 Jun 1 + -4:00 - WART 2004 Jun 20 + -3:00 - ART +# +# Tierra del Fuego, Antartida e Islas del Atlantico Sur (TF) +Zone America/Argentina/Ushuaia -4:33:12 - LMT 1894 Oct 31 + -4:16:48 - CMT 1920 May # Cordoba Mean Time + -4:00 - ART 1930 Dec + -4:00 Arg AR%sT 1969 Oct 5 + -3:00 Arg AR%sT 1999 Oct 3 + -4:00 Arg AR%sT 2000 Mar 3 + -3:00 - ART 2004 May 30 + -4:00 - WART 2004 Jun 20 -3:00 - ART # Aruba @@ -309,6 +434,11 @@ Zone America/La_Paz -4:32:36 - LMT 1890 # the Government decided to postpone DST, instead of changing the Constitution # (maybe, for the next elections, it will be possible to change the clock)... +# From Rodrigo Severo (2004-10-04): +# It's just the biannual change made necessary by the much hyped, supposedly +# modern Brazilian eletronic voting machines which, apparently, can't deal +# with a time change between the first and the second rounds of the elections. + # From Paul Eggert (2002-10-10): # The official decrees referenced below are mostly taken from # @@ -389,10 +519,10 @@ Rule Brazil 1992 only - Oct 25 0:00 1:00 S Rule Brazil 1993 only - Jan 31 0:00 0 - # Decree 942 (1993-09-28) # adopted by same states, plus AM. -# Decree 1,252 (1994-09-22) -# adopted by same states, minus AM. +# Decree 1,252 (1994-09-22; +# web page corrected 2004-01-07) adopted by same states, minus AM. # Decree 1,636 (1995-09-14) -# adopted by same states, plus TO. +# adopted by same states, plus MT and TO. # Decree 1,674 (1995-10-13) # adds AL, SE. Rule Brazil 1993 1995 - Oct Sun>=11 0:00 1:00 S @@ -443,25 +573,41 @@ Rule Brazil 2001 max - Feb Sun>=15 0:00 0 - # Decree 4,399 (2002-10-01) repeals DST in AL, CE, MA, PB, PE, PI, RN, SE. # Rule Brazil 2002 only - Nov 3 0:00 1:00 S +# Decree 4,844 (2003-09-24; corrected 2003-09-26) repeals DST in BA, MT, TO. +# +Rule Brazil 2003 only - Oct 19 0:00 1:00 S +# Decree 5,223 (2004-10-01) reestablishes DST in MT. +# +Rule Brazil 2004 only - Nov 2 0:00 1:00 S +# The latest ruleset listed above says that the following states observe DST: +# DF, ES, GO, MG, MS, MT, PR, RJ, RS, SC, SP. # -Rule Brazil 2003 max - Oct Sun>=8 0:00 1:00 S -# The latest decree listed above says that the following states observe DST: -# BA, DF, ES, GO, MG, MS, MT, PR, RJ, RS, SC, SP, TO. -# -# For dates after mid-2003, the above rules with TO="max" are guesses +Rule Brazil 2005 max - Oct Sun>=15 0:00 1:00 S +# For dates after mid-2005, the above rules with TO="max" are guesses # and are quite possibly wrong, but are more likely than no DST at all. # Zone NAME GMTOFF RULES FORMAT [UNTIL] # -# Atlantic islands: Fernando de Noronha, Trindade, Martin Vaz, -# Atol das Rocas, and Penedos de Sao Pedro e Sao Paulo +# Fernando de Noronha (administratively part of PE) Zone America/Noronha -2:09:40 - LMT 1914 -2:00 Brazil FN%sT 1990 Sep 17 + -2:00 - FNT 1999 Sep 30 + -2:00 Brazil FN%sT 2000 Oct 15 + -2:00 - FNT 2001 Sep 13 + -2:00 Brazil FN%sT 2002 Oct 1 -2:00 - FNT +# Other Atlantic islands have no permanent settlement. +# These include Trindade and Martin Vaz (administratively part of ES), +# Atol das Rocas (RN), and Penedos de Sao Pedro e Sao Paulo (PE). +# Fernando de Noronha was a separate territory from 1942-09-02 to 1989-01-01; +# it also included the Penedos. # # Amapa (AP), east Para (PA) # East Para includes Belem, Maraba, Serra Norte, and Sao Felix do Xingu. +# The division between east and west Para is the river Xingu. +# In the north a very small part from the river Javary (now Jari I guess, +# the border with Amapa) to the Amazon, then to the Xingu. Zone America/Belem -3:13:56 - LMT 1914 -3:00 Brazil BR%sT 1988 Sep 12 -3:00 - BRT @@ -489,7 +635,8 @@ Zone America/Recife -2:19:36 - LMT 1914 Zone America/Araguaina -3:12:48 - LMT 1914 -3:00 Brazil BR%sT 1990 Sep 17 -3:00 - BRT 1995 Sep 14 - -3:00 Brazil BR%sT + -3:00 Brazil BR%sT 2003 Sep 24 + -3:00 - BRT # # Alagoas (AL), Sergipe (SE) Zone America/Maceio -2:22:52 - LMT 1914 @@ -502,7 +649,14 @@ Zone America/Maceio -2:22:52 - LMT 1914 -3:00 Brazil BR%sT 2002 Oct 1 -3:00 - BRT # -# Bahia (BA), Goias (GO), Distrito Federal (DF), Minas Gerais (MG), +# Bahia (BA) +# There are too many Salvadors elsewhere, so use America/Bahia instead +# of America/Salvador. +Zone America/Bahia -2:34:04 - LMT 1914 + -3:00 Brazil BR%sT 2003 Sep 24 + -3:00 - BRT +# +# Goias (GO), Distrito Federal (DF), Minas Gerais (MG), # Espirito Santo (ES), Rio de Janeiro (RJ), Sao Paulo (SP), Parana (PR), # Santa Catarina (SC), Rio Grande do Sul (RS) Zone America/Sao_Paulo -3:06:28 - LMT 1914 @@ -510,8 +664,14 @@ Zone America/Sao_Paulo -3:06:28 - LMT 1914 -3:00 1:00 BRST 1964 -3:00 Brazil BR%sT # -# Mato Grosso (MT), Mato Grosso do Sul (MS) +# Mato Grosso do Sul (MS) +Zone America/Campo_Grande -3:38:28 - LMT 1914 + -4:00 Brazil AM%sT +# +# Mato Grosso (MT) Zone America/Cuiaba -3:44:20 - LMT 1914 + -4:00 Brazil AM%sT 2003 Sep 24 + -4:00 - AMT 2004 Oct 4 -4:00 Brazil AM%sT # # west Para (PA), Rondonia (RO) @@ -528,6 +688,8 @@ Zone America/Boa_Vista -4:02:40 - LMT 1914 -4:00 - AMT # # east Amazonas (AM): Boca do Acre, Jutai, Manaus, Floriano Peixoto +# The great circle line from Tabatinga to Porto Acre divides +# east from west Amazonas. Zone America/Manaus -4:00:04 - LMT 1914 -4:00 Brazil AM%sT 1988 Sep 12 -4:00 - AMT 1993 Sep 28 @@ -792,13 +954,22 @@ Zone America/Asuncion -3:50:40 - LMT 1890 -4:00 Para PY%sT # Peru +# +# +# From Evelyn C. Leeper via Mark Brader (2003-10-26): +# When we were in Peru in 1985-1986, they apparently switched over +# sometime between December 29 and January 3 while we were on the Amazon. +# +# From Paul Eggert (2003-11-02): +# Shanks doesn't have this transition. Assume 1986 was like 1987. + # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S Rule Peru 1938 only - Jan 1 0:00 1:00 S Rule Peru 1938 only - Apr 1 0:00 0 - Rule Peru 1938 1939 - Sep lastSun 0:00 1:00 S Rule Peru 1939 1940 - Mar Sun>=24 0:00 0 - -Rule Peru 1987 only - Jan 1 0:00 1:00 S -Rule Peru 1987 only - Apr 1 0:00 0 - +Rule Peru 1986 1987 - Jan 1 0:00 1:00 S +Rule Peru 1986 1987 - Apr 1 0:00 0 - Rule Peru 1990 only - Jan 1 0:00 1:00 S Rule Peru 1990 only - Apr 1 0:00 0 - # IATA is ambiguous for 1993/1995; go with Shanks. @@ -882,6 +1053,11 @@ Rule Uruguay 1990 1992 - Mar Sun>=1 0:00 0 - Rule Uruguay 1990 1991 - Oct Sun>=21 0:00 1:00 S Rule Uruguay 1992 only - Oct 18 0:00 1:00 S Rule Uruguay 1993 only - Feb 28 0:00 0 - +# From Eduardo Cota (2004-09-20): +# The uruguayan government has decreed a change in the local time.... +# http://www.presidencia.gub.uy/decretos/2004091502.htm +Rule Uruguay 2004 only - Sep Sun>=15 0:00 1:00 S +Rule Uruguay 2005 only - Mar Sun>=8 0:00 0 - # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone America/Montevideo -3:44:44 - LMT 1898 Jun 28 -3:44:44 - MMT 1920 May 1 # Montevideo MT diff --git a/zic.tproj/datfiles/zone.tab b/zic.tproj/datfiles/zone.tab new file mode 100644 index 0000000..34e940b --- /dev/null +++ b/zic.tproj/datfiles/zone.tab @@ -0,0 +1,409 @@ +# @(#)zone.tab 1.30 +# +# TZ zone descriptions +# +# From Paul Eggert (1996-08-05): +# +# This file contains a table with the following columns: +# 1. ISO 3166 2-character country code. See /usr/share/misc/iso3166. +# 2. Latitude and longitude of the zone's principal location +# in ISO 6709 sign-degrees-minutes-seconds format, +# either +-DDMM+-DDDMM or +-DDMMSS+-DDDMMSS, +# first latitude (+ is north), then longitude (+ is east). +# 3. Zone name used in value of TZ environment variable. +# 4. Comments; present if and only if the country has multiple rows. +# +# Columns are separated by a single tab. +# The table is sorted first by country, then an order within the country that +# (1) makes some geographical sense, and +# (2) puts the most populous zones first, where that does not contradict (1). +# +# Lines beginning with `#' are comments. +# +#country- +#code coordinates TZ comments +AD +4230+00131 Europe/Andorra +AE +2518+05518 Asia/Dubai +AF +3431+06912 Asia/Kabul +AG +1703-06148 America/Antigua +AI +1812-06304 America/Anguilla +AL +4120+01950 Europe/Tirane +AM +4011+04430 Asia/Yerevan +AN +1211-06900 America/Curacao +AO -0848+01314 Africa/Luanda +AQ -7750+16636 Antarctica/McMurdo McMurdo Station, Ross Island +AQ -9000+00000 Antarctica/South_Pole Amundsen-Scott Station, South Pole +AQ -6734-06808 Antarctica/Rothera Rothera Station, Adelaide Island +AQ -6448-06406 Antarctica/Palmer Palmer Station, Anvers Island +AQ -6736+06253 Antarctica/Mawson Mawson Station, Holme Bay +AQ -6835+07758 Antarctica/Davis Davis Station, Vestfold Hills +AQ -6617+11031 Antarctica/Casey Casey Station, Bailey Peninsula +AQ -7824+10654 Antarctica/Vostok Vostok Station, S Magnetic Pole +AQ -6640+14001 Antarctica/DumontDUrville Dumont-d'Urville Base, Terre Adelie +AQ -690022+0393524 Antarctica/Syowa Syowa Station, E Ongul I +AR -3436-05827 America/Argentina/Buenos_Aires Buenos Aires (BA, CF) +AR -3124-06411 America/Argentina/Cordoba most locations (CB, CC, CN, ER, FM, LP, MN, NQ, RN, SA, SE, SF, SL) +AR -2411-06518 America/Argentina/Jujuy Jujuy (JY) +AR -3124-06411 America/Argentina/Tucuman Tucuman (TM) +AR -2828-06547 America/Argentina/Catamarca Catamarca (CT) +AR -2926-06651 America/Argentina/La_Rioja La Rioja (LR) +AR -3132-06831 America/Argentina/San_Juan San Juan (SJ) +AR -3253-06849 America/Argentina/Mendoza Mendoza (MZ) +AR -4552-06730 America/Argentina/ComodRivadavia Chubut (CH) +AR -5138-06913 America/Argentina/Rio_Gallegos Santa Cruz (SC) +AR -5448-06818 America/Argentina/Ushuaia Tierra del Fuego (TF) +AS -1416-17042 Pacific/Pago_Pago +AT +4813+01620 Europe/Vienna +AU -3133+15905 Australia/Lord_Howe Lord Howe Island +AU -4253+14719 Australia/Hobart Tasmania +AU -3749+14458 Australia/Melbourne Victoria +AU -3352+15113 Australia/Sydney New South Wales - most locations +AU -3157+14127 Australia/Broken_Hill New South Wales - Yancowinna +AU -2728+15302 Australia/Brisbane Queensland - most locations +AU -2016+14900 Australia/Lindeman Queensland - Holiday Islands +AU -3455+13835 Australia/Adelaide South Australia +AU -1228+13050 Australia/Darwin Northern Territory +AU -3157+11551 Australia/Perth Western Australia +AW +1230-06858 America/Aruba +AX +6006+01957 Europe/Mariehamn +AZ +4023+04951 Asia/Baku +BA +4352+01825 Europe/Sarajevo +BB +1306-05937 America/Barbados +BD +2343+09025 Asia/Dhaka +BE +5050+00420 Europe/Brussels +BF +1222-00131 Africa/Ouagadougou +BG +4241+02319 Europe/Sofia +BH +2623+05035 Asia/Bahrain +BI -0323+02922 Africa/Bujumbura +BJ +0629+00237 Africa/Porto-Novo +BM +3217-06446 Atlantic/Bermuda +BN +0456+11455 Asia/Brunei +BO -1630-06809 America/La_Paz +BR -0351-03225 America/Noronha Atlantic islands +BR -0127-04829 America/Belem Amapa, E Para +BR -0343-03830 America/Fortaleza NE Brazil (MA, PI, CE, RN, PB) +BR -0803-03454 America/Recife Pernambuco +BR -0712-04812 America/Araguaina Tocantins +BR -0940-03543 America/Maceio Alagoas, Sergipe +BR -1259-03831 America/Bahia Bahia +BR -2332-04637 America/Sao_Paulo S & SE Brazil (GO, DF, MG, ES, RJ, SP, PR, SC, RS) +BR -2027-05437 America/Campo_Grande Mato Grosso do Sul +BR -1535-05605 America/Cuiaba Mato Grosso +BR -0846-06354 America/Porto_Velho W Para, Rondonia +BR +0249-06040 America/Boa_Vista Roraima +BR -0308-06001 America/Manaus E Amazonas +BR -0640-06952 America/Eirunepe W Amazonas +BR -0958-06748 America/Rio_Branco Acre +BS +2505-07721 America/Nassau +BT +2728+08939 Asia/Thimphu +BW -2545+02555 Africa/Gaborone +BY +5354+02734 Europe/Minsk +BZ +1730-08812 America/Belize +CA +4734-05243 America/St_Johns Newfoundland Island +CA +4439-06336 America/Halifax Atlantic Time - Nova Scotia (most places), NB, W Labrador, E Quebec & PEI +CA +4612-05957 America/Glace_Bay Atlantic Time - Nova Scotia - places that did not observe DST 1966-1971 +CA +5320-06025 America/Goose_Bay Atlantic Time - E Labrador +CA +4531-07334 America/Montreal Eastern Time - Quebec - most locations +CA +4339-07923 America/Toronto Eastern Time - Ontario - most locations +CA +4901-08816 America/Nipigon Eastern Time - Ontario & Quebec - places that did not observe DST 1967-1973 +CA +4823-08915 America/Thunder_Bay Eastern Time - Thunder Bay, Ontario +CA +6608-06544 America/Pangnirtung Eastern Standard Time - Pangnirtung, Nunavut +CA +6344-06828 America/Iqaluit Eastern Standard Time - east Nunavut +CA +6245-09210 America/Rankin_Inlet Eastern Standard Time - central Nunavut +CA +4953-09709 America/Winnipeg Central Time - Manitoba & west Ontario +CA +4843-09429 America/Rainy_River Central Time - Rainy River & Fort Frances, Ontario +CA +6903-10505 America/Cambridge_Bay Central Time - west Nunavut +CA +5024-10439 America/Regina Central Standard Time - Saskatchewan - most locations +CA +5017-10750 America/Swift_Current Central Standard Time - Saskatchewan - midwest +CA +5333-11328 America/Edmonton Mountain Time - Alberta, east British Columbia & west Saskatchewan +CA +6227-11421 America/Yellowknife Mountain Time - central Northwest Territories +CA +6825-11330 America/Inuvik Mountain Time - west Northwest Territories +CA +5946-12014 America/Dawson_Creek Mountain Standard Time - Dawson Creek & Fort Saint John, British Columbia +CA +4916-12307 America/Vancouver Pacific Time - west British Columbia +CA +6043-13503 America/Whitehorse Pacific Time - south Yukon +CA +6404-13925 America/Dawson Pacific Time - north Yukon +CC -1210+09655 Indian/Cocos +CD -0418+01518 Africa/Kinshasa west Dem. Rep. of Congo +CD -1140+02728 Africa/Lubumbashi east Dem. Rep. of Congo +CF +0422+01835 Africa/Bangui +CG -0416+01517 Africa/Brazzaville +CH +4723+00832 Europe/Zurich +CI +0519-00402 Africa/Abidjan +CK -2114-15946 Pacific/Rarotonga +CL -3327-07040 America/Santiago most locations +CL -2710-10927 Pacific/Easter Easter Island & Sala y Gomez +CM +0403+00942 Africa/Douala +CN +3114+12128 Asia/Shanghai east China - Beijing, Guangdong, Shanghai, etc. +CN +4545+12641 Asia/Harbin Heilongjiang +CN +2934+10635 Asia/Chongqing central China - Gansu, Guizhou, Sichuan, Yunnan, etc. +CN +4348+08735 Asia/Urumqi Tibet & most of Xinjiang Uyghur +CN +3929+07559 Asia/Kashgar southwest Xinjiang Uyghur +CO +0436-07405 America/Bogota +CR +0956-08405 America/Costa_Rica +CS +4450+02030 Europe/Belgrade +CU +2308-08222 America/Havana +CV +1455-02331 Atlantic/Cape_Verde +CX -1025+10543 Indian/Christmas +CY +3510+03322 Asia/Nicosia +CZ +5005+01426 Europe/Prague +DE +5230+01322 Europe/Berlin +DJ +1136+04309 Africa/Djibouti +DK +5540+01235 Europe/Copenhagen +DM +1518-06124 America/Dominica +DO +1828-06954 America/Santo_Domingo +DZ +3647+00303 Africa/Algiers +EC -0210-07950 America/Guayaquil mainland +EC -0054-08936 Pacific/Galapagos Galapagos Islands +EE +5925+02445 Europe/Tallinn +EG +3003+03115 Africa/Cairo +EH +2709-01312 Africa/El_Aaiun +ER +1520+03853 Africa/Asmera +ES +4024-00341 Europe/Madrid mainland +ES +3553-00519 Africa/Ceuta Ceuta & Melilla +ES +2806-01524 Atlantic/Canary Canary Islands +ET +0902+03842 Africa/Addis_Ababa +FI +6010+02458 Europe/Helsinki +FJ -1808+17825 Pacific/Fiji +FK -5142-05751 Atlantic/Stanley +FM +0931+13808 Pacific/Yap Yap +FM +0725+15147 Pacific/Truk Truk (Chuuk) +FM +0658+15813 Pacific/Ponape Ponape (Pohnpei) +FM +0519+16259 Pacific/Kosrae Kosrae +FO +6201-00646 Atlantic/Faeroe +FR +4852+00220 Europe/Paris +GA +0023+00927 Africa/Libreville +GB +512830-0001845 Europe/London Great Britain +GB +5435-00555 Europe/Belfast Northern Ireland +GD +1203-06145 America/Grenada +GE +4143+04449 Asia/Tbilisi +GF +0456-05220 America/Cayenne +GH +0533-00013 Africa/Accra +GI +3608-00521 Europe/Gibraltar +GL +6411-05144 America/Godthab most locations +GL +7646-01840 America/Danmarkshavn east coast, north of Scoresbysund +GL +7030-02215 America/Scoresbysund Scoresbysund / Ittoqqortoormiit +GL +7634-06847 America/Thule Thule / Pituffik +GM +1328-01639 Africa/Banjul +GN +0931-01343 Africa/Conakry +GP +1614-06132 America/Guadeloupe +GQ +0345+00847 Africa/Malabo +GR +3758+02343 Europe/Athens +GS -5416-03632 Atlantic/South_Georgia +GT +1438-09031 America/Guatemala +GU +1328+14445 Pacific/Guam +GW +1151-01535 Africa/Bissau +GY +0648-05810 America/Guyana +HK +2217+11409 Asia/Hong_Kong +HN +1406-08713 America/Tegucigalpa +HR +4548+01558 Europe/Zagreb +HT +1832-07220 America/Port-au-Prince +HU +4730+01905 Europe/Budapest +ID -0610+10648 Asia/Jakarta Java & Sumatra +ID -0002+10920 Asia/Pontianak west & central Borneo +ID -0507+11924 Asia/Makassar east & south Borneo, Celebes, Bali, Nusa Tengarra, west Timor +ID -0232+14042 Asia/Jayapura Irian Jaya & the Moluccas +IE +5320-00615 Europe/Dublin +IL +3146+03514 Asia/Jerusalem +IN +2232+08822 Asia/Calcutta +IO -0720+07225 Indian/Chagos +IQ +3321+04425 Asia/Baghdad +IR +3540+05126 Asia/Tehran +IS +6409-02151 Atlantic/Reykjavik +IT +4154+01229 Europe/Rome +JM +1800-07648 America/Jamaica +JO +3157+03556 Asia/Amman +JP +353916+1394441 Asia/Tokyo +KE -0117+03649 Africa/Nairobi +KG +4254+07436 Asia/Bishkek +KH +1133+10455 Asia/Phnom_Penh +KI +0125+17300 Pacific/Tarawa Gilbert Islands +KI -0308-17105 Pacific/Enderbury Phoenix Islands +KI +0152-15720 Pacific/Kiritimati Line Islands +KM -1141+04316 Indian/Comoro +KN +1718-06243 America/St_Kitts +KP +3901+12545 Asia/Pyongyang +KR +3733+12658 Asia/Seoul +KW +2920+04759 Asia/Kuwait +KY +1918-08123 America/Cayman +KZ +4315+07657 Asia/Almaty most locations +KZ +4448+06528 Asia/Qyzylorda Qyzylorda (Kyzylorda, Kzyl-Orda) +KZ +5017+05710 Asia/Aqtobe Aqtobe (Aktobe) +KZ +4431+05016 Asia/Aqtau Atyrau (Atirau, Gur'yev), Mangghystau (Mankistau) +KZ +5113+05121 Asia/Oral West Kazakhstan +LA +1758+10236 Asia/Vientiane +LB +3353+03530 Asia/Beirut +LC +1401-06100 America/St_Lucia +LI +4709+00931 Europe/Vaduz +LK +0656+07951 Asia/Colombo +LR +0618-01047 Africa/Monrovia +LS -2928+02730 Africa/Maseru +LT +5441+02519 Europe/Vilnius +LU +4936+00609 Europe/Luxembourg +LV +5657+02406 Europe/Riga +LY +3254+01311 Africa/Tripoli +MA +3339-00735 Africa/Casablanca +MC +4342+00723 Europe/Monaco +MD +4700+02850 Europe/Chisinau +MG -1855+04731 Indian/Antananarivo +MH +0709+17112 Pacific/Majuro most locations +MH +0905+16720 Pacific/Kwajalein Kwajalein +MK +4159+02126 Europe/Skopje +ML +1239-00800 Africa/Bamako southwest Mali +ML +1446-00301 Africa/Timbuktu northeast Mali +MM +1647+09610 Asia/Rangoon +MN +4755+10653 Asia/Ulaanbaatar most locations +MN +4801+09139 Asia/Hovd Bayan-Olgiy, Govi-Altai, Hovd, Uvs, Zavkhan +MN +4804+11430 Asia/Choibalsan Dornod, Sukhbaatar +MO +2214+11335 Asia/Macau +MP +1512+14545 Pacific/Saipan +MQ +1436-06105 America/Martinique +MR +1806-01557 Africa/Nouakchott +MS +1644-06213 America/Montserrat +MT +3554+01431 Europe/Malta +MU -2010+05730 Indian/Mauritius +MV +0410+07330 Indian/Maldives +MW -1547+03500 Africa/Blantyre +MX +1924-09909 America/Mexico_City Central Time - most locations +MX +2105-08646 America/Cancun Central Time - Quintana Roo +MX +2058-08937 America/Merida Central Time - Campeche, Yucatan +MX +2540-10019 America/Monterrey Central Time - Coahuila, Durango, Nuevo Leon, Tamaulipas +MX +2313-10625 America/Mazatlan Mountain Time - S Baja, Nayarit, Sinaloa +MX +2838-10605 America/Chihuahua Mountain Time - Chihuahua +MX +2904-11058 America/Hermosillo Mountain Standard Time - Sonora +MX +3232-11701 America/Tijuana Pacific Time +MY +0310+10142 Asia/Kuala_Lumpur peninsular Malaysia +MY +0133+11020 Asia/Kuching Sabah & Sarawak +MZ -2558+03235 Africa/Maputo +NA -2234+01706 Africa/Windhoek +NC -2216+16530 Pacific/Noumea +NE +1331+00207 Africa/Niamey +NF -2903+16758 Pacific/Norfolk +NG +0627+00324 Africa/Lagos +NI +1209-08617 America/Managua +NL +5222+00454 Europe/Amsterdam +NO +5955+01045 Europe/Oslo +NP +2743+08519 Asia/Katmandu +NR -0031+16655 Pacific/Nauru +NU -1901+16955 Pacific/Niue +NZ -3652+17446 Pacific/Auckland most locations +NZ -4357-17633 Pacific/Chatham Chatham Islands +OM +2336+05835 Asia/Muscat +PA +0858-07932 America/Panama +PE -1203-07703 America/Lima +PF -1732-14934 Pacific/Tahiti Society Islands +PF -0900-13930 Pacific/Marquesas Marquesas Islands +PF -2308-13457 Pacific/Gambier Gambier Islands +PG -0930+14710 Pacific/Port_Moresby +PH +1435+12100 Asia/Manila +PK +2452+06703 Asia/Karachi +PL +5215+02100 Europe/Warsaw +PM +4703-05620 America/Miquelon +PN -2504-13005 Pacific/Pitcairn +PR +182806-0660622 America/Puerto_Rico +PS +3130+03428 Asia/Gaza +PT +3843-00908 Europe/Lisbon mainland +PT +3238-01654 Atlantic/Madeira Madeira Islands +PT +3744-02540 Atlantic/Azores Azores +PW +0720+13429 Pacific/Palau +PY -2516-05740 America/Asuncion +QA +2517+05132 Asia/Qatar +RE -2052+05528 Indian/Reunion +RO +4426+02606 Europe/Bucharest +RU +5443+02030 Europe/Kaliningrad Moscow-01 - Kaliningrad +RU +5545+03735 Europe/Moscow Moscow+00 - west Russia +RU +5312+05009 Europe/Samara Moscow+01 - Caspian Sea +RU +5651+06036 Asia/Yekaterinburg Moscow+02 - Urals +RU +5500+07324 Asia/Omsk Moscow+03 - west Siberia +RU +5502+08255 Asia/Novosibirsk Moscow+03 - Novosibirsk +RU +5601+09250 Asia/Krasnoyarsk Moscow+04 - Yenisei River +RU +5216+10420 Asia/Irkutsk Moscow+05 - Lake Baikal +RU +6200+12940 Asia/Yakutsk Moscow+06 - Lena River +RU +4310+13156 Asia/Vladivostok Moscow+07 - Amur River +RU +4658+14242 Asia/Sakhalin Moscow+07 - Sakhalin Island +RU +5934+15048 Asia/Magadan Moscow+08 - Magadan +RU +5301+15839 Asia/Kamchatka Moscow+09 - Kamchatka +RU +6445+17729 Asia/Anadyr Moscow+10 - Bering Sea +RW -0157+03004 Africa/Kigali +SA +2438+04643 Asia/Riyadh +SB -0932+16012 Pacific/Guadalcanal +SC -0440+05528 Indian/Mahe +SD +1536+03232 Africa/Khartoum +SE +5920+01803 Europe/Stockholm +SG +0117+10351 Asia/Singapore +SH -1555-00542 Atlantic/St_Helena +SI +4603+01431 Europe/Ljubljana +SJ +7800+01600 Arctic/Longyearbyen Svalbard +SJ +7059-00805 Atlantic/Jan_Mayen Jan Mayen +SK +4809+01707 Europe/Bratislava +SL +0830-01315 Africa/Freetown +SM +4355+01228 Europe/San_Marino +SN +1440-01726 Africa/Dakar +SO +0204+04522 Africa/Mogadishu +SR +0550-05510 America/Paramaribo +ST +0020+00644 Africa/Sao_Tome +SV +1342-08912 America/El_Salvador +SY +3330+03618 Asia/Damascus +SZ -2618+03106 Africa/Mbabane +TC +2128-07108 America/Grand_Turk +TD +1207+01503 Africa/Ndjamena +TF -492110+0701303 Indian/Kerguelen +TG +0608+00113 Africa/Lome +TH +1345+10031 Asia/Bangkok +TJ +3835+06848 Asia/Dushanbe +TK -0922-17114 Pacific/Fakaofo +TL -0833+12535 Asia/Dili +TM +3757+05823 Asia/Ashgabat +TN +3648+01011 Africa/Tunis +TO -2110+17510 Pacific/Tongatapu +TR +4101+02858 Europe/Istanbul +TT +1039-06131 America/Port_of_Spain +TV -0831+17913 Pacific/Funafuti +TW +2503+12130 Asia/Taipei +TZ -0648+03917 Africa/Dar_es_Salaam +UA +5026+03031 Europe/Kiev most locations +UA +4837+02218 Europe/Uzhgorod Ruthenia +UA +4750+03510 Europe/Zaporozhye Zaporozh'ye, E Lugansk +UA +4457+03406 Europe/Simferopol central Crimea +UG +0019+03225 Africa/Kampala +UM +1700-16830 Pacific/Johnston Johnston Atoll +UM +2813-17722 Pacific/Midway Midway Islands +UM +1917+16637 Pacific/Wake Wake Island +US +404251-0740023 America/New_York Eastern Time +US +421953-0830245 America/Detroit Eastern Time - Michigan - most locations +US +381515-0854534 America/Louisville Eastern Time - Kentucky - Louisville area +US +364947-0845057 America/Kentucky/Monticello Eastern Time - Kentucky - Wayne County +US +394606-0860929 America/Indianapolis Eastern Standard Time - Indiana - most locations +US +382232-0862041 America/Indiana/Marengo Eastern Standard Time - Indiana - Crawford County +US +411745-0863730 America/Indiana/Knox Eastern Standard Time - Indiana - Starke County +US +384452-0850402 America/Indiana/Vevay Eastern Standard Time - Indiana - Switzerland County +US +415100-0873900 America/Chicago Central Time +US +450628-0873651 America/Menominee Central Time - Michigan - Wisconsin border +US +470659-1011757 America/North_Dakota/Center Central Time - North Dakota - Oliver County +US +394421-1045903 America/Denver Mountain Time +US +433649-1161209 America/Boise Mountain Time - south Idaho & east Oregon +US +364708-1084111 America/Shiprock Mountain Time - Navajo +US +332654-1120424 America/Phoenix Mountain Standard Time - Arizona +US +340308-1181434 America/Los_Angeles Pacific Time +US +611305-1495401 America/Anchorage Alaska Time +US +581807-1342511 America/Juneau Alaska Time - Alaska panhandle +US +593249-1394338 America/Yakutat Alaska Time - Alaska panhandle neck +US +643004-1652423 America/Nome Alaska Time - west Alaska +US +515248-1763929 America/Adak Aleutian Islands +US +211825-1575130 Pacific/Honolulu Hawaii +UY -3453-05611 America/Montevideo +UZ +3940+06648 Asia/Samarkand west Uzbekistan +UZ +4120+06918 Asia/Tashkent east Uzbekistan +VA +4154+01227 Europe/Vatican +VC +1309-06114 America/St_Vincent +VE +1030-06656 America/Caracas +VG +1827-06437 America/Tortola +VI +1821-06456 America/St_Thomas +VN +1045+10640 Asia/Saigon +VU -1740+16825 Pacific/Efate +WF -1318-17610 Pacific/Wallis +WS -1350-17144 Pacific/Apia +YE +1245+04512 Asia/Aden +YT -1247+04514 Indian/Mayotte +ZA -2615+02800 Africa/Johannesburg +ZM -1525+02817 Africa/Lusaka +ZW -1750+03103 Africa/Harare diff --git a/zic.tproj/ialloc.c b/zic.tproj/ialloc.c index f82638f..c81ef8b 100644 --- a/zic.tproj/ialloc.c +++ b/zic.tproj/ialloc.c @@ -1,34 +1,13 @@ -/* - * 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@ - */ -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char elsieid[] = "@(#)ialloc.c 8.28"; -#else -static char rcsid[] = "$OpenBSD: ialloc.c,v 1.3 1997/01/14 03:16:45 millert Exp $"; -#endif -#endif /* LIBC_SCCS and not lint */ +#ifndef lint +#ifndef NOID +static const char elsieid[] = "@(#)ialloc.c 8.29"; +#endif /* !defined NOID */ +#endif /* !defined lint */ + +#ifndef lint +static const char rcsid[] = + "$FreeBSD: src/usr.sbin/zic/ialloc.c,v 1.6 2000/11/28 18:18:56 charnier Exp $"; +#endif /* not lint */ /*LINTLIBRARY*/ @@ -36,13 +15,6 @@ static char rcsid[] = "$OpenBSD: ialloc.c,v 1.3 1997/01/14 03:16:45 millert Exp #define nonzero(n) (((n) == 0) ? 1 : (n)) -char * icalloc P((int nelem, int elsize)); -char * icatalloc P((char * old, const char * new)); -char * icpyalloc P((const char * string)); -char * imalloc P((int n)); -void * irealloc P((void * pointer, int size)); -void ifree P((char * pointer)); - char * imalloc(n) const int n; diff --git a/zic.tproj/private.h b/zic.tproj/private.h index 51f379d..47d9cb2 100644 --- a/zic.tproj/private.h +++ b/zic.tproj/private.h @@ -1,29 +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@ - */ -/* $OpenBSD: private.h,v 1.6 1997/01/14 03:16:48 millert Exp $ */ - #ifndef PRIVATE_H #define PRIVATE_H @@ -33,13 +7,14 @@ ** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). */ -/* OpenBSD defaults */ -#define TM_GMTOFF tm_gmtoff -#define TM_ZONE tm_zone -#define PCTS 1 -#define STD_INSPIRED 1 -#define HAVE_LONG_DOUBLE 1 -#define HAVE_STRERROR 1 +/* + * FreeBSD modifications: separate libc's privates from zic's. + * This makes it easier when we need to update one but not the other. + * I have removed all of the ifdef spaghetti which is not relevant to + * zic from this file. + * + * $FreeBSD: src/usr.sbin/zic/private.h,v 1.7 2004/06/20 21:41:11 stefanf Exp $ + */ /* ** This header is for use ONLY with the time conversion code. @@ -53,47 +28,41 @@ ** ID */ -#if 0 #ifndef lint #ifndef NOID -static char privatehid[] = "@(#)private.h 7.44"; +static const char privatehid[] = "@(#)private.h 7.53"; #endif /* !defined NOID */ #endif /* !defined lint */ -#endif /* ** Defaults for preprocessor symbols. ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'. */ -#ifndef HAVE_ADJTIME -#define HAVE_ADJTIME 1 -#endif /* !defined HAVE_ADJTIME */ - #ifndef HAVE_GETTEXT #define HAVE_GETTEXT 0 #endif /* !defined HAVE_GETTEXT */ -#ifndef HAVE_SETTIMEOFDAY -#define HAVE_SETTIMEOFDAY 3 -#endif /* !defined HAVE_SETTIMEOFDAY */ - #ifndef HAVE_STRERROR -#define HAVE_STRERROR 0 +#define HAVE_STRERROR 1 #endif /* !defined HAVE_STRERROR */ +#ifndef HAVE_SYMLINK +#define HAVE_SYMLINK 1 +#endif /* !defined HAVE_SYMLINK */ + +#ifndef HAVE_SYS_STAT_H +#define HAVE_SYS_STAT_H 1 +#endif /* !defined HAVE_SYS_STAT_H */ + +#ifndef HAVE_SYS_WAIT_H +#define HAVE_SYS_WAIT_H 1 +#endif /* !defined HAVE_SYS_WAIT_H */ + #ifndef HAVE_UNISTD_H #define HAVE_UNISTD_H 1 #endif /* !defined HAVE_UNISTD_H */ -#ifndef HAVE_UTMPX_H -#define HAVE_UTMPX_H 0 -#endif /* !defined HAVE_UTMPX_H */ - -#ifndef LOCALE_HOME -#define LOCALE_HOME "/usr/lib/locale" -#endif /* !defined LOCALE_HOME */ - /* ** Nested includes */ @@ -110,6 +79,10 @@ static char privatehid[] = "@(#)private.h 7.44"; #include "libintl.h" #endif /* HAVE_GETTEXT - 0 */ +#if HAVE_SYS_WAIT_H - 0 +#include /* for WIFEXITED and WEXITSTATUS */ +#endif /* HAVE_SYS_WAIT_H - 0 */ + #if HAVE_UNISTD_H - 0 #include "unistd.h" /* for F_OK and R_OK */ #endif /* HAVE_UNISTD_H - 0 */ @@ -126,89 +99,19 @@ static char privatehid[] = "@(#)private.h 7.44"; /* Unlike 's isdigit, this also works if c < 0 | c > UCHAR_MAX. */ #define is_digit(c) ((unsigned)(c) - '0' <= 9) -/* -** Workarounds for compilers/systems. -*/ - -/* -** SunOS 4.1.1 cc lacks const. -*/ - -#ifndef const -#ifndef __STDC__ -#define const -#endif /* !defined __STDC__ */ -#endif /* !defined const */ - -/* -** SunOS 4.1.1 cc lacks prototypes. -*/ - -#ifndef P -#ifdef __STDC__ -#define P(x) x -#endif /* defined __STDC__ */ -#ifndef __STDC__ -#define P(x) () -#endif /* !defined __STDC__ */ -#endif /* !defined P */ - -/* -** SunOS 4.1.1 headers lack EXIT_SUCCESS. -*/ - -#ifndef EXIT_SUCCESS -#define EXIT_SUCCESS 0 -#endif /* !defined EXIT_SUCCESS */ - -/* -** SunOS 4.1.1 headers lack EXIT_FAILURE. -*/ - -#ifndef EXIT_FAILURE -#define EXIT_FAILURE 1 -#endif /* !defined EXIT_FAILURE */ - -/* -** SunOS 4.1.1 headers lack FILENAME_MAX. -*/ - -#ifndef FILENAME_MAX - -#ifndef MAXPATHLEN -#ifdef unix -#include "sys/param.h" -#endif /* defined unix */ -#endif /* !defined MAXPATHLEN */ - -#ifdef MAXPATHLEN -#define FILENAME_MAX MAXPATHLEN -#endif /* defined MAXPATHLEN */ -#ifndef MAXPATHLEN -#define FILENAME_MAX 1024 /* Pure guesswork */ -#endif /* !defined MAXPATHLEN */ - -#endif /* !defined FILENAME_MAX */ - -/* -** SunOS 4.1.1 libraries lack remove. -*/ - -#ifndef remove -extern int unlink P((const char * filename)); -#define remove unlink -#endif /* !defined remove */ +#define P(x) x -#if 0 /* -** Some ancient errno.h implementations don't declare errno. -** But some newer errno.h implementations define it as a macro. -** Fix the former without affecting the latter. +** Private function declarations. */ -#ifndef errno -extern int errno; -#endif /* !defined errno */ -#endif +char * icalloc P((int nelem, int elsize)); +char * icatalloc P((char * old, const char * new)); +char * icpyalloc P((const char * string)); +char * imalloc P((int n)); +void * irealloc P((void * pointer, int size)); +void icfree P((char * pointer)); +void ifree P((char * pointer)); +char * scheck P((const char *string, const char *format)); /* ** Finally, some convenience items. @@ -238,7 +141,7 @@ extern int errno; ** add one more for a minus sign if the type is signed. */ #define INT_STRLEN_MAXIMUM(type) \ - ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 100 + 1 + TYPE_SIGNED(type)) + ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type)) #endif /* !defined INT_STRLEN_MAXIMUM */ /* @@ -284,7 +187,7 @@ extern int errno; #endif /* !defined TZ_DOMAIN */ /* -** UNIX was a registered trademark of UNIX System Laboratories in 1993. +** UNIX was a registered trademark of The Open Group in 2003. */ #endif /* !defined PRIVATE_H */ diff --git a/zic.tproj/scheck.c b/zic.tproj/scheck.c index bfb5ab2..009ef1e 100644 --- a/zic.tproj/scheck.c +++ b/zic.tproj/scheck.c @@ -1,46 +1,22 @@ -/* - * 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@ - */ -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char elsieid[] = "@(#)scheck.c 8.13"; -#else -static char rcsid[] = "$OpenBSD: scheck.c,v 1.4 1997/01/14 03:16:49 millert Exp $"; -#endif -#endif /* LIBC_SCCS and not lint */ +#ifndef lint +#ifndef NOID +static const char elsieid[] = "@(#)scheck.c 8.15"; +#endif /* !defined lint */ +#endif /* !defined NOID */ + +#ifndef lint +static const char rcsid[] = + "$FreeBSD: src/usr.sbin/zic/scheck.c,v 1.7 2001/07/18 11:27:04 dd Exp $"; +#endif /* not lint */ /*LINTLIBRARY*/ #include "private.h" -extern char * imalloc P((int n)); -extern void ifree P((char * p)); - char * scheck(string, format) const char * const string; -char * const format; +const char * const format; { register char * fbuf; register const char * fp; diff --git a/zic.tproj/tzfile.h b/zic.tproj/tzfile.h deleted file mode 100644 index 1702d15..0000000 --- a/zic.tproj/tzfile.h +++ /dev/null @@ -1,213 +0,0 @@ -/* - * 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@ - */ -/* $OpenBSD: tzfile.h,v 1.4 1997/01/14 03:16:52 millert Exp $ */ - -#ifndef TZFILE_H - -#define TZFILE_H - -/* -** This file is in the public domain, so clarified as of -** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). -*/ - -/* -** This header is for use ONLY with the time conversion code. -** There is no guarantee that it will remain unchanged, -** or that it will remain at all. -** Do NOT copy it to any system include directory. -** Thank you! -*/ - -/* -** ID -*/ - -#if 0 -#ifndef lint -#ifndef NOID -static char tzfilehid[] = "@(#)tzfile.h 7.9"; -#endif /* !defined NOID */ -#endif /* !defined lint */ -#endif - -/* -** Information about time zone files. -*/ - -#ifndef TZDIR -#define TZDIR "/usr/share/zoneinfo" /* Time zone object file directory */ -#endif /* !defined TZDIR */ - -#ifndef TZDEFAULT -#define TZDEFAULT "/etc/localtime" -#endif /* !defined TZDEFAULT */ - -#ifndef TZDEFRULES -#define TZDEFRULES "posixrules" -#endif /* !defined TZDEFRULES */ - -/* -** Each file begins with. . . -*/ - -struct tzhead { - char tzh_reserved[20]; /* reserved for future use */ - char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ - char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ - char tzh_leapcnt[4]; /* coded number of leap seconds */ - char tzh_timecnt[4]; /* coded number of transition times */ - char tzh_typecnt[4]; /* coded number of local time types */ - char tzh_charcnt[4]; /* coded number of abbr. chars */ -}; - -/* -** . . .followed by. . . -** -** tzh_timecnt (char [4])s coded transition times a la time(2) -** tzh_timecnt (unsigned char)s types of local time starting at above -** tzh_typecnt repetitions of -** one (char [4]) coded GMT offset in seconds -** one (unsigned char) used to set tm_isdst -** one (unsigned char) that's an abbreviation list index -** tzh_charcnt (char)s '\0'-terminated zone abbreviations -** tzh_leapcnt repetitions of -** one (char [4]) coded leap second transition times -** one (char [4]) total correction after above -** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition -** time is standard time, if FALSE, -** transition time is wall clock time -** if absent, transition times are -** assumed to be wall clock time -** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition -** time is GMT, if FALSE, -** transition time is local time -** if absent, transition times are -** assumed to be local time -*/ - -/* -** In the current implementation, "tzset()" refuses to deal with files that -** exceed any of the limits below. -*/ - -#ifndef TZ_MAX_TIMES -/* -** The TZ_MAX_TIMES value below is enough to handle a bit more than a -** year's worth of solar time (corrected daily to the nearest second) or -** 138 years of Pacific Presidential Election time -** (where there are three time zone transitions every fourth year). -*/ -#define TZ_MAX_TIMES 370 -#endif /* !defined TZ_MAX_TIMES */ - -#ifndef TZ_MAX_TYPES -#ifndef NOSOLAR -#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ -#endif /* !defined NOSOLAR */ -#ifdef NOSOLAR -/* -** Must be at least 14 for Europe/Riga as of Jan 12 1995, -** as noted by Earl Chew . -*/ -#define TZ_MAX_TYPES 20 /* Maximum number of local time types */ -#endif /* !defined NOSOLAR */ -#endif /* !defined TZ_MAX_TYPES */ - -#ifndef TZ_MAX_CHARS -#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ - /* (limited by what unsigned chars can hold) */ -#endif /* !defined TZ_MAX_CHARS */ - -#ifndef TZ_MAX_LEAPS -#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ -#endif /* !defined TZ_MAX_LEAPS */ - -#define SECSPERMIN 60 -#define MINSPERHOUR 60 -#define HOURSPERDAY 24 -#define DAYSPERWEEK 7 -#define DAYSPERNYEAR 365 -#define DAYSPERLYEAR 366 -#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) -#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY) -#define MONSPERYEAR 12 - -#define TM_SUNDAY 0 -#define TM_MONDAY 1 -#define TM_TUESDAY 2 -#define TM_WEDNESDAY 3 -#define TM_THURSDAY 4 -#define TM_FRIDAY 5 -#define TM_SATURDAY 6 - -#define TM_JANUARY 0 -#define TM_FEBRUARY 1 -#define TM_MARCH 2 -#define TM_APRIL 3 -#define TM_MAY 4 -#define TM_JUNE 5 -#define TM_JULY 6 -#define TM_AUGUST 7 -#define TM_SEPTEMBER 8 -#define TM_OCTOBER 9 -#define TM_NOVEMBER 10 -#define TM_DECEMBER 11 - -#define TM_YEAR_BASE 1900 - -#define EPOCH_YEAR 1970 -#define EPOCH_WDAY TM_THURSDAY - -/* -** Accurate only for the past couple of centuries; -** that will probably do. -*/ - -#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) - -#ifndef USG - -/* -** Use of the underscored variants may cause problems if you move your code to -** certain System-V-based systems; for maximum portability, use the -** underscore-free variants. The underscored variants are provided for -** backward compatibility only; they may disappear from future versions of -** this file. -*/ - -#define SECS_PER_MIN SECSPERMIN -#define MINS_PER_HOUR MINSPERHOUR -#define HOURS_PER_DAY HOURSPERDAY -#define DAYS_PER_WEEK DAYSPERWEEK -#define DAYS_PER_NYEAR DAYSPERNYEAR -#define DAYS_PER_LYEAR DAYSPERLYEAR -#define SECS_PER_HOUR SECSPERHOUR -#define SECS_PER_DAY SECSPERDAY -#define MONS_PER_YEAR MONSPERYEAR - -#endif /* !defined USG */ - -#endif /* !defined TZFILE_H */ diff --git a/zic.tproj/zic.8 b/zic.tproj/zic.8 index 004ff09..5d00937 100644 --- a/zic.tproj/zic.8 +++ b/zic.tproj/zic.8 @@ -1,94 +1,114 @@ -.\" $OpenBSD: zic.8,v 1.4 1997/01/14 03:16:57 millert Exp $ -.TH ZIC 8 -.SH NAME -zic \- time zone compiler -.SH SYNOPSIS -.B zic -[ -.B \-v -] [ -.B \-d -.I directory -] [ -.B \-l -.I localtime -] [ -.B \-p -.I posixrules -] [ -.B \-L -.I leapsecondfilename -] [ -.B \-s -] [ -.B \-y -.I command -] [ -.I filename -\&... ] -.SH DESCRIPTION -.if t .ds lq `` -.if t .ds rq '' -.if n .ds lq \&"\" -.if n .ds rq \&"\" -.de q -\\$3\*(lq\\$1\*(rq\\$2 -.. -.I Zic -reads text from the file(s) named on the command line +.\" $FreeBSD: src/usr.sbin/zic/zic.8,v 1.17 2004/07/02 23:13:00 ru Exp $ +.Dd June 20, 2004 +.Dt ZIC 8 +.Os +.Sh NAME +.Nm zic +.Nd timezone compiler +.Sh SYNOPSIS +.Nm +.Op Fl -version +.Op Fl Dsv +.Op Fl d Ar directory +.Op Fl g Ar group +.Op Fl L Ar leapsecondfilename +.Op Fl l Ar localtime +.Op Fl m Ar mode +.Op Fl p Ar posixrules +.Op Fl u Ar user +.Op Fl y Ar command +.Op Ar filename ... +.Sh DESCRIPTION +The +.Nm +utility reads text from the file(s) named on the command line and creates the time conversion information files specified in this input. If a -.I filename +.Ar filename is -.BR \- , +.Em - , the standard input is read. -.PP -These options are available: -.TP -.BI "\-d " directory +.Pp +The following options are available: +.Bl -tag -width indent +.It Fl -version +Output version information and exit. +.It Fl D +Do not automatically create directories. +If the input file(s) specify +an output file in a directory which does not already exist, the +default behavior is to attempt to create the directory. +If +.Fl D +is specified, +.Nm +will instead error out immediately. +.It Fl d Ar directory Create time conversion information files in the named directory rather than in the standard directory named below. -.TP -.BI "\-l " timezone -Use the given time zone as local time. -.I Zic -will act as if the input contained a link line of the form -.sp -.ti +.5i -Link \fItimezone\fP localtime -.TP -.BI "\-p " timezone -Use the given time zone's rules when handling POSIX-format -time zone environment variables. -.I Zic -will act as if the input contained a link line of the form -.sp -.ti +.5i -Link \fItimezone\fP posixrules -.TP -.BI "\-L " leapsecondfilename +.It Fl g Ar group +After creating each output file, change its group ownership to the +specified +.Ar group +(which can be either a name or a numeric group ID). +.It Fl L Ar leapsecondfilename Read leap second information from the file with the given name. If this option is not used, no leap second information appears in output files. -.TP -.B \-v +.It Fl l Ar timezone +Use the given +.Ar time zone +as local time. +The +.Nm +utility will act as if the input contained a link line of the form +.Bd -literal -offset indent +.No "Link timezone localtime +.Ed +(Note that this action has no effect on +.Fx , +since the local time zone is specified in +.Pa /etc/localtime +and not +.Pa /usr/share/zoneinfo/localtime . ) +.It Fl m Ar mode +After creating each output file, change its access mode to +.Ar mode . +Both numeric and alphabetic modes are accepted +(see +.Xr chmod 1 ) . +.It Fl p Ar timezone +Use the given +.Ar "time zone" Ns 's +rules when handling POSIX-format +time zone environment variables. +The +.Nm +utility will act as if the input contained a link line of the form +.Bd -literal -offset indent +.No "Link timezone posixrules +.Ed +.It Fl u Ar user +After creating each output file, change its owner to +.Ar user +(which can be either a name or a numeric user ID). +.It Fl v Complain if a year that appears in a data file is outside the range of years representable by -.IR time (3) +.Xr time 3 values. -.TP -.B \-s +.It Fl s Limit time values stored in output files to values that are the same whether they're taken to be signed or unsigned. You can use this option to generate SVVS-compatible files. -.TP -.BI "\-y " command +.It Fl y Ar command Use the given -.I command +.Ar command rather than -.B yearistype +.Em yearistype when checking year types (see below). -.PP +.El +.Pp Input lines are made up of fields. Fields are separated from one another by any number of white space characters. Leading and trailing white space on input lines is ignored. @@ -99,283 +119,241 @@ White space characters and sharp characters may be enclosed in double quotes Any line that is blank (after comment stripping) is ignored. Non-blank lines are expected to be of one of three types: rule lines, zone lines, and link lines. -.PP -A rule line has the form -.nf -.ti +.5i -.ta \w'Rule\0\0'u +\w'NAME\0\0'u +\w'FROM\0\0'u +\w'1973\0\0'u +\w'TYPE\0\0'u +\w'Apr\0\0'u +\w'lastSun\0\0'u +\w'2:00\0\0'u +\w'SAVE\0\0'u -.sp -Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S -.sp +.Pp +A rule line has the form: +.Dl "Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S For example: -.ti +.5i -.sp -Rule US 1967 1973 \- Apr lastSun 2:00 1:00 D -.sp -.fi +.Dl "Rule US 1967 1973 \- Apr lastSun 2:00 1:00 D +.Pp The fields that make up a rule line are: -.TP "\w'LETTER/S'u" -.B NAME -Gives the (arbitrary) name of the set of rules this rule is part of. -.TP -.B FROM -Gives the first year in which the rule applies. +.Bl -tag -width "LETTER/S" -offset indent +.It NAME +Give the (arbitrary) name of the set of rules this rule is part of. +.It FROM +Give the first year in which the rule applies. Any integer year can be supplied; the Gregorian calendar is assumed. The word -.B minimum +.Em minimum (or an abbreviation) means the minimum year representable as an integer. The word -.B maximum +.Em maximum (or an abbreviation) means the maximum year representable as an integer. Rules can describe times that are not representable as time values, with the unrepresentable times ignored; this allows rules to be portable among hosts with differing time value types. -.TP -.B TO -Gives the final year in which the rule applies. +.It TO +Give the final year in which the rule applies. In addition to -.B minimum +.Em minimum and -.B maximum +.Em maximum (as above), the word -.B only +.Em only (or an abbreviation) may be used to repeat the value of the -.B FROM +.Em FROM field. -.TP -.B TYPE -Gives the type of year in which the rule applies. +.It TYPE +Give the type of year in which the rule applies. If -.B TYPE +.Em TYPE is -.B \- +.Em \- then the rule applies in all years between -.B FROM +.Em FROM and -.B TO +.Em TO inclusive. If -.B TYPE +.Em TYPE is something else, then -.I zic +.Nm executes the command -.ti +.5i -\fByearistype\fP \fIyear\fP \fItype\fP -.br +.Li yearistype Ar year Ar type to check the type of a year: an exit status of zero is taken to mean that the year is of the given type; an exit status of one is taken to mean that the year is not of the given type. -.TP -.B IN -Names the month in which the rule takes effect. +.It IN +Name the month in which the rule takes effect. Month names may be abbreviated. -.TP -.B ON -Gives the day on which the rule takes effect. +.It ON +Give the day on which the rule takes effect. Recognized forms include: -.nf -.in +.5i -.sp -.ta \w'Sun<=25\0\0'u -5 the fifth of the month -lastSun the last Sunday in the month -lastMon the last Monday in the month -Sun>=8 first Sunday on or after the eighth -Sun<=25 last Sunday on or before the 25th -.fi -.in -.5i -.sp +.Pp +.Bl -tag -width lastSun -compact -offset indent +.It \&5 +the fifth of the month +.It lastSun +the last Sunday in the month +.It lastMon +the last Monday in the month +.It Sun>=8 +first Sunday on or after the eighth +.It Sun<=25 +last Sunday on or before the 25th +.El +.Pp Names of days of the week may be abbreviated or spelled out in full. Note that there must be no spaces within the -.B ON +.Em ON field. -.TP -.B AT -Gives the time of day at which the rule takes effect. +.It AT +Give the time of day at which the rule takes effect. Recognized forms include: -.nf -.in +.5i -.sp -.ta \w'1:28:13\0\0'u -2 time in hours -2:00 time in hours and minutes -15:00 24-hour format time (for times after noon) -1:28:14 time in hours, minutes, and seconds -.fi -.in -.5i -.sp +.Pp +.Bl -tag -width "\&1:28:14" -offset indent -compact +.It 2 +time in hours +.It 2:00 +time in hours and minutes +.It 15:00 +24-hour format time (for times after noon) +.It 1:28:14 +time in hours, minutes, and seconds +.El +.Pp +where hour 0 is midnight at the start of the day, +and hour 24 is midnight at the end of the day. Any of these forms may be followed by the letter -.B w +.Sq Li w if the given time is local -.q "wall clock" +.Dq "wall clock" time, -.B s +.Sq Li s if the given time is local -.q standard +.Dq standard time, or -.B u +.Sq Li u (or -.B g +.Sq Li g or -.BR z ) +.Sq Li z ) if the given time is universal time; in the absence of an indicator, wall clock time is assumed. -.TP -.B SAVE -Gives the amount of time to be added to local standard time when the rule is in +.It SAVE +Give the amount of time to be added to local standard time when the rule is in effect. This field has the same format as the -.B AT +.Em AT field (although, of course, the -.B w +.Sq Li w and -.B s +.Sq Li s suffixes are not used). -.TP -.B LETTER/S -Gives the -.q "variable part" +.It LETTER/S +Give the +.Dq "variable part" (for example, the -.q S +.Dq S or -.q D +.Dq D in -.q EST +.Dq EST or -.q EDT ) +.Dq EDT ) of time zone abbreviations to be used when this rule is in effect. If this field is -.BR \- , +.Em \- , the variable part is null. -.PP -A zone line has the form -.sp -.nf -.ti +.5i -.ta \w'Zone\0\0'u +\w'Australia/Adelaide\0\0'u +\w'GMTOFF\0\0'u +\w'RULES/SAVE\0\0'u +\w'FORMAT\0\0'u -Zone NAME GMTOFF RULES/SAVE FORMAT [UNTIL] -.sp +.El +.Pp +A zone line has the form: +.Dl "Zone NAME GMTOFF RULES/SAVE FORMAT [UNTIL] For example: -.sp -.ti +.5i -Zone Australia/Adelaide 9:30 Aus CST 1971 Oct 31 2:00 -.sp -.fi +.Dl "Zone Australia/Adelaide 9:30 Aus CST 1971 Oct 31 2:00 The fields that make up a zone line are: -.TP "\w'GMTOFF'u" -.B NAME +.Bl -tag -width indent +.It NAME The name of the time zone. This is the name used in creating the time conversion information file for the zone. -.TP -.B GMTOFF -The amount of time to add to GMT to get standard time in this zone. +.It GMTOFF +The amount of time to add to UTC to get standard time in this zone. This field has the same format as the -.B AT +.Em AT and -.B SAVE +.Em SAVE fields of rule lines; -begin the field with a minus sign if time must be subtracted from GMT. -.TP -.B RULES/SAVE +begin the field with a minus sign if time must be subtracted from UTC. +.It RULES/SAVE The name of the rule(s) that apply in the time zone or, alternately, an amount of time to add to local standard time. If this field is -.B \- +.Em \- then standard time always applies in the time zone. -.TP -.B FORMAT +.It FORMAT The format for time zone abbreviations in this time zone. The pair of characters -.B %s +.Em %s is used to show where the -.q "variable part" +.Dq "variable part" of the time zone abbreviation goes. Alternately, a slash (/) separates standard and daylight abbreviations. -.TP -.B UNTIL -The time at which the GMT offset or the rule(s) change for a location. +.It UNTIL +The time at which the UTC offset or the rule(s) change for a location. It is specified as a year, a month, a day, and a time of day. If this is specified, -the time zone information is generated from the given GMT offset +the time zone information is generated from the given UTC offset and rule change until the time specified. The month, day, and time of day have the same format as the IN, ON, and AT columns of a rule; trailing columns can be omitted, and default to the earliest possible value for the missing columns. -.IP +.Pp The next line must be a -.q continuation +.Dq continuation line; this has the same form as a zone line except that the string -.q Zone +.Dq Zone and the name are omitted, as the continuation line will place information starting at the time specified as the -.B UNTIL +.Em UNTIL field in the previous line in the file used by the previous line. Continuation lines may contain an -.B UNTIL +.Em UNTIL field, just as zone lines do, indicating that the next line is a further continuation. -.PP +.El +.Pp A link line has the form -.sp -.nf -.ti +.5i -.ta \w'Link\0\0'u +\w'Europe/Istanbul\0\0'u -Link LINK-FROM LINK-TO -.sp +.Dl "Link LINK-FROM LINK-TO For example: -.sp -.ti +.5i -Link Europe/Istanbul Asia/Istanbul -.sp -.fi +.Dl "Link Europe/Istanbul Asia/Istanbul The -.B LINK-FROM +.Em LINK-FROM field should appear as the -.B NAME +.Em NAME field in some zone line; the -.B LINK-TO +.Em LINK-TO field is used as an alternate name for that zone. -.PP +.Pp Except for continuation lines, lines may appear in any order in the input. -.PP +.Pp Lines in the file that describes leap seconds have the following form: -.nf -.ti +.5i -.ta \w'Leap\0\0'u +\w'YEAR\0\0'u +\w'MONTH\0\0'u +\w'DAY\0\0'u +\w'HH:MM:SS\0\0'u +\w'CORR\0\0'u -.sp -Leap YEAR MONTH DAY HH:MM:SS CORR R/S -.sp +.Dl "Leap YEAR MONTH DAY HH:MM:SS CORR R/S For example: -.ti +.5i -.sp -Leap 1974 Dec 31 23:59:60 + S -.sp -.fi +.Dl "Leap 1974 Dec 31 23:59:60 + S The -.BR YEAR , -.BR MONTH , -.BR DAY , +.Em YEAR , +.Em MONTH , +.Em DAY , and -.B HH:MM:SS +.Em HH:MM:SS fields tell when the leap second happened. The -.B CORR +.Em CORR field should be -.q + +.Dq + if a second was added or -.q - +.Dq - if a second was skipped. .\" There's no need to document the following, since it's impossible for more .\" than one leap second to be inserted or deleted at a time. @@ -389,24 +367,29 @@ if a second was skipped. .\" .q -- .\" if two seconds were skipped. The -.B R/S +.Em R/S field should be (an abbreviation of) -.q Stationary -if the leap second time given by the other fields should be interpreted as GMT +.Dq Stationary +if the leap second time given by the other fields should be interpreted as UTC or (an abbreviation of) -.q Rolling +.Dq Rolling if the leap second time given by the other fields should be interpreted as local wall clock time. -.SH NOTE +.Sh NOTE For areas with more than two types of local time, you may need to use local standard time in the -.B AT +.Em AT field of the earliest transition time's rule to ensure that the earliest transition time recorded in the compiled file is correct. -.SH FILE -/usr/share/zoneinfo standard directory used for created files -.SH "SEE ALSO" -ctime(3), tzfile(5), zdump(8) -.\" @(#)zic.8 7.14 +.Sh FILES +.Bl -tag -width /usr/share/zoneinfo -compact +.It /usr/share/zoneinfo +standard directory used for created files +.El +.Sh "SEE ALSO" +.Xr ctime 3 , +.Xr tzfile 5 , +.Xr zdump 8 +.\" @(#)zic.8 7.18 diff --git a/zic.tproj/zic.c b/zic.tproj/zic.c index 5bf725b..12659d0 100644 --- a/zic.tproj/zic.c +++ b/zic.tproj/zic.c @@ -1,47 +1,25 @@ -/* - * 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@ - */ -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char elsieid[] = "@(#)zic.c 7.80"; -#else -static char rcsid[] = "$OpenBSD: zic.c,v 1.6 1997/01/15 23:40:55 millert Exp $"; -#endif -#endif /* LIBC_SCCS and not lint */ +static const char elsieid[] = "@(#)zic.c 7.116"; + +#ifndef lint +static const char rcsid[] = + "$FreeBSD: src/usr.sbin/zic/zic.c,v 1.17 2004/10/19 20:30:09 ru Exp $"; +#endif /* not lint */ #include "private.h" -#include "locale.h" #include "tzfile.h" -#ifdef unix -#include "sys/stat.h" /* for umask manifest constants */ -#endif /* defined unix */ +#include +#include +#include /* for umask manifest constants */ +#include +#include + +#define MKDIR_UMASK (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) /* ** On some ancient hosts, predicates like `isspace(C)' are defined ** only if isascii(C) || C == EOF. Modern hosts obey the C Standard, ** which says they are defined only if C == ((unsigned char) C) || C == EOF. -** Neither the C Standard nor Posix require that `isascii' exist. +** Neither the C Standard nor POSIX require that `isascii' exist. ** For portability, we check both ancient and modern requirements. ** If isascii is not defined, the isascii check succeeds trivially. */ @@ -103,18 +81,6 @@ struct zone { time_t z_untiltime; }; -extern int getopt P((int argc, char * const argv[], - const char * options)); -extern char * icatalloc P((char * old, const char * new)); -extern char * icpyalloc P((const char * string)); -extern void ifree P((char * p)); -extern char * imalloc P((int n)); -extern void * irealloc P((void * old, int n)); -extern int link P((const char * fromname, const char * toname)); -extern char * optarg; -extern int optind; -extern char * scheck P((const char * string, const char * format)); - static void addtt P((time_t starttime, int type)); static int addtype P((long gmtoff, const char * abbr, int isdst, int ttisstd, int ttisgmt)); @@ -157,6 +123,8 @@ static void rulesub P((struct rule * rp, const char * typep, const char * monthp, const char * dayp, const char * timep)); static void setboundaries P((void)); +static void setgroup P((gid_t *flag, const char *name)); +static void setuser P((uid_t *flag, const char *name)); static time_t tadd P((time_t t1, long t2)); static void usage P((void)); static void writezone P((const char * name)); @@ -173,12 +141,13 @@ static int leapcnt; static int linenum; static time_t max_time; static int max_year; +static int max_year_representable; static time_t min_time; static int min_year; +static int min_year_representable; static int noise; static const char * rfilename; static int rlinenum; -static const char * progname; static int timecnt; static int typecnt; @@ -383,13 +352,8 @@ static char * memcheck(ptr) char * const ptr; { - if (ptr == NULL) { - const char *e = strerror(errno); - - (void) fprintf(stderr, _("%s: Memory exhausted: %s\n"), - progname, e); - (void) exit(EXIT_FAILURE); - } + if (ptr == NULL) + errx(EXIT_FAILURE, _("memory exhausted")); return ptr; } @@ -411,7 +375,7 @@ int errnum; extern int sys_nerr; return (errnum > 0 && errnum <= sys_nerr) ? - sys_errlist[errnum] : "Unknown system error"; + sys_errlist[errnum] : _("Unknown system error"); } #endif /* !(HAVE_STRERROR - 0) */ @@ -460,9 +424,9 @@ const char * const string; { char * cp; - cp = ecpyalloc("warning: "); + cp = ecpyalloc(_("warning: ")); cp = ecatalloc(cp, string); - error(string); + error(cp); ifree(cp); --errors; } @@ -470,8 +434,9 @@ const char * const string; static void usage P((void)) { - (void) fprintf(stderr, _("%s: usage is %s [ -s ] [ -v ] [ -l localtime ] [ -p posixrules ] [ -d directory ]\n\t[ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n"), - progname, progname); + (void) fprintf(stderr, "%s\n%s\n", +_("usage: zic [--version] [-s] [-v] [-l localtime] [-p posixrules] [-d directory]"), +_(" [-L leapseconds] [-y yearistype] [filename ... ]")); (void) exit(EXIT_FAILURE); } @@ -481,6 +446,11 @@ static const char * directory; static const char * leapsec; static const char * yitcommand; static int sflag = FALSE; +static int Dflag; +static uid_t uflag = (uid_t)-1; +static gid_t gflag = (gid_t)-1; +static mode_t mflag = (S_IRUSR | S_IRGRP | S_IROTH + | S_IWUSR); int main(argc, argv) @@ -501,60 +471,67 @@ char * argv[]; #endif /* defined TEXTDOMAINDIR */ (void) textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT - 0 */ - progname = argv[0]; - while ((c = getopt(argc, argv, "d:l:p:L:vsy:")) != -1) + for (i = 1; i < argc; ++i) + if (strcmp(argv[i], "--version") == 0) { + errx(EXIT_SUCCESS, "%s", elsieid); + } + while ((c = getopt(argc, argv, "Dd:g:l:m:p:L:u:vsy:")) != -1) switch (c) { default: usage(); + case 'D': + Dflag = 1; + break; case 'd': if (directory == NULL) directory = optarg; - else { - (void) fprintf(stderr, -_("%s: More than one -d option specified\n"), - progname); - (void) exit(EXIT_FAILURE); - } + else + errx(EXIT_FAILURE, +_("more than one -d option specified")); + break; + case 'g': + setgroup(&gflag, optarg); break; case 'l': if (lcltime == NULL) lcltime = optarg; - else { - (void) fprintf(stderr, -_("%s: More than one -l option specified\n"), - progname); - (void) exit(EXIT_FAILURE); - } + else + errx(EXIT_FAILURE, +_("more than one -l option specified")); break; + case 'm': + { + void *set = setmode(optarg); + if (set == NULL) + errx(EXIT_FAILURE, +_("invalid file mode")); + mflag = getmode(set, mflag); + free(set); + break; + } case 'p': if (psxrules == NULL) psxrules = optarg; - else { - (void) fprintf(stderr, -_("%s: More than one -p option specified\n"), - progname); - (void) exit(EXIT_FAILURE); - } + else + errx(EXIT_FAILURE, +_("more than one -p option specified")); + break; + case 'u': + setuser(&uflag, optarg); break; case 'y': if (yitcommand == NULL) yitcommand = optarg; - else { - (void) fprintf(stderr, -_("%s: More than one -y option specified\n"), - progname); - (void) exit(EXIT_FAILURE); - } + else + errx(EXIT_FAILURE, +_("more than one -y option specified")); break; case 'L': if (leapsec == NULL) leapsec = optarg; - else { - (void) fprintf(stderr, -_("%s: More than one -L option specified\n"), - progname); - (void) exit(EXIT_FAILURE); - } + else + errx(EXIT_FAILURE, +_("more than one -L option specified")); break; case 'v': noise = TRUE; @@ -593,12 +570,18 @@ _("%s: More than one -L option specified\n"), /* ** Make links. */ - for (i = 0; i < nlinks; ++i) + for (i = 0; i < nlinks; ++i) { + eat(links[i].l_filename, links[i].l_linenum); dolink(links[i].l_from, links[i].l_to); - if (lcltime != NULL) + } + if (lcltime != NULL) { + eat("command line", 1); dolink(lcltime, TZDEFAULT); - if (psxrules != NULL) + } + if (psxrules != NULL) { + eat("command line", 1); dolink(psxrules, TZDEFRULES); + } return (errors == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } @@ -631,15 +614,31 @@ const char * const tofile; if (!itsdir(toname)) (void) remove(toname); if (link(fromname, toname) != 0) { + int result; + if (mkdirs(toname) != 0) (void) exit(EXIT_FAILURE); - if (link(fromname, toname) != 0) { - const char *e = strerror(errno); - (void) fprintf(stderr, - _("%s: Can't link from %s to %s: %s\n"), - progname, fromname, toname, e); - (void) exit(EXIT_FAILURE); + result = link(fromname, toname); +#if (HAVE_SYMLINK - 0) + if (result != 0 && + access(fromname, F_OK) == 0 && + !itsdir(fromname)) { + const char *s = tofile; + register char * symlinkcontents = NULL; + while ((s = strchr(s+1, '/')) != NULL) + symlinkcontents = ecatalloc(symlinkcontents, "../"); + symlinkcontents = ecatalloc(symlinkcontents, fromfile); + + result = symlink(symlinkcontents, toname); + if (result == 0) +warning(_("hard link failed, symbolic link used")); + ifree(symlinkcontents); + } +#endif + if (result != 0) { + err(EXIT_FAILURE, _("can't link from %s to %s"), + fromname, toname); } } ifree(fromname); @@ -681,6 +680,8 @@ setboundaries P((void)) } min_year = TM_YEAR_BASE + gmtime(&min_time)->tm_year; max_year = TM_YEAR_BASE + gmtime(&max_time)->tm_year; + min_year_representable = min_year; + max_year_representable = max_year; } static int @@ -806,13 +807,8 @@ const char * name; if (strcmp(name, "-") == 0) { name = _("standard input"); fp = stdin; - } else if ((fp = fopen(name, "r")) == NULL) { - const char *e = strerror(errno); - - (void) fprintf(stderr, _("%s: Can't open %s: %s\n"), - progname, name, e); - (void) exit(EXIT_FAILURE); - } + } else if ((fp = fopen(name, "r")) == NULL) + err(EXIT_FAILURE, _("can't open %s"), name); wantcont = FALSE; for (num = 1; ; ++num) { eat(name, num); @@ -855,33 +851,22 @@ const char * name; break; case LC_LEAP: if (name != leapsec) - (void) fprintf(stderr, -_("%s: Leap line in non leap seconds file %s\n"), - progname, name); + warnx( +_("leap line in non leap seconds file %s"), name); else inleap(fields, nfields); wantcont = FALSE; break; default: /* "cannot happen" */ - (void) fprintf(stderr, -_("%s: panic: Invalid l_value %d\n"), - progname, lp->l_value); - (void) exit(EXIT_FAILURE); + errx(EXIT_FAILURE, +_("panic: invalid l_value %d"), lp->l_value); } } ifree((char *) fields); } - if (ferror(fp)) { - (void) fprintf(stderr, _("%s: Error reading %s\n"), - progname, filename); - (void) exit(EXIT_FAILURE); - } - if (fp != stdin && fclose(fp)) { - const char *e = strerror(errno); - - (void) fprintf(stderr, _("%s: Error closing %s: %s\n"), - progname, filename, e); - (void) exit(EXIT_FAILURE); - } + if (ferror(fp)) + errx(EXIT_FAILURE, _("error reading %s"), filename); + if (fp != stdin && fclose(fp)) + err(EXIT_FAILURE, _("error closing %s"), filename); if (wantcont) error(_("expected continuation line not found")); } @@ -919,12 +904,15 @@ const int signable; error(errstring); return 0; } - if (hh < 0 || hh >= HOURSPERDAY || + if ((hh < 0 || hh >= HOURSPERDAY || mm < 0 || mm >= MINSPERHOUR || - ss < 0 || ss > SECSPERMIN) { + ss < 0 || ss > SECSPERMIN) && + !(hh == HOURSPERDAY && mm == 0 && ss == 0)) { error(errstring); return 0; } + if (noise && hh == HOURSPERDAY) + warning(_("24:00 not handled by pre-1998 versions of zic")); return eitol(sign) * (eitol(hh * MINSPERHOUR + mm) * eitol(SECSPERMIN) + eitol(ss)); @@ -1048,7 +1036,7 @@ const int iscont; } z.z_filename = filename; z.z_linenum = linenum; - z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid GMT offset"), TRUE); + z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid UTC offset"), TRUE); if ((cp = strchr(fields[i_format], '%')) != 0) { if (*++cp != 's' || strchr(cp, '%') != 0) { error(_("invalid abbreviation format")); @@ -1149,14 +1137,15 @@ const int nfields; error(_("time before zero")); return; } - t = (time_t) dayoff * SECSPERDAY; - /* - ** Cheap overflow check. - */ - if (t / SECSPERDAY != dayoff) { - error(_("time overflow")); + if (dayoff < min_time / SECSPERDAY) { + error(_("time too small")); + return; + } + if (dayoff > max_time / SECSPERDAY) { + error(_("time too large")); return; } + t = (time_t) dayoff * SECSPERDAY; tod = gethms(fields[LP_TIME], _("invalid time of day"), FALSE); cp = fields[LP_CORR]; { @@ -1250,6 +1239,7 @@ const char * const timep; rp->r_todisstd = FALSE; rp->r_todisgmt = FALSE; *ep = '\0'; + break; case 'g': /* Greenwich */ case 'u': /* Universal */ case 'z': /* Zulu */ @@ -1274,13 +1264,16 @@ const char * const timep; rp->r_loyear = INT_MAX; break; default: /* "cannot happen" */ - (void) fprintf(stderr, - _("%s: panic: Invalid l_value %d\n"), - progname, lp->l_value); - (void) exit(EXIT_FAILURE); + errx(EXIT_FAILURE, + _("panic: invalid l_value %d"), lp->l_value); } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_loyear) != 1) { error(_("invalid starting year")); return; + } else if (noise) { + if (rp->r_loyear < min_year_representable) + warning(_("starting year too low to be represented")); + else if (rp->r_loyear > max_year_representable) + warning(_("starting year too high to be represented")); } cp = hiyearp; if ((lp = byword(cp, end_years)) != NULL) switch ((int) lp->l_value) { @@ -1294,13 +1287,16 @@ const char * const timep; rp->r_hiyear = rp->r_loyear; break; default: /* "cannot happen" */ - (void) fprintf(stderr, - _("%s: panic: Invalid l_value %d\n"), - progname, lp->l_value); - (void) exit(EXIT_FAILURE); + errx(EXIT_FAILURE, + _("panic: invalid l_value %d"), lp->l_value); } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_hiyear) != 1) { error(_("invalid ending year")); return; + } else if (noise) { + if (rp->r_loyear < min_year_representable) + warning(_("ending year too low to be represented")); + else if (rp->r_loyear > max_year_representable) + warning(_("ending year too high to be represented")); } if (rp->r_loyear > rp->r_hiyear) { error(_("starting year greater than ending year")); @@ -1315,6 +1311,8 @@ const char * const timep; } rp->r_yrtype = ecpyalloc(typep); } + if (rp->r_loyear < min_year && rp->r_loyear > 0) + min_year = rp->r_loyear; /* ** Day work. ** Accept things such as: @@ -1423,8 +1421,10 @@ const char * const name; toi = 0; fromi = 0; + while (fromi < timecnt && attypes[fromi].at < min_time) + ++fromi; if (isdsts[0] == 0) - while (attypes[fromi].type == 0) + while (fromi < timecnt && attypes[fromi].type == 0) ++fromi; /* handled by default rule */ for ( ; fromi < timecnt; ++fromi) { if (toi != 0 @@ -1452,26 +1452,18 @@ const char * const name; fullname = erealloc(fullname, (int) (strlen(directory) + 1 + strlen(name) + 1)); (void) sprintf(fullname, "%s/%s", directory, name); + /* - ** Remove old file, if any, to snap links. - */ - if (!itsdir(fullname) && remove(fullname) != 0 && errno != ENOENT) { - const char *e = strerror(errno); + * Remove old file, if any, to snap links. + */ + if (!itsdir(fullname) && remove(fullname) != 0 && errno != ENOENT) + err(EXIT_FAILURE, _("can't remove %s"), fullname); - (void) fprintf(stderr, _("%s: Can't remove %s: %s\n"), - progname, fullname, e); - (void) exit(EXIT_FAILURE); - } if ((fp = fopen(fullname, "wb")) == NULL) { if (mkdirs(fullname) != 0) (void) exit(EXIT_FAILURE); - if ((fp = fopen(fullname, "wb")) == NULL) { - const char *e = strerror(errno); - - (void) fprintf(stderr, _("%s: Can't create %s: %s\n"), - progname, fullname, e); - (void) exit(EXIT_FAILURE); - } + if ((fp = fopen(fullname, "wb")) == NULL) + err(EXIT_FAILURE, _("can't create %s"), fullname); } convert(eitol(typecnt), tzh.tzh_ttisgmtcnt); convert(eitol(typecnt), tzh.tzh_ttisstdcnt); @@ -1479,7 +1471,9 @@ const char * const name; convert(eitol(timecnt), tzh.tzh_timecnt); convert(eitol(typecnt), tzh.tzh_typecnt); convert(eitol(charcnt), tzh.tzh_charcnt); + (void) strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic); #define DO(field) (void) fwrite((void *) tzh.field, (size_t) sizeof tzh.field, (size_t) 1, fp) + DO(tzh_magic); DO(tzh_reserved); DO(tzh_ttisgmtcnt); DO(tzh_ttisstdcnt); @@ -1531,11 +1525,15 @@ const char * const name; (void) putc(ttisstds[i], fp); for (i = 0; i < typecnt; ++i) (void) putc(ttisgmts[i], fp); - if (ferror(fp) || fclose(fp)) { - (void) fprintf(stderr, _("%s: Error writing %s\n"), - progname, fullname); - (void) exit(EXIT_FAILURE); - } + if (ferror(fp) || fclose(fp)) + errx(EXIT_FAILURE, _("error writing %s"), fullname); + if (chmod(fullname, mflag) < 0) + err(EXIT_FAILURE, _("cannot change mode of %s to %03o"), + fullname, (unsigned)mflag); + if ((uflag != (uid_t)-1 || gflag != (gid_t)-1) + && chown(fullname, uflag, gflag) < 0) + err(EXIT_FAILURE, _("cannot change ownership of %s"), + fullname); } static void @@ -1585,16 +1583,16 @@ const int zonecount; typecnt = 0; charcnt = 0; /* - ** A guess that may well be corrected later. - */ - stdoff = 0; - /* ** Thanks to Earl Chew (earl@dnd.icp.nec.com.au) ** for noting the need to unconditionally initialize startttisstd. */ startttisstd = FALSE; startttisgmt = FALSE; for (i = 0; i < zonecount; ++i) { + /* + ** A guess that may well be corrected later. + */ + stdoff = 0; zp = &zpfirst[i]; usestart = i > 0 && (zp - 1)->z_untiltime > min_time; useuntil = i < (zonecount - 1); @@ -1614,8 +1612,7 @@ const int zonecount; if (usestart) { addtt(starttime, type); usestart = FALSE; - } - else if (stdoff != 0) + } else if (stdoff != 0) addtt(min_time, type); } else for (year = min_year; year <= max_year; ++year) { if (useuntil && year > zp->z_untilrule.r_hiyear) @@ -1643,7 +1640,7 @@ const int zonecount; INITIALIZE(ktime); if (useuntil) { /* - ** Turn untiltime into GMT + ** Turn untiltime into UTC ** assuming the current gmtoff and ** stdoff values. */ @@ -1749,8 +1746,22 @@ error(_("can't determine time zone abbreviation to use just after until time")); static void addtt(starttime, type) const time_t starttime; -const int type; +int type; { + if (starttime <= min_time || + (timecnt == 1 && attypes[0].at < min_time)) { + gmtoffs[0] = gmtoffs[type]; + isdsts[0] = isdsts[type]; + ttisstds[0] = ttisstds[type]; + ttisgmts[0] = ttisgmts[type]; + if (abbrinds[type] != 0) + (void) strcpy(chars, &chars[abbrinds[type]]); + abbrinds[0] = 0; + charcnt = strlen(chars) + 1; + typecnt = 1; + timecnt = 0; + type = 0; + } if (timecnt >= TZ_MAX_TIMES) { error(_("too many transitions?!")); (void) exit(EXIT_FAILURE); @@ -1878,13 +1889,14 @@ const char * const type; buf = erealloc(buf, (int) (132 + strlen(yitcommand) + strlen(type))); (void) sprintf(buf, "%s %d %s", yitcommand, year, type); result = system(buf); - if (result == 0) - return TRUE; - if (result == (1 << 8)) - return FALSE; - error(_("Wild result from command execution")); - (void) fprintf(stderr, _("%s: command was '%s', result was %d\n"), - progname, buf, result); + if (WIFEXITED(result)) switch (WEXITSTATUS(result)) { + case 0: + return TRUE; + case 1: + return FALSE; + } + error(_("wild result from command execution")); + warnx(_("command was '%s', result was %d"), buf, result); for ( ; ; ) (void) exit(EXIT_FAILURE); } @@ -1945,10 +1957,11 @@ register const struct lookup * const table; */ foundlp = NULL; for (lp = table; lp->l_word != NULL; ++lp) - if (itsabbr(word, lp->l_word)) + if (itsabbr(word, lp->l_word)) { if (foundlp == NULL) foundlp = lp; else return NULL; /* multiple inexact matches */ + } return foundlp; } @@ -1977,7 +1990,7 @@ register char * cp; else while ((*dp = *cp++) != '"') if (*dp != '\0') ++dp; - else error(_("Odd number of quotation marks")); + else error(_("odd number of quotation marks")); } while (*cp != '\0' && *cp != '#' && (!isascii(*cp) || !isspace((unsigned char) *cp))); if (isascii(*cp) && isspace((unsigned char) *cp)) @@ -2097,18 +2110,17 @@ register const int wantedy; --i; } if (i < 0 || i >= len_months[isleap(y)][m]) { - error(_("no day in month matches rule")); - (void) exit(EXIT_FAILURE); + if (noise) + warning(_("rule goes past start/end of month--will not work with pre-2004 versions of zic")); } } if (dayoff < 0 && !TYPE_SIGNED(time_t)) return min_time; + if (dayoff < min_time / SECSPERDAY) + return min_time; + if (dayoff > max_time / SECSPERDAY) + return max_time; t = (time_t) dayoff * SECSPERDAY; - /* - ** Cheap overflow check. - */ - if (t / SECSPERDAY != dayoff) - return (dayoff > 0) ? max_time : min_time; return tadd(t, rp->r_tod); } @@ -2134,7 +2146,7 @@ char * const argname; register char * name; register char * cp; - if (argname == NULL || *argname == '\0') + if (argname == NULL || *argname == '\0' || Dflag) return 0; cp = name = ecpyalloc(argname); while ((cp = strchr(cp + 1, '/')) != 0) { @@ -2152,13 +2164,13 @@ char * const argname; if (!itsdir(name)) { /* ** It doesn't seem to exist, so we try to create it. + ** Creation may fail because of the directory being + ** created by some other multiprocessor, so we get + ** to do extra checking. */ - if (mkdir(name, 0755) != 0) { - const char *e = strerror(errno); - - (void) fprintf(stderr, - _("%s: Can't create directory %s: %s\n"), - progname, name, e); + if (mkdir(name, MKDIR_UMASK) != 0 + && (errno != EEXIST || !itsdir(name))) { + warn(_("can't create directory %s"), name); ifree(name); return -1; } @@ -2176,15 +2188,64 @@ const int i; long l; l = i; - if ((i < 0 && l >= 0) || (i == 0 && l != 0) || (i > 0 && l <= 0)) { - (void) fprintf(stderr, - _("%s: %d did not sign extend correctly\n"), - progname, i); - (void) exit(EXIT_FAILURE); - } + if ((i < 0 && l >= 0) || (i == 0 && l != 0) || (i > 0 && l <= 0)) + errx(EXIT_FAILURE, _("%d did not sign extend correctly"), i); return l; } +#include +#include + +static void +setgroup(flag, name) + gid_t *flag; + const char *name; +{ + struct group *gr; + + if (*flag != (gid_t)-1) + errx(EXIT_FAILURE, _("multiple -g flags specified")); + + gr = getgrnam(name); + if (gr == 0) { + char *ep; + unsigned long ul; + + ul = strtoul(name, &ep, 10); + if (ul == (unsigned long)(gid_t)ul && *ep == '\0') { + *flag = ul; + return; + } + errx(EXIT_FAILURE, _("group `%s' not found"), name); + } + *flag = gr->gr_gid; +} + +static void +setuser(flag, name) + uid_t *flag; + const char *name; +{ + struct passwd *pw; + + if (*flag != (gid_t)-1) + errx(EXIT_FAILURE, _("multiple -u flags specified")); + + pw = getpwnam(name); + if (pw == 0) { + char *ep; + unsigned long ul; + + ul = strtoul(name, &ep, 10); + if (ul == (unsigned long)(gid_t)ul && *ep == '\0') { + *flag = ul; + return; + } + errx(EXIT_FAILURE, _("user `%s' not found"), name); + } + *flag = pw->pw_uid; +} + /* -** UNIX was a registered trademark of UNIX System Laboratories in 1993. +** UNIX was a registered trademark of The Open Group in 2003. */ -- 2.45.2