diff options
author | cvs2svn <cvs2svn@FreeBSD.org> | 2006-06-26 17:25:23 +0000 |
---|---|---|
committer | cvs2svn <cvs2svn@FreeBSD.org> | 2006-06-26 17:25:23 +0000 |
commit | eb5270bf8fb2f273b3a610d551484384417ac307 (patch) | |
tree | 3abcd9cb9fc2eae412e6cb927b04ecc4db559d3e | |
parent | 257c55772da29a31a2986189e9cff6b3d3b1516d (diff) |
This commit was manufactured by cvs2svn to create tag 'cvs_20060501'.vendor/OpenBSD/cvs_20060501
Notes
Notes:
svn path=/vendor/OpenBSD/dist/; revision=159952
svn path=/vendor/OpenBSD/cvs_20060501/; revision=159954; tag=vendor/OpenBSD/cvs_20060501
95 files changed, 0 insertions, 28964 deletions
diff --git a/etc/moduli b/etc/moduli deleted file mode 100644 index 6b94e2e231d7..000000000000 --- a/etc/moduli +++ /dev/null @@ -1,158 +0,0 @@ -# $OpenBSD: moduli,v 1.1 2001/06/22 22:07:54 provos Exp $ - -# Time Type Tests Tries Size Generator Modulus -20010328182134 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF5449C221CB -20010328182222 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF5449C95A43 -20010328182256 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF5449CC8CFB -20010328182409 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF5449D9BDB7 -20010328182628 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF5449FB6EF3 -20010328182708 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544A000153 -20010328182758 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544A06E9EB -20010328182946 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544A1F2C93 -20010328183015 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544A206ADB -20010328183112 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544A2A109B -20010328183143 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544A2BC1BB -20010328183301 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544A3ADCEB -20010328183532 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544A5E8BAF -20010328183646 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544A6D54D7 -20010328183712 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544A6EC46F -20010328184223 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544AB8626F -20010328184337 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544AC7DC73 -20010328184634 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544AEFF073 -20010328184714 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544AF594FF -20010328184807 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544AFEEC53 -20010328184910 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B0B3513 -20010328185030 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B165707 -20010328185334 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B3A9673 -20010328185423 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B426623 -20010328185451 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B4427DB -20010328185637 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B5E3FC7 -20010328185720 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B65964B -20010328185757 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B6A9373 -20010328185844 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B7203B3 -20010328185933 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B7A9FFF -20010328190006 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B7DAAD3 -20010328190054 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B855C2F -20010328190139 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B8C53EB -20010328190304 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544B9F26C3 -20010328190329 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544BA00697 -20010328190412 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544BA54313 -20010328190506 2 6 100 1023 5 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544BAEEF27 -20010328190550 2 6 100 1023 2 DCFAC4EFE89F5B082962AB9A67E8D63E84FA491E5D3874978815868595469163DA0661E6208A8C2CD4F83893B53864ADFD2154E8D8EFA146BAD808562E4BF6C90348FD79EEB3387D93FC7943BC450BA55399BA3CF3DFBD0D4E71800007B0E9D5F12E7A2CB7EA4E49812E715F8DC570C478DC2DEB1C49B0AE87A5DF544BB5CE0B -20010328200734 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC33395187 -20010328201124 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC334ED15B -20010328201358 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC3359FC07 -20010328201537 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC335F7A83 -20010328201829 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC336D1433 -20010328202120 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC337B253B -20010328202848 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC33A3D43F -20010328203335 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC33BF24A3 -20010328204332 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC34011B8B -20010328204443 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC3402A92F -20010328204617 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC3406D343 -20010328205458 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC3436FA2B -20010328210413 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC3471CF1B -20010328213513 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC352AF5EF -20010328215014 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC358CC3CB -20010328215520 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC35A9B7FF -20010328215733 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC35B2927F -20010328220114 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC35C47323 -20010328220334 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC35CFA9C3 -20010328220653 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC35E0BB37 -20010328220915 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC35E9CC23 -20010328221256 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC35FD7D67 -20010328221457 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC36052CCB -20010328222639 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC364A1E07 -20010328224126 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC36AD5557 -20010328225125 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC36EE57BF -20010328225751 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC3716A70B -20010328225943 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC371D010B -20010328230054 2 6 100 1534 5 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC371EB5C7 -20010328230301 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC37275F4B -20010328230628 2 6 100 1534 2 6DFD16D9669EDAF42EF5D4EED82AA84B0541DEC2045B6AF55021A184F32BCADE614A114137022C9A8B41C09AFC38199E7305864F70A8708F37FC2127264ECF4FA32391F243CC62B89602D3813082679E5BDF496BA9DFA4C818AD21EC261B6F11841E6F2DE1574CE95095841DAF052868CCD5E9BFCA543E0934B50A76A598E693136DE2D479AEF3785D97BAFF4FB85AB8D46DA424C4CC5E11ABCAF718837E16350982BF8A27728318EC02C71ED164F57CDB121B72614B7B7C406613EC3738C3F3 -20010329000424 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853ACAACAB -20010329001637 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853AE5BE0F -20010329002229 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853AEDE2D3 -20010329003652 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853B0F32CB -20010329005040 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853B30E503 -20010329014643 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853BC9AF57 -20010329021950 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853C205263 -20010329023256 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853C3F2E53 -20010329031049 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853CA28BBF -20010329032045 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853CB81103 -20010329052113 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853DF13B47 -20010329052449 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853DF3ED53 -20010329060404 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853E5D25E7 -20010329062856 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853E9CF013 -20010329063152 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853E9E1CEB -20010329070601 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853EF58B7F -20010329071302 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853F017697 -20010329072011 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853F0E72D3 -20010329072445 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853F14CE17 -20010329073641 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853F2EEBA3 -20010329075209 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853F52E927 -20010329080750 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853F776F8B -20010329084002 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853FC98043 -20010329084744 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853FD7EAAF -20010329090209 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993853FF9AF5F -20010329093527 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC3499385404E330B -20010329094652 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC349938540672D1F -20010329103445 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC349938540E4B213 -20010329111418 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC34993854144947F -20010329112031 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC3499385414F223B -20010329112413 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC349938541522073 -20010329114209 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC3499385417C8E53 -20010329125026 2 6 100 2046 2 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC3499385422E41AB -20010329132045 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC3499385427DD3FF -20010329134105 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC349938542AFA2D7 -20010329134914 2 6 100 2046 5 7ED0888B660A818F15E5F76A7F2BF10C99D74129DA04446C60116C9C800501060B8AFF075DCE0C08CEFDF695440E6F16FCCDB06359D080EF62D6485CBAEB94B92BE771D535B4EA9C5D14D84CD7649E25C7CFEA2C914486CC2BFDE77C4C0DF1D6DDED65FEE2F53A7FA690AFE38EE00C154FBAEFF935466B176CB0AED02458A552929F4EA7FC3E6F9F758DE7F22CC1F49641F492820441BDC109F0CE18F883FC93EA9AC4C1432682BA1C5B67BED8C861152A5F952A8CDCF1BCE02B8D93E80C113CE9FE2E4ACA49B2978B99A8C5FA231A77F5E7C604D44C7C6EA98D561294D4F7AB061432CAB8BBDCEC3659DE64F65265E6B9FC5F46879BB17CC349938542C04A37 -20010403222140 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B0AB16DAF -20010403225231 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B0AC56CFF -20010404053436 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B0C2F4B7F -20010404092851 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B0D04E7F7 -20010404093943 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B0D07794B -20010404102659 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B0D2BE8CF -20010404112553 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B0D5D012B -20010404174625 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B0EA59E17 -20010404184645 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B0ED6DA4F -20010404193402 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B0EFB39B3 -20010404230716 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B0FB07C1B -20010405044433 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B10DD9FC3 -20010405053429 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B11038737 -20010405062826 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B112E24E7 -20010405092601 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B11C9E9FB -20010405113007 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B123803EB -20010405122212 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B12612ED3 -20010405182035 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B13A25087 -20010405210758 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B142C4E23 -20010405220222 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B145878F3 -20010406020130 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B152AF6AB -20010406053538 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B15E78C8B -20010406073014 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B1649BFEF -20010406074100 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B164D4E3F -20010406103625 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B16E07B33 -20010406131946 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B17706243 -20010406170234 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B182FD957 -20010406182949 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B18768903 -20010406203157 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B18DCFC3B -20010407022825 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B1A1AF797 -20010407071024 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B1B1551E7 -20010407112402 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B1BF78EC7 -20010407123215 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B1C30021B -20010407161504 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B1CF27743 -20010407171629 2 6 100 3190 5 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B1D25FAD7 -20010407191502 2 6 100 3190 2 669BA3ED661F226A090BE5644A2BB4209371B78FC3E6848A095821993F59084CA5EE12052F977D01F0666F03F6573B199DFEC9AB94588C2C60DE3B3E7CF5094587919FCC3FB40A61C261E891A0F91D9FFC8F30CA12CF809DD8290DD786FA8B041FFAC5793C38F38757EA6790472AC2692185B554B0046E8C065C983C0ACC8D2F85AB4BEDF7CE233009218C9691FE44261580D4149F1D4471B0B5DF79E224252474EBC3B7B5490950BB438BF498E79F8794498B3A3B5FBB42829C3BBEA4067F28C23BE40377B986BD5443CCCF02405B8CCCAA09E8179F0168D4969994171A6AD98F81015BC84E10A44E1EFD2E0862C5D1AAFE99014715A36800DBD9A6C51C0226CC82A651DAE4F73D54C4D103C13D1C15CF8CCA67D5CB39F03C66F3B7467F8FFDCC5074CD0C1B2538FBF956971BF39314CEDD20E1B10DE16D86E10BE7FA5B1A706AEB4C356F49807A22072CD00559AF0A863788956651919E26A315EAD1D26E7C98FC4CFA35A0F04DD400A2991A1FFE5B271FEDE54375896A29F968BE1D511BA466A92AC3E3772709FC815B1D8C2753 -20010420002705 2 6 100 4094 2 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C10C1E08F3 -20010420005243 2 6 100 4094 2 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C10C219FB3 -20010420035225 2 6 100 4094 5 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C10C660B3F -20010420145749 2 6 100 4094 2 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C10D741313 -20010420205718 2 6 100 4094 2 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C10DD41193 -20010420232458 2 6 100 4094 5 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C10E0AB4EF -20010421003952 2 6 100 4094 5 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C10E22F857 -20010421013245 2 6 100 4094 2 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C10E31828B -20010421085157 2 6 100 4094 2 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C10EE28B2B -20010421092617 2 6 100 4094 2 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C10EE97A3B -20010421135621 2 6 100 4094 2 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C10F52C463 -20010422012438 2 6 100 4094 2 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C110627AF3 -20010422042530 2 6 100 4094 2 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C110A793B3 -20010422163438 2 6 100 4094 5 65B5B9F5ECFADB4CCB38D1BC894302E95B4843290F1A7A40579DF3E2FF98C1D3DA9F210857C784433DF32ADF9E0C80121211690E1FFB41B8DB4E86AFE388A09C9BB2C98EDC581C2E65D57F61BB920C3D1B7B058B5FADFF65D607DAFF443B8BA1ACE1A3A7B16EA0713F62537C6689E3C4A0F61198F3B054FCF140CFADD8622C0E7621998331E59DA6F72E9D608D0E58F526E95F485C7CA30A416617DA3CCFF722BB82362606283D054B34B83ECDB4C91BAB835944010EBE5E9FA7B016ED89891DD553CC71B5CF76EDB2A184B377F670D6AF191763EEFD175E48EA37EE18B9E44E2D017D845C444C8111816819866E490B52F7F879A0C6F401CF7859674F93E304365F4E8CB8C312EFB725732A46D7CF0C9D2939AEE25F428CEFC90959DBF8ADD612F343EF9BFCA2FBA61BD4BF93E1E54626D227FDA812E18D071579AB4EEAC9901DAB183BCB0D9F48732D92CE66B386EAE5D8212C9FD156DC3F09B171B5603E17A468D244F3B6880EBCDA189BA9E23E4A4C6C2995ACF264F8CE9D54B27316343C0BC19221F75E6A2AC68011741695E599F73460B7A042E0461DB189CDCE223B40336BF2251AE3B363159960C9F63B47EFC43790D474DABB9A686DAF21E0DD76533749FCA9F144FA9C243CEF1364C79D981ED81DC4635C73B7F8908BA190AA920ED370F815BC2F9B3D28ED87BE34A01498836222C17B70C246C03CA1C111D2A227 diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c deleted file mode 100644 index 26d67fff3f91..000000000000 --- a/lib/libc/gen/fts.c +++ /dev/null @@ -1,1104 +0,0 @@ -/* $OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $ */ - -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; -#else -static char rcsid[] = "$OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $"; -#endif -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/stat.h> - -#include <dirent.h> -#include <errno.h> -#include <fcntl.h> -#include <fts.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -static FTSENT *fts_alloc __P((FTS *, char *, int)); -static FTSENT *fts_build __P((FTS *, int)); -static void fts_lfree __P((FTSENT *)); -static void fts_load __P((FTS *, FTSENT *)); -static size_t fts_maxarglen __P((char * const *)); -static void fts_padjust __P((FTS *, FTSENT *)); -static int fts_palloc __P((FTS *, size_t)); -static FTSENT *fts_sort __P((FTS *, FTSENT *, int)); -static u_short fts_stat __P((FTS *, FTSENT *, int)); -static int fts_safe_changedir __P((FTS *, FTSENT *, int)); - -#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) - -#define CLR(opt) (sp->fts_options &= ~(opt)) -#define ISSET(opt) (sp->fts_options & (opt)) -#define SET(opt) (sp->fts_options |= (opt)) - -#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path)) -#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) - -/* fts_build flags */ -#define BCHILD 1 /* fts_children */ -#define BNAMES 2 /* fts_children, names only */ -#define BREAD 3 /* fts_read */ - -FTS * -fts_open(argv, options, compar) - char * const *argv; - register int options; - int (*compar) __P((const FTSENT **, const FTSENT **)); -{ - register FTS *sp; - register FTSENT *p, *root; - register int nitems; - FTSENT *parent, *tmp; - int len; - - /* Options check. */ - if (options & ~FTS_OPTIONMASK) { - errno = EINVAL; - return (NULL); - } - - /* Allocate/initialize the stream */ - if ((sp = malloc((u_int)sizeof(FTS))) == NULL) - return (NULL); - memset(sp, 0, sizeof(FTS)); - sp->fts_compar = compar; - sp->fts_options = options; - - /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ - if (ISSET(FTS_LOGICAL)) - SET(FTS_NOCHDIR); - - /* - * Start out with 1K of path space, and enough, in any case, - * to hold the user's paths. - */ - if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN))) - goto mem1; - - /* Allocate/initialize root's parent. */ - if ((parent = fts_alloc(sp, "", 0)) == NULL) - goto mem2; - parent->fts_level = FTS_ROOTPARENTLEVEL; - - /* Allocate/initialize root(s). */ - for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) { - /* Don't allow zero-length paths. */ - if ((len = strlen(*argv)) == 0) { - errno = ENOENT; - goto mem3; - } - - p = fts_alloc(sp, *argv, len); - p->fts_level = FTS_ROOTLEVEL; - p->fts_parent = parent; - p->fts_accpath = p->fts_name; - p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); - - /* Command-line "." and ".." are real directories. */ - if (p->fts_info == FTS_DOT) - p->fts_info = FTS_D; - - /* - * If comparison routine supplied, traverse in sorted - * order; otherwise traverse in the order specified. - */ - if (compar) { - p->fts_link = root; - root = p; - } else { - p->fts_link = NULL; - if (root == NULL) - tmp = root = p; - else { - tmp->fts_link = p; - tmp = p; - } - } - } - if (compar && nitems > 1) - root = fts_sort(sp, root, nitems); - - /* - * Allocate a dummy pointer and make fts_read think that we've just - * finished the node before the root(s); set p->fts_info to FTS_INIT - * so that everything about the "current" node is ignored. - */ - if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) - goto mem3; - sp->fts_cur->fts_link = root; - sp->fts_cur->fts_info = FTS_INIT; - - /* - * If using chdir(2), grab a file descriptor pointing to dot to ensure - * that we can get back here; this could be avoided for some paths, - * but almost certainly not worth the effort. Slashes, symbolic links, - * and ".." are all fairly nasty problems. Note, if we can't get the - * descriptor we run anyway, just more slowly. - */ - if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = open(".", O_RDONLY, 0)) < 0) - SET(FTS_NOCHDIR); - - return (sp); - -mem3: fts_lfree(root); - free(parent); -mem2: free(sp->fts_path); -mem1: free(sp); - return (NULL); -} - -static void -fts_load(sp, p) - FTS *sp; - register FTSENT *p; -{ - register int len; - register char *cp; - - /* - * Load the stream structure for the next traversal. Since we don't - * actually enter the directory until after the preorder visit, set - * the fts_accpath field specially so the chdir gets done to the right - * place and the user can access the first node. From fts_open it's - * known that the path will fit. - */ - len = p->fts_pathlen = p->fts_namelen; - memmove(sp->fts_path, p->fts_name, len + 1); - if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { - len = strlen(++cp); - memmove(p->fts_name, cp, len + 1); - p->fts_namelen = len; - } - p->fts_accpath = p->fts_path = sp->fts_path; - sp->fts_dev = p->fts_dev; -} - -int -fts_close(sp) - FTS *sp; -{ - register FTSENT *freep, *p; - int saved_errno; - - /* - * This still works if we haven't read anything -- the dummy structure - * points to the root list, so we step through to the end of the root - * list which has a valid parent pointer. - */ - if (sp->fts_cur) { - for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { - freep = p; - p = p->fts_link ? p->fts_link : p->fts_parent; - free(freep); - } - free(p); - } - - /* Free up child linked list, sort array, path buffer. */ - if (sp->fts_child) - fts_lfree(sp->fts_child); - if (sp->fts_array) - free(sp->fts_array); - free(sp->fts_path); - - /* Return to original directory, save errno if necessary. */ - if (!ISSET(FTS_NOCHDIR)) { - saved_errno = fchdir(sp->fts_rfd) ? errno : 0; - (void)close(sp->fts_rfd); - } - - /* Set errno and return. */ - if (!ISSET(FTS_NOCHDIR) && saved_errno) { - /* Free up the stream pointer. */ - free(sp); - errno = saved_errno; - return (-1); - } - - /* Free up the stream pointer. */ - free(sp); - return (0); -} - -/* - * Special case of "/" at the end of the path so that slashes aren't - * appended which would cause paths to be written as "....//foo". - */ -#define NAPPEND(p) \ - (p->fts_path[p->fts_pathlen - 1] == '/' \ - ? p->fts_pathlen - 1 : p->fts_pathlen) - -FTSENT * -fts_read(sp) - register FTS *sp; -{ - register FTSENT *p, *tmp; - register int instr; - register char *t; - int saved_errno; - - /* If finished or unrecoverable error, return NULL. */ - if (sp->fts_cur == NULL || ISSET(FTS_STOP)) - return (NULL); - - /* Set current node pointer. */ - p = sp->fts_cur; - - /* Save and zero out user instructions. */ - instr = p->fts_instr; - p->fts_instr = FTS_NOINSTR; - - /* Any type of file may be re-visited; re-stat and re-turn. */ - if (instr == FTS_AGAIN) { - p->fts_info = fts_stat(sp, p, 0); - return (p); - } - - /* - * Following a symlink -- SLNONE test allows application to see - * SLNONE and recover. If indirecting through a symlink, have - * keep a pointer to current location. If unable to get that - * pointer, follow fails. - */ - if (instr == FTS_FOLLOW && - (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { - p->fts_info = fts_stat(sp, p, 1); - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { - if ((p->fts_symfd = open(".", O_RDONLY, 0)) < 0) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else - p->fts_flags |= FTS_SYMFOLLOW; - } - return (p); - } - - /* Directory in pre-order. */ - if (p->fts_info == FTS_D) { - /* If skipped or crossed mount point, do post-order visit. */ - if (instr == FTS_SKIP || - (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { - if (p->fts_flags & FTS_SYMFOLLOW) - (void)close(p->fts_symfd); - if (sp->fts_child) { - fts_lfree(sp->fts_child); - sp->fts_child = NULL; - } - p->fts_info = FTS_DP; - return (p); - } - - /* Rebuild if only read the names and now traversing. */ - if (sp->fts_child && ISSET(FTS_NAMEONLY)) { - CLR(FTS_NAMEONLY); - fts_lfree(sp->fts_child); - sp->fts_child = NULL; - } - - /* - * Cd to the subdirectory. - * - * If have already read and now fail to chdir, whack the list - * to make the names come out right, and set the parent errno - * so the application will eventually get an error condition. - * Set the FTS_DONTCHDIR flag so that when we logically change - * directories back to the parent we don't do a chdir. - * - * If haven't read do so. If the read fails, fts_build sets - * FTS_STOP or the fts_info field of the node. - */ - if (sp->fts_child) { - if (fts_safe_changedir(sp, p, -1)) { - p->fts_errno = errno; - p->fts_flags |= FTS_DONTCHDIR; - for (p = sp->fts_child; p; p = p->fts_link) - p->fts_accpath = - p->fts_parent->fts_accpath; - } - } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { - if (ISSET(FTS_STOP)) - return (NULL); - return (p); - } - p = sp->fts_child; - sp->fts_child = NULL; - goto name; - } - - /* Move to the next node on this level. */ -next: tmp = p; - if ((p = p->fts_link)) { - free(tmp); - - /* - * If reached the top, return to the original directory (or - * the root of the tree), and load the paths for the next root. - */ - if (p->fts_level == FTS_ROOTLEVEL) { - if (FCHDIR(sp, sp->fts_rfd)) { - SET(FTS_STOP); - return (NULL); - } - fts_load(sp, p); - return (sp->fts_cur = p); - } - - /* - * User may have called fts_set on the node. If skipped, - * ignore. If followed, get a file descriptor so we can - * get back if necessary. - */ - if (p->fts_instr == FTS_SKIP) - goto next; - if (p->fts_instr == FTS_FOLLOW) { - p->fts_info = fts_stat(sp, p, 1); - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { - if ((p->fts_symfd = - open(".", O_RDONLY, 0)) < 0) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else - p->fts_flags |= FTS_SYMFOLLOW; - } - p->fts_instr = FTS_NOINSTR; - } - -name: t = sp->fts_path + NAPPEND(p->fts_parent); - *t++ = '/'; - memmove(t, p->fts_name, p->fts_namelen + 1); - return (sp->fts_cur = p); - } - - /* Move up to the parent node. */ - p = tmp->fts_parent; - free(tmp); - - if (p->fts_level == FTS_ROOTPARENTLEVEL) { - /* - * Done; free everything up and set errno to 0 so the user - * can distinguish between error and EOF. - */ - free(p); - errno = 0; - return (sp->fts_cur = NULL); - } - - /* NUL terminate the pathname. */ - sp->fts_path[p->fts_pathlen] = '\0'; - - /* - * Return to the parent directory. If at a root node or came through - * a symlink, go back through the file descriptor. Otherwise, cd up - * one directory. - */ - if (p->fts_level == FTS_ROOTLEVEL) { - if (FCHDIR(sp, sp->fts_rfd)) { - SET(FTS_STOP); - return (NULL); - } - } else if (p->fts_flags & FTS_SYMFOLLOW) { - if (FCHDIR(sp, p->fts_symfd)) { - saved_errno = errno; - (void)close(p->fts_symfd); - errno = saved_errno; - SET(FTS_STOP); - return (NULL); - } - (void)close(p->fts_symfd); - } else if (!(p->fts_flags & FTS_DONTCHDIR)) { - if (CHDIR(sp, "..")) { - SET(FTS_STOP); - return (NULL); - } - } - p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; - return (sp->fts_cur = p); -} - -/* - * Fts_set takes the stream as an argument although it's not used in this - * implementation; it would be necessary if anyone wanted to add global - * semantics to fts using fts_set. An error return is allowed for similar - * reasons. - */ -/* ARGSUSED */ -int -fts_set(sp, p, instr) - FTS *sp; - FTSENT *p; - int instr; -{ - if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW && - instr != FTS_NOINSTR && instr != FTS_SKIP) { - errno = EINVAL; - return (1); - } - p->fts_instr = instr; - return (0); -} - -FTSENT * -fts_children(sp, instr) - register FTS *sp; - int instr; -{ - register FTSENT *p; - int fd; - - if (instr && instr != FTS_NAMEONLY) { - errno = EINVAL; - return (NULL); - } - - /* Set current node pointer. */ - p = sp->fts_cur; - - /* - * Errno set to 0 so user can distinguish empty directory from - * an error. - */ - errno = 0; - - /* Fatal errors stop here. */ - if (ISSET(FTS_STOP)) - return (NULL); - - /* Return logical hierarchy of user's arguments. */ - if (p->fts_info == FTS_INIT) - return (p->fts_link); - - /* - * If not a directory being visited in pre-order, stop here. Could - * allow FTS_DNR, assuming the user has fixed the problem, but the - * same effect is available with FTS_AGAIN. - */ - if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) - return (NULL); - - /* Free up any previous child list. */ - if (sp->fts_child) - fts_lfree(sp->fts_child); - - if (instr == FTS_NAMEONLY) { - SET(FTS_NAMEONLY); - instr = BNAMES; - } else - instr = BCHILD; - - /* - * If using chdir on a relative path and called BEFORE fts_read does - * its chdir to the root of a traversal, we can lose -- we need to - * chdir into the subdirectory, and we don't know where the current - * directory is, so we can't get back so that the upcoming chdir by - * fts_read will work. - */ - if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || - ISSET(FTS_NOCHDIR)) - return (sp->fts_child = fts_build(sp, instr)); - - if ((fd = open(".", O_RDONLY, 0)) < 0) - return (NULL); - sp->fts_child = fts_build(sp, instr); - if (fchdir(fd)) - return (NULL); - (void)close(fd); - return (sp->fts_child); -} - -/* - * This is the tricky part -- do not casually change *anything* in here. The - * idea is to build the linked list of entries that are used by fts_children - * and fts_read. There are lots of special cases. - * - * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is - * set and it's a physical walk (so that symbolic links can't be directories), - * we can do things quickly. First, if it's a 4.4BSD file system, the type - * of the file is in the directory entry. Otherwise, we assume that the number - * of subdirectories in a node is equal to the number of links to the parent. - * The former skips all stat calls. The latter skips stat calls in any leaf - * directories and for any files after the subdirectories in the directory have - * been found, cutting the stat calls by about 2/3. - */ -static FTSENT * -fts_build(sp, type) - register FTS *sp; - int type; -{ - register struct dirent *dp; - register FTSENT *p, *head; - register int nitems; - FTSENT *cur, *tail; - DIR *dirp; - void *oldaddr; - int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno, - nostat, doadjust; - char *cp; - - /* Set current node pointer. */ - cur = sp->fts_cur; - - /* - * Open the directory for reading. If this fails, we're done. - * If being called from fts_read, set the fts_info field. - */ -#ifdef FTS_WHITEOUT - if (ISSET(FTS_WHITEOUT)) - oflag = DTF_NODUP|DTF_REWIND; - else - oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND; -#else -#define __opendir2(path, flag) opendir(path) -#endif - if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) { - if (type == BREAD) { - cur->fts_info = FTS_DNR; - cur->fts_errno = errno; - } - return (NULL); - } - - /* - * Nlinks is the number of possible entries of type directory in the - * directory if we're cheating on stat calls, 0 if we're not doing - * any stat calls at all, -1 if we're doing stats on everything. - */ - if (type == BNAMES) - nlinks = 0; - else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) { - nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2); - nostat = 1; - } else { - nlinks = -1; - nostat = 0; - } - -#ifdef notdef - (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink); - (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n", - ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT)); -#endif - /* - * If we're going to need to stat anything or we want to descend - * and stay in the directory, chdir. If this fails we keep going, - * but set a flag so we don't chdir after the post-order visit. - * We won't be able to stat anything, but we can still return the - * names themselves. Note, that since fts_read won't be able to - * chdir into the directory, it will have to return different path - * names than before, i.e. "a/b" instead of "b". Since the node - * has already been visited in pre-order, have to wait until the - * post-order visit to return the error. There is a special case - * here, if there was nothing to stat then it's not an error to - * not be able to stat. This is all fairly nasty. If a program - * needed sorted entries or stat information, they had better be - * checking FTS_NS on the returned nodes. - */ - cderrno = 0; - if (nlinks || type == BREAD) { - if (fts_safe_changedir(sp, cur, dirfd(dirp))) { - if (nlinks && type == BREAD) - cur->fts_errno = errno; - cur->fts_flags |= FTS_DONTCHDIR; - descend = 0; - cderrno = errno; - (void)closedir(dirp); - dirp = NULL; - } else - descend = 1; - } else - descend = 0; - - /* - * Figure out the max file name length that can be stored in the - * current path -- the inner loop allocates more path as necessary. - * We really wouldn't have to do the maxlen calculations here, we - * could do them in fts_read before returning the path, but it's a - * lot easier here since the length is part of the dirent structure. - * - * If not changing directories set a pointer so that can just append - * each new name into the path. - */ - len = NAPPEND(cur); - if (ISSET(FTS_NOCHDIR)) { - cp = sp->fts_path + len; - *cp++ = '/'; - } - len++; - maxlen = sp->fts_pathlen - len; - - level = cur->fts_level + 1; - - /* Read the directory, attaching each entry to the `link' pointer. */ - doadjust = 0; - for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) { - if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) - continue; - - if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL) - goto mem1; - if (dp->d_namlen >= maxlen) { /* include space for NUL */ - oldaddr = sp->fts_path; - if (fts_palloc(sp, dp->d_namlen +len + 1)) { - /* - * No more memory for path or structures. Save - * errno, free up the current structure and the - * structures already allocated. - */ -mem1: saved_errno = errno; - if (p) - free(p); - fts_lfree(head); - (void)closedir(dirp); - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - errno = saved_errno; - return (NULL); - } - /* Did realloc() change the pointer? */ - if (oldaddr != sp->fts_path) { - doadjust = 1; - if (ISSET(FTS_NOCHDIR)) - cp = sp->fts_path + len; - } - maxlen = sp->fts_pathlen - len; - } - - if (len + dp->d_namlen >= USHRT_MAX) { - /* - * In an FTSENT, fts_pathlen is a u_short so it is - * possible to wraparound here. If we do, free up - * the current structure and the structures already - * allocated, then error out with ENAMETOOLONG. - */ - free(p); - fts_lfree(head); - (void)closedir(dirp); - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - errno = ENAMETOOLONG; - return (NULL); - } - p->fts_level = level; - p->fts_parent = sp->fts_cur; - p->fts_pathlen = len + dp->d_namlen; - -#ifdef FTS_WHITEOUT - if (dp->d_type == DT_WHT) - p->fts_flags |= FTS_ISW; -#endif - - if (cderrno) { - if (nlinks) { - p->fts_info = FTS_NS; - p->fts_errno = cderrno; - } else - p->fts_info = FTS_NSOK; - p->fts_accpath = cur->fts_accpath; - } else if (nlinks == 0 -#ifdef DT_DIR - || (nostat && - dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN) -#endif - ) { - p->fts_accpath = - ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; - p->fts_info = FTS_NSOK; - } else { - /* Build a file name for fts_stat to stat. */ - if (ISSET(FTS_NOCHDIR)) { - p->fts_accpath = p->fts_path; - memmove(cp, p->fts_name, p->fts_namelen + 1); - } else - p->fts_accpath = p->fts_name; - /* Stat it. */ - p->fts_info = fts_stat(sp, p, 0); - - /* Decrement link count if applicable. */ - if (nlinks > 0 && (p->fts_info == FTS_D || - p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) - --nlinks; - } - - /* We walk in directory order so "ls -f" doesn't get upset. */ - p->fts_link = NULL; - if (head == NULL) - head = tail = p; - else { - tail->fts_link = p; - tail = p; - } - ++nitems; - } - if (dirp) - (void)closedir(dirp); - - /* - * If realloc() changed the address of the path, adjust the - * addresses for the rest of the tree and the dir list. - */ - if (doadjust) - fts_padjust(sp, head); - - /* - * If not changing directories, reset the path back to original - * state. - */ - if (ISSET(FTS_NOCHDIR)) { - if (len == sp->fts_pathlen || nitems == 0) - --cp; - *cp = '\0'; - } - - /* - * If descended after called from fts_children or after called from - * fts_read and nothing found, get back. At the root level we use - * the saved fd; if one of fts_open()'s arguments is a relative path - * to an empty directory, we wind up here with no other way back. If - * can't get back, we're done. - */ - if (descend && (type == BCHILD || !nitems) && - (cur->fts_level == FTS_ROOTLEVEL ? - FCHDIR(sp, sp->fts_rfd) : CHDIR(sp, ".."))) { - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - return (NULL); - } - - /* If didn't find anything, return NULL. */ - if (!nitems) { - if (type == BREAD) - cur->fts_info = FTS_DP; - return (NULL); - } - - /* Sort the entries. */ - if (sp->fts_compar && nitems > 1) - head = fts_sort(sp, head, nitems); - return (head); -} - -static u_short -fts_stat(sp, p, follow) - FTS *sp; - register FTSENT *p; - int follow; -{ - register FTSENT *t; - register dev_t dev; - register ino_t ino; - struct stat *sbp, sb; - int saved_errno; - - /* If user needs stat info, stat buffer already allocated. */ - sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp; - -#ifdef FTS_WHITEOUT - /* check for whiteout */ - if (p->fts_flags & FTS_ISW) { - if (sbp != &sb) { - memset(sbp, '\0', sizeof (*sbp)); - sbp->st_mode = S_IFWHT; - } - return (FTS_W); - } -#endif - - /* - * If doing a logical walk, or application requested FTS_FOLLOW, do - * a stat(2). If that fails, check for a non-existent symlink. If - * fail, set the errno from the stat call. - */ - if (ISSET(FTS_LOGICAL) || follow) { - if (stat(p->fts_accpath, sbp)) { - saved_errno = errno; - if (!lstat(p->fts_accpath, sbp)) { - errno = 0; - return (FTS_SLNONE); - } - p->fts_errno = saved_errno; - goto err; - } - } else if (lstat(p->fts_accpath, sbp)) { - p->fts_errno = errno; -err: memset(sbp, 0, sizeof(struct stat)); - return (FTS_NS); - } - - if (S_ISDIR(sbp->st_mode)) { - /* - * Set the device/inode. Used to find cycles and check for - * crossing mount points. Also remember the link count, used - * in fts_build to limit the number of stat calls. It is - * understood that these fields are only referenced if fts_info - * is set to FTS_D. - */ - dev = p->fts_dev = sbp->st_dev; - ino = p->fts_ino = sbp->st_ino; - p->fts_nlink = sbp->st_nlink; - - if (ISDOT(p->fts_name)) - return (FTS_DOT); - - /* - * Cycle detection is done by brute force when the directory - * is first encountered. If the tree gets deep enough or the - * number of symbolic links to directories is high enough, - * something faster might be worthwhile. - */ - for (t = p->fts_parent; - t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) - if (ino == t->fts_ino && dev == t->fts_dev) { - p->fts_cycle = t; - return (FTS_DC); - } - return (FTS_D); - } - if (S_ISLNK(sbp->st_mode)) - return (FTS_SL); - if (S_ISREG(sbp->st_mode)) - return (FTS_F); - return (FTS_DEFAULT); -} - -static FTSENT * -fts_sort(sp, head, nitems) - FTS *sp; - FTSENT *head; - register int nitems; -{ - register FTSENT **ap, *p; - - /* - * Construct an array of pointers to the structures and call qsort(3). - * Reassemble the array in the order returned by qsort. If unable to - * sort for memory reasons, return the directory entries in their - * current order. Allocate enough space for the current needs plus - * 40 so don't realloc one entry at a time. - */ - if (nitems > sp->fts_nitems) { - struct _ftsent **a; - - sp->fts_nitems = nitems + 40; - if ((a = realloc(sp->fts_array, - sp->fts_nitems * sizeof(FTSENT *))) == NULL) { - if (sp->fts_array) - free(sp->fts_array); - sp->fts_array = NULL; - sp->fts_nitems = 0; - return (head); - } - sp->fts_array = a; - } - for (ap = sp->fts_array, p = head; p; p = p->fts_link) - *ap++ = p; - qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar); - for (head = *(ap = sp->fts_array); --nitems; ++ap) - ap[0]->fts_link = ap[1]; - ap[0]->fts_link = NULL; - return (head); -} - -static FTSENT * -fts_alloc(sp, name, namelen) - FTS *sp; - char *name; - register int namelen; -{ - register FTSENT *p; - size_t len; - - /* - * The file name is a variable length array and no stat structure is - * necessary if the user has set the nostat bit. Allocate the FTSENT - * structure, the file name and the stat structure in one chunk, but - * be careful that the stat structure is reasonably aligned. Since the - * fts_name field is declared to be of size 1, the fts_name pointer is - * namelen + 2 before the first possible address of the stat structure. - */ - len = sizeof(FTSENT) + namelen; - if (!ISSET(FTS_NOSTAT)) - len += sizeof(struct stat) + ALIGNBYTES; - if ((p = malloc(len)) == NULL) - return (NULL); - - /* Copy the name and guarantee NUL termination. */ - memmove(p->fts_name, name, namelen); - p->fts_name[namelen] = '\0'; - - if (!ISSET(FTS_NOSTAT)) - p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2); - p->fts_namelen = namelen; - p->fts_path = sp->fts_path; - p->fts_errno = 0; - p->fts_flags = 0; - p->fts_instr = FTS_NOINSTR; - p->fts_number = 0; - p->fts_pointer = NULL; - return (p); -} - -static void -fts_lfree(head) - register FTSENT *head; -{ - register FTSENT *p; - - /* Free a linked list of structures. */ - while ((p = head)) { - head = head->fts_link; - free(p); - } -} - -/* - * Allow essentially unlimited paths; find, rm, ls should all work on any tree. - * Most systems will allow creation of paths much longer than MAXPATHLEN, even - * though the kernel won't resolve them. Add the size (not just what's needed) - * plus 256 bytes so don't realloc the path 2 bytes at a time. - */ -static int -fts_palloc(sp, more) - FTS *sp; - size_t more; -{ - char *p; - - sp->fts_pathlen += more + 256; - /* - * Check for possible wraparound. In an FTS, fts_pathlen is - * a signed int but in an FTSENT it is an unsigned short. - * We limit fts_pathlen to USHRT_MAX to be safe in both cases. - */ - if (sp->fts_pathlen < 0 || sp->fts_pathlen >= USHRT_MAX) { - if (sp->fts_path) - free(sp->fts_path); - sp->fts_path = NULL; - errno = ENAMETOOLONG; - return (1); - } - p = realloc(sp->fts_path, sp->fts_pathlen); - if (p == NULL) { - if (sp->fts_path) - free(sp->fts_path); - sp->fts_path = NULL; - return (1); - } - sp->fts_path = p; - return (0); -} - -/* - * When the path is realloc'd, have to fix all of the pointers in structures - * already returned. - */ -static void -fts_padjust(sp, head) - FTS *sp; - FTSENT *head; -{ - FTSENT *p; - char *addr = sp->fts_path; - -#define ADJUST(p) { \ - if ((p)->fts_accpath != (p)->fts_name) { \ - (p)->fts_accpath = \ - (char *)addr + ((p)->fts_accpath - (p)->fts_path); \ - } \ - (p)->fts_path = addr; \ -} - /* Adjust the current set of children. */ - for (p = sp->fts_child; p; p = p->fts_link) - ADJUST(p); - - /* Adjust the rest of the tree, including the current level. */ - for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { - ADJUST(p); - p = p->fts_link ? p->fts_link : p->fts_parent; - } -} - -static size_t -fts_maxarglen(argv) - char * const *argv; -{ - size_t len, max; - - for (max = 0; *argv; ++argv) - if ((len = strlen(*argv)) > max) - max = len; - return (max + 1); -} - -/* - * Change to dir specified by fd or p->fts_accpath without getting - * tricked by someone changing the world out from underneath us. - * Assumes p->fts_dev and p->fts_ino are filled in. - */ -static int -fts_safe_changedir(sp, p, fd) - FTS *sp; - FTSENT *p; - int fd; -{ - int ret, oerrno, newfd; - struct stat sb; - - newfd = fd; - if (ISSET(FTS_NOCHDIR)) - return (0); - if (fd < 0 && (newfd = open(p->fts_accpath, O_RDONLY, 0)) < 0) - return (-1); - if (fstat(newfd, &sb)) { - ret = -1; - goto bail; - } - if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) { - errno = ENOENT; /* disinformation */ - ret = -1; - goto bail; - } - ret = fchdir(newfd); -bail: - oerrno = errno; - if (fd < 0) - (void)close(newfd); - errno = oerrno; - return (ret); -} diff --git a/sbin/dhclient/Makefile b/sbin/dhclient/Makefile deleted file mode 100644 index 594c9aff1b4e..000000000000 --- a/sbin/dhclient/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -# $OpenBSD: Makefile,v 1.9 2004/05/04 12:52:05 henning Exp $ -# -# Copyright (c) 1996, 1997 The Internet Software Consortium. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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 <bsd.own.mk> - -SRCS= dhclient.c clparse.c alloc.c dispatch.c hash.c bpf.c options.c \ - tree.c conflex.c errwarn.c inet.c packet.c convert.c tables.c \ - parse.c privsep.c - -PROG= dhclient -MAN= dhclient.8 dhclient.conf.5 dhclient.leases.5 dhclient-script.8 - -CFLAGS+=-Wall - -beforeinstall: - ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ - ${.CURDIR}/dhclient-script ${DESTDIR}/sbin/dhclient-script - -.include <bsd.prog.mk> diff --git a/sbin/dhclient/alloc.c b/sbin/dhclient/alloc.c deleted file mode 100644 index cabb76d42989..000000000000 --- a/sbin/dhclient/alloc.c +++ /dev/null @@ -1,76 +0,0 @@ -/* $OpenBSD: alloc.c,v 1.9 2004/05/04 20:28:40 deraadt Exp $ */ - -/* Memory allocation... */ - -/* - * Copyright (c) 1995, 1996, 1998 The Internet Software Consortium. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include "dhcpd.h" - -struct string_list * -new_string_list(size_t size) -{ - struct string_list *rval; - - rval = calloc(1, sizeof(struct string_list) + size); - if (rval != NULL) - rval->string = ((char *)rval) + sizeof(struct string_list); - return (rval); -} - -struct hash_table * -new_hash_table(int count) -{ - struct hash_table *rval; - - rval = calloc(1, sizeof(struct hash_table) - - (DEFAULT_HASH_SIZE * sizeof(struct hash_bucket *)) + - (count * sizeof(struct hash_bucket *))); - if (rval == NULL) - return (NULL); - rval->hash_count = count; - return (rval); -} - -struct hash_bucket * -new_hash_bucket(void) -{ - struct hash_bucket *rval = calloc(1, sizeof(struct hash_bucket)); - - return (rval); -} diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c deleted file mode 100644 index 131a88f743d2..000000000000 --- a/sbin/dhclient/bpf.c +++ /dev/null @@ -1,374 +0,0 @@ -/* $OpenBSD: bpf.c,v 1.13 2004/05/05 14:28:58 deraadt Exp $ */ - -/* BPF socket interface code, originally contributed by Archie Cobbs. */ - -/* - * Copyright (c) 1995, 1996, 1998, 1999 - * The Internet Software Consortium. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include "dhcpd.h" -#include <sys/ioctl.h> -#include <sys/uio.h> - -#include <net/bpf.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/udp.h> -#include <netinet/if_ether.h> - -#define BPF_FORMAT "/dev/bpf%d" - -/* - * Called by get_interface_list for each interface that's discovered. - * Opens a packet filter for each interface and adds it to the select - * mask. - */ -int -if_register_bpf(struct interface_info *info) -{ - char filename[50]; - int sock, b; - - /* Open a BPF device */ - for (b = 0; 1; b++) { - snprintf(filename, sizeof(filename), BPF_FORMAT, b); - sock = open(filename, O_RDWR, 0); - if (sock < 0) { - if (errno == EBUSY) - continue; - else - error("Can't find free bpf: %m"); - } else - break; - } - - /* Set the BPF device to point at this interface. */ - if (ioctl(sock, BIOCSETIF, info->ifp) < 0) - error("Can't attach interface %s to bpf device %s: %m", - info->name, filename); - - return (sock); -} - -void -if_register_send(struct interface_info *info) -{ - /* - * If we're using the bpf API for sending and receiving, we - * don't need to register this interface twice. - */ - info->wfdesc = info->rfdesc; -} - -/* - * Packet filter program... - * - * XXX: Changes to the filter program may require changes to the - * constant offsets used in if_register_send to patch the BPF program! - */ -struct bpf_insn dhcp_bpf_filter[] = { - /* Make sure this is an IP packet... */ - BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 8), - - /* Make sure it's a UDP packet... */ - BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 23), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6), - - /* Make sure this isn't a fragment... */ - BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20), - BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 4, 0), - - /* Get the IP header length... */ - BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 14), - - /* Make sure it's to the right port... */ - BPF_STMT(BPF_LD + BPF_H + BPF_IND, 16), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1), /* patch */ - - /* If we passed all the tests, ask for the whole packet. */ - BPF_STMT(BPF_RET+BPF_K, (u_int)-1), - - /* Otherwise, drop it. */ - BPF_STMT(BPF_RET+BPF_K, 0), -}; - -int dhcp_bpf_filter_len = sizeof(dhcp_bpf_filter) / sizeof(struct bpf_insn); - -/* - * Packet write filter program: - * 'ip and udp and src port bootps and dst port (bootps or bootpc)' - */ -struct bpf_insn dhcp_bpf_wfilter[] = { - BPF_STMT(BPF_LD + BPF_B + BPF_IND, 14), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (IPVERSION << 4) + 5, 0, 12), - - /* Make sure this is an IP packet... */ - BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 10), - - /* Make sure it's a UDP packet... */ - BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 23), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 8), - - /* Make sure this isn't a fragment... */ - BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20), - BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 6, 0), /* patched */ - - /* Get the IP header length... */ - BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 14), - - /* Make sure it's from the right port... */ - BPF_STMT(BPF_LD + BPF_H + BPF_IND, 14), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 68, 0, 3), - - /* Make sure it is to the right ports ... */ - BPF_STMT(BPF_LD + BPF_H + BPF_IND, 16), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1), - - /* If we passed all the tests, ask for the whole packet. */ - BPF_STMT(BPF_RET+BPF_K, (u_int)-1), - - /* Otherwise, drop it. */ - BPF_STMT(BPF_RET+BPF_K, 0), -}; - -int dhcp_bpf_wfilter_len = sizeof(dhcp_bpf_wfilter) / sizeof(struct bpf_insn); - -void -if_register_receive(struct interface_info *info) -{ - struct bpf_version v; - struct bpf_program p; - int flag = 1, sz; - - /* Open a BPF device and hang it on this interface... */ - info->rfdesc = if_register_bpf(info); - - /* Make sure the BPF version is in range... */ - if (ioctl(info->rfdesc, BIOCVERSION, &v) < 0) - error("Can't get BPF version: %m"); - - if (v.bv_major != BPF_MAJOR_VERSION || - v.bv_minor < BPF_MINOR_VERSION) - error("Kernel BPF version out of range - recompile dhcpd!"); - - /* - * Set immediate mode so that reads return as soon as a packet - * comes in, rather than waiting for the input buffer to fill - * with packets. - */ - if (ioctl(info->rfdesc, BIOCIMMEDIATE, &flag) < 0) - error("Can't set immediate mode on bpf device: %m"); - - /* Get the required BPF buffer length from the kernel. */ - if (ioctl(info->rfdesc, BIOCGBLEN, &sz) < 0) - error("Can't get bpf buffer length: %m"); - info->rbuf_max = sz; - info->rbuf = malloc(info->rbuf_max); - if (!info->rbuf) - error("Can't allocate %lu bytes for bpf input buffer.", - (unsigned long)info->rbuf_max); - info->rbuf_offset = 0; - info->rbuf_len = 0; - - /* Set up the bpf filter program structure. */ - p.bf_len = dhcp_bpf_filter_len; - p.bf_insns = dhcp_bpf_filter; - - /* Patch the server port into the BPF program... - * - * XXX: changes to filter program may require changes to the - * insn number(s) used below! - */ - dhcp_bpf_filter[8].k = LOCAL_PORT; - - if (ioctl(info->rfdesc, BIOCSETF, &p) < 0) - error("Can't install packet filter program: %m"); - - /* Set up the bpf write filter program structure. */ - p.bf_len = dhcp_bpf_wfilter_len; - p.bf_insns = dhcp_bpf_wfilter; - - if (dhcp_bpf_wfilter[7].k == 0x1fff) - dhcp_bpf_wfilter[7].k = htons(IP_MF|IP_OFFMASK); - - if (ioctl(info->rfdesc, BIOCSETWF, &p) < 0) - error("Can't install write filter program: %m"); - - if (ioctl(info->rfdesc, BIOCLOCK, NULL) < 0) - error("Cannot lock bpf"); -} - -ssize_t -send_packet(struct interface_info *interface, struct dhcp_packet *raw, - size_t len, struct in_addr from, struct sockaddr_in *to, - struct hardware *hto) -{ - unsigned char buf[256]; - struct iovec iov[2]; - int result, bufp = 0; - - /* Assemble the headers... */ - assemble_hw_header(interface, buf, &bufp, hto); - assemble_udp_ip_header(buf, &bufp, from.s_addr, - to->sin_addr.s_addr, to->sin_port, (unsigned char *)raw, len); - - /* Fire it off */ - iov[0].iov_base = (char *)buf; - iov[0].iov_len = bufp; - iov[1].iov_base = (char *)raw; - iov[1].iov_len = len; - - result = writev(interface->wfdesc, iov, 2); - if (result < 0) - warning("send_packet: %m"); - return (result); -} - -ssize_t -receive_packet(struct interface_info *interface, unsigned char *buf, - size_t len, struct sockaddr_in *from, struct hardware *hfrom) -{ - int length = 0, offset = 0; - struct bpf_hdr hdr; - - /* - * All this complexity is because BPF doesn't guarantee that - * only one packet will be returned at a time. We're getting - * what we deserve, though - this is a terrible abuse of the BPF - * interface. Sigh. - */ - - /* Process packets until we get one we can return or until we've - * done a read and gotten nothing we can return... - */ - do { - /* If the buffer is empty, fill it. */ - if (interface->rbuf_offset == interface->rbuf_len) { - length = read(interface->rfdesc, interface->rbuf, - interface->rbuf_max); - if (length <= 0) - return (length); - interface->rbuf_offset = 0; - interface->rbuf_len = length; - } - - /* - * If there isn't room for a whole bpf header, something - * went wrong, but we'll ignore it and hope it goes - * away... XXX - */ - if (interface->rbuf_len - interface->rbuf_offset < - sizeof(hdr)) { - interface->rbuf_offset = interface->rbuf_len; - continue; - } - - /* Copy out a bpf header... */ - memcpy(&hdr, &interface->rbuf[interface->rbuf_offset], - sizeof(hdr)); - - /* - * If the bpf header plus data doesn't fit in what's - * left of the buffer, stick head in sand yet again... - */ - if (interface->rbuf_offset + hdr.bh_hdrlen + hdr.bh_caplen > - interface->rbuf_len) { - interface->rbuf_offset = interface->rbuf_len; - continue; - } - - /* - * If the captured data wasn't the whole packet, or if - * the packet won't fit in the input buffer, all we can - * do is drop it. - */ - if (hdr.bh_caplen != hdr.bh_datalen) { - interface->rbuf_offset += hdr.bh_hdrlen = hdr.bh_caplen; - continue; - } - - /* Skip over the BPF header... */ - interface->rbuf_offset += hdr.bh_hdrlen; - - /* Decode the physical header... */ - offset = decode_hw_header(interface->rbuf, - interface->rbuf_offset, hfrom); - - /* - * If a physical layer checksum failed (dunno of any - * physical layer that supports this, but WTH), skip - * this packet. - */ - if (offset < 0) { - interface->rbuf_offset += hdr.bh_caplen; - continue; - } - interface->rbuf_offset += offset; - hdr.bh_caplen -= offset; - - /* Decode the IP and UDP headers... */ - offset = decode_udp_ip_header(interface->rbuf, - interface->rbuf_offset, from, NULL, hdr.bh_caplen); - - /* If the IP or UDP checksum was bad, skip the packet... */ - if (offset < 0) { - interface->rbuf_offset += hdr.bh_caplen; - continue; - } - interface->rbuf_offset += offset; - hdr.bh_caplen -= offset; - - /* - * If there's not enough room to stash the packet data, - * we have to skip it (this shouldn't happen in real - * life, though). - */ - if (hdr.bh_caplen > len) { - interface->rbuf_offset += hdr.bh_caplen; - continue; - } - - /* Copy out the data in the packet... */ - memcpy(buf, interface->rbuf + interface->rbuf_offset, - hdr.bh_caplen); - interface->rbuf_offset += hdr.bh_caplen; - return (hdr.bh_caplen); - } while (!length); - return (0); -} diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c deleted file mode 100644 index 2777902c7767..000000000000 --- a/sbin/dhclient/clparse.c +++ /dev/null @@ -1,938 +0,0 @@ -/* $OpenBSD: clparse.c,v 1.18 2004/09/15 18:15:18 henning Exp $ */ - -/* Parser for dhclient config and lease files... */ - -/* - * Copyright (c) 1997 The Internet Software Consortium. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include "dhcpd.h" -#include "dhctoken.h" - -struct client_config top_level_config; -struct interface_info *dummy_interfaces; -extern struct interface_info *ifi; - -char client_script_name[] = "/sbin/dhclient-script"; - -/* - * client-conf-file :== client-declarations EOF - * client-declarations :== <nil> - * | client-declaration - * | client-declarations client-declaration - */ -int -read_client_conf(void) -{ - FILE *cfile; - char *val; - int token; - struct client_config *config; - - new_parse(path_dhclient_conf); - - /* Set up the initial dhcp option universe. */ - initialize_universes(); - - /* Initialize the top level client configuration. */ - memset(&top_level_config, 0, sizeof(top_level_config)); - - /* Set some defaults... */ - top_level_config.timeout = 60; - top_level_config.select_interval = 0; - top_level_config.reboot_timeout = 10; - top_level_config.retry_interval = 300; - top_level_config.backoff_cutoff = 15; - top_level_config.initial_interval = 3; - top_level_config.bootp_policy = ACCEPT; - top_level_config.script_name = client_script_name; - top_level_config.requested_options - [top_level_config.requested_option_count++] = DHO_SUBNET_MASK; - top_level_config.requested_options - [top_level_config.requested_option_count++] = DHO_BROADCAST_ADDRESS; - top_level_config.requested_options - [top_level_config.requested_option_count++] = DHO_TIME_OFFSET; - top_level_config.requested_options - [top_level_config.requested_option_count++] = DHO_ROUTERS; - top_level_config.requested_options - [top_level_config.requested_option_count++] = DHO_DOMAIN_NAME; - top_level_config.requested_options - [top_level_config.requested_option_count++] = - DHO_DOMAIN_NAME_SERVERS; - top_level_config.requested_options - [top_level_config.requested_option_count++] = DHO_HOST_NAME; - - if ((cfile = fopen(path_dhclient_conf, "r")) != NULL) { - do { - token = peek_token(&val, cfile); - if (token == EOF) - break; - parse_client_statement(cfile, NULL, &top_level_config); - } while (1); - token = next_token(&val, cfile); /* Clear the peek buffer */ - fclose(cfile); - } - - /* - * Set up state and config structures for clients that don't - * have per-interface configuration declarations. - */ - config = NULL; - if (!ifi->client) { - ifi->client = malloc(sizeof(struct client_state)); - if (!ifi->client) - error("no memory for client state."); - memset(ifi->client, 0, sizeof(*(ifi->client))); - } - if (!ifi->client->config) { - if (!config) { - config = malloc(sizeof(struct client_config)); - if (!config) - error("no memory for client config."); - memcpy(config, &top_level_config, - sizeof(top_level_config)); - } - ifi->client->config = config; - } - - return (!warnings_occurred); -} - -/* - * lease-file :== client-lease-statements EOF - * client-lease-statements :== <nil> - * | client-lease-statements LEASE client-lease-statement - */ -void -read_client_leases(void) -{ - FILE *cfile; - char *val; - int token; - - new_parse(path_dhclient_db); - - /* Open the lease file. If we can't open it, just return - - we can safely trust the server to remember our state. */ - if ((cfile = fopen(path_dhclient_db, "r")) == NULL) - return; - do { - token = next_token(&val, cfile); - if (token == EOF) - break; - if (token != LEASE) { - warning("Corrupt lease file - possible data loss!"); - skip_to_semi(cfile); - break; - } else - parse_client_lease_statement(cfile, 0); - - } while (1); - fclose(cfile); -} - -/* - * client-declaration :== - * SEND option-decl | - * DEFAULT option-decl | - * SUPERSEDE option-decl | - * PREPEND option-decl | - * APPEND option-decl | - * hardware-declaration | - * REQUEST option-list | - * REQUIRE option-list | - * TIMEOUT number | - * RETRY number | - * REBOOT number | - * SELECT_TIMEOUT number | - * SCRIPT string | - * interface-declaration | - * LEASE client-lease-statement | - * ALIAS client-lease-statement - */ -void -parse_client_statement(FILE *cfile, struct interface_info *ip, - struct client_config *config) -{ - int token; - char *val; - struct option *option; - - switch (next_token(&val, cfile)) { - case SEND: - parse_option_decl(cfile, &config->send_options[0]); - return; - case DEFAULT: - option = parse_option_decl(cfile, &config->defaults[0]); - if (option) - config->default_actions[option->code] = ACTION_DEFAULT; - return; - case SUPERSEDE: - option = parse_option_decl(cfile, &config->defaults[0]); - if (option) - config->default_actions[option->code] = - ACTION_SUPERSEDE; - return; - case APPEND: - option = parse_option_decl(cfile, &config->defaults[0]); - if (option) - config->default_actions[option->code] = ACTION_APPEND; - return; - case PREPEND: - option = parse_option_decl(cfile, &config->defaults[0]); - if (option) - config->default_actions[option->code] = ACTION_PREPEND; - return; - case MEDIA: - parse_string_list(cfile, &config->media, 1); - return; - case HARDWARE: - if (ip) - parse_hardware_param(cfile, &ip->hw_address); - else { - parse_warn("hardware address parameter %s", - "not allowed here."); - skip_to_semi(cfile); - } - return; - case REQUEST: - config->requested_option_count = - parse_option_list(cfile, config->requested_options); - return; - case REQUIRE: - memset(config->required_options, 0, - sizeof(config->required_options)); - parse_option_list(cfile, config->required_options); - return; - case TIMEOUT: - parse_lease_time(cfile, &config->timeout); - return; - case RETRY: - parse_lease_time(cfile, &config->retry_interval); - return; - case SELECT_TIMEOUT: - parse_lease_time(cfile, &config->select_interval); - return; - case REBOOT: - parse_lease_time(cfile, &config->reboot_timeout); - return; - case BACKOFF_CUTOFF: - parse_lease_time(cfile, &config->backoff_cutoff); - return; - case INITIAL_INTERVAL: - parse_lease_time(cfile, &config->initial_interval); - return; - case SCRIPT: - config->script_name = parse_string(cfile); - return; - case INTERFACE: - if (ip) - parse_warn("nested interface declaration."); - parse_interface_declaration(cfile, config); - return; - case LEASE: - parse_client_lease_statement(cfile, 1); - return; - case ALIAS: - parse_client_lease_statement(cfile, 2); - return; - case REJECT: - parse_reject_statement(cfile, config); - return; - default: - parse_warn("expecting a statement."); - skip_to_semi(cfile); - break; - } - token = next_token(&val, cfile); - if (token != SEMI) { - parse_warn("semicolon expected."); - skip_to_semi(cfile); - } -} - -int -parse_X(FILE *cfile, u_int8_t *buf, int max) -{ - int token; - char *val; - int len; - - token = peek_token(&val, cfile); - if (token == NUMBER_OR_NAME || token == NUMBER) { - len = 0; - do { - token = next_token(&val, cfile); - if (token != NUMBER && token != NUMBER_OR_NAME) { - parse_warn("expecting hexadecimal constant."); - skip_to_semi(cfile); - return (0); - } - convert_num(&buf[len], val, 16, 8); - if (len++ > max) { - parse_warn("hexadecimal constant too long."); - skip_to_semi(cfile); - return (0); - } - token = peek_token(&val, cfile); - if (token == COLON) - token = next_token(&val, cfile); - } while (token == COLON); - val = (char *)buf; - } else if (token == STRING) { - token = next_token(&val, cfile); - len = strlen(val); - if (len + 1 > max) { - parse_warn("string constant too long."); - skip_to_semi(cfile); - return (0); - } - memcpy(buf, val, len + 1); - } else { - parse_warn("expecting string or hexadecimal data"); - skip_to_semi(cfile); - return (0); - } - return (len); -} - -/* - * option-list :== option_name | - * option_list COMMA option_name - */ -int -parse_option_list(FILE *cfile, u_int8_t *list) -{ - int ix, i; - int token; - char *val; - - ix = 0; - do { - token = next_token(&val, cfile); - if (!is_identifier(token)) { - parse_warn("expected option name."); - skip_to_semi(cfile); - return (0); - } - for (i = 0; i < 256; i++) - if (!strcasecmp(dhcp_options[i].name, val)) - break; - - if (i == 256) { - parse_warn("%s: unexpected option name.", val); - skip_to_semi(cfile); - return (0); - } - list[ix++] = i; - if (ix == 256) { - parse_warn("%s: too many options.", val); - skip_to_semi(cfile); - return (0); - } - token = next_token(&val, cfile); - } while (token == COMMA); - if (token != SEMI) { - parse_warn("expecting semicolon."); - skip_to_semi(cfile); - return (0); - } - return (ix); -} - -/* - * interface-declaration :== - * INTERFACE string LBRACE client-declarations RBRACE - */ -void -parse_interface_declaration(FILE *cfile, struct client_config *outer_config) -{ - int token; - char *val; - struct interface_info *ip; - - token = next_token(&val, cfile); - if (token != STRING) { - parse_warn("expecting interface name (in quotes)."); - skip_to_semi(cfile); - return; - } - - ip = interface_or_dummy(val); - - if (!ip->client) - make_client_state(ip); - - if (!ip->client->config) - make_client_config(ip, outer_config); - - token = next_token(&val, cfile); - if (token != LBRACE) { - parse_warn("expecting left brace."); - skip_to_semi(cfile); - return; - } - - do { - token = peek_token(&val, cfile); - if (token == EOF) { - parse_warn("unterminated interface declaration."); - return; - } - if (token == RBRACE) - break; - parse_client_statement(cfile, ip, ip->client->config); - } while (1); - token = next_token(&val, cfile); -} - -struct interface_info * -interface_or_dummy(char *name) -{ - struct interface_info *ip; - - /* Find the interface (if any) that matches the name. */ - if (!strcmp(ifi->name, name)) - return (ifi); - - /* If it's not a real interface, see if it's on the dummy list. */ - for (ip = dummy_interfaces; ip; ip = ip->next) - if (!strcmp(ip->name, name)) - return (ip); - - /* - * If we didn't find an interface, make a dummy interface as a - * placeholder. - */ - ip = malloc(sizeof(*ip)); - if (!ip) - error("Insufficient memory to record interface %s", name); - memset(ip, 0, sizeof(*ip)); - strlcpy(ip->name, name, IFNAMSIZ); - ip->next = dummy_interfaces; - dummy_interfaces = ip; - return (ip); -} - -void -make_client_state(struct interface_info *ip) -{ - ip->client = malloc(sizeof(*(ip->client))); - if (!ip->client) - error("no memory for state on %s", ip->name); - memset(ip->client, 0, sizeof(*(ip->client))); -} - -void -make_client_config(struct interface_info *ip, struct client_config *config) -{ - ip->client->config = malloc(sizeof(struct client_config)); - if (!ip->client->config) - error("no memory for config for %s", ip->name); - memset(ip->client->config, 0, sizeof(*(ip->client->config))); - memcpy(ip->client->config, config, sizeof(*config)); -} - -/* - * client-lease-statement :== - * RBRACE client-lease-declarations LBRACE - * - * client-lease-declarations :== - * <nil> | - * client-lease-declaration | - * client-lease-declarations client-lease-declaration - */ -void -parse_client_lease_statement(FILE *cfile, int is_static) -{ - struct client_lease *lease, *lp, *pl; - struct interface_info *ip; - int token; - char *val; - - token = next_token(&val, cfile); - if (token != LBRACE) { - parse_warn("expecting left brace."); - skip_to_semi(cfile); - return; - } - - lease = malloc(sizeof(struct client_lease)); - if (!lease) - error("no memory for lease."); - memset(lease, 0, sizeof(*lease)); - lease->is_static = is_static; - - ip = NULL; - - do { - token = peek_token(&val, cfile); - if (token == EOF) { - parse_warn("unterminated lease declaration."); - return; - } - if (token == RBRACE) - break; - parse_client_lease_declaration(cfile, lease, &ip); - } while (1); - token = next_token(&val, cfile); - - /* If the lease declaration didn't include an interface - * declaration that we recognized, it's of no use to us. - */ - if (!ip) { - free_client_lease(lease); - return; - } - - /* Make sure there's a client state structure... */ - if (!ip->client) - make_client_state(ip); - - /* If this is an alias lease, it doesn't need to be sorted in. */ - if (is_static == 2) { - ip->client->alias = lease; - return; - } - - /* - * The new lease may supersede a lease that's not the active - * lease but is still on the lease list, so scan the lease list - * looking for a lease with the same address, and if we find it, - * toss it. - */ - pl = NULL; - for (lp = ip->client->leases; lp; lp = lp->next) { - if (lp->address.len == lease->address.len && - !memcmp(lp->address.iabuf, lease->address.iabuf, - lease->address.len)) { - if (pl) - pl->next = lp->next; - else - ip->client->leases = lp->next; - free_client_lease(lp); - break; - } - } - - /* - * If this is a preloaded lease, just put it on the list of - * recorded leases - don't make it the active lease. - */ - if (is_static) { - lease->next = ip->client->leases; - ip->client->leases = lease; - return; - } - - /* - * The last lease in the lease file on a particular interface is - * the active lease for that interface. Of course, we don't - * know what the last lease in the file is until we've parsed - * the whole file, so at this point, we assume that the lease we - * just parsed is the active lease for its interface. If - * there's already an active lease for the interface, and this - * lease is for the same ip address, then we just toss the old - * active lease and replace it with this one. If this lease is - * for a different address, then if the old active lease has - * expired, we dump it; if not, we put it on the list of leases - * for this interface which are still valid but no longer - * active. - */ - if (ip->client->active) { - if (ip->client->active->expiry < cur_time) - free_client_lease(ip->client->active); - else if (ip->client->active->address.len == - lease->address.len && - !memcmp(ip->client->active->address.iabuf, - lease->address.iabuf, lease->address.len)) - free_client_lease(ip->client->active); - else { - ip->client->active->next = ip->client->leases; - ip->client->leases = ip->client->active; - } - } - ip->client->active = lease; - - /* Phew. */ -} - -/* - * client-lease-declaration :== - * BOOTP | - * INTERFACE string | - * FIXED_ADDR ip_address | - * FILENAME string | - * SERVER_NAME string | - * OPTION option-decl | - * RENEW time-decl | - * REBIND time-decl | - * EXPIRE time-decl - */ -void -parse_client_lease_declaration(FILE *cfile, struct client_lease *lease, - struct interface_info **ipp) -{ - int token; - char *val; - struct interface_info *ip; - - switch (next_token(&val, cfile)) { - case BOOTP: - lease->is_bootp = 1; - break; - case INTERFACE: - token = next_token(&val, cfile); - if (token != STRING) { - parse_warn("expecting interface name (in quotes)."); - skip_to_semi(cfile); - break; - } - ip = interface_or_dummy(val); - *ipp = ip; - break; - case FIXED_ADDR: - if (!parse_ip_addr(cfile, &lease->address)) - return; - break; - case MEDIUM: - parse_string_list(cfile, &lease->medium, 0); - return; - case FILENAME: - lease->filename = parse_string(cfile); - return; - case SERVER_NAME: - lease->server_name = parse_string(cfile); - return; - case RENEW: - lease->renewal = parse_date(cfile); - return; - case REBIND: - lease->rebind = parse_date(cfile); - return; - case EXPIRE: - lease->expiry = parse_date(cfile); - return; - case OPTION: - parse_option_decl(cfile, lease->options); - return; - default: - parse_warn("expecting lease declaration."); - skip_to_semi(cfile); - break; - } - token = next_token(&val, cfile); - if (token != SEMI) { - parse_warn("expecting semicolon."); - skip_to_semi(cfile); - } -} - -struct option * -parse_option_decl(FILE *cfile, struct option_data *options) -{ - char *val; - int token; - u_int8_t buf[4]; - u_int8_t hunkbuf[1024]; - int hunkix = 0; - char *vendor; - char *fmt; - struct universe *universe; - struct option *option; - struct iaddr ip_addr; - u_int8_t *dp; - int len; - int nul_term = 0; - - token = next_token(&val, cfile); - if (!is_identifier(token)) { - parse_warn("expecting identifier after option keyword."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - if ((vendor = strdup(val)) == NULL) - error("no memory for vendor information."); - - token = peek_token(&val, cfile); - if (token == DOT) { - /* Go ahead and take the DOT token... */ - token = next_token(&val, cfile); - - /* The next token should be an identifier... */ - token = next_token(&val, cfile); - if (!is_identifier(token)) { - parse_warn("expecting identifier after '.'"); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - - /* Look up the option name hash table for the specified - vendor. */ - universe = ((struct universe *)hash_lookup(&universe_hash, - (unsigned char *)vendor, 0)); - /* If it's not there, we can't parse the rest of the - declaration. */ - if (!universe) { - parse_warn("no vendor named %s.", vendor); - skip_to_semi(cfile); - return (NULL); - } - } else { - /* Use the default hash table, which contains all the - standard dhcp option names. */ - val = vendor; - universe = &dhcp_universe; - } - - /* Look up the actual option info... */ - option = (struct option *)hash_lookup(universe->hash, - (unsigned char *)val, 0); - - /* If we didn't get an option structure, it's an undefined option. */ - if (!option) { - if (val == vendor) - parse_warn("no option named %s", val); - else - parse_warn("no option named %s for vendor %s", - val, vendor); - skip_to_semi(cfile); - return (NULL); - } - - /* Free the initial identifier token. */ - free(vendor); - - /* Parse the option data... */ - do { - for (fmt = option->format; *fmt; fmt++) { - if (*fmt == 'A') - break; - switch (*fmt) { - case 'X': - len = parse_X(cfile, &hunkbuf[hunkix], - sizeof(hunkbuf) - hunkix); - hunkix += len; - break; - case 't': /* Text string... */ - token = next_token(&val, cfile); - if (token != STRING) { - parse_warn("expecting string."); - skip_to_semi(cfile); - return (NULL); - } - len = strlen(val); - if (hunkix + len + 1 > sizeof(hunkbuf)) { - parse_warn("option data buffer %s", - "overflow"); - skip_to_semi(cfile); - return (NULL); - } - memcpy(&hunkbuf[hunkix], val, len + 1); - nul_term = 1; - hunkix += len; - break; - case 'I': /* IP address. */ - if (!parse_ip_addr(cfile, &ip_addr)) - return (NULL); - len = ip_addr.len; - dp = ip_addr.iabuf; -alloc: - if (hunkix + len > sizeof(hunkbuf)) { - parse_warn("option data buffer " - "overflow"); - skip_to_semi(cfile); - return (NULL); - } - memcpy(&hunkbuf[hunkix], dp, len); - hunkix += len; - break; - case 'L': /* Unsigned 32-bit integer... */ - case 'l': /* Signed 32-bit integer... */ - token = next_token(&val, cfile); - if (token != NUMBER) { -need_number: - parse_warn("expecting number."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - convert_num(buf, val, 0, 32); - len = 4; - dp = buf; - goto alloc; - case 's': /* Signed 16-bit integer. */ - case 'S': /* Unsigned 16-bit integer. */ - token = next_token(&val, cfile); - if (token != NUMBER) - goto need_number; - convert_num(buf, val, 0, 16); - len = 2; - dp = buf; - goto alloc; - case 'b': /* Signed 8-bit integer. */ - case 'B': /* Unsigned 8-bit integer. */ - token = next_token(&val, cfile); - if (token != NUMBER) - goto need_number; - convert_num(buf, val, 0, 8); - len = 1; - dp = buf; - goto alloc; - case 'f': /* Boolean flag. */ - token = next_token(&val, cfile); - if (!is_identifier(token)) { - parse_warn("expecting identifier."); -bad_flag: - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - if (!strcasecmp(val, "true") || - !strcasecmp(val, "on")) - buf[0] = 1; - else if (!strcasecmp(val, "false") || - !strcasecmp(val, "off")) - buf[0] = 0; - else { - parse_warn("expecting boolean."); - goto bad_flag; - } - len = 1; - dp = buf; - goto alloc; - default: - warning("Bad format %c in parse_option_param.", - *fmt); - skip_to_semi(cfile); - return (NULL); - } - } - token = next_token(&val, cfile); - } while (*fmt == 'A' && token == COMMA); - - if (token != SEMI) { - parse_warn("semicolon expected."); - skip_to_semi(cfile); - return (NULL); - } - - options[option->code].data = malloc(hunkix + nul_term); - if (!options[option->code].data) - error("out of memory allocating option data."); - memcpy(options[option->code].data, hunkbuf, hunkix + nul_term); - options[option->code].len = hunkix; - return (option); -} - -void -parse_string_list(FILE *cfile, struct string_list **lp, int multiple) -{ - int token; - char *val; - struct string_list *cur, *tmp; - - /* Find the last medium in the media list. */ - if (*lp) - for (cur = *lp; cur->next; cur = cur->next) - ; /* nothing */ - else - cur = NULL; - - do { - token = next_token(&val, cfile); - if (token != STRING) { - parse_warn("Expecting media options."); - skip_to_semi(cfile); - return; - } - - tmp = new_string_list(strlen(val) + 1); - if (tmp == NULL) - error("no memory for string list entry."); - strlcpy(tmp->string, val, strlen(val) + 1); - tmp->next = NULL; - - /* Store this medium at the end of the media list. */ - if (cur) - cur->next = tmp; - else - *lp = tmp; - cur = tmp; - - token = next_token(&val, cfile); - } while (multiple && token == COMMA); - - if (token != SEMI) { - parse_warn("expecting semicolon."); - skip_to_semi(cfile); - } -} - -void -parse_reject_statement(FILE *cfile, struct client_config *config) -{ - int token; - char *val; - struct iaddr addr; - struct iaddrlist *list; - - do { - if (!parse_ip_addr(cfile, &addr)) { - parse_warn("expecting IP address."); - skip_to_semi(cfile); - return; - } - - list = malloc(sizeof(struct iaddrlist)); - if (!list) - error("no memory for reject list!"); - - list->addr = addr; - list->next = config->reject_list; - config->reject_list = list; - - token = next_token(&val, cfile); - } while (token == COMMA); - - if (token != SEMI) { - parse_warn("expecting semicolon."); - skip_to_semi(cfile); - } -} diff --git a/sbin/dhclient/conflex.c b/sbin/dhclient/conflex.c deleted file mode 100644 index ee96bfeb9ca0..000000000000 --- a/sbin/dhclient/conflex.c +++ /dev/null @@ -1,525 +0,0 @@ -/* $OpenBSD: conflex.c,v 1.7 2004/09/15 19:02:38 deraadt Exp $ */ - -/* Lexical scanner for dhcpd config file... */ - -/* - * Copyright (c) 1995, 1996, 1997 The Internet Software Consortium. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include <ctype.h> - -#include "dhcpd.h" -#include "dhctoken.h" - -int lexline; -int lexchar; -char *token_line; -char *prev_line; -char *cur_line; -char *tlname; -int eol_token; - -static char line1[81]; -static char line2[81]; -static int lpos; -static int line; -static int tlpos; -static int tline; -static int token; -static int ugflag; -static char *tval; -static char tokbuf[1500]; - -static int get_char(FILE *); -static int get_token(FILE *); -static void skip_to_eol(FILE *); -static int read_string(FILE *); -static int read_number(int, FILE *); -static int read_num_or_name(int, FILE *); -static int intern(char *, int); - -void -new_parse(char *name) -{ - tlname = name; - lpos = line = 1; - cur_line = line1; - prev_line = line2; - token_line = cur_line; - cur_line[0] = prev_line[0] = 0; - warnings_occurred = 0; -} - -static int -get_char(FILE *cfile) -{ - int c = getc(cfile); - if (!ugflag) { - if (c == '\n') { - if (cur_line == line1) { - cur_line = line2; - prev_line = line1; - } else { - cur_line = line2; - prev_line = line1; - } - line++; - lpos = 1; - cur_line[0] = 0; - } else if (c != EOF) { - if (lpos <= 81) { - cur_line[lpos - 1] = c; - cur_line[lpos] = 0; - } - lpos++; - } - } else - ugflag = 0; - return (c); -} - -static int -get_token(FILE *cfile) -{ - int c, ttok; - static char tb[2]; - int l, p; - - do { - l = line; - p = lpos; - - c = get_char(cfile); - - if (!(c == '\n' && eol_token) && isascii(c) && isspace(c)) - continue; - if (c == '#') { - skip_to_eol(cfile); - continue; - } - if (c == '"') { - lexline = l; - lexchar = p; - ttok = read_string(cfile); - break; - } - if ((isascii(c) && isdigit(c)) || c == '-') { - lexline = l; - lexchar = p; - ttok = read_number(c, cfile); - break; - } else if (isascii(c) && isalpha(c)) { - lexline = l; - lexchar = p; - ttok = read_num_or_name(c, cfile); - break; - } else { - lexline = l; - lexchar = p; - tb[0] = c; - tb[1] = 0; - tval = tb; - ttok = c; - break; - } - } while (1); - return (ttok); -} - -int -next_token(char **rval, FILE *cfile) -{ - int rv; - - if (token) { - if (lexline != tline) - token_line = cur_line; - lexchar = tlpos; - lexline = tline; - rv = token; - token = 0; - } else { - rv = get_token(cfile); - token_line = cur_line; - } - if (rval) - *rval = tval; - - return (rv); -} - -int -peek_token(char **rval, FILE *cfile) -{ - int x; - - if (!token) { - tlpos = lexchar; - tline = lexline; - token = get_token(cfile); - if (lexline != tline) - token_line = prev_line; - x = lexchar; - lexchar = tlpos; - tlpos = x; - x = lexline; - lexline = tline; - tline = x; - } - if (rval) - *rval = tval; - - return (token); -} - -static void -skip_to_eol(FILE *cfile) -{ - int c; - - do { - c = get_char(cfile); - if (c == EOF) - return; - if (c == '\n') - return; - } while (1); -} - -static int -read_string(FILE *cfile) -{ - int i, c, bs = 0; - - for (i = 0; i < sizeof(tokbuf); i++) { - c = get_char(cfile); - if (c == EOF) { - parse_warn("eof in string constant"); - break; - } - if (bs) { - bs = 0; - tokbuf[i] = c; - } else if (c == '\\') - bs = 1; - else if (c == '"') - break; - else - tokbuf[i] = c; - } - /* - * Normally, I'd feel guilty about this, but we're talking about - * strings that'll fit in a DHCP packet here... - */ - if (i == sizeof(tokbuf)) { - parse_warn("string constant larger than internal buffer"); - i--; - } - tokbuf[i] = 0; - tval = tokbuf; - return (STRING); -} - -static int -read_number(int c, FILE *cfile) -{ - int seenx = 0, i = 0, token = NUMBER; - - tokbuf[i++] = c; - for (; i < sizeof(tokbuf); i++) { - c = get_char(cfile); - if (!seenx && c == 'x') - seenx = 1; - else if (!isascii(c) || !isxdigit(c)) { - ungetc(c, cfile); - ugflag = 1; - break; - } - tokbuf[i] = c; - } - if (i == sizeof(tokbuf)) { - parse_warn("numeric token larger than internal buffer"); - i--; - } - tokbuf[i] = 0; - tval = tokbuf; - - return (token); -} - -static int -read_num_or_name(int c, FILE *cfile) -{ - int i = 0; - int rv = NUMBER_OR_NAME; - - tokbuf[i++] = c; - for (; i < sizeof(tokbuf); i++) { - c = get_char(cfile); - if (!isascii(c) || (c != '-' && c != '_' && !isalnum(c))) { - ungetc(c, cfile); - ugflag = 1; - break; - } - if (!isxdigit(c)) - rv = NAME; - tokbuf[i] = c; - } - if (i == sizeof(tokbuf)) { - parse_warn("token larger than internal buffer"); - i--; - } - tokbuf[i] = 0; - tval = tokbuf; - - return (intern(tval, rv)); -} - -static int -intern(char *atom, int dfv) -{ - if (!isascii(atom[0])) - return (dfv); - - switch (tolower(atom[0])) { - case 'a': - if (!strcasecmp(atom + 1, "lways-reply-rfc1048")) - return (ALWAYS_REPLY_RFC1048); - if (!strcasecmp(atom + 1, "ppend")) - return (APPEND); - if (!strcasecmp(atom + 1, "llow")) - return (ALLOW); - if (!strcasecmp(atom + 1, "lias")) - return (ALIAS); - if (!strcasecmp(atom + 1, "bandoned")) - return (ABANDONED); - if (!strcasecmp(atom + 1, "uthoritative")) - return (AUTHORITATIVE); - break; - case 'b': - if (!strcasecmp(atom + 1, "ackoff-cutoff")) - return (BACKOFF_CUTOFF); - if (!strcasecmp(atom + 1, "ootp")) - return (BOOTP); - if (!strcasecmp(atom + 1, "ooting")) - return (BOOTING); - if (!strcasecmp(atom + 1, "oot-unknown-clients")) - return (BOOT_UNKNOWN_CLIENTS); - case 'c': - if (!strcasecmp(atom + 1, "lass")) - return (CLASS); - if (!strcasecmp(atom + 1, "iaddr")) - return (CIADDR); - if (!strcasecmp(atom + 1, "lient-identifier")) - return (CLIENT_IDENTIFIER); - if (!strcasecmp(atom + 1, "lient-hostname")) - return (CLIENT_HOSTNAME); - break; - case 'd': - if (!strcasecmp(atom + 1, "omain")) - return (DOMAIN); - if (!strcasecmp(atom + 1, "eny")) - return (DENY); - if (!strncasecmp(atom + 1, "efault", 6)) { - if (!atom[7]) - return (DEFAULT); - if (!strcasecmp(atom + 7, "-lease-time")) - return (DEFAULT_LEASE_TIME); - break; - } - if (!strncasecmp(atom + 1, "ynamic-bootp", 12)) { - if (!atom[13]) - return (DYNAMIC_BOOTP); - if (!strcasecmp(atom + 13, "-lease-cutoff")) - return (DYNAMIC_BOOTP_LEASE_CUTOFF); - if (!strcasecmp(atom + 13, "-lease-length")) - return (DYNAMIC_BOOTP_LEASE_LENGTH); - break; - } - break; - case 'e': - if (!strcasecmp(atom + 1, "thernet")) - return (ETHERNET); - if (!strcasecmp(atom + 1, "nds")) - return (ENDS); - if (!strcasecmp(atom + 1, "xpire")) - return (EXPIRE); - break; - case 'f': - if (!strcasecmp(atom + 1, "ilename")) - return (FILENAME); - if (!strcasecmp(atom + 1, "ixed-address")) - return (FIXED_ADDR); - if (!strcasecmp(atom + 1, "ddi")) - return (FDDI); - break; - case 'g': - if (!strcasecmp(atom + 1, "iaddr")) - return (GIADDR); - if (!strcasecmp(atom + 1, "roup")) - return (GROUP); - if (!strcasecmp(atom + 1, "et-lease-hostnames")) - return (GET_LEASE_HOSTNAMES); - break; - case 'h': - if (!strcasecmp(atom + 1, "ost")) - return (HOST); - if (!strcasecmp(atom + 1, "ardware")) - return (HARDWARE); - if (!strcasecmp(atom + 1, "ostname")) - return (HOSTNAME); - break; - case 'i': - if (!strcasecmp(atom + 1, "nitial-interval")) - return (INITIAL_INTERVAL); - if (!strcasecmp(atom + 1, "nterface")) - return (INTERFACE); - break; - case 'l': - if (!strcasecmp(atom + 1, "ease")) - return (LEASE); - break; - case 'm': - if (!strcasecmp(atom + 1, "ax-lease-time")) - return (MAX_LEASE_TIME); - if (!strncasecmp(atom + 1, "edi", 3)) { - if (!strcasecmp(atom + 4, "a")) - return (MEDIA); - if (!strcasecmp(atom + 4, "um")) - return (MEDIUM); - break; - } - break; - case 'n': - if (!strcasecmp(atom + 1, "ameserver")) - return (NAMESERVER); - if (!strcasecmp(atom + 1, "etmask")) - return (NETMASK); - if (!strcasecmp(atom + 1, "ext-server")) - return (NEXT_SERVER); - if (!strcasecmp(atom + 1, "ot")) - return (TOKEN_NOT); - break; - case 'o': - if (!strcasecmp(atom + 1, "ption")) - return (OPTION); - if (!strcasecmp(atom + 1, "ne-lease-per-client")) - return (ONE_LEASE_PER_CLIENT); - break; - case 'p': - if (!strcasecmp(atom + 1, "repend")) - return (PREPEND); - if (!strcasecmp(atom + 1, "acket")) - return (PACKET); - break; - case 'r': - if (!strcasecmp(atom + 1, "ange")) - return (RANGE); - if (!strcasecmp(atom + 1, "equest")) - return (REQUEST); - if (!strcasecmp(atom + 1, "equire")) - return (REQUIRE); - if (!strcasecmp(atom + 1, "etry")) - return (RETRY); - if (!strcasecmp(atom + 1, "enew")) - return (RENEW); - if (!strcasecmp(atom + 1, "ebind")) - return (REBIND); - if (!strcasecmp(atom + 1, "eboot")) - return (REBOOT); - if (!strcasecmp(atom + 1, "eject")) - return (REJECT); - break; - case 's': - if (!strcasecmp(atom + 1, "earch")) - return (SEARCH); - if (!strcasecmp(atom + 1, "tarts")) - return (STARTS); - if (!strcasecmp(atom + 1, "iaddr")) - return (SIADDR); - if (!strcasecmp(atom + 1, "ubnet")) - return (SUBNET); - if (!strcasecmp(atom + 1, "hared-network")) - return (SHARED_NETWORK); - if (!strcasecmp(atom + 1, "erver-name")) - return (SERVER_NAME); - if (!strcasecmp(atom + 1, "erver-identifier")) - return (SERVER_IDENTIFIER); - if (!strcasecmp(atom + 1, "elect-timeout")) - return (SELECT_TIMEOUT); - if (!strcasecmp(atom + 1, "end")) - return (SEND); - if (!strcasecmp(atom + 1, "cript")) - return (SCRIPT); - if (!strcasecmp(atom + 1, "upersede")) - return (SUPERSEDE); - break; - case 't': - if (!strcasecmp(atom + 1, "imestamp")) - return (TIMESTAMP); - if (!strcasecmp(atom + 1, "imeout")) - return (TIMEOUT); - if (!strcasecmp(atom + 1, "oken-ring")) - return (TOKEN_RING); - break; - case 'u': - if (!strncasecmp(atom + 1, "se", 2)) { - if (!strcasecmp(atom + 3, "r-class")) - return (USER_CLASS); - if (!strcasecmp(atom + 3, "-host-decl-names")) - return (USE_HOST_DECL_NAMES); - if (!strcasecmp(atom + 3, - "-lease-addr-for-default-route")) - return (USE_LEASE_ADDR_FOR_DEFAULT_ROUTE); - break; - } - if (!strcasecmp(atom + 1, "id")) - return (UID); - if (!strcasecmp(atom + 1, "nknown-clients")) - return (UNKNOWN_CLIENTS); - break; - case 'v': - if (!strcasecmp(atom + 1, "endor-class")) - return (VENDOR_CLASS); - break; - case 'y': - if (!strcasecmp(atom + 1, "iaddr")) - return (YIADDR); - break; - } - return (dfv); -} diff --git a/sbin/dhclient/convert.c b/sbin/dhclient/convert.c deleted file mode 100644 index 0626dc4b3a8e..000000000000 --- a/sbin/dhclient/convert.c +++ /dev/null @@ -1,114 +0,0 @@ -/* $OpenBSD: convert.c,v 1.5 2004/02/07 11:35:59 henning Exp $ */ - -/* - * Safe copying of option values into and out of the option buffer, - * which can't be assumed to be aligned. - */ - -/* - * Copyright (c) 1995, 1996 The Internet Software Consortium. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include "dhcpd.h" - -u_int32_t -getULong(unsigned char *buf) -{ - u_int32_t ibuf; - - memcpy(&ibuf, buf, sizeof(ibuf)); - return (ntohl(ibuf)); -} - -int32_t -getLong(unsigned char *(buf)) -{ - int32_t ibuf; - - memcpy(&ibuf, buf, sizeof(ibuf)); - return (ntohl(ibuf)); -} - -u_int16_t -getUShort(unsigned char *buf) -{ - u_int16_t ibuf; - - memcpy(&ibuf, buf, sizeof(ibuf)); - return (ntohs(ibuf)); -} - -int16_t -getShort(unsigned char *buf) -{ - int16_t ibuf; - - memcpy(&ibuf, buf, sizeof(ibuf)); - return (ntohs(ibuf)); -} - -void -putULong(unsigned char *obuf, u_int32_t val) -{ - u_int32_t tmp = htonl(val); - - memcpy(obuf, &tmp, sizeof(tmp)); -} - -void -putLong(unsigned char *obuf, int32_t val) -{ - int32_t tmp = htonl(val); - - memcpy(obuf, &tmp, sizeof(tmp)); -} - -void -putUShort(unsigned char *obuf, unsigned int val) -{ - u_int16_t tmp = htons(val); - - memcpy(obuf, &tmp, sizeof(tmp)); -} - -void -putShort(unsigned char *obuf, int val) -{ - int16_t tmp = htons(val); - - memcpy(obuf, &tmp, sizeof(tmp)); -} diff --git a/sbin/dhclient/dhclient-script b/sbin/dhclient/dhclient-script deleted file mode 100644 index 3a6ac1877f0c..000000000000 --- a/sbin/dhclient/dhclient-script +++ /dev/null @@ -1,227 +0,0 @@ -#!/bin/sh -# -# $OpenBSD: dhclient-script,v 1.6 2004/05/06 18:22:41 claudio Exp $ -# -# Copyright (c) 2003 Kenneth R Westerback <krw@openbsd.org> -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# -# - -# -# Helper functions that implement common actions. -# - -delete_old_address() { - if [ -n "$old_ip_address" ]; then - ifconfig $interface inet -alias $old_ip_address $medium - route delete "$old_ip_address" 127.0.0.1 >/dev/null 2>&1 - fi -} - -add_new_address() { - ifconfig $interface \ - inet $new_ip_address \ - netmask $new_subnet_mask \ - broadcast $new_broadcast_address \ - $medium - - # XXX Original TIMEOUT code did not do this unless $new_routers was set? - route add $new_ip_address 127.0.0.1 >/dev/null 2>&1 -} - -delete_old_alias() { - if [ -n "$alias_ip_address" ]; then - ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1 - route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 - fi -} - -add_new_alias() { - if [ -n "$alias_ip_address" ]; then - ifconfig $interface inet alias $alias_ip_address netmask \ - $alias_subnet_mask - route add $alias_ip_address 127.0.0.1 - fi -} - -delete_old_routes() { - # Delete existing default route. We only allow one, so no need to - # process $old_routers list. - route delete default >/dev/null 2>&1 - - if [ -n "$old_static_routes" ]; then - set $old_static_routes - while [ $# -gt 1 ]; do - route delete "$1" "$2" - shift; shift - done - fi - - arp -dan -} - -add_new_routes() { - route delete default >/dev/null 2>&1 - for router in $new_routers; do - if [ "$new_ip_address" = "$router" ]; then - route add default -iface $router >/dev/null 2>&1 - else - route add default $router >/dev/null 2>&1 - fi - # 2nd and subsequent default routers error out, so explicitly - # stop processing the list after the first one. - break - done - - if [ -n "$new_static_routes" ]; then - set $new_static_routes - while [ $# -gt 1 ]; do - route add $1 $2 - shift; shift - done - fi -} - -add_new_resolv_conf() { - # XXX Old code did not create/update resolv.conf unless both - # $new_domain_name and $new_domain_name_servers were provided. PR - # #3135 reported some ISP's only provide $new_domain_name_servers and - # thus broke the script. This code creates the resolv.conf if either - # are provided. - - rm -f /etc/resolv.conf.std - - if [ -n "$new_domain_name" ]; then - echo "search $new_domain_name" >>/etc/resolv.conf.std - fi - - if [ -n "$new_domain_name_servers" ]; then - for nameserver in $new_domain_name_servers; do - echo "nameserver $nameserver" >>/etc/resolv.conf.std - done - fi - - if [ -f /etc/resolv.conf.std ]; then - if [ -f /etc/resolv.conf.tail ]; then - cat /etc/resolv.conf.tail >>/etc/resolv.conf.std - fi - - # In case (e.g. during OpenBSD installs) /etc/resolv.conf - # is a symbolic link, take care to preserve the link and write - # the new data in the correct location. - - if [ -f /etc/resolv.conf ]; then - cat /etc/resolv.conf > /etc/resolv.conf.save - fi - cat /etc/resolv.conf.std > /etc/resolv.conf - rm -f /etc/resolv.conf.std - - # Try to ensure correct ownership and permissions. - chown -RL root:wheel /etc/resolv.conf - chmod -RL 644 /etc/resolv.conf - - return 0 - fi - - return 1 -} - -# -# Start of active code. -# - -if [ -n "$new_network_number" ]; then - echo "New Network Number: $new_network_number" -fi - -if [ -n "$new_broadcast_address" ]; then - echo "New Broadcast Address: $new_broadcast_address" -fi - -case $reason in -MEDIUM) - ifconfig $interface $medium - ifconfig $interface inet -alias 0.0.0.0 $medium >/dev/null 2>&1 - sleep 1 - ;; - -PREINIT) - delete_old_alias - ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 broadcast 255.255.255.255 up - ;; - -ARPCHECK|ARPSEND) - ;; - -BOUND|RENEW|REBIND|REBOOT) - if [ -n "$old_ip_address" ]; then - if [ "$old_ip_address" != "$alias_ip_address" ]; then - delete_old_alias - fi - if [ "$old_ip_address" != "$new_ip_address" ]; then - delete_old_address - delete_old_routes - fi - fi - if [ "$reason" = BOUND ] || \ - [ "$reason" = REBOOT ] || \ - [ -z "$old_ip_address" ] || \ - [ "$old_ip_address" != "$new_ip_address" ]; then - add_new_address - add_new_routes - fi - if [ "$new_ip_address" != "$alias_ip_address" ]; then - add_new_alias - fi - add_new_resolv_conf - ;; - -EXPIRE|FAIL) - delete_old_alias - if [ -n "$old_ip_address" ]; then - delete_old_address - delete_old_routes - fi - # XXX Why add alias we just deleted above? - add_new_alias - if [ -f /etc/resolv.conf.save ]; then - cat /etc/resolv.conf.save > /etc/resolv.conf - fi - ;; - -TIMEOUT) - delete_old_alias - add_new_address - sleep 1 - if [ -n "$new_routers" ]; then - set "$new_routers" - if ping -q -c 1 -w 1 "$1"; then - if [ "$new_ip_address" != "$alias_ip_address" ]; then - add_new_alias - fi - add_new_routes - if add_new_resolv_conf; then - exit 0 - fi - fi - fi - ifconfig $interface inet -alias $new_ip_address $medium - # XXX Why not a delete_old_address as before all other invocations of - # delete_old_routes? - delete_old_routes - exit 1 - ;; -esac - -exit 0 diff --git a/sbin/dhclient/dhclient-script.8 b/sbin/dhclient/dhclient-script.8 deleted file mode 100644 index 57a2abdc54ef..000000000000 --- a/sbin/dhclient/dhclient-script.8 +++ /dev/null @@ -1,246 +0,0 @@ -.\" $OpenBSD: dhclient-script.8,v 1.2 2004/04/09 18:30:15 jmc Exp $ -.\" -.\" Copyright (c) 1997 The Internet Software Consortium. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. -.\" -.\" This software has been written for the Internet Software Consortium -.\" by Ted Lemon <mellon@fugue.com> in cooperation with Vixie -.\" Enterprises. To learn more about the Internet Software Consortium, -.\" see ``http://www.isc.org/isc''. To learn more about Vixie -.\" Enterprises, see ``http://www.vix.com''. -.\" -.Dd January 1, 1997 -.Dt DHCLIENT-SCRIPT 8 -.Os -.Sh NAME -.Nm dhclient-script -.Nd DHCP client network configuration script -.Sh DESCRIPTION -The DHCP client network configuration script is invoked from time to -time by -.Xr dhclient 8 . -This script is used by the DHCP client to set each interface's initial -configuration prior to requesting an address, to test the address once it -has been offered, and to set the interface's final configuration once a -lease has been acquired. -If no lease is acquired, the script is used to test predefined leases, if -any, and also called once if no valid lease can be identified. -.Pp -.\" No standard client script exists for some operating systems, even though -.\" the actual client may work, so a pioneering user may well need to create -.\" a new script or modify an existing one. -In general, customizations specific to a particular computer should be done -in the -.Pa /etc/dhclient.conf -file. -.Sh OPERATION -When -.Xr dhclient 8 -needs to invoke the client configuration script, it sets up a number of -environment variables and runs -.Nm dhclient-script . -In all cases, -.Va $reason -is set to the name of the reason why the script has been invoked. -The following reasons are currently defined: -MEDIUM, PREINIT, ARPCHECK, ARPSEND, BOUND, RENEW, REBIND, REBOOT, -EXPIRE, FAIL and TIMEOUT. -.Bl -tag -width "ARPCHECK" -.It MEDIUM -The DHCP client is requesting that an interface's media type be set. -The interface name is passed in -.Va $interface , -and the media type is passed in -.Va $medium . -.It PREINIT -The DHCP client is requesting that an interface be configured as -required in order to send packets prior to receiving an actual address. -.\" For clients which use the BSD socket library, -This means configuring the interface with an IP address of 0.0.0.0 -and a broadcast address of 255.255.255.255. -.\" For other clients, it may be possible to simply configure the interface up -.\" without actually giving it an IP address at all. -The interface name is passed in -.Va $interface , -and the media type in -.Va $medium . -.Pp -If an IP alias has been declared in -.Xr dhclient.conf 5 , -its address will be passed in -.Va $alias_ip_address , -and that IP alias should be deleted from the interface, -along with any routes to it. -.It ARPSEND -The DHCP client is requesting that an address that has been offered to -it be checked to see if somebody else is using it, by sending an ARP -request for that address. -It's not clear how to implement this, so no examples exist yet. -The IP address to check is passed in -.Va $new_ip_address , -and the interface name is passed in -.Va $interface . -.It ARPCHECK -The DHCP client wants to know if a response to the ARP request sent -using ARPSEND has been received. -If one has, the script should exit with a nonzero status, indicating that -the offered address has already been requested and should be declined. -.Va $new_ip_address -and -.Va $interface -are set as with ARPSEND. -.It BOUND -The DHCP client has done an initial binding to a new address. -The new IP address is passed in -.Va $new_ip_address , -and the interface name is passed in -.Va $interface . -The media type is passed in -.Va $medium . -Any options acquired from the server are passed using the option name -described in -.Xr dhcp-options 5 , -except that dashes -.Pq Sq - -are replaced by underscores -.Pq Sq _ -in order to make valid shell variables, and the variable names start with new_. -So for example, the new subnet mask would be passed in -.Va $new_subnet_mask . -.Pp -When a binding has been completed, a lot of network parameters are -likely to need to be set up. -A new -.Pa /etc/resolv.conf -needs to be created, using the values of -.Va $new_domain_name -and -.Va $new_domain_name_servers -(which may list more than one server, separated by spaces). -A default route should be set using -.Va $new_routers , -and static routes may need to be set up using -.Va $new_static_routes . -.Pp -If an IP alias has been declared, it must be set up here. -The alias IP address will be written as -.Va $alias_ip_address , -and other DHCP options that are set for the alias (e.g., subnet mask) -will be passed in variables named as described previously except starting with -$alias_ instead of $new_. -Care should be taken that the alias IP address not be used if it is identical -to the bound IP address -.Pq Va $new_ip_address , -since the other alias parameters may be incorrect in this case. -.It RENEW -When a binding has been renewed, the script is called as in BOUND, -except that in addition to all the variables starting with $new_, -there is another set of variables starting with $old_. -Persistent settings that may have changed need to be deleted \- for example, -if a local route to the bound address is being configured, the old local -route should be deleted. -If the default route has changed, the old default route should be deleted. -If the static routes have changed, the old ones should be deleted. -Otherwise, processing can be done as with BOUND. -.It REBIND -The DHCP client has rebound to a new DHCP server. -This can be handled as with RENEW, except that if the IP address has changed, -the ARP table should be cleared. -.It REBOOT -The DHCP client has successfully reacquired its old address after a reboot. -This can be processed as with BOUND. -.It EXPIRE -The DHCP client has failed to renew its lease or acquire a new one, -and the lease has expired. -The IP address must be relinquished, and all related parameters should be -deleted, as in RENEW and REBIND. -.It FAIL -The DHCP client has been unable to contact any DHCP servers, and any -leases that have been tested have not proved to be valid. -The parameters from the last lease tested should be deconfigured. -This can be handled in the same way as EXPIRE. -.It TIMEOUT -The DHCP client has been unable to contact any DHCP servers. -However, an old lease has been identified, and its parameters have -been passed in as with BOUND. -The client configuration script should test these parameters and, -if it has reason to believe they are valid, should exit with a value of zero. -If not, it should exit with a nonzero value. -.El -.Pp -The usual way to test a lease is to set up the network as with REBIND -(since this may be called to test more than one lease) and then ping -the first router defined in -.Va $routers . -If a response is received, the lease must be valid for the network to -which the interface is currently connected. -It would be more complete to try to ping all of the routers listed in -.Va $new_routers , -as well as those listed in -.Va $new_static_routes , -but current scripts do not do this. -.\" .Sh FILES -.\" Each operating system should generally have its own script file, -.\" although the script files for similar operating systems may be similar -.\" or even identical. -.\" The script files included in the Internet Software Consortium DHCP -.\" distribution appear in the distribution tree under client/scripts, -.\" and bear the names of the operating systems on which they are intended -.\" to work. -.Sh SEE ALSO -.Xr dhclient.conf 5 , -.Xr dhclient.leases 5 , -.Xr dhclient 8 , -.Xr dhcpd 8 , -.Xr dhcrelay 8 -.Sh AUTHORS -The original version of -.Nm -was written for the Internet Software Consortium by -.An Ted Lemon Aq mellon@fugue.com -in cooperation with Vixie Enterprises. -.Pp -The -.Ox -implementation of -.Nm -was written by -.An Kenneth R. Westerback Aq krw@openbsd.org . -.Sh BUGS -If more than one interface is being used, there's no obvious way to -avoid clashes between server-supplied configuration parameters \- for -example, the stock dhclient-script rewrites -.Pa /etc/resolv.conf . -If more than one interface is being configured, -.Pa /etc/resolv.conf -will be repeatedly initialized to the values provided by one server, and then -the other. -Assuming the information provided by both servers is valid, this shouldn't -cause any real problems, but it could be confusing. diff --git a/sbin/dhclient/dhclient.8 b/sbin/dhclient/dhclient.8 deleted file mode 100644 index a12952f48d8c..000000000000 --- a/sbin/dhclient/dhclient.8 +++ /dev/null @@ -1,181 +0,0 @@ -.\" $OpenBSD: dhclient.8,v 1.3 2004/04/09 18:30:15 jmc Exp $ -.\" -.\" Copyright (c) 1997 The Internet Software Consortium. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. -.\" -.\" This software has been written for the Internet Software Consortium -.\" by Ted Lemon <mellon@fugue.com> in cooperation with Vixie -.\" Enterprises. To learn more about the Internet Software Consortium, -.\" see ``http://www.isc.org/isc''. To learn more about Vixie -.\" Enterprises, see ``http://www.vix.com''. -.Dd April 7, 2004 -.Dt DHCLIENT 8 -.Os -.Sh NAME -.Nm dhclient -.Nd Dynamic Host Configuration Protocol (DHCP) Client -.Sh SYNOPSIS -.Nm -.Op Fl dqu -.Op Fl c Ar file -.Op Fl l Ar file -.Ar interface -.Sh DESCRIPTION -The -.Nm -utility provides a means for configuring network interfaces using DHCP, BOOTP, -or if these protocols fail, by statically assigning an address. -.Pp -The name of the network interface that -.Nm -should attempt to -configure must be specified on the command line. -.Pp -The options are as follows: -.Bl -tag -width "-p port" -.It Fl c Ar file -Specify an alternate location, -.Ar file , -for the configuration file. -.It Fl d -Forces -.Nm -to always run as a foreground process. -By default, -.Nm -runs in the foreground until it has configured the interface, and then -will revert to running in the background. -.It Fl l Ar file -Specify an alternate location, -.Ar file , -for the leases file. -.It Fl q -Forces -.Nm -to be less verbose on startup. -.It Fl u -Forces -.Nm -to reject leases with unknown options in them. -The default behaviour is to accept such lease offers. -.El -.Pp -The DHCP protocol allows a host to contact a central server which -maintains a list of IP addresses which may be assigned on one or more -subnets. -A DHCP client may request an address from this pool, and -then use it on a temporary basis for communication on the network. -The DHCP protocol also provides a mechanism whereby a client can learn -important details about the network to which it is attached, such as -the location of a default router, the location of a name server, and -so on. -.Pp -On startup, -.Nm -reads -.Pa /etc/dhclient.conf -for configuration instructions. -It then gets a list of all the -network interfaces that are configured in the current system. -It then attempts to configure each interface with DHCP. -.Pp -In order to keep track of leases across system reboots and server -restarts, -.Nm -keeps a list of leases it has been assigned in the -.Pa /var/db/dhclient.leases.IFNAME -file. -.Qq IFNAME -represents the network interface of the DHCP client -.Pq e.g. em0 , -one for each interface. -On startup, after reading the -.Xr dhclient.conf 5 -file, -.Nm -reads the leases file to refresh its memory about what leases it has been -assigned. -.Pp -Old leases are kept around in case the DHCP server is unavailable when -.Nm -is first invoked (generally during the initial system boot -process). -In that event, old leases from the -.Pa dhclient.leases.IFNAME -file which have not yet expired are tested, and if they are determined to -be valid, they are used until either they expire or the DHCP server -becomes available. -.Pp -A mobile host which may sometimes need to access a network on which no -DHCP server exists may be preloaded with a lease for a fixed -address on that network. -When all attempts to contact a DHCP server have failed, -.Nm -will try to validate the static lease, and if it -succeeds, it will use that lease until it is restarted. -.Pp -A mobile host may also travel to some networks on which DHCP is not -available but BOOTP is. -In that case, it may be advantageous to -arrange with the network administrator for an entry on the BOOTP -database, so that the host can boot quickly on that network rather -than cycling through the list of old leases. -.Sh NOTES -You must have the Berkeley Packet Filter (BPF) configured in your kernel. -.Nm -requires at least one -.Pa /dev/bpf* -file for each broadcast network interface that is attached to your system. -See -.Xr bpf 4 -for more information. -.Sh FILES -.Bl -tag -width /var/db/dhclient.leases.IFNAME~ -compact -.It Pa /etc/dhclient.conf -DHCP client configuration file -.It Pa /var/db/dhclient.leases.IFNAME -database of acquired leases -.El -.Sh SEE ALSO -.Xr dhclient.conf 5 , -.Xr dhclient.leases 5 , -.Xr dhclient-script 8 , -.Xr dhcp 8 , -.Xr dhcpd 8 , -.Xr dhcrelay 8 -.Sh AUTHORS -.Nm -was written by -.An Ted Lemon Aq mellon@fugue.com -and -.An Elliot Poger Aq elliot@poger.com . -.Pp -The current implementation was reworked by -.An Henning Brauer Aq henning@openbsd.org . diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c deleted file mode 100644 index ef353c43724d..000000000000 --- a/sbin/dhclient/dhclient.c +++ /dev/null @@ -1,2373 +0,0 @@ -/* $OpenBSD: dhclient.c,v 1.63 2005/02/06 17:10:13 krw Exp $ */ - -/* - * Copyright 2004 Henning Brauer <henning@openbsd.org> - * Copyright (c) 1995, 1996, 1997, 1998, 1999 - * The Internet Software Consortium. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - * - * This client was substantially modified and enhanced by Elliot Poger - * for use on Linux while he was working on the MosquitoNet project at - * Stanford. - * - * The current version owes much to Elliot's Linux enhancements, but - * was substantially reorganized and partially rewritten by Ted Lemon - * so as to use the same networking framework that the Internet Software - * Consortium DHCP server uses. Much system-specific configuration code - * was moved into a shell script so that as support for more operating - * systems is added, it will not be necessary to port and maintain - * system-specific configuration code to these operating systems - instead, - * the shell script can invoke the native tools to accomplish the same - * purpose. - */ - -#include "dhcpd.h" -#include "privsep.h" - -#define PERIOD 0x2e -#define hyphenchar(c) ((c) == 0x2d) -#define bslashchar(c) ((c) == 0x5c) -#define periodchar(c) ((c) == PERIOD) -#define asterchar(c) ((c) == 0x2a) -#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) || \ - ((c) >= 0x61 && (c) <= 0x7a)) -#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39) - -#define borderchar(c) (alphachar(c) || digitchar(c)) -#define middlechar(c) (borderchar(c) || hyphenchar(c)) -#define domainchar(c) ((c) > 0x20 && (c) < 0x7f) - -#define CLIENT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin" - -time_t cur_time; -time_t default_lease_time = 43200; /* 12 hours... */ - -char *path_dhclient_conf = _PATH_DHCLIENT_CONF; -char *path_dhclient_db = NULL; - -int log_perror = 1; -int privfd; -int nullfd = -1; - -struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } }; -struct in_addr inaddr_any; -struct sockaddr_in sockaddr_broadcast; - -/* - * ASSERT_STATE() does nothing now; it used to be - * assert (state_is == state_shouldbe). - */ -#define ASSERT_STATE(state_is, state_shouldbe) {} - -#define TIME_MAX 2147483647 - -int log_priority; -int no_daemon; -int unknown_ok = 1; -int routefd; - -struct interface_info *ifi; - -int findproto(char *, int); -struct sockaddr *get_ifa(char *, int); -void routehandler(struct protocol *); -void usage(void); -int check_option(struct client_lease *l, int option); -int ipv4addrs(char * buf); -int res_hnok(const char *dn); -char *option_as_string(unsigned int code, unsigned char *data, int len); -int fork_privchld(int, int); - -#define ROUNDUP(a) \ - ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) -#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) - -time_t scripttime; - -int -findproto(char *cp, int n) -{ - struct sockaddr *sa; - int i; - - if (n == 0) - return -1; - for (i = 1; i; i <<= 1) { - if (i & n) { - sa = (struct sockaddr *)cp; - switch (i) { - case RTA_IFA: - case RTA_DST: - case RTA_GATEWAY: - case RTA_NETMASK: - if (sa->sa_family == AF_INET) - return AF_INET; - if (sa->sa_family == AF_INET6) - return AF_INET6; - break; - case RTA_IFP: - break; - } - ADVANCE(cp, sa); - } - } - return (-1); -} - -struct sockaddr * -get_ifa(char *cp, int n) -{ - struct sockaddr *sa; - int i; - - if (n == 0) - return (NULL); - for (i = 1; i; i <<= 1) - if (i & n) { - sa = (struct sockaddr *)cp; - if (i == RTA_IFA) - return (sa); - ADVANCE(cp, sa); - } - - return (NULL); -} -struct iaddr defaddr = { 4 }; - -/* ARGSUSED */ -void -routehandler(struct protocol *p) -{ - char msg[2048]; - struct rt_msghdr *rtm; - struct if_msghdr *ifm; - struct ifa_msghdr *ifam; - struct if_announcemsghdr *ifan; - struct client_lease *l; - time_t t = time(NULL); - struct sockaddr *sa; - struct iaddr a; - ssize_t n; - - n = read(routefd, &msg, sizeof(msg)); - rtm = (struct rt_msghdr *)msg; - if (n < sizeof(rtm->rtm_msglen) || n < rtm->rtm_msglen || - rtm->rtm_version != RTM_VERSION) - return; - - switch (rtm->rtm_type) { - case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)rtm; - if (ifam->ifam_index != ifi->index) - break; - if (findproto((char *)(ifam + 1), ifam->ifam_addrs) != AF_INET) - break; - if (ifi == NULL) - goto die; - sa = get_ifa((char *)(ifam + 1), ifam->ifam_addrs); - if (sa == NULL) - goto die; - - if ((a.len = sizeof(struct in_addr)) > sizeof(a.iabuf)) - error("king bula sez: len mismatch"); - memcpy(a.iabuf, &((struct sockaddr_in *)sa)->sin_addr, a.len); - if (addr_eq(a, defaddr)) - break; - - for (l = ifi->client->active; l != NULL; l = l->next) - if (addr_eq(a, l->address)) - break; - - if (l != NULL) /* new addr is the one we set */ - break; - - goto die; - case RTM_DELADDR: - ifam = (struct ifa_msghdr *)rtm; - if (ifam->ifam_index != ifi->index) - break; - if (findproto((char *)(ifam + 1), ifam->ifam_addrs) != AF_INET) - break; - if (scripttime == 0 || t < scripttime + 10) - break; - goto die; - case RTM_IFINFO: - ifm = (struct if_msghdr *)rtm; - if (ifm->ifm_index != ifi->index) - break; - if ((rtm->rtm_flags & RTF_UP) == 0) - goto die; - break; - case RTM_IFANNOUNCE: - ifan = (struct if_announcemsghdr *)rtm; - if (ifan->ifan_what == IFAN_DEPARTURE && - ifan->ifan_index == ifi->index) - goto die; - break; - default: - break; - } - return; - -die: - script_init("FAIL", NULL); - if (ifi->client->alias) - script_write_params("alias_", ifi->client->alias); - script_go(); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - extern char *__progname; - int ch, fd, quiet = 0, i = 0; - int pipe_fd[2]; - struct passwd *pw; - - /* Initially, log errors to stderr as well as to syslogd. */ - openlog(__progname, LOG_PID | LOG_NDELAY, DHCPD_LOG_FACILITY); - setlogmask(LOG_UPTO(LOG_INFO)); - - while ((ch = getopt(argc, argv, "c:dl:qu")) != -1) - switch (ch) { - case 'c': - path_dhclient_conf = optarg; - break; - case 'd': - no_daemon = 1; - break; - case 'l': - path_dhclient_db = optarg; - break; - case 'q': - quiet = 1; - break; - case 'u': - unknown_ok = 0; - break; - default: - usage(); - } - - argc -= optind; - argv += optind; - - if (argc != 1) - usage(); - - if ((ifi = calloc(1, sizeof(struct interface_info))) == NULL) - error("calloc"); - if (strlcpy(ifi->name, argv[0], IFNAMSIZ) >= IFNAMSIZ) - error("Interface name too long"); - if (path_dhclient_db == NULL && asprintf(&path_dhclient_db, "%s.%s", - _PATH_DHCLIENT_DB, ifi->name) == -1) - error("asprintf"); - - if (quiet) - log_perror = 0; - - tzset(); - time(&cur_time); - - memset(&sockaddr_broadcast, 0, sizeof(sockaddr_broadcast)); - sockaddr_broadcast.sin_family = AF_INET; - sockaddr_broadcast.sin_port = htons(REMOTE_PORT); - sockaddr_broadcast.sin_addr.s_addr = INADDR_BROADCAST; - sockaddr_broadcast.sin_len = sizeof(sockaddr_broadcast); - inaddr_any.s_addr = INADDR_ANY; - - read_client_conf(); - - if (!interface_link_status(ifi->name)) { - fprintf(stderr, "%s: no link ...", ifi->name); - fflush(stderr); - sleep(1); - while (!interface_link_status(ifi->name)) { - fprintf(stderr, "."); - fflush(stderr); - if (++i > 10) { - fprintf(stderr, " giving up\n"); - exit(1); - } - sleep(1); - } - fprintf(stderr, " got link\n"); - } - - if ((nullfd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1) - error("cannot open %s: %m", _PATH_DEVNULL); - - if ((pw = getpwnam("_dhcp")) == NULL) { - warning("no such user: _dhcp, falling back to \"nobody\""); - if ((pw = getpwnam("nobody")) == NULL) - error("no such user: nobody"); - } - - if (pipe(pipe_fd) == -1) - error("pipe"); - - fork_privchld(pipe_fd[0], pipe_fd[1]); - - close(pipe_fd[0]); - privfd = pipe_fd[1]; - - if ((fd = open(path_dhclient_db, O_RDONLY|O_EXLOCK|O_CREAT, 0)) == -1) - error("can't open and lock %s: %m", path_dhclient_db); - read_client_leases(); - rewrite_client_leases(); - close(fd); - - priv_script_init("PREINIT", NULL); - if (ifi->client->alias) - priv_script_write_params("alias_", ifi->client->alias); - priv_script_go(); - - if ((routefd = socket(PF_ROUTE, SOCK_RAW, 0)) != -1) - add_protocol("AF_ROUTE", routefd, routehandler, ifi); - - /* set up the interface */ - discover_interfaces(ifi); - - if (chroot(_PATH_VAREMPTY) == -1) - error("chroot"); - if (chdir("/") == -1) - error("chdir(\"/\")"); - - if (setgroups(1, &pw->pw_gid) || - setegid(pw->pw_gid) || setgid(pw->pw_gid) || - seteuid(pw->pw_uid) || setuid(pw->pw_uid)) - error("can't drop privileges: %m"); - - endpwent(); - - setproctitle("%s", ifi->name); - - ifi->client->state = S_INIT; - state_reboot(ifi); - - bootp_packet_handler = do_packet; - - dispatch(); - - /* not reached */ - return (0); -} - -void -usage(void) -{ - extern char *__progname; - - fprintf(stderr, "usage: %s [-dqu] ", __progname); - fprintf(stderr, "[-c conffile] [-l leasefile] interface\n"); - exit(1); -} - -/* - * Individual States: - * - * Each routine is called from the dhclient_state_machine() in one of - * these conditions: - * -> entering INIT state - * -> recvpacket_flag == 0: timeout in this state - * -> otherwise: received a packet in this state - * - * Return conditions as handled by dhclient_state_machine(): - * Returns 1, sendpacket_flag = 1: send packet, reset timer. - * Returns 1, sendpacket_flag = 0: just reset the timer (wait for a milestone). - * Returns 0: finish the nap which was interrupted for no good reason. - * - * Several per-interface variables are used to keep track of the process: - * active_lease: the lease that is being used on the interface - * (null pointer if not configured yet). - * offered_leases: leases corresponding to DHCPOFFER messages that have - * been sent to us by DHCP servers. - * acked_leases: leases corresponding to DHCPACK messages that have been - * sent to us by DHCP servers. - * sendpacket: DHCP packet we're trying to send. - * destination: IP address to send sendpacket to - * In addition, there are several relevant per-lease variables. - * T1_expiry, T2_expiry, lease_expiry: lease milestones - * In the active lease, these control the process of renewing the lease; - * In leases on the acked_leases list, this simply determines when we - * can no longer legitimately use the lease. - */ - -void -state_reboot(void *ipp) -{ - struct interface_info *ip = ipp; - - /* If we don't remember an active lease, go straight to INIT. */ - if (!ip->client->active || ip->client->active->is_bootp) { - state_init(ip); - return; - } - - /* We are in the rebooting state. */ - ip->client->state = S_REBOOTING; - - /* make_request doesn't initialize xid because it normally comes - from the DHCPDISCOVER, but we haven't sent a DHCPDISCOVER, - so pick an xid now. */ - ip->client->xid = arc4random(); - - /* Make a DHCPREQUEST packet, and set appropriate per-interface - flags. */ - make_request(ip, ip->client->active); - ip->client->destination = iaddr_broadcast; - ip->client->first_sending = cur_time; - ip->client->interval = ip->client->config->initial_interval; - - /* Zap the medium list... */ - ip->client->medium = NULL; - - /* Send out the first DHCPREQUEST packet. */ - send_request(ip); -} - -/* - * Called when a lease has completely expired and we've - * been unable to renew it. - */ -void -state_init(void *ipp) -{ - struct interface_info *ip = ipp; - - ASSERT_STATE(state, S_INIT); - - /* Make a DHCPDISCOVER packet, and set appropriate per-interface - flags. */ - make_discover(ip, ip->client->active); - ip->client->xid = ip->client->packet.xid; - ip->client->destination = iaddr_broadcast; - ip->client->state = S_SELECTING; - ip->client->first_sending = cur_time; - ip->client->interval = ip->client->config->initial_interval; - - /* Add an immediate timeout to cause the first DHCPDISCOVER packet - to go out. */ - send_discover(ip); -} - -/* - * state_selecting is called when one or more DHCPOFFER packets - * have been received and a configurable period of time has passed. - */ -void -state_selecting(void *ipp) -{ - struct interface_info *ip = ipp; - struct client_lease *lp, *next, *picked; - - ASSERT_STATE(state, S_SELECTING); - - /* Cancel state_selecting and send_discover timeouts, since either - one could have got us here. */ - cancel_timeout(state_selecting, ip); - cancel_timeout(send_discover, ip); - - /* We have received one or more DHCPOFFER packets. Currently, - the only criterion by which we judge leases is whether or - not we get a response when we arp for them. */ - picked = NULL; - for (lp = ip->client->offered_leases; lp; lp = next) { - next = lp->next; - - /* Check to see if we got an ARPREPLY for the address - in this particular lease. */ - if (!picked) { - script_init("ARPCHECK", lp->medium); - script_write_params("check_", lp); - - /* If the ARPCHECK code detects another - machine using the offered address, it exits - nonzero. We need to send a DHCPDECLINE and - toss the lease. */ - if (script_go()) { - make_decline(ip, lp); - send_decline(ip); - goto freeit; - } - picked = lp; - picked->next = NULL; - } else { -freeit: - free_client_lease(lp); - } - } - ip->client->offered_leases = NULL; - - /* If we just tossed all the leases we were offered, go back - to square one. */ - if (!picked) { - ip->client->state = S_INIT; - state_init(ip); - return; - } - - /* If it was a BOOTREPLY, we can just take the address right now. */ - if (!picked->options[DHO_DHCP_MESSAGE_TYPE].len) { - ip->client->new = picked; - - /* Make up some lease expiry times - XXX these should be configurable. */ - ip->client->new->expiry = cur_time + 12000; - ip->client->new->renewal += cur_time + 8000; - ip->client->new->rebind += cur_time + 10000; - - ip->client->state = S_REQUESTING; - - /* Bind to the address we received. */ - bind_lease(ip); - return; - } - - /* Go to the REQUESTING state. */ - ip->client->destination = iaddr_broadcast; - ip->client->state = S_REQUESTING; - ip->client->first_sending = cur_time; - ip->client->interval = ip->client->config->initial_interval; - - /* Make a DHCPREQUEST packet from the lease we picked. */ - make_request(ip, picked); - ip->client->xid = ip->client->packet.xid; - - /* Toss the lease we picked - we'll get it back in a DHCPACK. */ - free_client_lease(picked); - - /* Add an immediate timeout to send the first DHCPREQUEST packet. */ - send_request(ip); -} - -/* state_requesting is called when we receive a DHCPACK message after - having sent out one or more DHCPREQUEST packets. */ - -void -dhcpack(struct packet *packet) -{ - struct interface_info *ip = packet->interface; - struct client_lease *lease; - - /* If we're not receptive to an offer right now, or if the offer - has an unrecognizable transaction id, then just drop it. */ - if (packet->interface->client->xid != packet->raw->xid || - (packet->interface->hw_address.hlen != packet->raw->hlen) || - (memcmp(packet->interface->hw_address.haddr, - packet->raw->chaddr, packet->raw->hlen))) - return; - - if (ip->client->state != S_REBOOTING && - ip->client->state != S_REQUESTING && - ip->client->state != S_RENEWING && - ip->client->state != S_REBINDING) - return; - - note("DHCPACK from %s", piaddr(packet->client_addr)); - - lease = packet_to_lease(packet); - if (!lease) { - note("packet_to_lease failed."); - return; - } - - ip->client->new = lease; - - /* Stop resending DHCPREQUEST. */ - cancel_timeout(send_request, ip); - - /* Figure out the lease time. */ - if (ip->client->new->options[DHO_DHCP_LEASE_TIME].data) - ip->client->new->expiry = getULong( - ip->client->new->options[DHO_DHCP_LEASE_TIME].data); - else - ip->client->new->expiry = default_lease_time; - /* A number that looks negative here is really just very large, - because the lease expiry offset is unsigned. */ - if (ip->client->new->expiry < 0) - ip->client->new->expiry = TIME_MAX; - /* XXX should be fixed by resetting the client state */ - if (ip->client->new->expiry < 60) - ip->client->new->expiry = 60; - - /* Take the server-provided renewal time if there is one; - otherwise figure it out according to the spec. */ - if (ip->client->new->options[DHO_DHCP_RENEWAL_TIME].len) - ip->client->new->renewal = getULong( - ip->client->new->options[DHO_DHCP_RENEWAL_TIME].data); - else - ip->client->new->renewal = ip->client->new->expiry / 2; - - /* Same deal with the rebind time. */ - if (ip->client->new->options[DHO_DHCP_REBINDING_TIME].len) - ip->client->new->rebind = getULong( - ip->client->new->options[DHO_DHCP_REBINDING_TIME].data); - else - ip->client->new->rebind = ip->client->new->renewal + - ip->client->new->renewal / 2 + ip->client->new->renewal / 4; - - ip->client->new->expiry += cur_time; - /* Lease lengths can never be negative. */ - if (ip->client->new->expiry < cur_time) - ip->client->new->expiry = TIME_MAX; - ip->client->new->renewal += cur_time; - if (ip->client->new->renewal < cur_time) - ip->client->new->renewal = TIME_MAX; - ip->client->new->rebind += cur_time; - if (ip->client->new->rebind < cur_time) - ip->client->new->rebind = TIME_MAX; - - bind_lease(ip); -} - -void -bind_lease(struct interface_info *ip) -{ - /* Remember the medium. */ - ip->client->new->medium = ip->client->medium; - - /* Write out the new lease. */ - write_client_lease(ip, ip->client->new, 0); - - /* Run the client script with the new parameters. */ - script_init((ip->client->state == S_REQUESTING ? "BOUND" : - (ip->client->state == S_RENEWING ? "RENEW" : - (ip->client->state == S_REBOOTING ? "REBOOT" : "REBIND"))), - ip->client->new->medium); - if (ip->client->active && ip->client->state != S_REBOOTING) - script_write_params("old_", ip->client->active); - script_write_params("new_", ip->client->new); - if (ip->client->alias) - script_write_params("alias_", ip->client->alias); - script_go(); - - /* Replace the old active lease with the new one. */ - if (ip->client->active) - free_client_lease(ip->client->active); - ip->client->active = ip->client->new; - ip->client->new = NULL; - - /* Set up a timeout to start the renewal process. */ - add_timeout(ip->client->active->renewal, state_bound, ip); - - note("bound to %s -- renewal in %d seconds.", - piaddr(ip->client->active->address), - ip->client->active->renewal - cur_time); - ip->client->state = S_BOUND; - reinitialize_interfaces(); - go_daemon(); -} - -/* - * state_bound is called when we've successfully bound to a particular - * lease, but the renewal time on that lease has expired. We are - * expected to unicast a DHCPREQUEST to the server that gave us our - * original lease. - */ -void -state_bound(void *ipp) -{ - struct interface_info *ip = ipp; - - ASSERT_STATE(state, S_BOUND); - - /* T1 has expired. */ - make_request(ip, ip->client->active); - ip->client->xid = ip->client->packet.xid; - - if (ip->client->active->options[DHO_DHCP_SERVER_IDENTIFIER].len == 4) { - memcpy(ip->client->destination.iabuf, ip->client->active-> - options[DHO_DHCP_SERVER_IDENTIFIER].data, 4); - ip->client->destination.len = 4; - } else - ip->client->destination = iaddr_broadcast; - - ip->client->first_sending = cur_time; - ip->client->interval = ip->client->config->initial_interval; - ip->client->state = S_RENEWING; - - /* Send the first packet immediately. */ - send_request(ip); -} - -void -bootp(struct packet *packet) -{ - struct iaddrlist *ap; - - if (packet->raw->op != BOOTREPLY) - return; - - /* If there's a reject list, make sure this packet's sender isn't - on it. */ - for (ap = packet->interface->client->config->reject_list; - ap; ap = ap->next) { - if (addr_eq(packet->client_addr, ap->addr)) { - note("BOOTREPLY from %s rejected.", piaddr(ap->addr)); - return; - } - } - dhcpoffer(packet); -} - -void -dhcp(struct packet *packet) -{ - struct iaddrlist *ap; - void (*handler)(struct packet *); - char *type; - - switch (packet->packet_type) { - case DHCPOFFER: - handler = dhcpoffer; - type = "DHCPOFFER"; - break; - case DHCPNAK: - handler = dhcpnak; - type = "DHCPNACK"; - break; - case DHCPACK: - handler = dhcpack; - type = "DHCPACK"; - break; - default: - return; - } - - /* If there's a reject list, make sure this packet's sender isn't - on it. */ - for (ap = packet->interface->client->config->reject_list; - ap; ap = ap->next) { - if (addr_eq(packet->client_addr, ap->addr)) { - note("%s from %s rejected.", type, piaddr(ap->addr)); - return; - } - } - (*handler)(packet); -} - -void -dhcpoffer(struct packet *packet) -{ - struct interface_info *ip = packet->interface; - struct client_lease *lease, *lp; - int i; - int arp_timeout_needed, stop_selecting; - char *name = packet->options[DHO_DHCP_MESSAGE_TYPE].len ? - "DHCPOFFER" : "BOOTREPLY"; - - /* If we're not receptive to an offer right now, or if the offer - has an unrecognizable transaction id, then just drop it. */ - if (ip->client->state != S_SELECTING || - packet->interface->client->xid != packet->raw->xid || - (packet->interface->hw_address.hlen != packet->raw->hlen) || - (memcmp(packet->interface->hw_address.haddr, - packet->raw->chaddr, packet->raw->hlen))) - return; - - note("%s from %s", name, piaddr(packet->client_addr)); - - - /* If this lease doesn't supply the minimum required parameters, - blow it off. */ - for (i = 0; ip->client->config->required_options[i]; i++) { - if (!packet->options[ip->client->config-> - required_options[i]].len) { - note("%s isn't satisfactory.", name); - return; - } - } - - /* If we've already seen this lease, don't record it again. */ - for (lease = ip->client->offered_leases; - lease; lease = lease->next) { - if (lease->address.len == sizeof(packet->raw->yiaddr) && - !memcmp(lease->address.iabuf, - &packet->raw->yiaddr, lease->address.len)) { - debug("%s already seen.", name); - return; - } - } - - lease = packet_to_lease(packet); - if (!lease) { - note("packet_to_lease failed."); - return; - } - - /* If this lease was acquired through a BOOTREPLY, record that - fact. */ - if (!packet->options[DHO_DHCP_MESSAGE_TYPE].len) - lease->is_bootp = 1; - - /* Record the medium under which this lease was offered. */ - lease->medium = ip->client->medium; - - /* Send out an ARP Request for the offered IP address. */ - script_init("ARPSEND", lease->medium); - script_write_params("check_", lease); - /* If the script can't send an ARP request without waiting, - we'll be waiting when we do the ARPCHECK, so don't wait now. */ - if (script_go()) - arp_timeout_needed = 0; - else - arp_timeout_needed = 2; - - /* Figure out when we're supposed to stop selecting. */ - stop_selecting = - ip->client->first_sending + ip->client->config->select_interval; - - /* If this is the lease we asked for, put it at the head of the - list, and don't mess with the arp request timeout. */ - if (lease->address.len == ip->client->requested_address.len && - !memcmp(lease->address.iabuf, - ip->client->requested_address.iabuf, - ip->client->requested_address.len)) { - lease->next = ip->client->offered_leases; - ip->client->offered_leases = lease; - } else { - /* If we already have an offer, and arping for this - offer would take us past the selection timeout, - then don't extend the timeout - just hope for the - best. */ - if (ip->client->offered_leases && - (cur_time + arp_timeout_needed) > stop_selecting) - arp_timeout_needed = 0; - - /* Put the lease at the end of the list. */ - lease->next = NULL; - if (!ip->client->offered_leases) - ip->client->offered_leases = lease; - else { - for (lp = ip->client->offered_leases; lp->next; - lp = lp->next) - ; /* nothing */ - lp->next = lease; - } - } - - /* If we're supposed to stop selecting before we've had time - to wait for the ARPREPLY, add some delay to wait for - the ARPREPLY. */ - if (stop_selecting - cur_time < arp_timeout_needed) - stop_selecting = cur_time + arp_timeout_needed; - - /* If the selecting interval has expired, go immediately to - state_selecting(). Otherwise, time out into - state_selecting at the select interval. */ - if (stop_selecting <= 0) - state_selecting(ip); - else { - add_timeout(stop_selecting, state_selecting, ip); - cancel_timeout(send_discover, ip); - } -} - -/* Allocate a client_lease structure and initialize it from the parameters - in the specified packet. */ - -struct client_lease * -packet_to_lease(struct packet *packet) -{ - struct client_lease *lease; - int i; - - lease = malloc(sizeof(struct client_lease)); - - if (!lease) { - warning("dhcpoffer: no memory to record lease."); - return (NULL); - } - - memset(lease, 0, sizeof(*lease)); - - /* Copy the lease options. */ - for (i = 0; i < 256; i++) { - if (packet->options[i].len) { - lease->options[i].data = - malloc(packet->options[i].len + 1); - if (!lease->options[i].data) { - warning("dhcpoffer: no memory for option %d", i); - free_client_lease(lease); - return (NULL); - } else { - memcpy(lease->options[i].data, - packet->options[i].data, - packet->options[i].len); - lease->options[i].len = - packet->options[i].len; - lease->options[i].data[lease->options[i].len] = - 0; - } - if (!check_option(lease,i)) { - /* ignore a bogus lease offer */ - warning("Invalid lease option - ignoring offer"); - free_client_lease(lease); - return (NULL); - } - } - } - - lease->address.len = sizeof(packet->raw->yiaddr); - memcpy(lease->address.iabuf, &packet->raw->yiaddr, lease->address.len); - - /* If the server name was filled out, copy it. */ - if ((!packet->options[DHO_DHCP_OPTION_OVERLOAD].len || - !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 2)) && - packet->raw->sname[0]) { - lease->server_name = malloc(DHCP_SNAME_LEN + 1); - if (!lease->server_name) { - warning("dhcpoffer: no memory for server name."); - free_client_lease(lease); - return (NULL); - } - memcpy(lease->server_name, packet->raw->sname, DHCP_SNAME_LEN); - lease->server_name[DHCP_SNAME_LEN]='\0'; - if (!res_hnok(lease->server_name) ) { - warning("Bogus server name %s", lease->server_name ); - free_client_lease(lease); - return (NULL); - } - - } - - /* Ditto for the filename. */ - if ((!packet->options[DHO_DHCP_OPTION_OVERLOAD].len || - !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 1)) && - packet->raw->file[0]) { - /* Don't count on the NUL terminator. */ - lease->filename = malloc(DHCP_FILE_LEN + 1); - if (!lease->filename) { - warning("dhcpoffer: no memory for filename."); - free_client_lease(lease); - return (NULL); - } - memcpy(lease->filename, packet->raw->file, DHCP_FILE_LEN); - lease->filename[DHCP_FILE_LEN]='\0'; - } - return lease; -} - -void -dhcpnak(struct packet *packet) -{ - struct interface_info *ip = packet->interface; - - /* If we're not receptive to an offer right now, or if the offer - has an unrecognizable transaction id, then just drop it. */ - if (packet->interface->client->xid != packet->raw->xid || - (packet->interface->hw_address.hlen != packet->raw->hlen) || - (memcmp(packet->interface->hw_address.haddr, - packet->raw->chaddr, packet->raw->hlen))) - return; - - if (ip->client->state != S_REBOOTING && - ip->client->state != S_REQUESTING && - ip->client->state != S_RENEWING && - ip->client->state != S_REBINDING) - return; - - note("DHCPNAK from %s", piaddr(packet->client_addr)); - - if (!ip->client->active) { - note("DHCPNAK with no active lease.\n"); - return; - } - - free_client_lease(ip->client->active); - ip->client->active = NULL; - - /* Stop sending DHCPREQUEST packets... */ - cancel_timeout(send_request, ip); - - ip->client->state = S_INIT; - state_init(ip); -} - -/* Send out a DHCPDISCOVER packet, and set a timeout to send out another - one after the right interval has expired. If we don't get an offer by - the time we reach the panic interval, call the panic function. */ - -void -send_discover(void *ipp) -{ - struct interface_info *ip = ipp; - int interval, increase = 1; - - /* Figure out how long it's been since we started transmitting. */ - interval = cur_time - ip->client->first_sending; - - /* If we're past the panic timeout, call the script and tell it - we haven't found anything for this interface yet. */ - if (interval > ip->client->config->timeout) { - state_panic(ip); - return; - } - - /* If we're selecting media, try the whole list before doing - the exponential backoff, but if we've already received an - offer, stop looping, because we obviously have it right. */ - if (!ip->client->offered_leases && - ip->client->config->media) { - int fail = 0; -again: - if (ip->client->medium) { - ip->client->medium = ip->client->medium->next; - increase = 0; - } - if (!ip->client->medium) { - if (fail) - error("No valid media types for %s!", ip->name); - ip->client->medium = ip->client->config->media; - increase = 1; - } - - note("Trying medium \"%s\" %d", ip->client->medium->string, - increase); - script_init("MEDIUM", ip->client->medium); - if (script_go()) - goto again; - } - - /* - * If we're supposed to increase the interval, do so. If it's - * currently zero (i.e., we haven't sent any packets yet), set - * it to one; otherwise, add to it a random number between zero - * and two times itself. On average, this means that it will - * double with every transmission. - */ - if (increase) { - if (!ip->client->interval) - ip->client->interval = - ip->client->config->initial_interval; - else { - ip->client->interval += (arc4random() >> 2) % - (2 * ip->client->interval); - } - - /* Don't backoff past cutoff. */ - if (ip->client->interval > - ip->client->config->backoff_cutoff) - ip->client->interval = - ((ip->client->config->backoff_cutoff / 2) - + ((arc4random() >> 2) % - ip->client->config->backoff_cutoff)); - } else if (!ip->client->interval) - ip->client->interval = - ip->client->config->initial_interval; - - /* If the backoff would take us to the panic timeout, just use that - as the interval. */ - if (cur_time + ip->client->interval > - ip->client->first_sending + ip->client->config->timeout) - ip->client->interval = - (ip->client->first_sending + - ip->client->config->timeout) - cur_time + 1; - - /* Record the number of seconds since we started sending. */ - if (interval < 65536) - ip->client->packet.secs = htons(interval); - else - ip->client->packet.secs = htons(65535); - ip->client->secs = ip->client->packet.secs; - - note("DHCPDISCOVER on %s to %s port %d interval %d", - ip->name, inet_ntoa(sockaddr_broadcast.sin_addr), - ntohs(sockaddr_broadcast.sin_port), ip->client->interval); - - /* Send out a packet. */ - (void)send_packet(ip, &ip->client->packet, ip->client->packet_length, - inaddr_any, &sockaddr_broadcast, NULL); - - add_timeout(cur_time + ip->client->interval, send_discover, ip); -} - -/* - * state_panic gets called if we haven't received any offers in a preset - * amount of time. When this happens, we try to use existing leases - * that haven't yet expired, and failing that, we call the client script - * and hope it can do something. - */ -void -state_panic(void *ipp) -{ - struct interface_info *ip = ipp; - struct client_lease *loop = ip->client->active; - struct client_lease *lp; - - note("No DHCPOFFERS received."); - - /* We may not have an active lease, but we may have some - predefined leases that we can try. */ - if (!ip->client->active && ip->client->leases) - goto activate_next; - - /* Run through the list of leases and see if one can be used. */ - while (ip->client->active) { - if (ip->client->active->expiry > cur_time) { - note("Trying recorded lease %s", - piaddr(ip->client->active->address)); - /* Run the client script with the existing - parameters. */ - script_init("TIMEOUT", - ip->client->active->medium); - script_write_params("new_", ip->client->active); - if (ip->client->alias) - script_write_params("alias_", - ip->client->alias); - - /* If the old lease is still good and doesn't - yet need renewal, go into BOUND state and - timeout at the renewal time. */ - if (!script_go()) { - if (cur_time < - ip->client->active->renewal) { - ip->client->state = S_BOUND; - note("bound: renewal in %d seconds.", - ip->client->active->renewal - - cur_time); - add_timeout( - ip->client->active->renewal, - state_bound, ip); - } else { - ip->client->state = S_BOUND; - note("bound: immediate renewal."); - state_bound(ip); - } - reinitialize_interfaces(); - go_daemon(); - return; - } - } - - /* If there are no other leases, give up. */ - if (!ip->client->leases) { - ip->client->leases = ip->client->active; - ip->client->active = NULL; - break; - } - -activate_next: - /* Otherwise, put the active lease at the end of the - lease list, and try another lease.. */ - for (lp = ip->client->leases; lp->next; lp = lp->next) - ; - lp->next = ip->client->active; - if (lp->next) - lp->next->next = NULL; - ip->client->active = ip->client->leases; - ip->client->leases = ip->client->leases->next; - - /* If we already tried this lease, we've exhausted the - set of leases, so we might as well give up for - now. */ - if (ip->client->active == loop) - break; - else if (!loop) - loop = ip->client->active; - } - - /* No leases were available, or what was available didn't work, so - tell the shell script that we failed to allocate an address, - and try again later. */ - note("No working leases in persistent database - sleeping.\n"); - script_init("FAIL", NULL); - if (ip->client->alias) - script_write_params("alias_", ip->client->alias); - script_go(); - ip->client->state = S_INIT; - add_timeout(cur_time + ip->client->config->retry_interval, state_init, - ip); - go_daemon(); -} - -void -send_request(void *ipp) -{ - struct interface_info *ip = ipp; - struct sockaddr_in destination; - struct in_addr from; - int interval; - - /* Figure out how long it's been since we started transmitting. */ - interval = cur_time - ip->client->first_sending; - - /* If we're in the INIT-REBOOT or REQUESTING state and we're - past the reboot timeout, go to INIT and see if we can - DISCOVER an address... */ - /* XXX In the INIT-REBOOT state, if we don't get an ACK, it - means either that we're on a network with no DHCP server, - or that our server is down. In the latter case, assuming - that there is a backup DHCP server, DHCPDISCOVER will get - us a new address, but we could also have successfully - reused our old address. In the former case, we're hosed - anyway. This is not a win-prone situation. */ - if ((ip->client->state == S_REBOOTING || - ip->client->state == S_REQUESTING) && - interval > ip->client->config->reboot_timeout) { -cancel: - ip->client->state = S_INIT; - cancel_timeout(send_request, ip); - state_init(ip); - return; - } - - /* If we're in the reboot state, make sure the media is set up - correctly. */ - if (ip->client->state == S_REBOOTING && - !ip->client->medium && - ip->client->active->medium ) { - script_init("MEDIUM", ip->client->active->medium); - - /* If the medium we chose won't fly, go to INIT state. */ - if (script_go()) - goto cancel; - - /* Record the medium. */ - ip->client->medium = ip->client->active->medium; - } - - /* If the lease has expired, relinquish the address and go back - to the INIT state. */ - if (ip->client->state != S_REQUESTING && - cur_time > ip->client->active->expiry) { - /* Run the client script with the new parameters. */ - script_init("EXPIRE", NULL); - script_write_params("old_", ip->client->active); - if (ip->client->alias) - script_write_params("alias_", ip->client->alias); - script_go(); - - /* Now do a preinit on the interface so that we can - discover a new address. */ - script_init("PREINIT", NULL); - if (ip->client->alias) - script_write_params("alias_", ip->client->alias); - script_go(); - - ip->client->state = S_INIT; - state_init(ip); - return; - } - - /* Do the exponential backoff... */ - if (!ip->client->interval) - ip->client->interval = ip->client->config->initial_interval; - else - ip->client->interval += ((arc4random() >> 2) % - (2 * ip->client->interval)); - - /* Don't backoff past cutoff. */ - if (ip->client->interval > - ip->client->config->backoff_cutoff) - ip->client->interval = - ((ip->client->config->backoff_cutoff / 2) + - ((arc4random() >> 2) % ip->client->interval)); - - /* If the backoff would take us to the expiry time, just set the - timeout to the expiry time. */ - if (ip->client->state != S_REQUESTING && - cur_time + ip->client->interval > - ip->client->active->expiry) - ip->client->interval = - ip->client->active->expiry - cur_time + 1; - - /* If the lease T2 time has elapsed, or if we're not yet bound, - broadcast the DHCPREQUEST rather than unicasting. */ - memset(&destination, 0, sizeof(destination)); - if (ip->client->state == S_REQUESTING || - ip->client->state == S_REBOOTING || - cur_time > ip->client->active->rebind) - destination.sin_addr.s_addr = INADDR_BROADCAST; - else - memcpy(&destination.sin_addr.s_addr, - ip->client->destination.iabuf, - sizeof(destination.sin_addr.s_addr)); - destination.sin_port = htons(REMOTE_PORT); - destination.sin_family = AF_INET; - destination.sin_len = sizeof(destination); - - if (ip->client->state != S_REQUESTING) - memcpy(&from, ip->client->active->address.iabuf, - sizeof(from)); - else - from.s_addr = INADDR_ANY; - - /* Record the number of seconds since we started sending. */ - if (ip->client->state == S_REQUESTING) - ip->client->packet.secs = ip->client->secs; - else { - if (interval < 65536) - ip->client->packet.secs = htons(interval); - else - ip->client->packet.secs = htons(65535); - } - - note("DHCPREQUEST on %s to %s port %d", ip->name, - inet_ntoa(destination.sin_addr), ntohs(destination.sin_port)); - - /* Send out a packet. */ - (void) send_packet(ip, &ip->client->packet, ip->client->packet_length, - from, &destination, NULL); - - add_timeout(cur_time + ip->client->interval, send_request, ip); -} - -void -send_decline(void *ipp) -{ - struct interface_info *ip = ipp; - - note("DHCPDECLINE on %s to %s port %d", ip->name, - inet_ntoa(sockaddr_broadcast.sin_addr), - ntohs(sockaddr_broadcast.sin_port)); - - /* Send out a packet. */ - (void) send_packet(ip, &ip->client->packet, ip->client->packet_length, - inaddr_any, &sockaddr_broadcast, NULL); -} - -void -make_discover(struct interface_info *ip, struct client_lease *lease) -{ - unsigned char discover = DHCPDISCOVER; - struct tree_cache *options[256]; - struct tree_cache option_elements[256]; - int i; - - memset(option_elements, 0, sizeof(option_elements)); - memset(options, 0, sizeof(options)); - memset(&ip->client->packet, 0, sizeof(ip->client->packet)); - - /* Set DHCP_MESSAGE_TYPE to DHCPDISCOVER */ - i = DHO_DHCP_MESSAGE_TYPE; - options[i] = &option_elements[i]; - options[i]->value = &discover; - options[i]->len = sizeof(discover); - options[i]->buf_size = sizeof(discover); - options[i]->timeout = 0xFFFFFFFF; - - /* Request the options we want */ - i = DHO_DHCP_PARAMETER_REQUEST_LIST; - options[i] = &option_elements[i]; - options[i]->value = ip->client->config->requested_options; - options[i]->len = ip->client->config->requested_option_count; - options[i]->buf_size = - ip->client->config->requested_option_count; - options[i]->timeout = 0xFFFFFFFF; - - /* If we had an address, try to get it again. */ - if (lease) { - ip->client->requested_address = lease->address; - i = DHO_DHCP_REQUESTED_ADDRESS; - options[i] = &option_elements[i]; - options[i]->value = lease->address.iabuf; - options[i]->len = lease->address.len; - options[i]->buf_size = lease->address.len; - options[i]->timeout = 0xFFFFFFFF; - } else - ip->client->requested_address.len = 0; - - /* Send any options requested in the config file. */ - for (i = 0; i < 256; i++) - if (!options[i] && - ip->client->config->send_options[i].data) { - options[i] = &option_elements[i]; - options[i]->value = - ip->client->config->send_options[i].data; - options[i]->len = - ip->client->config->send_options[i].len; - options[i]->buf_size = - ip->client->config->send_options[i].len; - options[i]->timeout = 0xFFFFFFFF; - } - - /* Set up the option buffer... */ - ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, - options, 0, 0, 0, NULL, 0); - if (ip->client->packet_length < BOOTP_MIN_LEN) - ip->client->packet_length = BOOTP_MIN_LEN; - - ip->client->packet.op = BOOTREQUEST; - ip->client->packet.htype = ip->hw_address.htype; - ip->client->packet.hlen = ip->hw_address.hlen; - ip->client->packet.hops = 0; - ip->client->packet.xid = arc4random(); - ip->client->packet.secs = 0; /* filled in by send_discover. */ - ip->client->packet.flags = 0; - - memset(&(ip->client->packet.ciaddr), - 0, sizeof(ip->client->packet.ciaddr)); - memset(&(ip->client->packet.yiaddr), - 0, sizeof(ip->client->packet.yiaddr)); - memset(&(ip->client->packet.siaddr), - 0, sizeof(ip->client->packet.siaddr)); - memset(&(ip->client->packet.giaddr), - 0, sizeof(ip->client->packet.giaddr)); - memcpy(ip->client->packet.chaddr, - ip->hw_address.haddr, ip->hw_address.hlen); -} - - -void -make_request(struct interface_info *ip, struct client_lease * lease) -{ - unsigned char request = DHCPREQUEST; - struct tree_cache *options[256]; - struct tree_cache option_elements[256]; - int i; - - memset(options, 0, sizeof(options)); - memset(&ip->client->packet, 0, sizeof(ip->client->packet)); - - /* Set DHCP_MESSAGE_TYPE to DHCPREQUEST */ - i = DHO_DHCP_MESSAGE_TYPE; - options[i] = &option_elements[i]; - options[i]->value = &request; - options[i]->len = sizeof(request); - options[i]->buf_size = sizeof(request); - options[i]->timeout = 0xFFFFFFFF; - - /* Request the options we want */ - i = DHO_DHCP_PARAMETER_REQUEST_LIST; - options[i] = &option_elements[i]; - options[i]->value = ip->client->config->requested_options; - options[i]->len = ip->client->config->requested_option_count; - options[i]->buf_size = - ip->client->config->requested_option_count; - options[i]->timeout = 0xFFFFFFFF; - - /* If we are requesting an address that hasn't yet been assigned - to us, use the DHCP Requested Address option. */ - if (ip->client->state == S_REQUESTING) { - /* Send back the server identifier... */ - i = DHO_DHCP_SERVER_IDENTIFIER; - options[i] = &option_elements[i]; - options[i]->value = lease->options[i].data; - options[i]->len = lease->options[i].len; - options[i]->buf_size = lease->options[i].len; - options[i]->timeout = 0xFFFFFFFF; - } - if (ip->client->state == S_REQUESTING || - ip->client->state == S_REBOOTING) { - ip->client->requested_address = lease->address; - i = DHO_DHCP_REQUESTED_ADDRESS; - options[i] = &option_elements[i]; - options[i]->value = lease->address.iabuf; - options[i]->len = lease->address.len; - options[i]->buf_size = lease->address.len; - options[i]->timeout = 0xFFFFFFFF; - } else - ip->client->requested_address.len = 0; - - /* Send any options requested in the config file. */ - for (i = 0; i < 256; i++) - if (!options[i] && - ip->client->config->send_options[i].data) { - options[i] = &option_elements[i]; - options[i]->value = - ip->client->config->send_options[i].data; - options[i]->len = - ip->client->config->send_options[i].len; - options[i]->buf_size = - ip->client->config->send_options[i].len; - options[i]->timeout = 0xFFFFFFFF; - } - - /* Set up the option buffer... */ - ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, - options, 0, 0, 0, NULL, 0); - if (ip->client->packet_length < BOOTP_MIN_LEN) - ip->client->packet_length = BOOTP_MIN_LEN; - - ip->client->packet.op = BOOTREQUEST; - ip->client->packet.htype = ip->hw_address.htype; - ip->client->packet.hlen = ip->hw_address.hlen; - ip->client->packet.hops = 0; - ip->client->packet.xid = ip->client->xid; - ip->client->packet.secs = 0; /* Filled in by send_request. */ - - /* If we own the address we're requesting, put it in ciaddr; - otherwise set ciaddr to zero. */ - if (ip->client->state == S_BOUND || - ip->client->state == S_RENEWING || - ip->client->state == S_REBINDING) { - memcpy(&ip->client->packet.ciaddr, - lease->address.iabuf, lease->address.len); - ip->client->packet.flags = 0; - } else { - memset(&ip->client->packet.ciaddr, 0, - sizeof(ip->client->packet.ciaddr)); - ip->client->packet.flags = 0; - } - - memset(&ip->client->packet.yiaddr, 0, - sizeof(ip->client->packet.yiaddr)); - memset(&ip->client->packet.siaddr, 0, - sizeof(ip->client->packet.siaddr)); - memset(&ip->client->packet.giaddr, 0, - sizeof(ip->client->packet.giaddr)); - memcpy(ip->client->packet.chaddr, - ip->hw_address.haddr, ip->hw_address.hlen); -} - -void -make_decline(struct interface_info *ip, struct client_lease *lease) -{ - struct tree_cache *options[256], message_type_tree; - struct tree_cache requested_address_tree; - struct tree_cache server_id_tree, client_id_tree; - unsigned char decline = DHCPDECLINE; - int i; - - memset(options, 0, sizeof(options)); - memset(&ip->client->packet, 0, sizeof(ip->client->packet)); - - /* Set DHCP_MESSAGE_TYPE to DHCPDECLINE */ - i = DHO_DHCP_MESSAGE_TYPE; - options[i] = &message_type_tree; - options[i]->value = &decline; - options[i]->len = sizeof(decline); - options[i]->buf_size = sizeof(decline); - options[i]->timeout = 0xFFFFFFFF; - - /* Send back the server identifier... */ - i = DHO_DHCP_SERVER_IDENTIFIER; - options[i] = &server_id_tree; - options[i]->value = lease->options[i].data; - options[i]->len = lease->options[i].len; - options[i]->buf_size = lease->options[i].len; - options[i]->timeout = 0xFFFFFFFF; - - /* Send back the address we're declining. */ - i = DHO_DHCP_REQUESTED_ADDRESS; - options[i] = &requested_address_tree; - options[i]->value = lease->address.iabuf; - options[i]->len = lease->address.len; - options[i]->buf_size = lease->address.len; - options[i]->timeout = 0xFFFFFFFF; - - /* Send the uid if the user supplied one. */ - i = DHO_DHCP_CLIENT_IDENTIFIER; - if (ip->client->config->send_options[i].len) { - options[i] = &client_id_tree; - options[i]->value = ip->client->config->send_options[i].data; - options[i]->len = ip->client->config->send_options[i].len; - options[i]->buf_size = ip->client->config->send_options[i].len; - options[i]->timeout = 0xFFFFFFFF; - } - - - /* Set up the option buffer... */ - ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, - options, 0, 0, 0, NULL, 0); - if (ip->client->packet_length < BOOTP_MIN_LEN) - ip->client->packet_length = BOOTP_MIN_LEN; - - ip->client->packet.op = BOOTREQUEST; - ip->client->packet.htype = ip->hw_address.htype; - ip->client->packet.hlen = ip->hw_address.hlen; - ip->client->packet.hops = 0; - ip->client->packet.xid = ip->client->xid; - ip->client->packet.secs = 0; /* Filled in by send_request. */ - ip->client->packet.flags = 0; - - /* ciaddr must always be zero. */ - memset(&ip->client->packet.ciaddr, 0, - sizeof(ip->client->packet.ciaddr)); - memset(&ip->client->packet.yiaddr, 0, - sizeof(ip->client->packet.yiaddr)); - memset(&ip->client->packet.siaddr, 0, - sizeof(ip->client->packet.siaddr)); - memset(&ip->client->packet.giaddr, 0, - sizeof(ip->client->packet.giaddr)); - memcpy(ip->client->packet.chaddr, - ip->hw_address.haddr, ip->hw_address.hlen); -} - -void -free_client_lease(struct client_lease *lease) -{ - int i; - - if (lease->server_name) - free(lease->server_name); - if (lease->filename) - free(lease->filename); - for (i = 0; i < 256; i++) { - if (lease->options[i].len) - free(lease->options[i].data); - } - free(lease); -} - -FILE *leaseFile; - -void -rewrite_client_leases(void) -{ - struct client_lease *lp; - - if (!leaseFile) { - leaseFile = fopen(path_dhclient_db, "w"); - if (!leaseFile) - error("can't create %s: %m", path_dhclient_db); - } else { - fflush(leaseFile); - rewind(leaseFile); - } - - for (lp = ifi->client->leases; lp; lp = lp->next) - write_client_lease(ifi, lp, 1); - if (ifi->client->active) - write_client_lease(ifi, ifi->client->active, 1); - - fflush(leaseFile); - ftruncate(fileno(leaseFile), ftello(leaseFile)); - fsync(fileno(leaseFile)); -} - -void -write_client_lease(struct interface_info *ip, struct client_lease *lease, - int rewrite) -{ - static int leases_written; - struct tm *t; - int i; - - if (!rewrite) { - if (leases_written++ > 20) { - rewrite_client_leases(); - leases_written = 0; - } - } - - /* If the lease came from the config file, we don't need to stash - a copy in the lease database. */ - if (lease->is_static) - return; - - if (!leaseFile) { /* XXX */ - leaseFile = fopen(path_dhclient_db, "w"); - if (!leaseFile) - error("can't create %s: %m", path_dhclient_db); - } - - fprintf(leaseFile, "lease {\n"); - if (lease->is_bootp) - fprintf(leaseFile, " bootp;\n"); - fprintf(leaseFile, " interface \"%s\";\n", ip->name); - fprintf(leaseFile, " fixed-address %s;\n", piaddr(lease->address)); - if (lease->filename) - fprintf(leaseFile, " filename \"%s\";\n", lease->filename); - if (lease->server_name) - fprintf(leaseFile, " server-name \"%s\";\n", - lease->server_name); - if (lease->medium) - fprintf(leaseFile, " medium \"%s\";\n", lease->medium->string); - for (i = 0; i < 256; i++) - if (lease->options[i].len) - fprintf(leaseFile, " option %s %s;\n", - dhcp_options[i].name, - pretty_print_option(i, lease->options[i].data, - lease->options[i].len, 1, 1)); - - t = gmtime(&lease->renewal); - fprintf(leaseFile, " renew %d %d/%d/%d %02d:%02d:%02d;\n", - t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); - t = gmtime(&lease->rebind); - fprintf(leaseFile, " rebind %d %d/%d/%d %02d:%02d:%02d;\n", - t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); - t = gmtime(&lease->expiry); - fprintf(leaseFile, " expire %d %d/%d/%d %02d:%02d:%02d;\n", - t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); - fprintf(leaseFile, "}\n"); - fflush(leaseFile); -} - -void -script_init(char *reason, struct string_list *medium) -{ - size_t len, mediumlen = 0; - struct imsg_hdr hdr; - struct buf *buf; - int errs; - - if (medium != NULL && medium->string != NULL) - mediumlen = strlen(medium->string); - - hdr.code = IMSG_SCRIPT_INIT; - hdr.len = sizeof(struct imsg_hdr) + - sizeof(size_t) + mediumlen + - sizeof(size_t) + strlen(reason); - - if ((buf = buf_open(hdr.len)) == NULL) - error("buf_open: %m"); - - errs = 0; - errs += buf_add(buf, &hdr, sizeof(hdr)); - errs += buf_add(buf, &mediumlen, sizeof(mediumlen)); - if (mediumlen > 0) - errs += buf_add(buf, medium->string, mediumlen); - len = strlen(reason); - errs += buf_add(buf, &len, sizeof(len)); - errs += buf_add(buf, reason, len); - - if (errs) - error("buf_add: %m"); - - if (buf_close(privfd, buf) == -1) - error("buf_close: %m"); -} - -void -priv_script_init(char *reason, char *medium) -{ - struct interface_info *ip = ifi; - - if (ip) { - ip->client->scriptEnvsize = 100; - if (ip->client->scriptEnv == NULL) - ip->client->scriptEnv = - malloc(ip->client->scriptEnvsize * sizeof(char *)); - if (ip->client->scriptEnv == NULL) - error("script_init: no memory for environment"); - - ip->client->scriptEnv[0] = strdup(CLIENT_PATH); - if (ip->client->scriptEnv[0] == NULL) - error("script_init: no memory for environment"); - - ip->client->scriptEnv[1] = NULL; - - script_set_env(ip->client, "", "interface", ip->name); - - if (medium) - script_set_env(ip->client, "", "medium", medium); - - script_set_env(ip->client, "", "reason", reason); - } -} - -void -priv_script_write_params(char *prefix, struct client_lease *lease) -{ - struct interface_info *ip = ifi; - u_int8_t dbuf[1500]; - int i, len = 0; - char tbuf[128]; - - script_set_env(ip->client, prefix, "ip_address", - piaddr(lease->address)); - - if (lease->options[DHO_SUBNET_MASK].len && - (lease->options[DHO_SUBNET_MASK].len < - sizeof(lease->address.iabuf))) { - struct iaddr netmask, subnet, broadcast; - - memcpy(netmask.iabuf, lease->options[DHO_SUBNET_MASK].data, - lease->options[DHO_SUBNET_MASK].len); - netmask.len = lease->options[DHO_SUBNET_MASK].len; - - subnet = subnet_number(lease->address, netmask); - if (subnet.len) { - script_set_env(ip->client, prefix, "network_number", - piaddr(subnet)); - if (!lease->options[DHO_BROADCAST_ADDRESS].len) { - broadcast = broadcast_addr(subnet, netmask); - if (broadcast.len) - script_set_env(ip->client, prefix, - "broadcast_address", - piaddr(broadcast)); - } - } - } - - if (lease->filename) - script_set_env(ip->client, prefix, "filename", lease->filename); - if (lease->server_name) - script_set_env(ip->client, prefix, "server_name", - lease->server_name); - for (i = 0; i < 256; i++) { - u_int8_t *dp = NULL; - - if (ip->client->config->defaults[i].len) { - if (lease->options[i].len) { - switch ( - ip->client->config->default_actions[i]) { - case ACTION_DEFAULT: - dp = lease->options[i].data; - len = lease->options[i].len; - break; - case ACTION_SUPERSEDE: -supersede: - dp = ip->client-> - config->defaults[i].data; - len = ip->client-> - config->defaults[i].len; - break; - case ACTION_PREPEND: - len = ip->client-> - config->defaults[i].len + - lease->options[i].len; - if (len > sizeof(dbuf)) { - warning("no space to %s %s", - "prepend option", - dhcp_options[i].name); - goto supersede; - } - dp = dbuf; - memcpy(dp, - ip->client-> - config->defaults[i].data, - ip->client-> - config->defaults[i].len); - memcpy(dp + ip->client-> - config->defaults[i].len, - lease->options[i].data, - lease->options[i].len); - dp[len] = '\0'; - break; - case ACTION_APPEND: - len = ip->client-> - config->defaults[i].len + - lease->options[i].len; - if (len > sizeof(dbuf)) { - warning("no space to %s %s", - "append option", - dhcp_options[i].name); - goto supersede; - } - dp = dbuf; - memcpy(dp, - lease->options[i].data, - lease->options[i].len); - memcpy(dp + lease->options[i].len, - ip->client-> - config->defaults[i].data, - ip->client-> - config->defaults[i].len); - dp[len] = '\0'; - } - } else { - dp = ip->client-> - config->defaults[i].data; - len = ip->client-> - config->defaults[i].len; - } - } else if (lease->options[i].len) { - len = lease->options[i].len; - dp = lease->options[i].data; - } else { - len = 0; - } - if (len) { - char name[256]; - - if (dhcp_option_ev_name(name, sizeof(name), - &dhcp_options[i])) - script_set_env(ip->client, prefix, name, - pretty_print_option(i, dp, len, 0, 0)); - } - } - snprintf(tbuf, sizeof(tbuf), "%d", (int)lease->expiry); - script_set_env(ip->client, prefix, "expiry", tbuf); -} - -void -script_write_params(char *prefix, struct client_lease *lease) -{ - size_t fn_len = 0, sn_len = 0, pr_len = 0; - struct imsg_hdr hdr; - struct buf *buf; - int errs, i; - - if (lease->filename != NULL) - fn_len = strlen(lease->filename); - if (lease->server_name != NULL) - sn_len = strlen(lease->server_name); - if (prefix != NULL) - pr_len = strlen(prefix); - - hdr.code = IMSG_SCRIPT_WRITE_PARAMS; - hdr.len = sizeof(hdr) + sizeof(struct client_lease) + - sizeof(size_t) + fn_len + sizeof(size_t) + sn_len + - sizeof(size_t) + pr_len; - - for (i = 0; i < 256; i++) - hdr.len += sizeof(int) + lease->options[i].len; - - scripttime = time(NULL); - - if ((buf = buf_open(hdr.len)) == NULL) - error("buf_open: %m"); - - errs = 0; - errs += buf_add(buf, &hdr, sizeof(hdr)); - errs += buf_add(buf, lease, sizeof(struct client_lease)); - errs += buf_add(buf, &fn_len, sizeof(fn_len)); - errs += buf_add(buf, lease->filename, fn_len); - errs += buf_add(buf, &sn_len, sizeof(sn_len)); - errs += buf_add(buf, lease->server_name, sn_len); - errs += buf_add(buf, &pr_len, sizeof(pr_len)); - errs += buf_add(buf, prefix, pr_len); - - for (i = 0; i < 256; i++) { - errs += buf_add(buf, &lease->options[i].len, - sizeof(lease->options[i].len)); - errs += buf_add(buf, lease->options[i].data, - lease->options[i].len); - } - - if (errs) - error("buf_add: %m"); - - if (buf_close(privfd, buf) == -1) - error("buf_close: %m"); -} - -int -script_go(void) -{ - struct imsg_hdr hdr; - struct buf *buf; - int ret; - - scripttime = time(NULL); - - hdr.code = IMSG_SCRIPT_GO; - hdr.len = sizeof(struct imsg_hdr); - - if ((buf = buf_open(hdr.len)) == NULL) - error("buf_open: %m"); - - if (buf_add(buf, &hdr, sizeof(hdr))) - error("buf_add: %m"); - - if (buf_close(privfd, buf) == -1) - error("buf_close: %m"); - - bzero(&hdr, sizeof(hdr)); - buf_read(privfd, &hdr, sizeof(hdr)); - if (hdr.code != IMSG_SCRIPT_GO_RET) - error("unexpected msg type %u", hdr.code); - if (hdr.len != sizeof(hdr) + sizeof(int)) - error("received corrupted message"); - buf_read(privfd, &ret, sizeof(ret)); - - return (ret); -} - -int -priv_script_go(void) -{ - char *scriptName, *argv[2], **envp, *epp[3], reason[] = "REASON=NBI"; - static char client_path[] = CLIENT_PATH; - struct interface_info *ip = ifi; - int pid, wpid, wstatus; - - scripttime = time(NULL); - - if (ip) { - scriptName = ip->client->config->script_name; - envp = ip->client->scriptEnv; - } else { - scriptName = top_level_config.script_name; - epp[0] = reason; - epp[1] = client_path; - epp[2] = NULL; - envp = epp; - } - - argv[0] = scriptName; - argv[1] = NULL; - - pid = fork(); - if (pid < 0) { - error("fork: %m"); - wstatus = 0; - } else if (pid) { - do { - wpid = wait(&wstatus); - } while (wpid != pid && wpid > 0); - if (wpid < 0) { - error("wait: %m"); - wstatus = 0; - } - } else { - execve(scriptName, argv, envp); - error("execve (%s, ...): %m", scriptName); - } - - if (ip) - script_flush_env(ip->client); - - return (wstatus & 0xff); -} - -void -script_set_env(struct client_state *client, const char *prefix, - const char *name, const char *value) -{ - int i, j, namelen; - - namelen = strlen(name); - - for (i = 0; client->scriptEnv[i]; i++) - if (strncmp(client->scriptEnv[i], name, namelen) == 0 && - client->scriptEnv[i][namelen] == '=') - break; - - if (client->scriptEnv[i]) - /* Reuse the slot. */ - free(client->scriptEnv[i]); - else { - /* New variable. Expand if necessary. */ - if (i >= client->scriptEnvsize - 1) { - char **newscriptEnv; - int newscriptEnvsize = client->scriptEnvsize + 50; - - newscriptEnv = realloc(client->scriptEnv, - newscriptEnvsize); - if (newscriptEnv == NULL) { - free(client->scriptEnv); - client->scriptEnv = NULL; - client->scriptEnvsize = 0; - error("script_set_env: no memory for variable"); - } - client->scriptEnv = newscriptEnv; - client->scriptEnvsize = newscriptEnvsize; - } - /* need to set the NULL pointer at end of array beyond - the new slot. */ - client->scriptEnv[i + 1] = NULL; - } - /* Allocate space and format the variable in the appropriate slot. */ - client->scriptEnv[i] = malloc(strlen(prefix) + strlen(name) + 1 + - strlen(value) + 1); - if (client->scriptEnv[i] == NULL) - error("script_set_env: no memory for variable assignment"); - - /* No `` or $() command substitution allowed in environment values! */ - for (j=0; j < strlen(value); j++) - switch (value[j]) { - case '`': - case '$': - error("illegal character (%c) in value '%s'", value[j], - value); - /* not reached */ - } - snprintf(client->scriptEnv[i], strlen(prefix) + strlen(name) + - 1 + strlen(value) + 1, "%s%s=%s", prefix, name, value); -} - -void -script_flush_env(struct client_state *client) -{ - int i; - - for (i = 0; client->scriptEnv[i]; i++) { - free(client->scriptEnv[i]); - client->scriptEnv[i] = NULL; - } - client->scriptEnvsize = 0; -} - -int -dhcp_option_ev_name(char *buf, size_t buflen, struct option *option) -{ - int i; - - for (i = 0; option->name[i]; i++) { - if (i + 1 == buflen) - return 0; - if (option->name[i] == '-') - buf[i] = '_'; - else - buf[i] = option->name[i]; - } - - buf[i] = 0; - return 1; -} - -void -go_daemon(void) -{ - static int state = 0; - - if (no_daemon || state) - return; - - state = 1; - - /* Stop logging to stderr... */ - log_perror = 0; - - if (daemon(1, 0) == -1) - error("daemon"); - - /* we are chrooted, daemon(3) fails to open /dev/null */ - if (nullfd != -1) { - dup2(nullfd, STDIN_FILENO); - dup2(nullfd, STDOUT_FILENO); - dup2(nullfd, STDERR_FILENO); - close(nullfd); - nullfd = -1; - } -} - -int -check_option(struct client_lease *l, int option) -{ - char *opbuf; - char *sbuf; - - /* we use this, since this is what gets passed to dhclient-script */ - - opbuf = pretty_print_option(option, l->options[option].data, - l->options[option].len, 0, 0); - - sbuf = option_as_string(option, l->options[option].data, - l->options[option].len); - - switch (option) { - case DHO_SUBNET_MASK: - case DHO_TIME_SERVERS: - case DHO_NAME_SERVERS: - case DHO_ROUTERS: - case DHO_DOMAIN_NAME_SERVERS: - case DHO_LOG_SERVERS: - case DHO_COOKIE_SERVERS: - case DHO_LPR_SERVERS: - case DHO_IMPRESS_SERVERS: - case DHO_RESOURCE_LOCATION_SERVERS: - case DHO_SWAP_SERVER: - case DHO_BROADCAST_ADDRESS: - case DHO_NIS_SERVERS: - case DHO_NTP_SERVERS: - case DHO_NETBIOS_NAME_SERVERS: - case DHO_NETBIOS_DD_SERVER: - case DHO_FONT_SERVERS: - case DHO_DHCP_SERVER_IDENTIFIER: - if (!ipv4addrs(opbuf)) { - warning("Invalid IP address in option: %s", opbuf); - return (0); - } - return (1) ; - case DHO_HOST_NAME: - case DHO_DOMAIN_NAME: - case DHO_NIS_DOMAIN: - if (!res_hnok(sbuf)) { - warning("Bogus Host Name option %d: %s (%s)", option, - sbuf, opbuf); - return (0); - } - return (1); - case DHO_PAD: - case DHO_TIME_OFFSET: - case DHO_BOOT_SIZE: - case DHO_MERIT_DUMP: - case DHO_ROOT_PATH: - case DHO_EXTENSIONS_PATH: - case DHO_IP_FORWARDING: - case DHO_NON_LOCAL_SOURCE_ROUTING: - case DHO_POLICY_FILTER: - case DHO_MAX_DGRAM_REASSEMBLY: - case DHO_DEFAULT_IP_TTL: - case DHO_PATH_MTU_AGING_TIMEOUT: - case DHO_PATH_MTU_PLATEAU_TABLE: - case DHO_INTERFACE_MTU: - case DHO_ALL_SUBNETS_LOCAL: - case DHO_PERFORM_MASK_DISCOVERY: - case DHO_MASK_SUPPLIER: - case DHO_ROUTER_DISCOVERY: - case DHO_ROUTER_SOLICITATION_ADDRESS: - case DHO_STATIC_ROUTES: - case DHO_TRAILER_ENCAPSULATION: - case DHO_ARP_CACHE_TIMEOUT: - case DHO_IEEE802_3_ENCAPSULATION: - case DHO_DEFAULT_TCP_TTL: - case DHO_TCP_KEEPALIVE_INTERVAL: - case DHO_TCP_KEEPALIVE_GARBAGE: - case DHO_VENDOR_ENCAPSULATED_OPTIONS: - case DHO_NETBIOS_NODE_TYPE: - case DHO_NETBIOS_SCOPE: - case DHO_X_DISPLAY_MANAGER: - case DHO_DHCP_REQUESTED_ADDRESS: - case DHO_DHCP_LEASE_TIME: - case DHO_DHCP_OPTION_OVERLOAD: - case DHO_DHCP_MESSAGE_TYPE: - case DHO_DHCP_PARAMETER_REQUEST_LIST: - case DHO_DHCP_MESSAGE: - case DHO_DHCP_MAX_MESSAGE_SIZE: - case DHO_DHCP_RENEWAL_TIME: - case DHO_DHCP_REBINDING_TIME: - case DHO_DHCP_CLASS_IDENTIFIER: - case DHO_DHCP_CLIENT_IDENTIFIER: - case DHO_DHCP_USER_CLASS_ID: - case DHO_END: - return (1); - default: - warning("unknown dhcp option value 0x%x", option); - return (unknown_ok); - } -} - -int -res_hnok(const char *dn) -{ - int pch = PERIOD, ch = *dn++; - - while (ch != '\0') { - int nch = *dn++; - - if (periodchar(ch)) { - ; - } else if (periodchar(pch)) { - if (!borderchar(ch)) - return (0); - } else if (periodchar(nch) || nch == '\0') { - if (!borderchar(ch)) - return (0); - } else { - if (!middlechar(ch)) - return (0); - } - pch = ch, ch = nch; - } - return (1); -} - -/* Does buf consist only of dotted decimal ipv4 addrs? - * return how many if so, - * otherwise, return 0 - */ -int -ipv4addrs(char * buf) -{ - struct in_addr jnk; - int count = 0; - - while (inet_aton(buf, &jnk) == 1){ - count++; - while (periodchar(*buf) || digitchar(*buf)) - buf++; - if (*buf == '\0') - return (count); - while (*buf == ' ') - buf++; - } - return (0); -} - - -char * -option_as_string(unsigned int code, unsigned char *data, int len) -{ - static char optbuf[32768]; /* XXX */ - char *op = optbuf; - int opleft = sizeof(optbuf); - unsigned char *dp = data; - - if (code > 255) - error("option_as_string: bad code %d", code); - - for (; dp < data + len; dp++) { - if (!isascii(*dp) || !isprint(*dp)) { - if (dp + 1 != data + len || *dp != 0) { - snprintf(op, opleft, "\\%03o", *dp); - op += 4; - opleft -= 4; - } - } else if (*dp == '"' || *dp == '\'' || *dp == '$' || - *dp == '`' || *dp == '\\') { - *op++ = '\\'; - *op++ = *dp; - opleft -= 2; - } else { - *op++ = *dp; - opleft--; - } - } - if (opleft < 1) - goto toobig; - *op = 0; - return optbuf; -toobig: - warning("dhcp option too large"); - return "<error>"; -} - -int -fork_privchld(int fd, int fd2) -{ - struct pollfd pfd[1]; - int nfds; - - switch (fork()) { - case -1: - error("cannot fork"); - case 0: - break; - default: - return (0); - } - - setproctitle("%s [priv]", ifi->name); - - dup2(nullfd, STDIN_FILENO); - dup2(nullfd, STDOUT_FILENO); - dup2(nullfd, STDERR_FILENO); - close(nullfd); - close(fd2); - - for (;;) { - pfd[0].fd = fd; - pfd[0].events = POLLIN; - if ((nfds = poll(pfd, 1, INFTIM)) == -1) - if (errno != EINTR) - error("poll error"); - - if (nfds == 0 || !(pfd[0].revents & POLLIN)) - continue; - - dispatch_imsg(fd); - } -} diff --git a/sbin/dhclient/dhclient.conf b/sbin/dhclient/dhclient.conf deleted file mode 100644 index 147e0045a5d8..000000000000 --- a/sbin/dhclient/dhclient.conf +++ /dev/null @@ -1,36 +0,0 @@ -send host-name "andare.fugue.com"; -send dhcp-client-identifier 1:0:a0:24:ab:fb:9c; -send dhcp-lease-time 3600; -supersede domain-name "fugue.com home.vix.com"; -prepend domain-name-servers 127.0.0.1; -request subnet-mask, broadcast-address, time-offset, routers, - domain-name, domain-name-servers, host-name; -require subnet-mask, domain-name-servers; -timeout 60; -retry 60; -reboot 10; -select-timeout 5; -initial-interval 2; -script "/etc/dhclient-script"; -media "-link0 -link1 -link2", "link0 link1"; -reject 192.33.137.209; - -alias { - interface "ep0"; - fixed-address 192.5.5.213; - option subnet-mask 255.255.255.255; -} - -lease { - interface "ep0"; - fixed-address 192.33.137.200; - medium "link0 link1"; - option host-name "andare.swiftmedia.com"; - option subnet-mask 255.255.255.0; - option broadcast-address 192.33.137.255; - option routers 192.33.137.250; - option domain-name-servers 127.0.0.1; - renew 2 2000/1/12 00:00:01; - rebind 2 2000/1/12 00:00:01; - expire 2 2000/1/12 00:00:01; -} diff --git a/sbin/dhclient/dhclient.conf.5 b/sbin/dhclient/dhclient.conf.5 deleted file mode 100644 index daf6f79c9537..000000000000 --- a/sbin/dhclient/dhclient.conf.5 +++ /dev/null @@ -1,541 +0,0 @@ -.\" $OpenBSD: dhclient.conf.5,v 1.5 2004/11/01 23:10:18 henning Exp $ -.\" -.\" Copyright (c) 1997 The Internet Software Consortium. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. -.\" -.\" This software has been written for the Internet Software Consortium -.\" by Ted Lemon <mellon@fugue.com> in cooperation with Vixie -.\" Enterprises. To learn more about the Internet Software Consortium, -.\" see ``http://www.isc.org/isc''. To learn more about Vixie -.\" Enterprises, see ``http://www.vix.com''. -.\" -.Dd January 1, 1997 -.Dt DHCLIENT.CONF 5 -.Os -.Sh NAME -.Nm dhclient.conf -.Nd DHCP client configuration file -.Sh DESCRIPTION -The -.Nm -file contains configuration information for -.Xr dhclient 8 , -the Internet Software Consortium DHCP Client. -.Pp -The -.Nm -file is a free-form ASCII text file. -It is parsed by the recursive-descent parser built into -.Xr dhclient 8 . -The file may contain extra tabs and newlines for formatting purposes. -Keywords in the file are case-insensitive. -Comments may be placed anywhere within the file (except within quotes). -Comments begin with the -.Sq # -character and end at the end of the line. -.Pp -The -.Nm -file can be used to configure the behaviour of the client in a wide variety -of ways: protocol timing, information requested from the server, information -required of the server, defaults to use if the server does not provide -certain information, values with which to override information provided by -the server, or values to prepend or append to information provided by the -server. -The configuration file can also be preinitialized with addresses to -use on networks that don't have DHCP servers. -.Sh PROTOCOL TIMING -The timing behaviour of the client need not be configured by the user. -If no timing configuration is provided by the user, a fairly -reasonable timing behaviour will be used by default \- one which -results in fairly timely updates without placing an inordinate load on -the server. -.Pp -The following statements can be used to adjust the timing behaviour of -the DHCP client if required, however: -.Bl -tag -width Ds -.It Ic timeout Ar time ; -The -.Ic timeout -statement determines the amount of time that must pass between the -time that the client begins to try to determine its address and the -time that it decides that it's not going to be able to contact a server. -By default, this timeout is sixty seconds. -After the timeout has passed, if there are any static leases defined in the -configuration file, or any leases remaining in the lease database that -have not yet expired, the client will loop through these leases -attempting to validate them, and if it finds one that appears to be -valid, it will use that lease's address. -If there are no valid static leases or unexpired leases in the lease database, -the client will restart the protocol after the defined retry interval. -.It Ic retry Ar time ; -The -.Ic retry -statement determines the time that must pass after the client has -determined that there is no DHCP server present before it tries again -to contact a DHCP server. -By default, this is five minutes. -.It Ic select-timeout Ar time ; -It is possible (some might say desirable) for there to be more than -one DHCP server serving any given network. -In this case, it is possible that a client may be sent more than one offer -in response to its initial lease discovery message. -It may be that one of these offers is preferable to the other -(e.g., one offer may have the address the client previously used, -and the other may not). -.Pp -The -.Ic select-timeout -is the time after the client sends its first lease discovery request -at which it stops waiting for offers from servers, assuming that it -has received at least one such offer. -If no offers have been received by the time the -.Ic select-timeout -has expired, the client will accept the first offer that arrives. -.Pp -By default, the -.Ic select-timeout -is zero seconds \- that is, the client will take the first offer it sees. -.It Ic reboot Ar time ; -When the client is restarted, it first tries to reacquire the last -address it had. -This is called the INIT-REBOOT state. -If it is still attached to the same network it was attached to when it last -ran, this is the quickest way to get started. -The -.Ic reboot -statement sets the time that must elapse after the client first tries -to reacquire its old address before it gives up and tries to discover -a new address. -By default, the reboot timeout is ten seconds. -.It Ic backoff-cutoff Ar time ; -The client uses an exponential backoff algorithm with some randomness, -so that if many clients try to configure themselves at the same time, -they will not make their requests in lockstep. -The -.Ic backoff-cutoff -statement determines the maximum amount of time that the client is -allowed to back off. -It defaults to two minutes. -.It Ic initial-interval Ar time ; -The -.Ic initial-interval -statement sets the amount of time between the first attempt to reach a -server and the second attempt to reach a server. -Each time a message is sent, the interval between messages is incremented by -twice the current interval multiplied by a random number between zero and one. -If it is greater than the backoff-cutoff amount, it is set to that -amount. -It defaults to ten seconds. -.El -.Sh LEASE REQUIREMENTS AND REQUESTS -The DHCP protocol allows the client to request that the server send it -specific information, and not send it other information that it is not -prepared to accept. -The protocol also allows the client to reject offers from servers if they -don't contain information the client needs, or if the information provided -is not satisfactory. -.Pp -There is a variety of data contained in offers that DHCP servers send -to DHCP clients. -The data that can be specifically requested is what are called -.Em DHCP Options . -DHCP Options are defined in -.Xr dhcp-options 5 . -.Bl -tag -width Ds -.It Xo -.Ic request Op Ar option -.Oo , Ar ... option Oc ; -.Xc -The -.Ic request -statement causes the client to request that any server responding to the -client send the client its values for the specified options. -Only the option names should be specified in the request statement \- not -option parameters. -.It Xo -.Ic require Op Ar option -.Oo , Ar ... option Oc ; -.Xc -The -.Ic require -statement lists options that must be sent in order for an offer to be accepted. -Offers that do not contain all the listed options will be ignored. -.It Xo -.Ic send No { Op Ar option declaration -.Oo , Ar ... option declaration Oc } -.Xc -The -.Ic send -statement causes the client to send the specified options to the server with -the specified values. -These are full option declarations as described in -.Xr dhcp-options 5 . -Options that are always sent in the DHCP protocol should not be specified -here, except that the client can specify a -.Ar dhcp-lease-time -option other than the default requested lease time, which is two hours. -The other obvious use for this statement is to send information to the server -that will allow it to differentiate between this client and other -clients or kinds of clients. -.El -.Sh OPTION MODIFIERS -In some cases, a client may receive option data from the server which -is not really appropriate for that client, or may not receive -information that it needs, and for which a useful default value exists. -It may also receive information which is useful, but which needs to be -supplemented with local information. -To handle these needs, several option modifiers are available. -.Bl -tag -width Ds -.It Xo -.Ic default No { Op Ar option declaration -.Oo , Ar ... option declaration Oc } -.Xc -If for some set of options the client should use the value supplied by -the server, but needs to use some default value if no value was supplied -by the server, these values can be defined in the -.Ic default -statement. -.It Xo -.Ic supersede No { Op Ar option declaration -.Oo , Ar ... option declaration Oc } -.Xc -If for some set of options the client should always use its own value -rather than any value supplied by the server, these values can be defined -in the -.Ic supersede -statement. -.It Xo -.Ic prepend No { Op Ar option declaration -.Oo , Ar ... option declaration Oc } -.Xc -If for some set of options the client should use a value you supply, -and then use the values supplied by the server, if any, -these values can be defined in the -.Ic prepend -statement. -The -.Ic prepend -statement can only be used for options which allow more than one value to -be given. -This restriction is not enforced \- if violated, the results are unpredictable. -.It Xo -.Ic append No { Op Ar option declaration -.Oo , Ar ... option declaration Oc } -.Xc -If for some set of options the client should first use the values -supplied by the server, if any, and then use values you supply, these -values can be defined in the -.Ic append -statement. -The -.Ic append -statement can only be used for options which allow more than one value to -be given. -This restriction is not enforced \- if you ignore it, -the behaviour will be unpredictable. -.El -.Sh LEASE DECLARATIONS -The lease declaration: -.Pp -.Xo -.Ic \ \& lease No { Ar lease-declaration -.Oo Ar ... lease-declaration Oc } -.Xc -.Pp -The DHCP client may decide after some period of time (see -.Sx PROTOCOL TIMING ) -that it is not going to succeed in contacting a server. -At that time, it consults its own database of old leases and tests each one -that has not yet timed out by pinging the listed router for that lease to -see if that lease could work. -It is possible to define one or more -.Em fixed -leases in the client configuration file for networks where there is no DHCP -or BOOTP service, so that the client can still automatically configure its -address. -This is done with the -.Ic lease -statement. -.Pp -NOTE: the lease statement is also used in the -.Pa dhclient.leases -file in order to record leases that have been received from DHCP servers. -Some of the syntax for leases as described below is only needed in the -.Pa dhclient.leases -file. -Such syntax is documented here for completeness. -.Pp -A lease statement consists of the lease keyword, followed by a left -curly brace, followed by one or more lease declaration statements, -followed by a right curly brace. -The following lease declarations are possible: -.Bl -tag -width Ds -.It Ic bootp ; -The -.Ic bootp -statement is used to indicate that the lease was acquired using the -BOOTP protocol rather than the DHCP protocol. -It is never necessary to specify this in the client configuration file. -The client uses this syntax in its lease database file. -.It Ic interface Ar \&"string\&" ; -The -.Ic interface -lease statement is used to indicate the interface on which the lease is valid. -If set, this lease will only be tried on a particular interface. -When the client receives a lease from a server, it always records the -interface number on which it received that lease. -If predefined leases are specified in the -.Nm -file, the interface should also be specified, although this is not required. -.It Ic fixed-address Ar ip-address ; -The -.Ic fixed-address -statement is used to set the IP address of a particular lease. -This is required for all lease statements. -The IP address must be specified as a dotted quad (e.g., 12.34.56.78). -.It Ic filename Ar \&"string\&" ; -The -.Ic filename -statement specifies the name of the boot filename to use. -This is not used by the standard client configuration script, but is -included for completeness. -.It Ic server-name Ar \&"string\&" ; -The -.Ic server-name -statement specifies the name of the boot server name to use. -This is also not used by the standard client configuration script. -.It Ic option Ar option-declaration ; -The -.Ic option -statement is used to specify the value of an option supplied by the server, -or, in the case of predefined leases declared in -.Nm dhclient.conf , -the value that the user wishes the client configuration script to use if the -predefined lease is used. -.It Ic script Ar \&"script-name\&" ; -The -.Ic script -statement is used to specify the pathname of the DHCP client configuration -script. -This script is used by the DHCP client to set each interface's initial -configuration prior to requesting an address, to test the address once it -has been offered, and to set the interface's final configuration once a -lease has been acquired. -If no lease is acquired, the script is used to test predefined leases, if -any, and also called once if no valid lease can be identified. -For more information, see -.Xr dhclient.leases 5 . -.It Ic medium Ar \&"media setup\&" ; -The -.Ic medium -statement can be used on systems where network interfaces cannot -automatically determine the type of network to which they are connected. -The media setup string is a system-dependent parameter which is passed -to the DHCP client configuration script when initializing the interface. -On -.Ux -and UNIX-like systems, the argument is passed on the ifconfig command line -when configuring the interface. -.Pp -The DHCP client automatically declares this parameter if it used a -media type (see the -.Ic media -statement) when configuring the interface in order to obtain a lease. -This statement should be used in predefined leases only if the network -interface requires media type configuration. -.It Ic renew Ar date ; -.It Ic rebind Ar date ; -.It Ic expire Ar date ; -The -.Ic renew -statement defines the time at which the DHCP client should begin trying to -contact its server to renew a lease that it is using. -The -.Ic rebind -statement defines the time at which the DHCP client should begin to try to -contact -.Em any -DHCP server in order to renew its lease. -The -.Ic expire -statement defines the time at which the DHCP client must stop using a lease -if it has not been able to contact a server in order to renew it. -.El -.Pp -These declarations are automatically set in leases acquired by the -DHCP client, but must also be configured in predefined leases \- a -predefined lease whose expiry time has passed will not be used by the -DHCP client. -.Pp -Dates are specified as follows: -.Pp -.Ar \ \&<weekday> -.Sm off -.Ar <year> No / Ar <month> No / Ar <day> -.Ar <hour> : <minute> : <second> -.Sm on -.Pp -The weekday is present to make it easy for a human to tell when a -lease expires \- it's specified as a number from zero to six, with zero -being Sunday. -When declaring a predefined lease, it can always be specified as zero. -The year is specified with the century, so it should generally be four -digits except for really long leases. -The month is specified as a number starting with 1 for January. -The day of the month is likewise specified starting with 1. -The hour is a number between 0 and 23, -the minute a number between 0 and 59, -and the second also a number between 0 and 59. -.Sh ALIAS DECLARATIONS -.Ic alias No { Ar declarations ... No } -.Pp -Some DHCP clients running TCP/IP roaming protocols may require that in -addition to the lease they may acquire via DHCP, their interface also -be configured with a predefined IP alias so that they can have a -permanent IP address even while roaming. -The Internet Software Consortium DHCP client doesn't support roaming with -fixed addresses directly, but in order to facilitate such experimentation, -the DHCP client can be set up to configure an IP alias using the -.Ic alias -declaration. -.Pp -The -.Ic alias -declaration resembles a lease declaration, except that options other than -the subnet-mask option are ignored by the standard client configuration -script, and expiry times are ignored. -A typical alias declaration includes an interface declaration, a fixed-address -declaration for the IP alias address, and a subnet-mask option declaration. -A medium statement should never be included in an alias declaration. -.Sh OTHER DECLARATIONS -.Bl -tag -width Ds -.It Ic reject Ar ip-address ; -The -.Ic reject -statement causes the DHCP client to reject offers from servers who use -the specified address as a server identifier. -This can be used to avoid being configured by rogue or misconfigured DHCP -servers, although it should be a last resort \- better to track down -the bad DHCP server and fix it. -.It Xo -.Ic interface Ar \&"name\&" No { Ar declarations -.Ar ... No } -.Xc -A client with more than one network interface may require different -behaviour depending on which interface is being configured. -All timing parameters and declarations other than lease and alias -declarations can be enclosed in an interface declaration, and those -parameters will then be used only for the interface that matches the -specified name. -Interfaces for which there is no interface declaration will use the -parameters declared outside of any interface declaration, -or the default settings. -.It Xo -.Ic media Ar \&"media setup\&" -.Oo , Ar \&"media setup\&" , ... Oc ; -.Xc -The -.Ic media -statement defines one or more media configuration parameters which may -be tried while attempting to acquire an IP address. -The DHCP client will cycle through each media setup string on the list, -configuring the interface using that setup and attempting to boot, -and then trying the next one. -This can be used for network interfaces which aren't capable of sensing -the media type unaided \- whichever media type succeeds in getting a request -to the server and hearing the reply is probably right (no guarantees). -.Pp -The media setup is only used for the initial phase of address -acquisition (the DHCPDISCOVER and DHCPOFFER packets). -Once an address has been acquired, the DHCP client will record it in its -lease database and will record the media type used to acquire the address. -Whenever the client tries to renew the lease, it will use that same media type. -The lease must expire before the client will go back to cycling through media -types. -.El -.Sh EXAMPLES -The following configuration file is used on a laptop -which has an IP alias of 192.5.5.213, and has one interface, -ep0 (a 3Com 3C589C). -Booting intervals have been shortened somewhat from the default, because -the client is known to spend most of its time on networks with little DHCP -activity. -The laptop does roam to multiple networks. -.Bd -literal -offset indent -timeout 60; -retry 60; -reboot 10; -select-timeout 5; -initial-interval 2; -reject 192.33.137.209; - -interface "ep0" { - send host-name "andare.fugue.com"; - send dhcp-client-identifier 1:0:a0:24:ab:fb:9c; - send dhcp-lease-time 3600; - supersede domain-name "fugue.com rc.vix.com home.vix.com"; - prepend domain-name-servers 127.0.0.1; - request subnet-mask, broadcast-address, time-offset, routers, - domain-name, domain-name-servers, host-name; - require subnet-mask, domain-name-servers; - script "/etc/dhclient-script"; - media "media 10baseT/UTP", "media 10base2/BNC"; -} - -alias { - interface "ep0"; - fixed-address 192.5.5.213; - option subnet-mask 255.255.255.255; -} -.Ed -.Pp -This is a very complicated -.Nm -file \- in general, yours should be much simpler. -In many cases, it's sufficient to just create an empty -.Nm -file \- the defaults are usually fine. -.Sh SEE ALSO -.Xr dhclient.leases 5 , -.Xr dhcp-options 5 , -.Xr dhcpd.conf 5 , -.Xr dhclient 8 , -.Xr dhcpd 8 -.Pp -RFC 2132, RFC 2131. -.Sh AUTHORS -.Xr dhclient 8 -was written by -.An Ted Lemon Aq mellon@vix.com -under a contract with Vixie Labs. -.Pp -The current implementation was reworked by -.An Henning Brauer Aq henning@openbsd.org . diff --git a/sbin/dhclient/dhclient.leases.5 b/sbin/dhclient/dhclient.leases.5 deleted file mode 100644 index d5a8a2958767..000000000000 --- a/sbin/dhclient/dhclient.leases.5 +++ /dev/null @@ -1,87 +0,0 @@ -.\" $OpenBSD: dhclient.leases.5,v 1.4 2004/04/15 08:59:47 jmc Exp $ -.\" -.\" Copyright (c) 1997 The Internet Software Consortium. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. -.\" -.\" This software has been written for the Internet Software Consortium -.\" by Ted Lemon <mellon@fugue.com> in cooperation with Vixie -.\" Enterprises. To learn more about the Internet Software Consortium, -.\" see ``http://www.isc.org/isc''. To learn more about Vixie -.\" Enterprises, see ``http://www.vix.com''. -.\" -.Dd January 1, 1997 -.Dt DHCLIENT.LEASES 5 -.Os -.Sh NAME -.Nm dhclient.leases -.Nd DHCP client lease database -.Sh DESCRIPTION -The Internet Software Consortium DHCP client keeps a persistent -database of leases that it has acquired that are still valid. -The database is a free-form ASCII file containing one valid declaration -per lease. -If more than one declaration appears for a given lease, -the last one in the file is used. -The file is written as a log, so this is not an unusual occurrence. -.Pp -The lease file is named -.Qq dhclient.leases.IFNAME , -where -.Qq IFNAME -represents the network interface the DHCP client acquired the lease on. -For example, if -.Xr dhclient 8 -is configured for the em0 network device, -the lease file will be named -.Qq dhclient.leases.em0 . -.Pp -The format of the lease declarations is described in -.Xr dhclient.conf 5 . -.Sh FILES -.Bl -tag -width "/var/db/dhclient.leases.IFNAME " -.It /var/db/dhclient.leases.IFNAME -Current lease file. -.El -.Sh SEE ALSO -.Xr dhclient.conf 5 , -.Xr dhcp-options 5 , -.Xr dhcpd.conf 5 , -.Xr dhclient 8 , -.Xr dhcpd 8 -.Pp -RFC 2132, RFC 2131. -.Sh AUTHORS -.Xr dhclient 8 -was written by -.An Ted Lemon Aq mellon@vix.com -under a contract with Vixie Labs. -.Pp -The current implementation was reworked by -.An Henning Brauer Aq henning@openbsd.org . diff --git a/sbin/dhclient/dhcp-options.5 b/sbin/dhclient/dhcp-options.5 deleted file mode 100644 index da3dd1c3c079..000000000000 --- a/sbin/dhclient/dhcp-options.5 +++ /dev/null @@ -1,590 +0,0 @@ -.\" $OpenBSD: dhcp-options.5,v 1.5 2005/03/02 15:30:42 jmc Exp $ -.\" -.\" Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. -.\" -.\" This software has been written for the Internet Software Consortium -.\" by Ted Lemon <mellon@fugue.com> in cooperation with Vixie -.\" Enterprises. To learn more about the Internet Software Consortium, -.\" see ``http://www.isc.org/isc''. To learn more about Vixie -.\" Enterprises, see ``http://www.vix.com''. -.\" -.Dd January 1, 1995 -.Dt DHCP-OPTIONS 5 -.Os -.Sh NAME -.Nm dhcp-options -.Nd Dynamic Host Configuration Protocol options -.Sh DESCRIPTION -The Dynamic Host Configuration protocol allows the client to receive -.Ic options -from the DHCP server describing the network configuration and various -services that are available on the network. -When configuring -.Xr dhcpd 8 -or -.Xr dhclient 8 , -options must often be declared. -The syntax for declaring options, and the names and formats of the options -that can be declared, are documented here. -.Sh REFERENCE: OPTION STATEMENTS -DHCP -.Ic option -statements always start with the -.Ic option -keyword, followed by an option name, followed by option data. -The option names and data formats are described below. -It is not necessary to exhaustively specify all DHCP options \- -only those options which are needed by clients must be specified. -.Pp -Option data comes in a variety of formats, as defined below: -.Pp -The -.Ar ip-address -data type can be entered either as an explicit IP address -(e.g., 239.254.197.10) or as a domain name (e.g., haagen.isc.org). -A domain name must resolve to a single IP address. -.Pp -The -.Ar int32 -data type specifies a signed 32-bit integer. -The -.Ar uint32 -data type specifies an unsigned 32-bit integer. -The -.Ar int16 -and -.Ar uint16 -data types specify signed and unsigned 16-bit integers. -The -.Ar int8 -and -.Ar uint8 -data types specify signed and unsigned 8-bit integers. -Unsigned 8-bit integers are also sometimes referred to as octets. -.Pp -The -.Ar string -data type specifies an -.Tn NVT -.Pq Network Virtual Terminal -.Tn ASCII -string, which must be enclosed in double quotes \- for example, -to specify a domain-name option, the syntax would be -.Pp -.Dl option domain-name \&"isc.org\&"; -.Pp -The -.Ar flag -data type specifies a boolean value. -Booleans can be either true or false -(or on or off, if that makes more sense to you). -.Pp -The -.Ar data-string -data type specifies either an -.Tn NVT ASCII -string enclosed in double quotes, or a series of octets specified in -hexadecimal, separated by colons. -For example: -.Pp -.Dl option dhcp-client-identifier \&"CLIENT-FOO\&"; -or -.Dl option dhcp-client-identifier 43:4c:49:45:54:2d:46:4f:4f; -.Pp -The documentation for the various options mentioned below is taken -from the IETF draft document on DHCP options, RFC 2132. -Options which are not listed by name may be defined by the name -.Pf option\- Ns Ar nnn , -where -.Ar nnn -is the decimal number of the option code. -These options may be followed either by a string, enclosed in quotes, or by -a series of octets, expressed as two-digit hexadecimal numbers separated -by colons. -For example: -.Bd -literal -offset indent -option option-133 "my-option-133-text"; -option option-129 1:54:c9:2b:47; -.Ed -.Pp -Because -.Xr dhcpd 8 -does not know the format of these undefined option codes, -no checking is done to ensure the correctness of the entered data. -.Pp -The standard options are: -.Ss RFC 1497 Vendor Extensions -.Bl -tag -width Ds -.It Ic option subnet-mask Ar ip-address ; -The -.Ic subnet-mask -option specifies the client's subnet mask as per RFC 950. -If no subnet-mask option is provided anywhere in scope, as a last resort -.Xr dhcpd 8 -will use the subnet mask from the subnet declaration for the network on -which an address is being assigned. -However, -.Em any -subnet-mask option declaration that is in scope for the address being -assigned will override the subnet mask specified in the subnet declaration. -.It Ic option time-offset Ar int32 ; -The -.Ic time-offset -option specifies the offset of the client's subnet in seconds from -Coordinated Universal Time (UTC). -.It Xo -.Ic option routers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic routers -option specifies a list of IP addresses for routers on the client's subnet. -Routers should be listed in order of preference. -.It Xo -.Ic option time-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic time-server -option specifies a list of RFC 868 time servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option ien116-name-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic ien116-name-servers -option specifies a list of IEN 116 name servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option domain-name-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic domain-name-servers -option specifies a list of Domain Name System (STD 13, RFC 1035) name servers -available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option log-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic log-servers -option specifies a list of MIT-LCS UDP log servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option cookie-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic cookie-servers -option specifies a list of RFC 865 cookie servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option lpr-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic lpr-servers -option specifies a list of RFC 1179 line printer servers available to the -client. -Servers should be listed in order of preference. -.It Xo -.Ic option impress-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic impress-servers -option specifies a list of Imagen Impress servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option resource-location-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -This option specifies a list of RFC 887 Resource Location servers available -to the client. -Servers should be listed in order of preference. -.It Ic option host-name Ar string ; -This option specifies the name of the client. -The name may or may not be qualified with the local domain name -(it is preferable to use the -.Ic domain-name -option to specify the domain name). -See RFC 1035 for character set restrictions. -.It Ic option boot-size Ar uint16 ; -This option specifies the length in 512-octet blocks of the default -boot image for the client. -.It Ic option merit-dump Ar string ; -This option specifies the pathname of a file to which the client's -core image should be dumped in the event the client crashes. -The path is formatted as a character string consisting of characters from -the -.Tn NVT ASCII -character set. -.It Ic option domain-name Ar string ; -This option specifies the domain name that the client should use when -resolving hostnames via the Domain Name System. -.It Ic option swap-server Ar ip-address ; -This specifies the IP address of the client's swap server. -.It Ic option root-path Ar string ; -This option specifies the pathname that contains the client's root disk. -The path is formatted as a character string consisting of characters from -the -.Tn NVT ASCII -character set. -.El -.Ss IP Layer Parameters per Host -.Bl -tag -width Ds -.It Ic option ip-forwarding Ar flag ; -This option specifies whether the client should configure its IP layer -for packet forwarding. -A value of 0 means disable IP forwarding, and a value of 1 means enable -IP forwarding. -.It Ic option non-local-source-routing Ar flag ; -This option specifies whether the client should configure its IP -layer to allow forwarding of datagrams with non-local source routes -(see Section 3.3.5 of [4] for a discussion of this topic). -A value of 0 means disallow forwarding of such datagrams, and a value of 1 -means allow forwarding. -.It Xo -.Ic option policy-filter Ar ip-address ip-address -.Oo , Ar ip-address ip-address ... Oc ; -.Xc -This option specifies policy filters for non-local source routing. -The filters consist of a list of IP addresses and masks which specify -destination/mask pairs with which to filter incoming source routes. -.Pp -Any source-routed datagram whose next-hop address does not match one -of the filters should be discarded by the client. -.Pp -See STD 3 (RFC 1122) for further information. -.It Ic option max-dgram-reassembly Ar uint16 ; -This option specifies the maximum size datagram that the client should be -prepared to reassemble. -The minimum legal value is 576. -.It Ic option default-ip-ttl Ar uint8 ; -This option specifies the default time-to-live that the client should -use on outgoing datagrams. -.It Ic option path-mtu-aging-timeout Ar uint32 ; -This option specifies the timeout (in seconds) to use when aging Path -MTU values discovered by the mechanism defined in RFC 1191. -.It Xo -.Ic option path-mtu-plateau-table Ar uint16 -.Oo , Ar uint16 ... Oc ; -.Xc -This option specifies a table of MTU sizes to use when performing -Path MTU Discovery as defined in RFC 1191. -The table is formatted as a list of 16-bit unsigned integers, -ordered from smallest to largest. -The minimum MTU value cannot be smaller than 68. -.El -.Ss IP Layer Parameters per Interface -.Bl -tag -width Ds -.It Ic option interface-mtu Ar uint16 ; -This option specifies the MTU to use on this interface. -The minimum legal value for the MTU is 68. -.It Ic option all-subnets-local Ar flag ; -This option specifies whether or not the client may assume that all subnets -of the IP network to which the client is connected use the same MTU as the -subnet of that network to which the client is directly connected. -A value of 1 indicates that all subnets share the same MTU. -A value of 0 means that the client should assume that some subnets of the -directly connected network may have smaller MTUs. -.It Ic option broadcast-address Ar ip-address ; -This option specifies the broadcast address in use on the client's subnet. -Legal values for broadcast addresses are specified in section 3.2.1.3 of -STD 3 (RFC 1122). -.It Ic option perform-mask-discovery Ar flag ; -This option specifies whether or not the client should perform subnet mask -discovery using ICMP. -A value of 0 indicates that the client should not perform mask discovery. -A value of 1 means that the client should perform mask discovery. -.It Ic option mask-supplier Ar flag ; -This option specifies whether or not the client should respond to subnet mask -requests using ICMP. -A value of 0 indicates that the client should not respond. -A value of 1 means that the client should respond. -.It Ic option router-discovery Ar flag ; -This option specifies whether or not the client should solicit routers using -the Router Discovery mechanism defined in RFC 1256. -A value of 0 indicates that the client should not perform router discovery. -A value of 1 means that the client should perform router discovery. -.It Ic option router-solicitation-address Ar ip-address ; -This option specifies the address to which the client should transmit -router solicitation requests. -.It Xo -.Ic option static-routes Ar ip-address ip-address -.Oo , Ar ip-address ip-address ... Oc ; -.Xc -This option specifies a list of static routes that the client should -install in its routing cache. -If multiple routes to the same destination are specified, they are listed -in descending order of priority. -.Pp -The routes consist of a list of IP address pairs. -The first address is the destination address, -and the second address is the router for the destination. -.Pp -The default route (0.0.0.0) is an illegal destination for a static route. -To specify the default route, use the -.Ic routers -option. -.El -.Ss Link Layer Parameters per Interface -.Bl -tag -width Ds -.It Ic option trailer-encapsulation Ar flag ; -This option specifies whether or not the client should negotiate the -use of trailers (RFC 893 [14]) when using the ARP protocol. -A value of 0 indicates that the client should not attempt to use trailers. -A value of 1 means that the client should attempt to use trailers. -.It Ic option arp-cache-timeout Ar uint32 ; -This option specifies the timeout in seconds for ARP cache entries. -.It Ic option ieee802-3-encapsulation Ar flag ; -This option specifies whether or not the client should use Ethernet -Version 2 (RFC 894) or IEEE 802.3 (RFC 1042) encapsulation if the -interface is an Ethernet. -A value of 0 indicates that the client should use RFC 894 encapsulation. -A value of 1 means that the client should use RFC 1042 encapsulation. -.El -.Ss TCP Parameters -.Bl -tag -width Ds -.It Ic option default-tcp-ttl Ar uint8 ; -This option specifies the default TTL that the client should use when -sending TCP segments. -The minimum value is 1. -.It Ic option tcp-keepalive-interval Ar uint32 ; -This option specifies the interval (in seconds) that the client TCP -should wait before sending a keepalive message on a TCP connection. -The time is specified as a 32-bit unsigned integer. -A value of zero indicates that the client should not generate keepalive -messages on connections unless specifically requested by an application. -.It Ic option tcp-keepalive-garbage Ar flag ; -This option specifies whether or not the client should send TCP keepalive -messages with an octet of garbage for compatibility with older implementations. -A value of 0 indicates that a garbage octet should not be sent. -A value of 1 indicates that a garbage octet should be sent. -.El -.Ss Application and Service Parameters -.Bl -tag -width Ds -.It Ic option nis-domain Ar string ; -This option specifies the name of the client's NIS (Sun Network Information -Services) domain. -The domain is formatted as a character string consisting of characters -from the -.Tn NVT ASCII -character set. -.It Xo -.Ic option nis-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -This option specifies a list of IP addresses indicating NIS servers -available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option ntp-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -This option specifies a list of IP addresses indicating NTP (RFC 1035) -servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option netbios-name-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The NetBIOS name server (NBNS) option specifies a list of RFC 1001/1002 -NBNS name servers listed in order of preference. -NetBIOS Name Service is currently more commonly referred to as WINS. -WINS servers can be specified using the -.Ic netbios-name-servers -option. -.It Xo -.Ic option netbios-dd-server Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The NetBIOS datagram distribution server (NBDD) option specifies a -list of RFC 1001/1002 NBDD servers listed in order of preference. -.It Ic option netbios-node-type Ar uint8 ; -The NetBIOS node type option allows NetBIOS over TCP/IP clients which -are configurable to be configured as described in RFC 1001/1002. -The value is specified as a single octet which identifies the client type. -.Pp -Possible node types are: -.Bl -tag -width Ds -.It 1 -B-node: Broadcast - no WINS -.It 2 -P-node: Peer - WINS only -.It 4 -M-node: Mixed - broadcast, then WINS -.It 8 -H-node: Hybrid - WINS, then broadcast -.El -.It Ic option netbios-scope Ar string ; -The NetBIOS scope option specifies the NetBIOS over TCP/IP scope -parameter for the client as specified in RFC 1001/1002. -See RFC 1001, RFC 1002, and RFC 1035 for character-set restrictions. -.It Xo -.Ic option font-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -This option specifies a list of X Window System Font servers available -to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option x-display-manager Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -This option specifies a list of systems that are running the X Window -System Display Manager and are available to the client. -Addresses should be listed in order of preference. -.It Ic option dhcp-client-identifier Ar data-string ; -This option can be used to specify a DHCP client identifier in a -host declaration, so that -.Xr dhcpd 8 -can find the host record by matching against the client identifier. -.It Ic option nisplus-domain Ar string ; -This option specifies the name of the client's NIS+ domain. -The domain is formatted as a character string consisting of characters -from the -.Tn NVT ASCII -character set. -.It Xo -.Ic option nisplus-servers Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -This option specifies a list of IP addresses indicating NIS+ servers -available to the client. -Servers should be listed in order of preference. -.It Ic option tftp-server-name Ar string ; -This option is used to identify a TFTP server and, if supported by the -client, should have the same effect as the -.Ic server-name -declaration. -BOOTP clients are unlikely to support this option. -Some DHCP clients will support it, and others actually require it. -.It Ic option bootfile-name Ar string ; -This option is used to identify a bootstrap file. -If supported by the client, it should have the same effect as the -.Ic filename -declaration. -BOOTP clients are unlikely to support this option. -Some DHCP clients will support it, and others actually require it. -.It Xo -.Ic option mobile-ip-home-agent Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -This option specifies a list of IP addresses indicating mobile IP -home agents available to the client. -Agents should be listed in order of preference, although normally there -will be only one such agent. -.It Xo -.Ic option smtp-server Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic smtp-server -option specifies a list of SMTP servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option pop-server Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic pop-server -option specifies a list of POP3 servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option nntp-server Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic nntp-server -option specifies a list of NNTP servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option www-server Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic www-server -option specifies a list of WWW servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option finger-server Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic finger-server -option specifies a list of -.Xr finger 1 -servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option irc-server Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic irc-server -option specifies a list of IRC servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option streettalk-server Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The -.Ic streettalk-server -option specifies a list of StreetTalk servers available to the client. -Servers should be listed in order of preference. -.It Xo -.Ic option streettalk-directory-assistance-server Ar ip-address -.Oo , Ar ip-address ... Oc ; -.Xc -The StreetTalk Directory Assistance (STDA) server option specifies a -list of STDA servers available to the client. -Servers should be listed in order of preference. -.El -.Sh SEE ALSO -.Xr dhclient.conf 5 , -.Xr dhcpd.conf 5 , -.Xr dhcpd.leases 5 , -.Xr dhclient 8 , -.Xr dhcpd 8 -.Pp -RFC 2131, RFC 2132. -.Sh AUTHORS -.Xr dhcpd 8 -was written by -.An Ted Lemon Aq mellon@vix.com -under a contract with Vixie Labs. -.Pp -The current implementation was reworked by -.An Henning Brauer Aq henning@openbsd.org . diff --git a/sbin/dhclient/dhcp.h b/sbin/dhclient/dhcp.h deleted file mode 100644 index 33f51224a378..000000000000 --- a/sbin/dhclient/dhcp.h +++ /dev/null @@ -1,168 +0,0 @@ -/* $OpenBSD: dhcp.h,v 1.5 2004/05/04 15:49:49 deraadt Exp $ */ - -/* Protocol structures... */ - -/* - * Copyright (c) 1995, 1996 The Internet Software Consortium. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#define DHCP_UDP_OVERHEAD (14 + /* Ethernet header */ \ - 20 + /* IP header */ \ - 8) /* UDP header */ -#define DHCP_SNAME_LEN 64 -#define DHCP_FILE_LEN 128 -#define DHCP_FIXED_NON_UDP 236 -#define DHCP_FIXED_LEN (DHCP_FIXED_NON_UDP + DHCP_UDP_OVERHEAD) - /* Everything but options. */ -#define DHCP_MTU_MAX 1500 -#define DHCP_OPTION_LEN (DHCP_MTU_MAX - DHCP_FIXED_LEN) - -#define BOOTP_MIN_LEN 300 -#define DHCP_MIN_LEN 548 - -struct dhcp_packet { - u_int8_t op; /* Message opcode/type */ - u_int8_t htype; /* Hardware addr type (see net/if_types.h) */ - u_int8_t hlen; /* Hardware addr length */ - u_int8_t hops; /* Number of relay agent hops from client */ - u_int32_t xid; /* Transaction ID */ - u_int16_t secs; /* Seconds since client started looking */ - u_int16_t flags; /* Flag bits */ - struct in_addr ciaddr; /* Client IP address (if already in use) */ - struct in_addr yiaddr; /* Client IP address */ - struct in_addr siaddr; /* IP address of next server to talk to */ - struct in_addr giaddr; /* DHCP relay agent IP address */ - unsigned char chaddr[16]; /* Client hardware address */ - char sname[DHCP_SNAME_LEN]; /* Server name */ - char file[DHCP_FILE_LEN]; /* Boot filename */ - unsigned char options[DHCP_OPTION_LEN]; - /* Optional parameters - (actual length dependent on MTU). */ -}; - -/* BOOTP (rfc951) message types */ -#define BOOTREQUEST 1 -#define BOOTREPLY 2 - -/* Possible values for flags field... */ -#define BOOTP_BROADCAST 32768L - -/* Possible values for hardware type (htype) field... */ -#define HTYPE_ETHER 1 /* Ethernet */ -#define HTYPE_IEEE802 6 /* IEEE 802.2 Token Ring... */ -#define HTYPE_FDDI 8 /* FDDI... */ - -/* Magic cookie validating dhcp options field (and bootp vendor - extensions field). */ -#define DHCP_OPTIONS_COOKIE "\143\202\123\143" - -/* DHCP Option codes: */ - -#define DHO_PAD 0 -#define DHO_SUBNET_MASK 1 -#define DHO_TIME_OFFSET 2 -#define DHO_ROUTERS 3 -#define DHO_TIME_SERVERS 4 -#define DHO_NAME_SERVERS 5 -#define DHO_DOMAIN_NAME_SERVERS 6 -#define DHO_LOG_SERVERS 7 -#define DHO_COOKIE_SERVERS 8 -#define DHO_LPR_SERVERS 9 -#define DHO_IMPRESS_SERVERS 10 -#define DHO_RESOURCE_LOCATION_SERVERS 11 -#define DHO_HOST_NAME 12 -#define DHO_BOOT_SIZE 13 -#define DHO_MERIT_DUMP 14 -#define DHO_DOMAIN_NAME 15 -#define DHO_SWAP_SERVER 16 -#define DHO_ROOT_PATH 17 -#define DHO_EXTENSIONS_PATH 18 -#define DHO_IP_FORWARDING 19 -#define DHO_NON_LOCAL_SOURCE_ROUTING 20 -#define DHO_POLICY_FILTER 21 -#define DHO_MAX_DGRAM_REASSEMBLY 22 -#define DHO_DEFAULT_IP_TTL 23 -#define DHO_PATH_MTU_AGING_TIMEOUT 24 -#define DHO_PATH_MTU_PLATEAU_TABLE 25 -#define DHO_INTERFACE_MTU 26 -#define DHO_ALL_SUBNETS_LOCAL 27 -#define DHO_BROADCAST_ADDRESS 28 -#define DHO_PERFORM_MASK_DISCOVERY 29 -#define DHO_MASK_SUPPLIER 30 -#define DHO_ROUTER_DISCOVERY 31 -#define DHO_ROUTER_SOLICITATION_ADDRESS 32 -#define DHO_STATIC_ROUTES 33 -#define DHO_TRAILER_ENCAPSULATION 34 -#define DHO_ARP_CACHE_TIMEOUT 35 -#define DHO_IEEE802_3_ENCAPSULATION 36 -#define DHO_DEFAULT_TCP_TTL 37 -#define DHO_TCP_KEEPALIVE_INTERVAL 38 -#define DHO_TCP_KEEPALIVE_GARBAGE 39 -#define DHO_NIS_DOMAIN 40 -#define DHO_NIS_SERVERS 41 -#define DHO_NTP_SERVERS 42 -#define DHO_VENDOR_ENCAPSULATED_OPTIONS 43 -#define DHO_NETBIOS_NAME_SERVERS 44 -#define DHO_NETBIOS_DD_SERVER 45 -#define DHO_NETBIOS_NODE_TYPE 46 -#define DHO_NETBIOS_SCOPE 47 -#define DHO_FONT_SERVERS 48 -#define DHO_X_DISPLAY_MANAGER 49 -#define DHO_DHCP_REQUESTED_ADDRESS 50 -#define DHO_DHCP_LEASE_TIME 51 -#define DHO_DHCP_OPTION_OVERLOAD 52 -#define DHO_DHCP_MESSAGE_TYPE 53 -#define DHO_DHCP_SERVER_IDENTIFIER 54 -#define DHO_DHCP_PARAMETER_REQUEST_LIST 55 -#define DHO_DHCP_MESSAGE 56 -#define DHO_DHCP_MAX_MESSAGE_SIZE 57 -#define DHO_DHCP_RENEWAL_TIME 58 -#define DHO_DHCP_REBINDING_TIME 59 -#define DHO_DHCP_CLASS_IDENTIFIER 60 -#define DHO_DHCP_CLIENT_IDENTIFIER 61 -#define DHO_DHCP_USER_CLASS_ID 77 -#define DHO_END 255 - -/* DHCP message types. */ -#define DHCPDISCOVER 1 -#define DHCPOFFER 2 -#define DHCPREQUEST 3 -#define DHCPDECLINE 4 -#define DHCPACK 5 -#define DHCPNAK 6 -#define DHCPRELEASE 7 -#define DHCPINFORM 8 diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h deleted file mode 100644 index 8097f14b1de1..000000000000 --- a/sbin/dhclient/dhcpd.h +++ /dev/null @@ -1,437 +0,0 @@ -/* $OpenBSD: dhcpd.h,v 1.33 2004/05/06 22:29:15 deraadt Exp $ */ - -/* - * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> - * Copyright (c) 1995, 1996, 1997, 1998, 1999 - * The Internet Software Consortium. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include <sys/types.h> - -#include <sys/socket.h> -#include <sys/sockio.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <sys/un.h> -#include <sys/wait.h> - -#include <net/if.h> -#include <net/if_dl.h> -#include <net/route.h> - -#include <netinet/in.h> -#include <arpa/inet.h> - -#include <ctype.h> -#include <errno.h> -#include <fcntl.h> -#include <limits.h> -#include <netdb.h> -#include <paths.h> -#include <unistd.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <time.h> -#include <unistd.h> - -#include "dhcp.h" -#include "tree.h" - -#define LOCAL_PORT 68 -#define REMOTE_PORT 67 - -struct option_data { - int len; - u_int8_t *data; -}; - -struct string_list { - struct string_list *next; - char *string; -}; - -struct iaddr { - int len; - unsigned char iabuf[16]; -}; - -struct iaddrlist { - struct iaddrlist *next; - struct iaddr addr; -}; - -struct packet { - struct dhcp_packet *raw; - int packet_length; - int packet_type; - int options_valid; - int client_port; - struct iaddr client_addr; - struct interface_info *interface; - struct hardware *haddr; - struct option_data options[256]; -}; - -struct hardware { - u_int8_t htype; - u_int8_t hlen; - u_int8_t haddr[16]; -}; - -struct client_lease { - struct client_lease *next; - time_t expiry, renewal, rebind; - struct iaddr address; - char *server_name; - char *filename; - struct string_list *medium; - unsigned int is_static : 1; - unsigned int is_bootp : 1; - struct option_data options[256]; -}; - -/* Possible states in which the client can be. */ -enum dhcp_state { - S_REBOOTING, - S_INIT, - S_SELECTING, - S_REQUESTING, - S_BOUND, - S_RENEWING, - S_REBINDING -}; - -struct client_config { - struct option_data defaults[256]; - enum { - ACTION_DEFAULT, - ACTION_SUPERSEDE, - ACTION_PREPEND, - ACTION_APPEND - } default_actions[256]; - - struct option_data send_options[256]; - u_int8_t required_options[256]; - u_int8_t requested_options[256]; - int requested_option_count; - time_t timeout; - time_t initial_interval; - time_t retry_interval; - time_t select_interval; - time_t reboot_timeout; - time_t backoff_cutoff; - struct string_list *media; - char *script_name; - enum { IGNORE, ACCEPT, PREFER } - bootp_policy; - struct string_list *medium; - struct iaddrlist *reject_list; -}; - -struct client_state { - struct client_lease *active; - struct client_lease *new; - struct client_lease *offered_leases; - struct client_lease *leases; - struct client_lease *alias; - enum dhcp_state state; - struct iaddr destination; - u_int32_t xid; - u_int16_t secs; - time_t first_sending; - time_t interval; - struct string_list *medium; - struct dhcp_packet packet; - int packet_length; - struct iaddr requested_address; - struct client_config *config; - char **scriptEnv; - int scriptEnvsize; - struct string_list *env; - int envc; -}; - -struct interface_info { - struct interface_info *next; - struct hardware hw_address; - struct in_addr primary_address; - char name[IFNAMSIZ]; - int rfdesc; - int wfdesc; - unsigned char *rbuf; - size_t rbuf_max; - size_t rbuf_offset; - size_t rbuf_len; - struct ifreq *ifp; - struct client_state *client; - int noifmedia; - int errors; - int dead; - u_int16_t index; -}; - -struct timeout { - struct timeout *next; - time_t when; - void (*func)(void *); - void *what; -}; - -struct protocol { - struct protocol *next; - int fd; - void (*handler)(struct protocol *); - void *local; -}; - -#define DEFAULT_HASH_SIZE 97 - -struct hash_bucket { - struct hash_bucket *next; - unsigned char *name; - int len; - unsigned char *value; -}; - -struct hash_table { - int hash_count; - struct hash_bucket *buckets[DEFAULT_HASH_SIZE]; -}; - -/* Default path to dhcpd config file. */ -#define _PATH_DHCLIENT_CONF "/etc/dhclient.conf" -#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases" -#define DHCPD_LOG_FACILITY LOG_DAEMON - -#define MAX_TIME 0x7fffffff -#define MIN_TIME 0 - -/* External definitions... */ - -/* options.c */ -int cons_options(struct packet *, struct dhcp_packet *, int, - struct tree_cache **, int, int, int, u_int8_t *, int); -char *pretty_print_option(unsigned int, - unsigned char *, int, int, int); -void do_packet(struct interface_info *, struct dhcp_packet *, - int, unsigned int, struct iaddr, struct hardware *); - -/* errwarn.c */ -extern int warnings_occurred; -void error(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -int warning(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -int note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -int debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -int parse_warn(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); - -/* conflex.c */ -extern int lexline, lexchar; -extern char *token_line, *tlname; -extern char comments[4096]; -extern int comment_index; -extern int eol_token; -void new_parse(char *); -int next_token(char **, FILE *); -int peek_token(char **, FILE *); - -/* parse.c */ -void skip_to_semi(FILE *); -int parse_semi(FILE *); -char *parse_string(FILE *); -int parse_ip_addr(FILE *, struct iaddr *); -void parse_hardware_param(FILE *, struct hardware *); -void parse_lease_time(FILE *, time_t *); -unsigned char *parse_numeric_aggregate(FILE *, unsigned char *, int *, - int, int, int); -void convert_num(unsigned char *, char *, int, int); -time_t parse_date(FILE *); - -/* tree.c */ -pair cons(caddr_t, pair); - -/* alloc.c */ -struct string_list *new_string_list(size_t size); -struct hash_table *new_hash_table(int); -struct hash_bucket *new_hash_bucket(void); - -/* bpf.c */ -int if_register_bpf(struct interface_info *); -void if_register_send(struct interface_info *); -void if_register_receive(struct interface_info *); -ssize_t send_packet(struct interface_info *, struct dhcp_packet *, size_t, - struct in_addr, struct sockaddr_in *, struct hardware *); -ssize_t receive_packet(struct interface_info *, unsigned char *, size_t, - struct sockaddr_in *, struct hardware *); - -/* dispatch.c */ -extern void (*bootp_packet_handler)(struct interface_info *, - struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *); -void discover_interfaces(struct interface_info *); -void reinitialize_interfaces(void); -void dispatch(void); -void got_one(struct protocol *); -void add_timeout(time_t, void (*)(void *), void *); -void cancel_timeout(void (*)(void *), void *); -void add_protocol(char *, int, void (*)(struct protocol *), void *); -void remove_protocol(struct protocol *); -int interface_link_status(char *); - -/* hash.c */ -struct hash_table *new_hash(void); -void add_hash(struct hash_table *, unsigned char *, int, unsigned char *); -unsigned char *hash_lookup(struct hash_table *, unsigned char *, int); - -/* tables.c */ -extern struct option dhcp_options[256]; -extern unsigned char dhcp_option_default_priority_list[]; -extern int sizeof_dhcp_option_default_priority_list; -extern struct hash_table universe_hash; -extern struct universe dhcp_universe; -void initialize_universes(void); - -/* convert.c */ -u_int32_t getULong(unsigned char *); -int32_t getLong(unsigned char *); -u_int16_t getUShort(unsigned char *); -int16_t getShort(unsigned char *); -void putULong(unsigned char *, u_int32_t); -void putLong(unsigned char *, int32_t); -void putUShort(unsigned char *, unsigned int); -void putShort(unsigned char *, int); - -/* inet.c */ -struct iaddr subnet_number(struct iaddr, struct iaddr); -struct iaddr broadcast_addr(struct iaddr, struct iaddr); -int addr_eq(struct iaddr, struct iaddr); -char *piaddr(struct iaddr); - -/* dhclient.c */ -extern char *path_dhclient_conf; -extern char *path_dhclient_db; -extern time_t cur_time; -extern int log_priority; -extern int log_perror; - -extern struct client_config top_level_config; - -void dhcpoffer(struct packet *); -void dhcpack(struct packet *); -void dhcpnak(struct packet *); - -void send_discover(void *); -void send_request(void *); -void send_decline(void *); - -void state_reboot(void *); -void state_init(void *); -void state_selecting(void *); -void state_requesting(void *); -void state_bound(void *); -void state_panic(void *); - -void bind_lease(struct interface_info *); - -void make_discover(struct interface_info *, struct client_lease *); -void make_request(struct interface_info *, struct client_lease *); -void make_decline(struct interface_info *, struct client_lease *); - -void free_client_lease(struct client_lease *); -void rewrite_client_leases(void); -void write_client_lease(struct interface_info *, struct client_lease *, int); - -void priv_script_init(char *, char *); -void priv_script_write_params(char *, struct client_lease *); -int priv_script_go(void); - -void script_init(char *, struct string_list *); -void script_write_params(char *, struct client_lease *); -int script_go(void); -void client_envadd(struct client_state *, - const char *, const char *, const char *, ...); -void script_set_env(struct client_state *, const char *, const char *, - const char *); -void script_flush_env(struct client_state *); -int dhcp_option_ev_name(char *, size_t, struct option *); - -struct client_lease *packet_to_lease(struct packet *); -void go_daemon(void); -void client_location_changed(void); - -void bootp(struct packet *); -void dhcp(struct packet *); - -/* packet.c */ -void assemble_hw_header(struct interface_info *, unsigned char *, - int *, struct hardware *); -void assemble_udp_ip_header(unsigned char *, int *, u_int32_t, u_int32_t, - unsigned int, unsigned char *, int); -ssize_t decode_hw_header(unsigned char *, int, struct hardware *); -ssize_t decode_udp_ip_header(unsigned char *, int, struct sockaddr_in *, - unsigned char *, int); - -/* ethernet.c */ -void assemble_ethernet_header(struct interface_info *, unsigned char *, - int *, struct hardware *); -ssize_t decode_ethernet_header(struct interface_info *, unsigned char *, - int, struct hardware *); - -/* clparse.c */ -int read_client_conf(void); -void read_client_leases(void); -void parse_client_statement(FILE *, struct interface_info *, - struct client_config *); -int parse_X(FILE *, u_int8_t *, int); -int parse_option_list(FILE *, u_int8_t *); -void parse_interface_declaration(FILE *, struct client_config *); -struct interface_info *interface_or_dummy(char *); -void make_client_state(struct interface_info *); -void make_client_config(struct interface_info *, struct client_config *); -void parse_client_lease_statement(FILE *, int); -void parse_client_lease_declaration(FILE *, struct client_lease *, - struct interface_info **); -struct option *parse_option_decl(FILE *, struct option_data *); -void parse_string_list(FILE *, struct string_list **, int); -void parse_reject_statement(FILE *, struct client_config *); - -/* privsep.c */ -struct buf *buf_open(size_t); -int buf_add(struct buf *, void *, size_t); -int buf_close(int, struct buf *); -ssize_t buf_read(int, void *, size_t); -void dispatch_imsg(int); diff --git a/sbin/dhclient/dhctoken.h b/sbin/dhclient/dhctoken.h deleted file mode 100644 index 7b23242fbac0..000000000000 --- a/sbin/dhclient/dhctoken.h +++ /dev/null @@ -1,136 +0,0 @@ -/* $OpenBSD: dhctoken.h,v 1.2 2004/02/04 12:16:56 henning Exp $ */ - -/* Tokens for config file lexer and parser. */ - -/* - * Copyright (c) 1995, 1996, 1997, 1998, 1999 - * The Internet Software Consortium. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#define SEMI ';' -#define DOT '.' -#define COLON ':' -#define COMMA ',' -#define SLASH '/' -#define LBRACE '{' -#define RBRACE '}' - -#define FIRST_TOKEN HOST -#define HOST 256 -#define HARDWARE 257 -#define FILENAME 258 -#define FIXED_ADDR 259 -#define OPTION 260 -#define ETHERNET 261 -#define STRING 262 -#define NUMBER 263 -#define NUMBER_OR_NAME 264 -#define NAME 265 -#define TIMESTAMP 266 -#define STARTS 267 -#define ENDS 268 -#define UID 269 -#define CLASS 270 -#define LEASE 271 -#define RANGE 272 -#define PACKET 273 -#define CIADDR 274 -#define YIADDR 275 -#define SIADDR 276 -#define GIADDR 277 -#define SUBNET 278 -#define NETMASK 279 -#define DEFAULT_LEASE_TIME 280 -#define MAX_LEASE_TIME 281 -#define VENDOR_CLASS 282 -#define USER_CLASS 283 -#define SHARED_NETWORK 284 -#define SERVER_NAME 285 -#define DYNAMIC_BOOTP 286 -#define SERVER_IDENTIFIER 287 -#define DYNAMIC_BOOTP_LEASE_CUTOFF 288 -#define DYNAMIC_BOOTP_LEASE_LENGTH 289 -#define BOOT_UNKNOWN_CLIENTS 290 -#define NEXT_SERVER 291 -#define TOKEN_RING 292 -#define GROUP 293 -#define ONE_LEASE_PER_CLIENT 294 -#define GET_LEASE_HOSTNAMES 295 -#define USE_HOST_DECL_NAMES 296 -#define SEND 297 -#define CLIENT_IDENTIFIER 298 -#define REQUEST 299 -#define REQUIRE 300 -#define TIMEOUT 301 -#define RETRY 302 -#define SELECT_TIMEOUT 303 -#define SCRIPT 304 -#define INTERFACE 305 -#define RENEW 306 -#define REBIND 307 -#define EXPIRE 308 -#define UNKNOWN_CLIENTS 309 -#define ALLOW 310 -#define BOOTP 311 -#define DENY 312 -#define BOOTING 313 -#define DEFAULT 314 -#define MEDIA 315 -#define MEDIUM 316 -#define ALIAS 317 -#define REBOOT 318 -#define ABANDONED 319 -#define BACKOFF_CUTOFF 320 -#define INITIAL_INTERVAL 321 -#define NAMESERVER 322 -#define DOMAIN 323 -#define SEARCH 324 -#define SUPERSEDE 325 -#define APPEND 326 -#define PREPEND 327 -#define HOSTNAME 328 -#define CLIENT_HOSTNAME 329 -#define REJECT 330 -#define FDDI 331 -#define USE_LEASE_ADDR_FOR_DEFAULT_ROUTE 332 -#define AUTHORITATIVE 333 -#define TOKEN_NOT 334 -#define ALWAYS_REPLY_RFC1048 335 - -#define is_identifier(x) ((x) >= FIRST_TOKEN && \ - (x) != STRING && \ - (x) != NUMBER && \ - (x) != EOF) diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c deleted file mode 100644 index a0d7e90e865a..000000000000 --- a/sbin/dhclient/dispatch.c +++ /dev/null @@ -1,495 +0,0 @@ -/* $OpenBSD: dispatch.c,v 1.31 2004/09/21 04:07:03 david Exp $ */ - -/* - * Copyright 2004 Henning Brauer <henning@openbsd.org> - * Copyright (c) 1995, 1996, 1997, 1998, 1999 - * The Internet Software Consortium. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include "dhcpd.h" - -#include <sys/ioctl.h> - -#include <net/if_media.h> -#include <ifaddrs.h> -#include <poll.h> - -struct protocol *protocols; -struct timeout *timeouts; -static struct timeout *free_timeouts; -static int interfaces_invalidated; -void (*bootp_packet_handler)(struct interface_info *, - struct dhcp_packet *, int, unsigned int, - struct iaddr, struct hardware *); - -static int interface_status(struct interface_info *ifinfo); - -/* - * Use getifaddrs() to get a list of all the attached interfaces. For - * each interface that's of type INET and not the loopback interface, - * register that interface with the network I/O software, figure out - * what subnet it's on, and add it to the list of interfaces. - */ -void -discover_interfaces(struct interface_info *iface) -{ - struct ifaddrs *ifap, *ifa; - struct sockaddr_in foo; - struct ifreq *tif; - - if (getifaddrs(&ifap) != 0) - error("getifaddrs failed"); - - for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { - if ((ifa->ifa_flags & IFF_LOOPBACK) || - (ifa->ifa_flags & IFF_POINTOPOINT) || - (!(ifa->ifa_flags & IFF_UP))) - continue; - - if (strcmp(iface->name, ifa->ifa_name)) - continue; - - /* - * If we have the capability, extract link information - * and record it in a linked list. - */ - if (ifa->ifa_addr->sa_family == AF_LINK) { - struct sockaddr_dl *foo = - (struct sockaddr_dl *)ifa->ifa_addr; - - iface->index = foo->sdl_index; - iface->hw_address.hlen = foo->sdl_alen; - iface->hw_address.htype = HTYPE_ETHER; /* XXX */ - memcpy(iface->hw_address.haddr, - LLADDR(foo), foo->sdl_alen); - } else if (ifa->ifa_addr->sa_family == AF_INET) { - struct iaddr addr; - - memcpy(&foo, ifa->ifa_addr, sizeof(foo)); - if (foo.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) - continue; - if (!iface->ifp) { - int len = IFNAMSIZ + ifa->ifa_addr->sa_len; - if ((tif = malloc(len)) == NULL) - error("no space to remember ifp"); - strlcpy(tif->ifr_name, ifa->ifa_name, IFNAMSIZ); - memcpy(&tif->ifr_addr, ifa->ifa_addr, - ifa->ifa_addr->sa_len); - iface->ifp = tif; - iface->primary_address = foo.sin_addr; - } - addr.len = 4; - memcpy(addr.iabuf, &foo.sin_addr.s_addr, addr.len); - } - } - - if (!iface->ifp) - error("%s: not found", iface->name); - - /* Register the interface... */ - if_register_receive(iface); - if_register_send(iface); - add_protocol(iface->name, iface->rfdesc, got_one, iface); - freeifaddrs(ifap); -} - -void -reinitialize_interfaces(void) -{ - interfaces_invalidated = 1; -} - -/* - * Wait for packets to come in using poll(). When a packet comes in, - * call receive_packet to receive the packet and possibly strip hardware - * addressing information from it, and then call through the - * bootp_packet_handler hook to try to do something with it. - */ -void -dispatch(void) -{ - int count, i, to_msec, nfds = 0; - struct protocol *l; - struct pollfd *fds; - time_t howlong; - - for (l = protocols; l; l = l->next) - nfds++; - - fds = malloc(nfds * sizeof(struct pollfd)); - if (fds == NULL) - error("Can't allocate poll structures."); - - do { - /* - * Call any expired timeouts, and then if there's still - * a timeout registered, time out the select call then. - */ -another: - if (timeouts) { - struct timeout *t; - - if (timeouts->when <= cur_time) { - t = timeouts; - timeouts = timeouts->next; - (*(t->func))(t->what); - t->next = free_timeouts; - free_timeouts = t; - goto another; - } - - /* - * Figure timeout in milliseconds, and check for - * potential overflow, so we can cram into an - * int for poll, while not polling with a - * negative timeout and blocking indefinitely. - */ - howlong = timeouts->when - cur_time; - if (howlong > INT_MAX / 1000) - howlong = INT_MAX / 1000; - to_msec = howlong * 1000; - } else - to_msec = -1; - - /* Set up the descriptors to be polled. */ - for (i = 0, l = protocols; l; l = l->next) { - struct interface_info *ip = l->local; - - if (ip && (l->handler != got_one || !ip->dead)) { - fds[i].fd = l->fd; - fds[i].events = POLLIN; - fds[i].revents = 0; - i++; - } - } - - if (i == 0) - error("No live interfaces to poll on - exiting."); - - /* Wait for a packet or a timeout... XXX */ - count = poll(fds, nfds, to_msec); - - /* Not likely to be transitory... */ - if (count == -1) { - if (errno == EAGAIN || errno == EINTR) { - time(&cur_time); - continue; - } else - error("poll: %m"); - } - - /* Get the current time... */ - time(&cur_time); - - i = 0; - for (l = protocols; l; l = l->next) { - struct interface_info *ip; - ip = l->local; - if ((fds[i].revents & (POLLIN | POLLHUP))) { - fds[i].revents = 0; - if (ip && (l->handler != got_one || - !ip->dead)) - (*(l->handler))(l); - if (interfaces_invalidated) - break; - } - i++; - } - interfaces_invalidated = 0; - } while (1); -} - - -void -got_one(struct protocol *l) -{ - struct sockaddr_in from; - struct hardware hfrom; - struct iaddr ifrom; - ssize_t result; - union { - /* - * Packet input buffer. Must be as large as largest - * possible MTU. - */ - unsigned char packbuf[4095]; - struct dhcp_packet packet; - } u; - struct interface_info *ip = l->local; - - if ((result = receive_packet(ip, u.packbuf, sizeof(u), &from, - &hfrom)) == -1) { - warning("receive_packet failed on %s: %s", ip->name, - strerror(errno)); - ip->errors++; - if ((!interface_status(ip)) || - (ip->noifmedia && ip->errors > 20)) { - /* our interface has gone away. */ - warning("Interface %s no longer appears valid.", - ip->name); - ip->dead = 1; - interfaces_invalidated = 1; - close(l->fd); - remove_protocol(l); - free(ip); - } - return; - } - if (result == 0) - return; - - if (bootp_packet_handler) { - ifrom.len = 4; - memcpy(ifrom.iabuf, &from.sin_addr, ifrom.len); - - (*bootp_packet_handler)(ip, &u.packet, result, - from.sin_port, ifrom, &hfrom); - } -} - -int -interface_status(struct interface_info *ifinfo) -{ - char *ifname = ifinfo->name; - int ifsock = ifinfo->rfdesc; - struct ifreq ifr; - struct ifmediareq ifmr; - - /* get interface flags */ - memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); - if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) { - syslog(LOG_ERR, "ioctl(SIOCGIFFLAGS) on %s: %m", ifname); - goto inactive; - } - - /* - * if one of UP and RUNNING flags is dropped, - * the interface is not active. - */ - if ((ifr.ifr_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) - goto inactive; - - /* Next, check carrier on the interface, if possible */ - if (ifinfo->noifmedia) - goto active; - memset(&ifmr, 0, sizeof(ifmr)); - strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name)); - if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { - if (errno != EINVAL) { - syslog(LOG_DEBUG, "ioctl(SIOCGIFMEDIA) on %s: %m", - ifname); - - ifinfo->noifmedia = 1; - goto active; - } - /* - * EINVAL (or ENOTTY) simply means that the interface - * does not support the SIOCGIFMEDIA ioctl. We regard it alive. - */ - ifinfo->noifmedia = 1; - goto active; - } - if (ifmr.ifm_status & IFM_AVALID) { - switch (ifmr.ifm_active & IFM_NMASK) { - case IFM_ETHER: - if (ifmr.ifm_status & IFM_ACTIVE) - goto active; - else - goto inactive; - break; - default: - goto inactive; - } - } -inactive: - return (0); -active: - return (1); -} - -void -add_timeout(time_t when, void (*where)(void *), void *what) -{ - struct timeout *t, *q; - - /* See if this timeout supersedes an existing timeout. */ - t = NULL; - for (q = timeouts; q; q = q->next) { - if (q->func == where && q->what == what) { - if (t) - t->next = q->next; - else - timeouts = q->next; - break; - } - t = q; - } - - /* If we didn't supersede a timeout, allocate a timeout - structure now. */ - if (!q) { - if (free_timeouts) { - q = free_timeouts; - free_timeouts = q->next; - q->func = where; - q->what = what; - } else { - q = malloc(sizeof(struct timeout)); - if (!q) - error("Can't allocate timeout structure!"); - q->func = where; - q->what = what; - } - } - - q->when = when; - - /* Now sort this timeout into the timeout list. */ - - /* Beginning of list? */ - if (!timeouts || timeouts->when > q->when) { - q->next = timeouts; - timeouts = q; - return; - } - - /* Middle of list? */ - for (t = timeouts; t->next; t = t->next) { - if (t->next->when > q->when) { - q->next = t->next; - t->next = q; - return; - } - } - - /* End of list. */ - t->next = q; - q->next = NULL; -} - -void -cancel_timeout(void (*where)(void *), void *what) -{ - struct timeout *t, *q; - - /* Look for this timeout on the list, and unlink it if we find it. */ - t = NULL; - for (q = timeouts; q; q = q->next) { - if (q->func == where && q->what == what) { - if (t) - t->next = q->next; - else - timeouts = q->next; - break; - } - t = q; - } - - /* If we found the timeout, put it on the free list. */ - if (q) { - q->next = free_timeouts; - free_timeouts = q; - } -} - -/* Add a protocol to the list of protocols... */ -void -add_protocol(char *name, int fd, void (*handler)(struct protocol *), - void *local) -{ - struct protocol *p; - - p = malloc(sizeof(*p)); - if (!p) - error("can't allocate protocol struct for %s", name); - - p->fd = fd; - p->handler = handler; - p->local = local; - p->next = protocols; - protocols = p; -} - -void -remove_protocol(struct protocol *proto) -{ - struct protocol *p, *next, *prev; - - prev = NULL; - for (p = protocols; p; p = next) { - next = p->next; - if (p == proto) { - if (prev) - prev->next = p->next; - else - protocols = p->next; - free(p); - } - } -} - -int -interface_link_status(char *ifname) -{ - struct ifmediareq ifmr; - int sock; - - if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) - error("Can't create socket"); - - memset(&ifmr, 0, sizeof(ifmr)); - strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name)); - if (ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmr) == -1) { - /* EINVAL -> link state unknown. treat as active */ - if (errno != EINVAL) - syslog(LOG_DEBUG, "ioctl(SIOCGIFMEDIA) on %s: %m", - ifname); - close(sock); - return (1); - } - close(sock); - - if (ifmr.ifm_status & IFM_AVALID) { - if ((ifmr.ifm_active & IFM_NMASK) == IFM_ETHER) { - if (ifmr.ifm_status & IFM_ACTIVE) - return (1); - else - return (0); - } - } - return (1); -} diff --git a/sbin/dhclient/errwarn.c b/sbin/dhclient/errwarn.c deleted file mode 100644 index 03b75478457c..000000000000 --- a/sbin/dhclient/errwarn.c +++ /dev/null @@ -1,234 +0,0 @@ -/* $OpenBSD: errwarn.c,v 1.7 2004/05/04 22:23:01 mickey Exp $ */ - -/* Errors and warnings... */ - -/* - * Copyright (c) 1996 The Internet Software Consortium. - * All Rights Reserved. - * Copyright (c) 1995 RadioMail Corporation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of RadioMail Corporation, the Internet Software - * Consortium 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 RADIOMAIL CORPORATION, THE INTERNET - * SOFTWARE CONSORTIUM 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 RADIOMAIL CORPORATION 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. - * - * This software was written for RadioMail Corporation by Ted Lemon - * under a contract with Vixie Enterprises. Further modifications have - * been made for the Internet Software Consortium under a contract - * with Vixie Laboratories. - */ - -#include <errno.h> - -#include "dhcpd.h" - -static void do_percentm(char *obuf, size_t size, char *ibuf); - -static char mbuf[1024]; -static char fbuf[1024]; - -int warnings_occurred; - -/* - * Log an error message, then exit. - */ -void -error(char *fmt, ...) -{ - va_list list; - - do_percentm(fbuf, sizeof(fbuf), fmt); - - va_start(list, fmt); - vsnprintf(mbuf, sizeof(mbuf), fbuf, list); - va_end(list); - -#ifndef DEBUG - syslog(log_priority | LOG_ERR, "%s", mbuf); -#endif - - /* Also log it to stderr? */ - if (log_perror) { - write(2, mbuf, strlen(mbuf)); - write(2, "\n", 1); - } - - syslog(LOG_CRIT, "exiting."); - if (log_perror) { - fprintf(stderr, "exiting.\n"); - fflush(stderr); - } - exit(1); -} - -/* - * Log a warning message... - */ -int -warning(char *fmt, ...) -{ - va_list list; - - do_percentm(fbuf, sizeof(fbuf), fmt); - - va_start(list, fmt); - vsnprintf(mbuf, sizeof(mbuf), fbuf, list); - va_end(list); - -#ifndef DEBUG - syslog(log_priority | LOG_ERR, "%s", mbuf); -#endif - - if (log_perror) { - write(2, mbuf, strlen(mbuf)); - write(2, "\n", 1); - } - - return (0); -} - -/* - * Log a note... - */ -int -note(char *fmt, ...) -{ - va_list list; - - do_percentm(fbuf, sizeof(fbuf), fmt); - - va_start(list, fmt); - vsnprintf(mbuf, sizeof(mbuf), fbuf, list); - va_end(list); - -#ifndef DEBUG - syslog(log_priority | LOG_INFO, "%s", mbuf); -#endif - - if (log_perror) { - write(2, mbuf, strlen(mbuf)); - write(2, "\n", 1); - } - - return (0); -} - -/* - * Log a debug message... - */ -int -debug(char *fmt, ...) -{ - va_list list; - - do_percentm(fbuf, sizeof(fbuf), fmt); - - va_start(list, fmt); - vsnprintf(mbuf, sizeof(mbuf), fbuf, list); - va_end(list); - -#ifndef DEBUG - syslog(log_priority | LOG_DEBUG, "%s", mbuf); -#endif - - if (log_perror) { - write(2, mbuf, strlen(mbuf)); - write(2, "\n", 1); - } - - return (0); -} - -/* - * Find %m in the input string and substitute an error message string. - */ -static void -do_percentm(char *obuf, size_t size, char *ibuf) -{ - char ch; - char *s = ibuf; - char *t = obuf; - size_t prlen; - size_t fmt_left; - int saved_errno = errno; - - /* - * We wouldn't need this mess if printf handled %m, or if - * strerror() had been invented before syslog(). - */ - for (fmt_left = size; (ch = *s); ++s) { - if (ch == '%' && s[1] == 'm') { - ++s; - prlen = snprintf(t, fmt_left, "%s", - strerror(saved_errno)); - if (prlen >= fmt_left) - prlen = fmt_left - 1; - t += prlen; - fmt_left -= prlen; - } else { - if (fmt_left > 1) { - *t++ = ch; - fmt_left--; - } - } - } - *t = '\0'; -} - -int -parse_warn(char *fmt, ...) -{ - va_list list; - static char spaces[] = - " " - " "; /* 80 spaces */ - - do_percentm(mbuf, sizeof(mbuf), fmt); - snprintf(fbuf, sizeof(fbuf), "%s line %d: %s", tlname, lexline, mbuf); - va_start(list, fmt); - vsnprintf(mbuf, sizeof(mbuf), fbuf, list); - va_end(list); - -#ifndef DEBUG - syslog(log_priority | LOG_ERR, "%s", mbuf); - syslog(log_priority | LOG_ERR, "%s", token_line); - if (lexline < 81) - syslog(log_priority | LOG_ERR, - "%s^", &spaces[sizeof(spaces) - lexchar]); -#endif - - if (log_perror) { - write(2, mbuf, strlen(mbuf)); - write(2, "\n", 1); - write(2, token_line, strlen(token_line)); - write(2, "\n", 1); - write(2, spaces, lexchar - 1); - write(2, "^\n", 2); - } - - warnings_occurred = 1; - - return (0); -} diff --git a/sbin/dhclient/hash.c b/sbin/dhclient/hash.c deleted file mode 100644 index 4f1795b24351..000000000000 --- a/sbin/dhclient/hash.c +++ /dev/null @@ -1,119 +0,0 @@ -/* $OpenBSD: hash.c,v 1.9 2004/05/10 15:30:47 deraadt Exp $ */ - -/* Routines for manipulating hash tables... */ - -/* - * Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include "dhcpd.h" - -static int do_hash(unsigned char *, int, int); - -struct hash_table * -new_hash(void) -{ - struct hash_table *rv = new_hash_table(DEFAULT_HASH_SIZE); - - if (!rv) - return (rv); - memset(&rv->buckets[0], 0, - DEFAULT_HASH_SIZE * sizeof(struct hash_bucket *)); - return (rv); -} - -static int -do_hash(unsigned char *name, int len, int size) -{ - unsigned char *s = name; - int accum = 0, i = len; - - while (i--) { - /* Add the character in... */ - accum += *s++; - /* Add carry back in... */ - while (accum > 255) - accum = (accum & 255) + (accum >> 8); - } - return (accum % size); -} - -void add_hash(struct hash_table *table, unsigned char *name, int len, - unsigned char *pointer) -{ - struct hash_bucket *bp; - int hashno; - - if (!table) - return; - if (!len) - len = strlen((char *)name); - - hashno = do_hash(name, len, table->hash_count); - bp = new_hash_bucket(); - - if (!bp) { - warning("Can't add %s to hash table.", name); - return; - } - bp->name = name; - bp->value = pointer; - bp->next = table->buckets[hashno]; - bp->len = len; - table->buckets[hashno] = bp; -} - -unsigned char * -hash_lookup(struct hash_table *table, unsigned char *name, int len) -{ - struct hash_bucket *bp; - int hashno; - - if (!table) - return (NULL); - - if (!len) - len = strlen((char *)name); - - hashno = do_hash(name, len, table->hash_count); - - for (bp = table->buckets[hashno]; bp; bp = bp->next) - if (len == bp->len && !memcmp(bp->name, name, len)) - return (bp->value); - - return (NULL); -} diff --git a/sbin/dhclient/inet.c b/sbin/dhclient/inet.c deleted file mode 100644 index a52847596e12..000000000000 --- a/sbin/dhclient/inet.c +++ /dev/null @@ -1,118 +0,0 @@ -/* $OpenBSD: inet.c,v 1.7 2004/05/04 21:48:16 deraadt Exp $ */ - -/* - * Subroutines to manipulate internet addresses in a safely portable - * way... - */ - -/* - * Copyright (c) 1996 The Internet Software Consortium. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include "dhcpd.h" - -/* - * Return just the network number of an internet address... - */ -struct iaddr -subnet_number(struct iaddr addr, struct iaddr mask) -{ - struct iaddr rv; - int i; - - rv.len = 0; - - /* Both addresses must have the same length... */ - if (addr.len != mask.len) - return (rv); - - rv.len = addr.len; - for (i = 0; i < rv.len; i++) - rv.iabuf[i] = addr.iabuf[i] & mask.iabuf[i]; - return (rv); -} - -/* - * Given a subnet number and netmask, return the address on that subnet - * for which the host portion of the address is all ones (the standard - * broadcast address). - */ -struct iaddr -broadcast_addr(struct iaddr subnet, struct iaddr mask) -{ - struct iaddr rv; - int i; - - if (subnet.len != mask.len) { - rv.len = 0; - return (rv); - } - - for (i = 0; i < subnet.len; i++) - rv.iabuf[i] = subnet.iabuf[i] | (~mask.iabuf[i] & 255); - rv.len = subnet.len; - - return (rv); -} - -int -addr_eq(struct iaddr addr1, struct iaddr addr2) -{ - if (addr1.len != addr2.len) - return (0); - return (memcmp(addr1.iabuf, addr2.iabuf, addr1.len) == 0); -} - -char * -piaddr(struct iaddr addr) -{ - static char pbuf[32]; - struct in_addr a; - char *s; - - memcpy(&a, &(addr.iabuf), sizeof(struct in_addr)); - - if (addr.len == 0) - strlcpy(pbuf, "<null address>", sizeof(pbuf)); - else { - s = inet_ntoa(a); - if (s != NULL) - strlcpy(pbuf, s, sizeof(pbuf)); - else - strlcpy(pbuf, "<invalid address>", sizeof(pbuf)); - } - return (pbuf); -} diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c deleted file mode 100644 index 9c8e8fc743f1..000000000000 --- a/sbin/dhclient/options.c +++ /dev/null @@ -1,717 +0,0 @@ -/* $OpenBSD: options.c,v 1.15 2004/12/26 03:17:07 deraadt Exp $ */ - -/* DHCP options parsing and reassembly. */ - -/* - * Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include <ctype.h> - -#define DHCP_OPTION_DATA -#include "dhcpd.h" - -int bad_options = 0; -int bad_options_max = 5; - -void parse_options(struct packet *); -void parse_option_buffer(struct packet *, unsigned char *, int); -int store_options(unsigned char *, int, struct tree_cache **, - unsigned char *, int, int, int, int); - - -/* - * Parse all available options out of the specified packet. - */ -void -parse_options(struct packet *packet) -{ - /* Initially, zero all option pointers. */ - memset(packet->options, 0, sizeof(packet->options)); - - /* If we don't see the magic cookie, there's nothing to parse. */ - if (memcmp(packet->raw->options, DHCP_OPTIONS_COOKIE, 4)) { - packet->options_valid = 0; - return; - } - - /* - * Go through the options field, up to the end of the packet or - * the End field. - */ - parse_option_buffer(packet, &packet->raw->options[4], - packet->packet_length - DHCP_FIXED_NON_UDP - 4); - - /* - * If we parsed a DHCP Option Overload option, parse more - * options out of the buffer(s) containing them. - */ - if (packet->options_valid && - packet->options[DHO_DHCP_OPTION_OVERLOAD].data) { - if (packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 1) - parse_option_buffer(packet, - (unsigned char *)packet->raw->file, - sizeof(packet->raw->file)); - if (packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 2) - parse_option_buffer(packet, - (unsigned char *)packet->raw->sname, - sizeof(packet->raw->sname)); - } -} - -/* - * Parse options out of the specified buffer, storing addresses of - * option values in packet->options and setting packet->options_valid if - * no errors are encountered. - */ -void -parse_option_buffer(struct packet *packet, - unsigned char *buffer, int length) -{ - unsigned char *s, *t, *end = buffer + length; - int len, code; - - for (s = buffer; *s != DHO_END && s < end; ) { - code = s[0]; - - /* Pad options don't have a length - just skip them. */ - if (code == DHO_PAD) { - s++; - continue; - } - if (s + 2 > end) { - len = 65536; - goto bogus; - } - - /* - * All other fields (except end, see above) have a - * one-byte length. - */ - len = s[1]; - - /* - * If the length is outrageous, silently skip the rest, - * and mark the packet bad. Unfortunately some crappy - * dhcp servers always seem to give us garbage on the - * end of a packet. so rather than keep refusing, give - * up and try to take one after seeing a few without - * anything good. - */ - if (s + len + 2 > end) { - bogus: - bad_options++; - warning("option %s (%d) %s.", - dhcp_options[code].name, len, - "larger than buffer"); - if (bad_options == bad_options_max) { - packet->options_valid = 1; - bad_options = 0; - warning("Many bogus options seen in offers. " - "Taking this offer in spite of bogus " - "options - hope for the best!"); - } else { - warning("rejecting bogus offer."); - packet->options_valid = 0; - } - return; - } - /* - * If we haven't seen this option before, just make - * space for it and copy it there. - */ - if (!packet->options[code].data) { - if (!(t = calloc(1, len + 1))) - error("Can't allocate storage for option %s.", - dhcp_options[code].name); - /* - * Copy and NUL-terminate the option (in case - * it's an ASCII string. - */ - memcpy(t, &s[2], len); - t[len] = 0; - packet->options[code].len = len; - packet->options[code].data = t; - } else { - /* - * If it's a repeat, concatenate it to whatever - * we last saw. This is really only required - * for clients, but what the heck... - */ - t = calloc(1, len + packet->options[code].len + 1); - if (!t) - error("Can't expand storage for option %s.", - dhcp_options[code].name); - memcpy(t, packet->options[code].data, - packet->options[code].len); - memcpy(t + packet->options[code].len, - &s[2], len); - packet->options[code].len += len; - t[packet->options[code].len] = 0; - free(packet->options[code].data); - packet->options[code].data = t; - } - s += len + 2; - } - packet->options_valid = 1; -} - -/* - * cons options into a big buffer, and then split them out into the - * three separate buffers if needed. This allows us to cons up a set of - * vendor options using the same routine. - */ -int -cons_options(struct packet *inpacket, struct dhcp_packet *outpacket, - int mms, struct tree_cache **options, - int overload, /* Overload flags that may be set. */ - int terminate, int bootpp, u_int8_t *prl, int prl_len) -{ - unsigned char priority_list[300], buffer[4096]; - int priority_len, main_buffer_size, mainbufix, bufix; - int option_size, length; - - /* - * If the client has provided a maximum DHCP message size, use - * that; otherwise, if it's BOOTP, only 64 bytes; otherwise use - * up to the minimum IP MTU size (576 bytes). - * - * XXX if a BOOTP client specifies a max message size, we will - * honor it. - */ - if (!mms && - inpacket && - inpacket->options[DHO_DHCP_MAX_MESSAGE_SIZE].data && - (inpacket->options[DHO_DHCP_MAX_MESSAGE_SIZE].len >= - sizeof(u_int16_t))) - mms = getUShort( - inpacket->options[DHO_DHCP_MAX_MESSAGE_SIZE].data); - - if (mms) - main_buffer_size = mms - DHCP_FIXED_LEN; - else if (bootpp) - main_buffer_size = 64; - else - main_buffer_size = 576 - DHCP_FIXED_LEN; - - if (main_buffer_size > sizeof(buffer)) - main_buffer_size = sizeof(buffer); - - /* Preload the option priority list with mandatory options. */ - priority_len = 0; - priority_list[priority_len++] = DHO_DHCP_MESSAGE_TYPE; - priority_list[priority_len++] = DHO_DHCP_SERVER_IDENTIFIER; - priority_list[priority_len++] = DHO_DHCP_LEASE_TIME; - priority_list[priority_len++] = DHO_DHCP_MESSAGE; - - /* - * If the client has provided a list of options that it wishes - * returned, use it to prioritize. Otherwise, prioritize based - * on the default priority list. - */ - if (inpacket && - inpacket->options[DHO_DHCP_PARAMETER_REQUEST_LIST].data) { - int prlen = - inpacket->options[DHO_DHCP_PARAMETER_REQUEST_LIST].len; - if (prlen + priority_len > sizeof(priority_list)) - prlen = sizeof(priority_list) - priority_len; - - memcpy(&priority_list[priority_len], - inpacket->options[DHO_DHCP_PARAMETER_REQUEST_LIST].data, - prlen); - priority_len += prlen; - prl = priority_list; - } else if (prl) { - if (prl_len + priority_len > sizeof(priority_list)) - prl_len = sizeof(priority_list) - priority_len; - - memcpy(&priority_list[priority_len], prl, prl_len); - priority_len += prl_len; - prl = priority_list; - } else { - memcpy(&priority_list[priority_len], - dhcp_option_default_priority_list, - sizeof_dhcp_option_default_priority_list); - priority_len += sizeof_dhcp_option_default_priority_list; - } - - /* Copy the options into the big buffer... */ - option_size = store_options( - buffer, - (main_buffer_size - 7 + ((overload & 1) ? DHCP_FILE_LEN : 0) + - ((overload & 2) ? DHCP_SNAME_LEN : 0)), - options, priority_list, priority_len, main_buffer_size, - (main_buffer_size + ((overload & 1) ? DHCP_FILE_LEN : 0)), - terminate); - - /* Put the cookie up front... */ - memcpy(outpacket->options, DHCP_OPTIONS_COOKIE, 4); - mainbufix = 4; - - /* - * If we're going to have to overload, store the overload option - * at the beginning. If we can, though, just store the whole - * thing in the packet's option buffer and leave it at that. - */ - if (option_size <= main_buffer_size - mainbufix) { - memcpy(&outpacket->options[mainbufix], - buffer, option_size); - mainbufix += option_size; - if (mainbufix < main_buffer_size) - outpacket->options[mainbufix++] = DHO_END; - length = DHCP_FIXED_NON_UDP + mainbufix; - } else { - outpacket->options[mainbufix++] = DHO_DHCP_OPTION_OVERLOAD; - outpacket->options[mainbufix++] = 1; - if (option_size > - main_buffer_size - mainbufix + DHCP_FILE_LEN) - outpacket->options[mainbufix++] = 3; - else - outpacket->options[mainbufix++] = 1; - - memcpy(&outpacket->options[mainbufix], - buffer, main_buffer_size - mainbufix); - bufix = main_buffer_size - mainbufix; - length = DHCP_FIXED_NON_UDP + mainbufix; - if (overload & 1) { - if (option_size - bufix <= DHCP_FILE_LEN) { - memcpy(outpacket->file, - &buffer[bufix], option_size - bufix); - mainbufix = option_size - bufix; - if (mainbufix < DHCP_FILE_LEN) - outpacket->file[mainbufix++] = (char)DHO_END; - while (mainbufix < DHCP_FILE_LEN) - outpacket->file[mainbufix++] = (char)DHO_PAD; - } else { - memcpy(outpacket->file, - &buffer[bufix], DHCP_FILE_LEN); - bufix += DHCP_FILE_LEN; - } - } - if ((overload & 2) && option_size < bufix) { - memcpy(outpacket->sname, - &buffer[bufix], option_size - bufix); - - mainbufix = option_size - bufix; - if (mainbufix < DHCP_SNAME_LEN) - outpacket->file[mainbufix++] = (char)DHO_END; - while (mainbufix < DHCP_SNAME_LEN) - outpacket->file[mainbufix++] = (char)DHO_PAD; - } - } - return (length); -} - -/* - * Store all the requested options into the requested buffer. - */ -int -store_options(unsigned char *buffer, int buflen, struct tree_cache **options, - unsigned char *priority_list, int priority_len, int first_cutoff, - int second_cutoff, int terminate) -{ - int bufix = 0, option_stored[256], i, ix, tto; - - /* Zero out the stored-lengths array. */ - memset(option_stored, 0, sizeof(option_stored)); - - /* - * Copy out the options in the order that they appear in the - * priority list... - */ - for (i = 0; i < priority_len; i++) { - /* Code for next option to try to store. */ - int code = priority_list[i]; - int optstart; - - /* - * Number of bytes left to store (some may already have - * been stored by a previous pass). - */ - int length; - - /* If no data is available for this option, skip it. */ - if (!options[code]) { - continue; - } - - /* - * The client could ask for things that are mandatory, - * in which case we should avoid storing them twice... - */ - if (option_stored[code]) - continue; - option_stored[code] = 1; - - /* We should now have a constant length for the option. */ - length = options[code]->len; - - /* Do we add a NUL? */ - if (terminate && dhcp_options[code].format[0] == 't') { - length++; - tto = 1; - } else - tto = 0; - - /* Try to store the option. */ - - /* - * If the option's length is more than 255, we must - * store it in multiple hunks. Store 255-byte hunks - * first. However, in any case, if the option data will - * cross a buffer boundary, split it across that - * boundary. - */ - ix = 0; - - optstart = bufix; - while (length) { - unsigned char incr = length > 255 ? 255 : length; - - /* - * If this hunk of the buffer will cross a - * boundary, only go up to the boundary in this - * pass. - */ - if (bufix < first_cutoff && - bufix + incr > first_cutoff) - incr = first_cutoff - bufix; - else if (bufix < second_cutoff && - bufix + incr > second_cutoff) - incr = second_cutoff - bufix; - - /* - * If this option is going to overflow the - * buffer, skip it. - */ - if (bufix + 2 + incr > buflen) { - bufix = optstart; - break; - } - - /* Everything looks good - copy it in! */ - buffer[bufix] = code; - buffer[bufix + 1] = incr; - if (tto && incr == length) { - memcpy(buffer + bufix + 2, - options[code]->value + ix, incr - 1); - buffer[bufix + 2 + incr - 1] = 0; - } else - memcpy(buffer + bufix + 2, - options[code]->value + ix, incr); - length -= incr; - ix += incr; - bufix += 2 + incr; - } - } - return (bufix); -} - -/* - * Format the specified option so that a human can easily read it. - */ -char * -pretty_print_option(unsigned int code, unsigned char *data, int len, - int emit_commas, int emit_quotes) -{ - static char optbuf[32768]; /* XXX */ - int hunksize = 0, numhunk = -1, numelem = 0; - char fmtbuf[32], *op = optbuf; - int i, j, k, opleft = sizeof(optbuf); - unsigned char *dp = data; - struct in_addr foo; - char comma; - - /* Code should be between 0 and 255. */ - if (code > 255) - error("pretty_print_option: bad code %d", code); - - if (emit_commas) - comma = ','; - else - comma = ' '; - - /* Figure out the size of the data. */ - for (i = 0; dhcp_options[code].format[i]; i++) { - if (!numhunk) { - warning("%s: Excess information in format string: %s", - dhcp_options[code].name, - &(dhcp_options[code].format[i])); - break; - } - numelem++; - fmtbuf[i] = dhcp_options[code].format[i]; - switch (dhcp_options[code].format[i]) { - case 'A': - --numelem; - fmtbuf[i] = 0; - numhunk = 0; - break; - case 'X': - for (k = 0; k < len; k++) - if (!isascii(data[k]) || - !isprint(data[k])) - break; - if (k == len) { - fmtbuf[i] = 't'; - numhunk = -2; - } else { - fmtbuf[i] = 'x'; - hunksize++; - comma = ':'; - numhunk = 0; - } - fmtbuf[i + 1] = 0; - break; - case 't': - fmtbuf[i] = 't'; - fmtbuf[i + 1] = 0; - numhunk = -2; - break; - case 'I': - case 'l': - case 'L': - hunksize += 4; - break; - case 's': - case 'S': - hunksize += 2; - break; - case 'b': - case 'B': - case 'f': - hunksize++; - break; - case 'e': - break; - default: - warning("%s: garbage in format string: %s", - dhcp_options[code].name, - &(dhcp_options[code].format[i])); - break; - } - } - - /* Check for too few bytes... */ - if (hunksize > len) { - warning("%s: expecting at least %d bytes; got %d", - dhcp_options[code].name, hunksize, len); - return ("<error>"); - } - /* Check for too many bytes... */ - if (numhunk == -1 && hunksize < len) - warning("%s: %d extra bytes", - dhcp_options[code].name, len - hunksize); - - /* If this is an array, compute its size. */ - if (!numhunk) - numhunk = len / hunksize; - /* See if we got an exact number of hunks. */ - if (numhunk > 0 && numhunk * hunksize < len) - warning("%s: %d extra bytes at end of array", - dhcp_options[code].name, len - numhunk * hunksize); - - /* A one-hunk array prints the same as a single hunk. */ - if (numhunk < 0) - numhunk = 1; - - /* Cycle through the array (or hunk) printing the data. */ - for (i = 0; i < numhunk; i++) { - for (j = 0; j < numelem; j++) { - int opcount; - switch (fmtbuf[j]) { - case 't': - if (emit_quotes) { - *op++ = '"'; - opleft--; - } - for (; dp < data + len; dp++) { - if (!isascii(*dp) || - !isprint(*dp)) { - if (dp + 1 != data + len || - *dp != 0) { - snprintf(op, opleft, - "\\%03o", *dp); - op += 4; - opleft -= 4; - } - } else if (*dp == '"' || - *dp == '\'' || - *dp == '$' || - *dp == '`' || - *dp == '\\') { - *op++ = '\\'; - *op++ = *dp; - opleft -= 2; - } else { - *op++ = *dp; - opleft--; - } - } - if (emit_quotes) { - *op++ = '"'; - opleft--; - } - - *op = 0; - break; - case 'I': - foo.s_addr = htonl(getULong(dp)); - opcount = strlcpy(op, inet_ntoa(foo), opleft); - if (opcount >= opleft) - goto toobig; - opleft -= opcount; - dp += 4; - break; - case 'l': - opcount = snprintf(op, opleft, "%ld", - (long)getLong(dp)); - if (opcount >= opleft || opcount == -1) - goto toobig; - opleft -= opcount; - dp += 4; - break; - case 'L': - opcount = snprintf(op, opleft, "%ld", - (unsigned long)getULong(dp)); - if (opcount >= opleft || opcount == -1) - goto toobig; - opleft -= opcount; - dp += 4; - break; - case 's': - opcount = snprintf(op, opleft, "%d", - getShort(dp)); - if (opcount >= opleft || opcount == -1) - goto toobig; - opleft -= opcount; - dp += 2; - break; - case 'S': - opcount = snprintf(op, opleft, "%d", - getUShort(dp)); - if (opcount >= opleft || opcount == -1) - goto toobig; - opleft -= opcount; - dp += 2; - break; - case 'b': - opcount = snprintf(op, opleft, "%d", - *(char *)dp++); - if (opcount >= opleft || opcount == -1) - goto toobig; - opleft -= opcount; - break; - case 'B': - opcount = snprintf(op, opleft, "%d", *dp++); - if (opcount >= opleft || opcount == -1) - goto toobig; - opleft -= opcount; - break; - case 'x': - opcount = snprintf(op, opleft, "%x", *dp++); - if (opcount >= opleft || opcount == -1) - goto toobig; - opleft -= opcount; - break; - case 'f': - opcount = strlcpy(op, - *dp++ ? "true" : "false", opleft); - if (opcount >= opleft) - goto toobig; - opleft -= opcount; - break; - default: - warning("Unexpected format code %c", fmtbuf[j]); - } - op += strlen(op); - opleft -= strlen(op); - if (opleft < 1) - goto toobig; - if (j + 1 < numelem && comma != ':') { - *op++ = ' '; - opleft--; - } - } - if (i + 1 < numhunk) { - *op++ = comma; - opleft--; - } - if (opleft < 1) - goto toobig; - - } - return (optbuf); - toobig: - warning("dhcp option too large"); - return ("<error>"); -} - -void -do_packet(struct interface_info *interface, struct dhcp_packet *packet, - int len, unsigned int from_port, struct iaddr from, struct hardware *hfrom) -{ - struct packet tp; - int i; - - if (packet->hlen > sizeof(packet->chaddr)) { - note("Discarding packet with invalid hlen."); - return; - } - - memset(&tp, 0, sizeof(tp)); - tp.raw = packet; - tp.packet_length = len; - tp.client_port = from_port; - tp.client_addr = from; - tp.interface = interface; - tp.haddr = hfrom; - - parse_options(&tp); - if (tp.options_valid && - tp.options[DHO_DHCP_MESSAGE_TYPE].data) - tp.packet_type = tp.options[DHO_DHCP_MESSAGE_TYPE].data[0]; - if (tp.packet_type) - dhcp(&tp); - else - bootp(&tp); - - /* Free the data associated with the options. */ - for (i = 0; i < 256; i++) - if (tp.options[i].len && tp.options[i].data) - free(tp.options[i].data); -} diff --git a/sbin/dhclient/packet.c b/sbin/dhclient/packet.c deleted file mode 100644 index 1a22044d40a1..000000000000 --- a/sbin/dhclient/packet.c +++ /dev/null @@ -1,253 +0,0 @@ -/* $OpenBSD: packet.c,v 1.9 2004/05/04 18:58:50 deraadt Exp $ */ - -/* Packet assembly code, originally contributed by Archie Cobbs. */ - -/* - * Copyright (c) 1995, 1996, 1999 The Internet Software Consortium. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include "dhcpd.h" - -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/udp.h> -#include <netinet/if_ether.h> - -#define ETHER_HEADER_SIZE (ETHER_ADDR_LEN * 2 + sizeof(u_int16_t)) - -u_int32_t checksum(unsigned char *, unsigned, u_int32_t); -u_int32_t wrapsum(u_int32_t); - -void assemble_ethernet_header(struct interface_info *, unsigned char *, - int *, struct hardware *); -ssize_t decode_ethernet_header(struct interface_info *, unsigned char *, - int bufix, struct hardware *); - -u_int32_t -checksum(unsigned char *buf, unsigned nbytes, u_int32_t sum) -{ - int i; - - /* Checksum all the pairs of bytes first... */ - for (i = 0; i < (nbytes & ~1U); i += 2) { - sum += (u_int16_t)ntohs(*((u_int16_t *)(buf + i))); - if (sum > 0xFFFF) - sum -= 0xFFFF; - } - - /* - * If there's a single byte left over, checksum it, too. - * Network byte order is big-endian, so the remaining byte is - * the high byte. - */ - if (i < nbytes) { - sum += buf[i] << 8; - if (sum > 0xFFFF) - sum -= 0xFFFF; - } - - return (sum); -} - -u_int32_t -wrapsum(u_int32_t sum) -{ - sum = ~sum & 0xFFFF; - return (htons(sum)); -} - -void -assemble_hw_header(struct interface_info *interface, unsigned char *buf, - int *bufix, struct hardware *to) -{ - struct ether_header eh; - - if (to != NULL && to->hlen == 6) /* XXX */ - memcpy(eh.ether_dhost, to->haddr, sizeof(eh.ether_dhost)); - else - memset(eh.ether_dhost, 0xff, sizeof(eh.ether_dhost)); - if (interface->hw_address.hlen == sizeof(eh.ether_shost)) - memcpy(eh.ether_shost, interface->hw_address.haddr, - sizeof(eh.ether_shost)); - else - memset(eh.ether_shost, 0x00, sizeof(eh.ether_shost)); - - eh.ether_type = htons(ETHERTYPE_IP); - - memcpy(&buf[*bufix], &eh, ETHER_HEADER_SIZE); - *bufix += ETHER_HEADER_SIZE; -} - -void -assemble_udp_ip_header(unsigned char *buf, int *bufix, u_int32_t from, - u_int32_t to, unsigned int port, unsigned char *data, int len) -{ - struct ip ip; - struct udphdr udp; - - ip.ip_v = 4; - ip.ip_hl = 5; - ip.ip_tos = IPTOS_LOWDELAY; - ip.ip_len = htons(sizeof(ip) + sizeof(udp) + len); - ip.ip_id = 0; - ip.ip_off = 0; - ip.ip_ttl = 16; - ip.ip_p = IPPROTO_UDP; - ip.ip_sum = 0; - ip.ip_src.s_addr = from; - ip.ip_dst.s_addr = to; - - ip.ip_sum = wrapsum(checksum((unsigned char *)&ip, sizeof(ip), 0)); - memcpy(&buf[*bufix], &ip, sizeof(ip)); - *bufix += sizeof(ip); - - udp.uh_sport = htons(LOCAL_PORT); /* XXX */ - udp.uh_dport = port; /* XXX */ - udp.uh_ulen = htons(sizeof(udp) + len); - memset(&udp.uh_sum, 0, sizeof(udp.uh_sum)); - - udp.uh_sum = wrapsum(checksum((unsigned char *)&udp, sizeof(udp), - checksum(data, len, checksum((unsigned char *)&ip.ip_src, - 2 * sizeof(ip.ip_src), - IPPROTO_UDP + (u_int32_t)ntohs(udp.uh_ulen))))); - - memcpy(&buf[*bufix], &udp, sizeof(udp)); - *bufix += sizeof(udp); -} - -ssize_t -decode_hw_header(unsigned char *buf, int bufix, struct hardware *from) -{ - struct ether_header eh; - - memcpy(&eh, buf + bufix, ETHER_HEADER_SIZE); - - memcpy(from->haddr, eh.ether_shost, sizeof(eh.ether_shost)); - from->htype = ARPHRD_ETHER; - from->hlen = sizeof(eh.ether_shost); - - return (sizeof(eh)); -} - -ssize_t -decode_udp_ip_header(unsigned char *buf, int bufix, struct sockaddr_in *from, - unsigned char *data, int buflen) -{ - struct ip *ip; - struct udphdr *udp; - u_int32_t ip_len = (buf[bufix] & 0xf) << 2; - u_int32_t sum, usum; - static int ip_packets_seen; - static int ip_packets_bad_checksum; - static int udp_packets_seen; - static int udp_packets_bad_checksum; - static int udp_packets_length_checked; - static int udp_packets_length_overflow; - int len = 0; - - ip = (struct ip *)(buf + bufix); - udp = (struct udphdr *)(buf + bufix + ip_len); - - /* Check the IP header checksum - it should be zero. */ - ip_packets_seen++; - if (wrapsum(checksum(buf + bufix, ip_len, 0)) != 0) { - ip_packets_bad_checksum++; - if (ip_packets_seen > 4 && - (ip_packets_seen / ip_packets_bad_checksum) < 2) { - note("%d bad IP checksums seen in %d packets", - ip_packets_bad_checksum, ip_packets_seen); - ip_packets_seen = ip_packets_bad_checksum = 0; - } - return (-1); - } - - if (ntohs(ip->ip_len) != buflen) - debug("ip length %d disagrees with bytes received %d.", - ntohs(ip->ip_len), buflen); - - memcpy(&from->sin_addr, &ip->ip_src, 4); - - /* - * Compute UDP checksums, including the ``pseudo-header'', the - * UDP header and the data. If the UDP checksum field is zero, - * we're not supposed to do a checksum. - */ - if (!data) { - data = buf + bufix + ip_len + sizeof(*udp); - len = ntohs(udp->uh_ulen) - sizeof(*udp); - udp_packets_length_checked++; - if (len + data > buf + bufix + buflen) { - udp_packets_length_overflow++; - if (udp_packets_length_checked > 4 && - (udp_packets_length_checked / - udp_packets_length_overflow) < 2) { - note("%d udp packets in %d too long - dropped", - udp_packets_length_overflow, - udp_packets_length_checked); - udp_packets_length_overflow = - udp_packets_length_checked = 0; - } - return (-1); - } - if (len + data != buf + bufix + buflen) - debug("accepting packet with data after udp payload."); - } - - usum = udp->uh_sum; - udp->uh_sum = 0; - - sum = wrapsum(checksum((unsigned char *)udp, sizeof(*udp), - checksum(data, len, checksum((unsigned char *)&ip->ip_src, - 2 * sizeof(ip->ip_src), - IPPROTO_UDP + (u_int32_t)ntohs(udp->uh_ulen))))); - - udp_packets_seen++; - if (usum && usum != sum) { - udp_packets_bad_checksum++; - if (udp_packets_seen > 4 && - (udp_packets_seen / udp_packets_bad_checksum) < 2) { - note("%d bad udp checksums in %d packets", - udp_packets_bad_checksum, udp_packets_seen); - udp_packets_seen = udp_packets_bad_checksum = 0; - } - return (-1); - } - - memcpy(&from->sin_port, &udp->uh_sport, sizeof(udp->uh_sport)); - - return (ip_len + sizeof(*udp)); -} diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c deleted file mode 100644 index e8870bc12ae3..000000000000 --- a/sbin/dhclient/parse.c +++ /dev/null @@ -1,577 +0,0 @@ -/* $OpenBSD: parse.c,v 1.11 2004/05/05 23:07:47 deraadt Exp $ */ - -/* Common parser code for dhcpd and dhclient. */ - -/* - * Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include "dhcpd.h" -#include "dhctoken.h" - -/* Skip to the semicolon ending the current statement. If we encounter - * braces, the matching closing brace terminates the statement. If we - * encounter a right brace but haven't encountered a left brace, return - * leaving the brace in the token buffer for the caller. If we see a - * semicolon and haven't seen a left brace, return. This lets us skip - * over: - * - * statement; - * statement foo bar { } - * statement foo bar { statement { } } - * statement} - * - * ...et cetera. - */ -void -skip_to_semi(FILE *cfile) -{ - int brace_count = 0, token; - char *val; - - do { - token = peek_token(&val, cfile); - if (token == RBRACE) { - if (brace_count) { - token = next_token(&val, cfile); - if (!--brace_count) - return; - } else - return; - } else if (token == LBRACE) { - brace_count++; - } else if (token == SEMI && !brace_count) { - token = next_token(&val, cfile); - return; - } else if (token == '\n') { - /* - * EOL only happens when parsing - * /etc/resolv.conf, and we treat it like a - * semicolon because the resolv.conf file is - * line-oriented. - */ - token = next_token(&val, cfile); - return; - } - token = next_token(&val, cfile); - } while (token != EOF); -} - -int -parse_semi(FILE *cfile) -{ - int token; - char *val; - - token = next_token(&val, cfile); - if (token != SEMI) { - parse_warn("semicolon expected."); - skip_to_semi(cfile); - return (0); - } - return (1); -} - -/* - * string-parameter :== STRING SEMI - */ -char * -parse_string(FILE *cfile) -{ - char *val, *s; - int token; - - token = next_token(&val, cfile); - if (token != STRING) { - parse_warn("filename must be a string"); - skip_to_semi(cfile); - return (NULL); - } - s = malloc(strlen(val) + 1); - if (!s) - error("no memory for string %s.", val); - strlcpy(s, val, strlen(val) + 1); - - if (!parse_semi(cfile)) - return (NULL); - return (s); -} - -int -parse_ip_addr(FILE *cfile, struct iaddr *addr) -{ - addr->len = 4; - if (parse_numeric_aggregate(cfile, addr->iabuf, - &addr->len, DOT, 10, 8)) - return (1); - return (0); -} - -/* - * hardware-parameter :== HARDWARE ETHERNET csns SEMI - * csns :== NUMBER | csns COLON NUMBER - */ -void -parse_hardware_param(FILE *cfile, struct hardware *hardware) -{ - unsigned char *t; - int token, hlen; - char *val; - - token = next_token(&val, cfile); - switch (token) { - case ETHERNET: - hardware->htype = HTYPE_ETHER; - break; - case TOKEN_RING: - hardware->htype = HTYPE_IEEE802; - break; - case FDDI: - hardware->htype = HTYPE_FDDI; - break; - default: - parse_warn("expecting a network hardware type"); - skip_to_semi(cfile); - return; - } - - /* - * Parse the hardware address information. Technically, it - * would make a lot of sense to restrict the length of the data - * we'll accept here to the length of a particular hardware - * address type. Unfortunately, there are some broken clients - * out there that put bogus data in the chaddr buffer, and we - * accept that data in the lease file rather than simply failing - * on such clients. Yuck. - */ - hlen = 0; - t = parse_numeric_aggregate(cfile, NULL, &hlen, COLON, 16, 8); - if (!t) - return; - if (hlen > sizeof(hardware->haddr)) { - free(t); - parse_warn("hardware address too long"); - } else { - hardware->hlen = hlen; - memcpy((unsigned char *)&hardware->haddr[0], t, - hardware->hlen); - if (hlen < sizeof(hardware->haddr)) - memset(&hardware->haddr[hlen], 0, - sizeof(hardware->haddr) - hlen); - free(t); - } - - token = next_token(&val, cfile); - if (token != SEMI) { - parse_warn("expecting semicolon."); - skip_to_semi(cfile); - } -} - -/* - * lease-time :== NUMBER SEMI - */ -void -parse_lease_time(FILE *cfile, time_t *timep) -{ - char *val; - int token; - - token = next_token(&val, cfile); - if (token != NUMBER) { - parse_warn("Expecting numeric lease time"); - skip_to_semi(cfile); - return; - } - convert_num((unsigned char *)timep, val, 10, 32); - /* Unswap the number - convert_num returns stuff in NBO. */ - *timep = ntohl(*timep); /* XXX */ - - parse_semi(cfile); -} - -/* - * No BNF for numeric aggregates - that's defined by the caller. What - * this function does is to parse a sequence of numbers separated by the - * token specified in separator. If max is zero, any number of numbers - * will be parsed; otherwise, exactly max numbers are expected. Base - * and size tell us how to internalize the numbers once they've been - * tokenized. - */ -unsigned char * -parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max, - int separator, int base, int size) -{ - unsigned char *bufp = buf, *s = NULL; - int token, count = 0; - char *val, *t; - pair c = NULL; - - if (!bufp && *max) { - bufp = malloc(*max * size / 8); - if (!bufp) - error("can't allocate space for numeric aggregate"); - } else - s = bufp; - - do { - if (count) { - token = peek_token(&val, cfile); - if (token != separator) { - if (!*max) - break; - if (token != RBRACE && token != LBRACE) - token = next_token(&val, cfile); - parse_warn("too few numbers."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - token = next_token(&val, cfile); - } - token = next_token(&val, cfile); - - if (token == EOF) { - parse_warn("unexpected end of file"); - break; - } - - /* Allow NUMBER_OR_NAME if base is 16. */ - if (token != NUMBER && - (base != 16 || token != NUMBER_OR_NAME)) { - parse_warn("expecting numeric value."); - skip_to_semi(cfile); - return (NULL); - } - /* - * If we can, convert the number now; otherwise, build a - * linked list of all the numbers. - */ - if (s) { - convert_num(s, val, base, size); - s += size / 8; - } else { - t = malloc(strlen(val) + 1); - if (!t) - error("no temp space for number."); - strlcpy(t, val, strlen(val) + 1); - c = cons(t, c); - } - } while (++count != *max); - - /* If we had to cons up a list, convert it now. */ - if (c) { - bufp = malloc(count * size / 8); - if (!bufp) - error("can't allocate space for numeric aggregate."); - s = bufp + count - size / 8; - *max = count; - } - while (c) { - pair cdr = c->cdr; - convert_num(s, (char *)c->car, base, size); - s -= size / 8; - /* Free up temp space. */ - free(c->car); - free(c); - c = cdr; - } - return (bufp); -} - -void -convert_num(unsigned char *buf, char *str, int base, int size) -{ - int negative = 0, tval, max; - u_int32_t val = 0; - char *ptr = str; - - if (*ptr == '-') { - negative = 1; - ptr++; - } - - /* If base wasn't specified, figure it out from the data. */ - if (!base) { - if (ptr[0] == '0') { - if (ptr[1] == 'x') { - base = 16; - ptr += 2; - } else if (isascii(ptr[1]) && isdigit(ptr[1])) { - base = 8; - ptr += 1; - } else - base = 10; - } else - base = 10; - } - - do { - tval = *ptr++; - /* XXX assumes ASCII... */ - if (tval >= 'a') - tval = tval - 'a' + 10; - else if (tval >= 'A') - tval = tval - 'A' + 10; - else if (tval >= '0') - tval -= '0'; - else { - warning("Bogus number: %s.", str); - break; - } - if (tval >= base) { - warning("Bogus number: %s: digit %d not in base %d", - str, tval, base); - break; - } - val = val * base + tval; - } while (*ptr); - - if (negative) - max = (1 << (size - 1)); - else - max = (1 << (size - 1)) + ((1 << (size - 1)) - 1); - if (val > max) { - switch (base) { - case 8: - warning("value %s%o exceeds max (%d) for precision.", - negative ? "-" : "", val, max); - break; - case 16: - warning("value %s%x exceeds max (%d) for precision.", - negative ? "-" : "", val, max); - break; - default: - warning("value %s%u exceeds max (%d) for precision.", - negative ? "-" : "", val, max); - break; - } - } - - if (negative) - switch (size) { - case 8: - *buf = -(unsigned long)val; - break; - case 16: - putShort(buf, -(unsigned long)val); - break; - case 32: - putLong(buf, -(unsigned long)val); - break; - default: - warning("Unexpected integer size: %d", size); - break; - } - else - switch (size) { - case 8: - *buf = (u_int8_t)val; - break; - case 16: - putUShort(buf, (u_int16_t)val); - break; - case 32: - putULong(buf, val); - break; - default: - warning("Unexpected integer size: %d", size); - break; - } -} - -/* - * date :== NUMBER NUMBER SLASH NUMBER SLASH NUMBER - * NUMBER COLON NUMBER COLON NUMBER SEMI - * - * Dates are always in GMT; first number is day of week; next is - * year/month/day; next is hours:minutes:seconds on a 24-hour - * clock. - */ -time_t -parse_date(FILE *cfile) -{ - static int months[11] = { 31, 59, 90, 120, 151, 181, - 212, 243, 273, 304, 334 }; - int guess, token; - struct tm tm; - char *val; - - /* Day of week... */ - token = next_token(&val, cfile); - if (token != NUMBER) { - parse_warn("numeric day of week expected."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - tm.tm_wday = atoi(val); - - /* Year... */ - token = next_token(&val, cfile); - if (token != NUMBER) { - parse_warn("numeric year expected."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - tm.tm_year = atoi(val); - if (tm.tm_year > 1900) - tm.tm_year -= 1900; - - /* Slash separating year from month... */ - token = next_token(&val, cfile); - if (token != SLASH) { - parse_warn("expected slash separating year from month."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - - /* Month... */ - token = next_token(&val, cfile); - if (token != NUMBER) { - parse_warn("numeric month expected."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - tm.tm_mon = atoi(val) - 1; - - /* Slash separating month from day... */ - token = next_token(&val, cfile); - if (token != SLASH) { - parse_warn("expected slash separating month from day."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - - /* Month... */ - token = next_token(&val, cfile); - if (token != NUMBER) { - parse_warn("numeric day of month expected."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - tm.tm_mday = atoi(val); - - /* Hour... */ - token = next_token(&val, cfile); - if (token != NUMBER) { - parse_warn("numeric hour expected."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - tm.tm_hour = atoi(val); - - /* Colon separating hour from minute... */ - token = next_token(&val, cfile); - if (token != COLON) { - parse_warn("expected colon separating hour from minute."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - - /* Minute... */ - token = next_token(&val, cfile); - if (token != NUMBER) { - parse_warn("numeric minute expected."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - tm.tm_min = atoi(val); - - /* Colon separating minute from second... */ - token = next_token(&val, cfile); - if (token != COLON) { - parse_warn("expected colon separating hour from minute."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - - /* Minute... */ - token = next_token(&val, cfile); - if (token != NUMBER) { - parse_warn("numeric minute expected."); - if (token != SEMI) - skip_to_semi(cfile); - return (NULL); - } - tm.tm_sec = atoi(val); - tm.tm_isdst = 0; - - /* XXX: We assume that mktime does not use tm_yday. */ - tm.tm_yday = 0; - - /* Make sure the date ends in a semicolon... */ - token = next_token(&val, cfile); - if (token != SEMI) { - parse_warn("semicolon expected."); - skip_to_semi(cfile); - return (NULL); - } - - /* Guess the time value... */ - guess = ((((((365 * (tm.tm_year - 70) + /* Days in years since '70 */ - (tm.tm_year - 69) / 4 + /* Leap days since '70 */ - (tm.tm_mon /* Days in months this year */ - ? months[tm.tm_mon - 1] - : 0) + - (tm.tm_mon > 1 && /* Leap day this year */ - !((tm.tm_year - 72) & 3)) + - tm.tm_mday - 1) * 24) + /* Day of month */ - tm.tm_hour) * 60) + - tm.tm_min) * 60) + tm.tm_sec; - - /* - * This guess could be wrong because of leap seconds or other - * weirdness we don't know about that the system does. For - * now, we're just going to accept the guess, but at some point - * it might be nice to do a successive approximation here to get - * an exact value. Even if the error is small, if the server - * is restarted frequently (and thus the lease database is - * reread), the error could accumulate into something - * significant. - */ - return (guess); -} diff --git a/sbin/dhclient/privsep.c b/sbin/dhclient/privsep.c deleted file mode 100644 index cf47e56ceb6e..000000000000 --- a/sbin/dhclient/privsep.c +++ /dev/null @@ -1,235 +0,0 @@ -/* $OpenBSD: privsep.c,v 1.7 2004/05/10 18:34:42 deraadt Exp $ */ - -/* - * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT - * OF OR IN CONNECTION WITH THE USE, ABUSE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "dhcpd.h" -#include "privsep.h" - -struct buf * -buf_open(size_t len) -{ - struct buf *buf; - - if ((buf = calloc(1, sizeof(struct buf))) == NULL) - return (NULL); - if ((buf->buf = malloc(len)) == NULL) { - free(buf); - return (NULL); - } - buf->size = len; - - return (buf); -} - -int -buf_add(struct buf *buf, void *data, size_t len) -{ - if (buf->wpos + len > buf->size) - return (-1); - - memcpy(buf->buf + buf->wpos, data, len); - buf->wpos += len; - return (0); -} - -int -buf_close(int sock, struct buf *buf) -{ - ssize_t n; - - do { - n = write(sock, buf->buf + buf->rpos, buf->size - buf->rpos); - if (n != -1) - buf->rpos += n; - if (n == 0) { /* connection closed */ - errno = 0; - return (-1); - } - } while (n == -1 && (errno == EAGAIN || errno == EINTR)); - - if (buf->rpos < buf->size) - error("short write: wanted %lu got %ld bytes", - (unsigned long)buf->size, (long)buf->rpos); - - free(buf->buf); - free(buf); - return (n); -} - -ssize_t -buf_read(int sock, void *buf, size_t nbytes) -{ - ssize_t n, r = 0; - char *p = buf; - - do { - n = read(sock, p, nbytes); - if (n == 0) - error("connection closed"); - if (n != -1) { - r += n; - p += n; - nbytes -= n; - } - } while (n == -1 && (errno == EINTR || errno == EAGAIN)); - - if (n == -1) - error("buf_read: %m"); - - if (r < nbytes) - error("short read: wanted %lu got %ld bytes", - (unsigned long)nbytes, (long)r); - - return (r); -} - -void -dispatch_imsg(int fd) -{ - struct imsg_hdr hdr; - char *medium, *reason, *filename, - *servername, *prefix; - size_t medium_len, reason_len, filename_len, - servername_len, prefix_len, totlen; - struct client_lease lease; - int ret, i, optlen; - struct buf *buf; - - buf_read(fd, &hdr, sizeof(hdr)); - - switch (hdr.code) { - case IMSG_SCRIPT_INIT: - if (hdr.len < sizeof(hdr) + sizeof(size_t)) - error("corrupted message received"); - buf_read(fd, &medium_len, sizeof(medium_len)); - if (hdr.len < medium_len + sizeof(size_t) + sizeof(hdr) - + sizeof(size_t) || medium_len == SIZE_T_MAX) - error("corrupted message received"); - if (medium_len > 0) { - if ((medium = calloc(1, medium_len + 1)) == NULL) - error("%m"); - buf_read(fd, medium, medium_len); - } else - medium = NULL; - - buf_read(fd, &reason_len, sizeof(reason_len)); - if (hdr.len < medium_len + reason_len + sizeof(hdr) || - reason_len == SIZE_T_MAX) - error("corrupted message received"); - if (reason_len > 0) { - if ((reason = calloc(1, reason_len + 1)) == NULL) - error("%m"); - buf_read(fd, reason, reason_len); - } else - reason = NULL; - - priv_script_init(reason, medium); - free(reason); - free(medium); - break; - case IMSG_SCRIPT_WRITE_PARAMS: - bzero(&lease, sizeof lease); - totlen = sizeof(hdr) + sizeof(lease) + sizeof(size_t); - if (hdr.len < totlen) - error("corrupted message received"); - buf_read(fd, &lease, sizeof(lease)); - - buf_read(fd, &filename_len, sizeof(filename_len)); - totlen += filename_len + sizeof(size_t); - if (hdr.len < totlen || filename_len == SIZE_T_MAX) - error("corrupted message received"); - if (filename_len > 0) { - if ((filename = calloc(1, filename_len + 1)) == NULL) - error("%m"); - buf_read(fd, filename, filename_len); - } else - filename = NULL; - - buf_read(fd, &servername_len, sizeof(servername_len)); - totlen += servername_len + sizeof(size_t); - if (hdr.len < totlen || servername_len == SIZE_T_MAX) - error("corrupted message received"); - if (servername_len > 0) { - if ((servername = - calloc(1, servername_len + 1)) == NULL) - error("%m"); - buf_read(fd, servername, servername_len); - } else - servername = NULL; - - buf_read(fd, &prefix_len, sizeof(prefix_len)); - totlen += prefix_len; - if (hdr.len < totlen || prefix_len == SIZE_T_MAX) - error("corrupted message received"); - if (prefix_len > 0) { - if ((prefix = calloc(1, prefix_len + 1)) == NULL) - error("%m"); - buf_read(fd, prefix, prefix_len); - } else - prefix = NULL; - - for (i = 0; i < 256; i++) { - totlen += sizeof(optlen); - if (hdr.len < totlen) - error("corrupted message received"); - buf_read(fd, &optlen, sizeof(optlen)); - lease.options[i].data = NULL; - lease.options[i].len = optlen; - if (optlen > 0) { - totlen += optlen; - if (hdr.len < totlen || optlen == SIZE_T_MAX) - error("corrupted message received"); - lease.options[i].data = - calloc(1, optlen + 1); - if (lease.options[i].data == NULL) - error("%m"); - buf_read(fd, lease.options[i].data, optlen); - } - } - lease.server_name = servername; - lease.filename = filename; - - priv_script_write_params(prefix, &lease); - - free(servername); - free(filename); - free(prefix); - for (i = 0; i < 256; i++) - if (lease.options[i].len > 0) - free(lease.options[i].data); - break; - case IMSG_SCRIPT_GO: - if (hdr.len != sizeof(hdr)) - error("corrupted message received"); - - ret = priv_script_go(); - - hdr.code = IMSG_SCRIPT_GO_RET; - hdr.len = sizeof(struct imsg_hdr) + sizeof(int); - if ((buf = buf_open(hdr.len)) == NULL) - error("buf_open: %m"); - if (buf_add(buf, &hdr, sizeof(hdr))) - error("buf_add: %m"); - if (buf_add(buf, &ret, sizeof(ret))) - error("buf_add: %m"); - if (buf_close(fd, buf) == -1) - error("buf_close: %m"); - break; - default: - error("received unknown message, code %d", hdr.code); - } -} diff --git a/sbin/dhclient/privsep.h b/sbin/dhclient/privsep.h deleted file mode 100644 index f30284eeefeb..000000000000 --- a/sbin/dhclient/privsep.h +++ /dev/null @@ -1,47 +0,0 @@ -/* $OpenBSD: privsep.h,v 1.2 2004/05/04 18:51:18 henning Exp $ */ - -/* - * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT - * OF OR IN CONNECTION WITH THE USE, ABUSE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <sys/types.h> - -#include <poll.h> -#include <pwd.h> - -struct buf { - u_char *buf; - size_t size; - size_t wpos; - size_t rpos; -}; - -enum imsg_code { - IMSG_NONE, - IMSG_SCRIPT_INIT, - IMSG_SCRIPT_WRITE_PARAMS, - IMSG_SCRIPT_GO, - IMSG_SCRIPT_GO_RET -}; - -struct imsg_hdr { - enum imsg_code code; - size_t len; -}; - -struct buf *buf_open(size_t); -int buf_add(struct buf *, void *, size_t); -int buf_close(int, struct buf *); -ssize_t buf_read(int sock, void *, size_t); diff --git a/sbin/dhclient/tables.c b/sbin/dhclient/tables.c deleted file mode 100644 index 6648756952c9..000000000000 --- a/sbin/dhclient/tables.c +++ /dev/null @@ -1,430 +0,0 @@ -/* $OpenBSD: tables.c,v 1.4 2004/05/04 20:28:40 deraadt Exp $ */ - -/* Tables of information... */ - -/* - * Copyright (c) 1995, 1996 The Internet Software Consortium. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include "dhcpd.h" - -/* - * DHCP Option names, formats and codes, from RFC1533. - * - * Format codes: - * - * e - end of data - * I - IP address - * l - 32-bit signed integer - * L - 32-bit unsigned integer - * s - 16-bit signed integer - * S - 16-bit unsigned integer - * b - 8-bit signed integer - * B - 8-bit unsigned integer - * t - ASCII text - * f - flag (true or false) - * A - array of whatever precedes (e.g., IA means array of IP addresses) - */ - -struct universe dhcp_universe; -struct option dhcp_options[256] = { - { "pad", "", &dhcp_universe, 0 }, - { "subnet-mask", "I", &dhcp_universe, 1 }, - { "time-offset", "l", &dhcp_universe, 2 }, - { "routers", "IA", &dhcp_universe, 3 }, - { "time-servers", "IA", &dhcp_universe, 4 }, - { "ien116-name-servers", "IA", &dhcp_universe, 5 }, - { "domain-name-servers", "IA", &dhcp_universe, 6 }, - { "log-servers", "IA", &dhcp_universe, 7 }, - { "cookie-servers", "IA", &dhcp_universe, 8 }, - { "lpr-servers", "IA", &dhcp_universe, 9 }, - { "impress-servers", "IA", &dhcp_universe, 10 }, - { "resource-location-servers", "IA", &dhcp_universe, 11 }, - { "host-name", "X", &dhcp_universe, 12 }, - { "boot-size", "S", &dhcp_universe, 13 }, - { "merit-dump", "t", &dhcp_universe, 14 }, - { "domain-name", "t", &dhcp_universe, 15 }, - { "swap-server", "I", &dhcp_universe, 16 }, - { "root-path", "t", &dhcp_universe, 17 }, - { "extensions-path", "t", &dhcp_universe, 18 }, - { "ip-forwarding", "f", &dhcp_universe, 19 }, - { "non-local-source-routing", "f", &dhcp_universe, 20 }, - { "policy-filter", "IIA", &dhcp_universe, 21 }, - { "max-dgram-reassembly", "S", &dhcp_universe, 22 }, - { "default-ip-ttl", "B", &dhcp_universe, 23 }, - { "path-mtu-aging-timeout", "L", &dhcp_universe, 24 }, - { "path-mtu-plateau-table", "SA", &dhcp_universe, 25 }, - { "interface-mtu", "S", &dhcp_universe, 26 }, - { "all-subnets-local", "f", &dhcp_universe, 27 }, - { "broadcast-address", "I", &dhcp_universe, 28 }, - { "perform-mask-discovery", "f", &dhcp_universe, 29 }, - { "mask-supplier", "f", &dhcp_universe, 30 }, - { "router-discovery", "f", &dhcp_universe, 31 }, - { "router-solicitation-address", "I", &dhcp_universe, 32 }, - { "static-routes", "IIA", &dhcp_universe, 33 }, - { "trailer-encapsulation", "f", &dhcp_universe, 34 }, - { "arp-cache-timeout", "L", &dhcp_universe, 35 }, - { "ieee802-3-encapsulation", "f", &dhcp_universe, 36 }, - { "default-tcp-ttl", "B", &dhcp_universe, 37 }, - { "tcp-keepalive-interval", "L", &dhcp_universe, 38 }, - { "tcp-keepalive-garbage", "f", &dhcp_universe, 39 }, - { "nis-domain", "t", &dhcp_universe, 40 }, - { "nis-servers", "IA", &dhcp_universe, 41 }, - { "ntp-servers", "IA", &dhcp_universe, 42 }, - { "vendor-encapsulated-options", "X", &dhcp_universe, 43 }, - { "netbios-name-servers", "IA", &dhcp_universe, 44 }, - { "netbios-dd-server", "IA", &dhcp_universe, 45 }, - { "netbios-node-type", "B", &dhcp_universe, 46 }, - { "netbios-scope", "t", &dhcp_universe, 47 }, - { "font-servers", "IA", &dhcp_universe, 48 }, - { "x-display-manager", "IA", &dhcp_universe, 49 }, - { "dhcp-requested-address", "I", &dhcp_universe, 50 }, - { "dhcp-lease-time", "L", &dhcp_universe, 51 }, - { "dhcp-option-overload", "B", &dhcp_universe, 52 }, - { "dhcp-message-type", "B", &dhcp_universe, 53 }, - { "dhcp-server-identifier", "I", &dhcp_universe, 54 }, - { "dhcp-parameter-request-list", "BA", &dhcp_universe, 55 }, - { "dhcp-message", "t", &dhcp_universe, 56 }, - { "dhcp-max-message-size", "S", &dhcp_universe, 57 }, - { "dhcp-renewal-time", "L", &dhcp_universe, 58 }, - { "dhcp-rebinding-time", "L", &dhcp_universe, 59 }, - { "dhcp-class-identifier", "t", &dhcp_universe, 60 }, - { "dhcp-client-identifier", "X", &dhcp_universe, 61 }, - { "option-62", "X", &dhcp_universe, 62 }, - { "option-63", "X", &dhcp_universe, 63 }, - { "nisplus-domain", "t", &dhcp_universe, 64 }, - { "nisplus-servers", "IA", &dhcp_universe, 65 }, - { "tftp-server-name", "t", &dhcp_universe, 66 }, - { "bootfile-name", "t", &dhcp_universe, 67 }, - { "mobile-ip-home-agent", "IA", &dhcp_universe, 68 }, - { "smtp-server", "IA", &dhcp_universe, 69 }, - { "pop-server", "IA", &dhcp_universe, 70 }, - { "nntp-server", "IA", &dhcp_universe, 71 }, - { "www-server", "IA", &dhcp_universe, 72 }, - { "finger-server", "IA", &dhcp_universe, 73 }, - { "irc-server", "IA", &dhcp_universe, 74 }, - { "streettalk-server", "IA", &dhcp_universe, 75 }, - { "streettalk-directory-assistance-server", "IA", &dhcp_universe, 76 }, - { "user-class", "t", &dhcp_universe, 77 }, - { "option-78", "X", &dhcp_universe, 78 }, - { "option-79", "X", &dhcp_universe, 79 }, - { "option-80", "X", &dhcp_universe, 80 }, - { "option-81", "X", &dhcp_universe, 81 }, - { "option-82", "X", &dhcp_universe, 82 }, - { "option-83", "X", &dhcp_universe, 83 }, - { "option-84", "X", &dhcp_universe, 84 }, - { "nds-servers", "IA", &dhcp_universe, 85 }, - { "nds-tree-name", "X", &dhcp_universe, 86 }, - { "nds-context", "X", &dhcp_universe, 87 }, - { "option-88", "X", &dhcp_universe, 88 }, - { "option-89", "X", &dhcp_universe, 89 }, - { "option-90", "X", &dhcp_universe, 90 }, - { "option-91", "X", &dhcp_universe, 91 }, - { "option-92", "X", &dhcp_universe, 92 }, - { "option-93", "X", &dhcp_universe, 93 }, - { "option-94", "X", &dhcp_universe, 94 }, - { "option-95", "X", &dhcp_universe, 95 }, - { "option-96", "X", &dhcp_universe, 96 }, - { "option-97", "X", &dhcp_universe, 97 }, - { "option-98", "X", &dhcp_universe, 98 }, - { "option-99", "X", &dhcp_universe, 99 }, - { "option-100", "X", &dhcp_universe, 100 }, - { "option-101", "X", &dhcp_universe, 101 }, - { "option-102", "X", &dhcp_universe, 102 }, - { "option-103", "X", &dhcp_universe, 103 }, - { "option-104", "X", &dhcp_universe, 104 }, - { "option-105", "X", &dhcp_universe, 105 }, - { "option-106", "X", &dhcp_universe, 106 }, - { "option-107", "X", &dhcp_universe, 107 }, - { "option-108", "X", &dhcp_universe, 108 }, - { "option-109", "X", &dhcp_universe, 109 }, - { "option-110", "X", &dhcp_universe, 110 }, - { "option-111", "X", &dhcp_universe, 111 }, - { "option-112", "X", &dhcp_universe, 112 }, - { "option-113", "X", &dhcp_universe, 113 }, - { "option-114", "X", &dhcp_universe, 114 }, - { "option-115", "X", &dhcp_universe, 115 }, - { "option-116", "X", &dhcp_universe, 116 }, - { "option-117", "X", &dhcp_universe, 117 }, - { "option-118", "X", &dhcp_universe, 118 }, - { "option-119", "X", &dhcp_universe, 119 }, - { "option-120", "X", &dhcp_universe, 120 }, - { "option-121", "X", &dhcp_universe, 121 }, - { "option-122", "X", &dhcp_universe, 122 }, - { "option-123", "X", &dhcp_universe, 123 }, - { "option-124", "X", &dhcp_universe, 124 }, - { "option-125", "X", &dhcp_universe, 125 }, - { "option-126", "X", &dhcp_universe, 126 }, - { "option-127", "X", &dhcp_universe, 127 }, - { "option-128", "X", &dhcp_universe, 128 }, - { "option-129", "X", &dhcp_universe, 129 }, - { "option-130", "X", &dhcp_universe, 130 }, - { "option-131", "X", &dhcp_universe, 131 }, - { "option-132", "X", &dhcp_universe, 132 }, - { "option-133", "X", &dhcp_universe, 133 }, - { "option-134", "X", &dhcp_universe, 134 }, - { "option-135", "X", &dhcp_universe, 135 }, - { "option-136", "X", &dhcp_universe, 136 }, - { "option-137", "X", &dhcp_universe, 137 }, - { "option-138", "X", &dhcp_universe, 138 }, - { "option-139", "X", &dhcp_universe, 139 }, - { "option-140", "X", &dhcp_universe, 140 }, - { "option-141", "X", &dhcp_universe, 141 }, - { "option-142", "X", &dhcp_universe, 142 }, - { "option-143", "X", &dhcp_universe, 143 }, - { "option-144", "X", &dhcp_universe, 144 }, - { "option-145", "X", &dhcp_universe, 145 }, - { "option-146", "X", &dhcp_universe, 146 }, - { "option-147", "X", &dhcp_universe, 147 }, - { "option-148", "X", &dhcp_universe, 148 }, - { "option-149", "X", &dhcp_universe, 149 }, - { "option-150", "X", &dhcp_universe, 150 }, - { "option-151", "X", &dhcp_universe, 151 }, - { "option-152", "X", &dhcp_universe, 152 }, - { "option-153", "X", &dhcp_universe, 153 }, - { "option-154", "X", &dhcp_universe, 154 }, - { "option-155", "X", &dhcp_universe, 155 }, - { "option-156", "X", &dhcp_universe, 156 }, - { "option-157", "X", &dhcp_universe, 157 }, - { "option-158", "X", &dhcp_universe, 158 }, - { "option-159", "X", &dhcp_universe, 159 }, - { "option-160", "X", &dhcp_universe, 160 }, - { "option-161", "X", &dhcp_universe, 161 }, - { "option-162", "X", &dhcp_universe, 162 }, - { "option-163", "X", &dhcp_universe, 163 }, - { "option-164", "X", &dhcp_universe, 164 }, - { "option-165", "X", &dhcp_universe, 165 }, - { "option-166", "X", &dhcp_universe, 166 }, - { "option-167", "X", &dhcp_universe, 167 }, - { "option-168", "X", &dhcp_universe, 168 }, - { "option-169", "X", &dhcp_universe, 169 }, - { "option-170", "X", &dhcp_universe, 170 }, - { "option-171", "X", &dhcp_universe, 171 }, - { "option-172", "X", &dhcp_universe, 172 }, - { "option-173", "X", &dhcp_universe, 173 }, - { "option-174", "X", &dhcp_universe, 174 }, - { "option-175", "X", &dhcp_universe, 175 }, - { "option-176", "X", &dhcp_universe, 176 }, - { "option-177", "X", &dhcp_universe, 177 }, - { "option-178", "X", &dhcp_universe, 178 }, - { "option-179", "X", &dhcp_universe, 179 }, - { "option-180", "X", &dhcp_universe, 180 }, - { "option-181", "X", &dhcp_universe, 181 }, - { "option-182", "X", &dhcp_universe, 182 }, - { "option-183", "X", &dhcp_universe, 183 }, - { "option-184", "X", &dhcp_universe, 184 }, - { "option-185", "X", &dhcp_universe, 185 }, - { "option-186", "X", &dhcp_universe, 186 }, - { "option-187", "X", &dhcp_universe, 187 }, - { "option-188", "X", &dhcp_universe, 188 }, - { "option-189", "X", &dhcp_universe, 189 }, - { "option-190", "X", &dhcp_universe, 190 }, - { "option-191", "X", &dhcp_universe, 191 }, - { "option-192", "X", &dhcp_universe, 192 }, - { "option-193", "X", &dhcp_universe, 193 }, - { "option-194", "X", &dhcp_universe, 194 }, - { "option-195", "X", &dhcp_universe, 195 }, - { "option-196", "X", &dhcp_universe, 196 }, - { "option-197", "X", &dhcp_universe, 197 }, - { "option-198", "X", &dhcp_universe, 198 }, - { "option-199", "X", &dhcp_universe, 199 }, - { "option-200", "X", &dhcp_universe, 200 }, - { "option-201", "X", &dhcp_universe, 201 }, - { "option-202", "X", &dhcp_universe, 202 }, - { "option-203", "X", &dhcp_universe, 203 }, - { "option-204", "X", &dhcp_universe, 204 }, - { "option-205", "X", &dhcp_universe, 205 }, - { "option-206", "X", &dhcp_universe, 206 }, - { "option-207", "X", &dhcp_universe, 207 }, - { "option-208", "X", &dhcp_universe, 208 }, - { "option-209", "X", &dhcp_universe, 209 }, - { "option-210", "X", &dhcp_universe, 210 }, - { "option-211", "X", &dhcp_universe, 211 }, - { "option-212", "X", &dhcp_universe, 212 }, - { "option-213", "X", &dhcp_universe, 213 }, - { "option-214", "X", &dhcp_universe, 214 }, - { "option-215", "X", &dhcp_universe, 215 }, - { "option-216", "X", &dhcp_universe, 216 }, - { "option-217", "X", &dhcp_universe, 217 }, - { "option-218", "X", &dhcp_universe, 218 }, - { "option-219", "X", &dhcp_universe, 219 }, - { "option-220", "X", &dhcp_universe, 220 }, - { "option-221", "X", &dhcp_universe, 221 }, - { "option-222", "X", &dhcp_universe, 222 }, - { "option-223", "X", &dhcp_universe, 223 }, - { "option-224", "X", &dhcp_universe, 224 }, - { "option-225", "X", &dhcp_universe, 225 }, - { "option-226", "X", &dhcp_universe, 226 }, - { "option-227", "X", &dhcp_universe, 227 }, - { "option-228", "X", &dhcp_universe, 228 }, - { "option-229", "X", &dhcp_universe, 229 }, - { "option-230", "X", &dhcp_universe, 230 }, - { "option-231", "X", &dhcp_universe, 231 }, - { "option-232", "X", &dhcp_universe, 232 }, - { "option-233", "X", &dhcp_universe, 233 }, - { "option-234", "X", &dhcp_universe, 234 }, - { "option-235", "X", &dhcp_universe, 235 }, - { "option-236", "X", &dhcp_universe, 236 }, - { "option-237", "X", &dhcp_universe, 237 }, - { "option-238", "X", &dhcp_universe, 238 }, - { "option-239", "X", &dhcp_universe, 239 }, - { "option-240", "X", &dhcp_universe, 240 }, - { "option-241", "X", &dhcp_universe, 241 }, - { "option-242", "X", &dhcp_universe, 242 }, - { "option-243", "X", &dhcp_universe, 243 }, - { "option-244", "X", &dhcp_universe, 244 }, - { "option-245", "X", &dhcp_universe, 245 }, - { "option-246", "X", &dhcp_universe, 246 }, - { "option-247", "X", &dhcp_universe, 247 }, - { "option-248", "X", &dhcp_universe, 248 }, - { "option-249", "X", &dhcp_universe, 249 }, - { "option-250", "X", &dhcp_universe, 250 }, - { "option-251", "X", &dhcp_universe, 251 }, - { "option-252", "X", &dhcp_universe, 252 }, - { "option-253", "X", &dhcp_universe, 253 }, - { "option-254", "X", &dhcp_universe, 254 }, - { "option-end", "e", &dhcp_universe, 255 }, -}; - -/* - * Default dhcp option priority list (this is ad hoc and should not be - * mistaken for a carefully crafted and optimized list). - */ -unsigned char dhcp_option_default_priority_list[] = { - DHO_DHCP_REQUESTED_ADDRESS, - DHO_DHCP_OPTION_OVERLOAD, - DHO_DHCP_MAX_MESSAGE_SIZE, - DHO_DHCP_RENEWAL_TIME, - DHO_DHCP_REBINDING_TIME, - DHO_DHCP_CLASS_IDENTIFIER, - DHO_DHCP_CLIENT_IDENTIFIER, - DHO_SUBNET_MASK, - DHO_TIME_OFFSET, - DHO_ROUTERS, - DHO_TIME_SERVERS, - DHO_NAME_SERVERS, - DHO_DOMAIN_NAME_SERVERS, - DHO_HOST_NAME, - DHO_LOG_SERVERS, - DHO_COOKIE_SERVERS, - DHO_LPR_SERVERS, - DHO_IMPRESS_SERVERS, - DHO_RESOURCE_LOCATION_SERVERS, - DHO_HOST_NAME, - DHO_BOOT_SIZE, - DHO_MERIT_DUMP, - DHO_DOMAIN_NAME, - DHO_SWAP_SERVER, - DHO_ROOT_PATH, - DHO_EXTENSIONS_PATH, - DHO_IP_FORWARDING, - DHO_NON_LOCAL_SOURCE_ROUTING, - DHO_POLICY_FILTER, - DHO_MAX_DGRAM_REASSEMBLY, - DHO_DEFAULT_IP_TTL, - DHO_PATH_MTU_AGING_TIMEOUT, - DHO_PATH_MTU_PLATEAU_TABLE, - DHO_INTERFACE_MTU, - DHO_ALL_SUBNETS_LOCAL, - DHO_BROADCAST_ADDRESS, - DHO_PERFORM_MASK_DISCOVERY, - DHO_MASK_SUPPLIER, - DHO_ROUTER_DISCOVERY, - DHO_ROUTER_SOLICITATION_ADDRESS, - DHO_STATIC_ROUTES, - DHO_TRAILER_ENCAPSULATION, - DHO_ARP_CACHE_TIMEOUT, - DHO_IEEE802_3_ENCAPSULATION, - DHO_DEFAULT_TCP_TTL, - DHO_TCP_KEEPALIVE_INTERVAL, - DHO_TCP_KEEPALIVE_GARBAGE, - DHO_NIS_DOMAIN, - DHO_NIS_SERVERS, - DHO_NTP_SERVERS, - DHO_VENDOR_ENCAPSULATED_OPTIONS, - DHO_NETBIOS_NAME_SERVERS, - DHO_NETBIOS_DD_SERVER, - DHO_NETBIOS_NODE_TYPE, - DHO_NETBIOS_SCOPE, - DHO_FONT_SERVERS, - DHO_X_DISPLAY_MANAGER, - DHO_DHCP_PARAMETER_REQUEST_LIST, - - /* Presently-undefined options... */ - 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, - 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, - 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, - 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, - 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, - 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, - 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, - 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, - 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, - 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, - 251, 252, 253, 254, -}; - -int sizeof_dhcp_option_default_priority_list = - sizeof(dhcp_option_default_priority_list); - -struct hash_table universe_hash; - -void -initialize_universes(void) -{ - int i; - - dhcp_universe.name = "dhcp"; - dhcp_universe.hash = new_hash(); - if (!dhcp_universe.hash) - error("Can't allocate dhcp option hash table."); - for (i = 0; i < 256; i++) { - dhcp_universe.options[i] = &dhcp_options[i]; - add_hash(dhcp_universe.hash, - (unsigned char *)dhcp_options[i].name, 0, - (unsigned char *)&dhcp_options[i]); - } - universe_hash.hash_count = DEFAULT_HASH_SIZE; - add_hash(&universe_hash, - (unsigned char *)dhcp_universe.name, 0, - (unsigned char *)&dhcp_universe); -} diff --git a/sbin/dhclient/tree.c b/sbin/dhclient/tree.c deleted file mode 100644 index 89ac450ac5ba..000000000000 --- a/sbin/dhclient/tree.c +++ /dev/null @@ -1,56 +0,0 @@ -/* $OpenBSD: tree.c,v 1.13 2004/05/06 22:29:15 deraadt Exp $ */ - -/* Routines for manipulating parse trees... */ - -/* - * Copyright (c) 1995, 1996, 1997 The Internet Software Consortium. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -#include "dhcpd.h" - -extern int h_errno; - -pair -cons(caddr_t car, pair cdr) -{ - pair foo = calloc(1, sizeof(*foo)); - if (!foo) - error("no memory for cons."); - foo->car = car; - foo->cdr = cdr; - return (foo); -} diff --git a/sbin/dhclient/tree.h b/sbin/dhclient/tree.h deleted file mode 100644 index 04e08e7c820c..000000000000 --- a/sbin/dhclient/tree.h +++ /dev/null @@ -1,66 +0,0 @@ -/* $OpenBSD: tree.h,v 1.5 2004/05/06 22:29:15 deraadt Exp $ */ - -/* Definitions for address trees... */ - -/* - * Copyright (c) 1995 The Internet Software Consortium. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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. - * - * This software has been written for the Internet Software Consortium - * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie - * Enterprises. To learn more about the Internet Software Consortium, - * see ``http://www.vix.com/isc''. To learn more about Vixie - * Enterprises, see ``http://www.vix.com''. - */ - -/* A pair of pointers, suitable for making a linked list. */ -typedef struct _pair { - caddr_t car; - struct _pair *cdr; -} *pair; - -struct tree_cache { - unsigned char *value; - int len; - int buf_size; - time_t timeout; -}; - -struct universe { - char *name; - struct hash_table *hash; - struct option *options[256]; -}; - -struct option { - char *name; - char *format; - struct universe *universe; - unsigned char code; -}; diff --git a/share/man/man3/tree.3 b/share/man/man3/tree.3 deleted file mode 100644 index 2d43ac1f09b0..000000000000 --- a/share/man/man3/tree.3 +++ /dev/null @@ -1,453 +0,0 @@ -.\" $OpenBSD: tree.3,v 1.7 2002/06/12 01:09:20 provos Exp $ -.\"/* -.\" * Copyright 2002 Niels Provos <provos@citi.umich.edu> -.\" * 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 Niels Provos. -.\" * 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. -.\" */ -.Dd February 24, 2002 -.Dt TREE 3 -.Os -.Sh NAME -.Nm SPLAY_PROTOTYPE, -.Nm SPLAY_GENERATE, -.Nm SPLAY_ENTRY , -.Nm SPLAY_HEAD , -.Nm SPLAY_INITIALIZER , -.Nm SPLAY_ROOT , -.Nm SPLAY_EMPTY , -.Nm SPLAY_NEXT , -.Nm SPLAY_MIN , -.Nm SPLAY_MAX , -.Nm SPLAY_FIND , -.Nm SPLAY_LEFT , -.Nm SPLAY_RIGHT , -.Nm SPLAY_FOREACH , -.Nm SPLAY_INIT , -.Nm SPLAY_INSERT , -.Nm SPLAY_REMOVE , -.Nm RB_PROTOTYPE, -.Nm RB_GENERATE, -.Nm RB_ENTRY , -.Nm RB_HEAD , -.Nm RB_INITIALIZER , -.Nm RB_ROOT , -.Nm RB_EMPTY , -.Nm RB_NEXT , -.Nm RB_MIN , -.Nm RB_MAX , -.Nm RB_FIND , -.Nm RB_LEFT , -.Nm RB_RIGHT , -.Nm RB_PARENT , -.Nm RB_FOREACH , -.Nm RB_INIT , -.Nm RB_INSERT , -.Nm RB_REMOVE -.Nd "implementations of splay and red-black trees" -.Sh SYNOPSIS -.Fd #include <sys/tree.h> -.Pp -.Fn SPLAY_PROTOTYPE "NAME" "TYPE" "FIELD" "CMP" -.Fn SPLAY_GENERATE "NAME" "TYPE" "FIELD" "CMP" -.Fn SPLAY_ENTRY "TYPE" -.Fn SPLAY_HEAD "HEADNAME" "TYPE" -.Ft "struct TYPE *" -.Fn SPLAY_INITIALIZER "SPLAY_HEAD *head" -.Fn SPLAY_ROOT "SPLAY_HEAD *head" -.Ft "bool" -.Fn SPLAY_EMPTY "SPLAY_HEAD *head" -.Ft "struct TYPE *" -.Fn SPLAY_NEXT "NAME" "SPLAY_HEAD *head" "struct TYPE *elm" -.Ft "struct TYPE *" -.Fn SPLAY_MIN "NAME" "SPLAY_HEAD *head" -.Ft "struct TYPE *" -.Fn SPLAY_MAX "NAME" "SPLAY_HEAD *head" -.Ft "struct TYPE *" -.Fn SPLAY_FIND "NAME" "SPLAY_HEAD *head" "struct TYPE *elm" -.Ft "struct TYPE *" -.Fn SPLAY_LEFT "struct TYPE *elm" "SPLAY_ENTRY NAME" -.Ft "struct TYPE *" -.Fn SPLAY_RIGHT "struct TYPE *elm" "SPLAY_ENTRY NAME" -.Fn SPLAY_FOREACH "VARNAME" "NAME" "SPLAY_HEAD *head" -.Ft void -.Fn SPLAY_INIT "SPLAY_HEAD *head" -.Ft "struct TYPE *" -.Fn SPLAY_INSERT "NAME" "SPLAY_HEAD *head" "struct TYPE *elm" -.Ft "struct TYPE *" -.Fn SPLAY_REMOVE "NAME" "SPLAY_HEAD *head" "struct TYPE *elm" -.Pp -.Fn RB_PROTOTYPE "NAME" "TYPE" "FIELD" "CMP" -.Fn RB_GENERATE "NAME" "TYPE" "FIELD" "CMP" -.Fn RB_ENTRY "TYPE" -.Fn RB_HEAD "HEADNAME" "TYPE" -.Fn RB_INITIALIZER "RB_HEAD *head" -.Ft "struct TYPE *" -.Fn RB_ROOT "RB_HEAD *head" -.Ft "bool" -.Fn RB_EMPTY "RB_HEAD *head" -.Ft "struct TYPE *" -.Fn RB_NEXT "NAME" "RB_HEAD *head" "struct TYPE *elm" -.Ft "struct TYPE *" -.Fn RB_MIN "NAME" "RB_HEAD *head" -.Ft "struct TYPE *" -.Fn RB_MAX "NAME" "RB_HEAD *head" -.Ft "struct TYPE *" -.Fn RB_FIND "NAME" "RB_HEAD *head" "struct TYPE *elm" -.Ft "struct TYPE *" -.Fn RB_LEFT "struct TYPE *elm" "RB_ENTRY NAME" -.Ft "struct TYPE *" -.Fn RB_RIGHT "struct TYPE *elm" "RB_ENTRY NAME" -.Ft "struct TYPE *" -.Fn RB_PARENT "struct TYPE *elm" "RB_ENTRY NAME" -.Fn RB_FOREACH "VARNAME" "NAME" "RB_HEAD *head" -.Ft void -.Fn RB_INIT "RB_HEAD *head" -.Ft "struct TYPE *" -.Fn RB_INSERT "NAME" "RB_HEAD *head" "struct TYPE *elm" -.Ft "struct TYPE *" -.Fn RB_REMOVE "NAME" "RB_HEAD *head" "struct TYPE *elm" -.Sh DESCRIPTION -These macros defines data structures for different types of trees: -splay trees and red-black trees. -.Pp -In the macro definitions, -.Fa TYPE -is the name tag of a user defined structure that must contain a field of type -.Li SPLAY_ENTRY , -or -.Li RB_ENTRY , -named -.Fa ENTRYNAME . -The argument -.Fa HEADNAME -is the name tag of a user defined structure that must be declared -using the macros -.Fn SPLAY_HEAD , -or -.Fn RB_HEAD . -The argument -.Fa NAME -has to be a unique name prefix for every tree that is defined. -.Pp -The function prototypes are declared with either -.Li SPLAY_PROTOTYPE, -or -.Li RB_PROTOTYPE . -The function bodies are generated with either -.Li SPLAY_GENERATE, -or -.Li RB_GENERATE . -See the examples below for further explanation of how these macros are used. -.Sh SPLAY TREES -A splay tree is a self-organizing data structure. Every operation -on the tree causes a splay to happen. The splay moves the requested -node to the root of the tree and partly rebalances it. -.Pp -This has the benefit that request locality causes faster lookups as -the requested nodes move to the top of the tree. On the other hand, -every lookup causes memory writes. -.Pp -The Balance Theorem bounds the total access time for m operations -and n inserts on an initially empty tree as O((m + n)lg n). The -amortized cost for a sequence of m accesses to a splay tree is O(lg n); -.Pp -A splay tree is headed by a structure defined by the -.Fn SPLAY_HEAD -macro. -A -.Fa SPLAY_HEAD -structure is declared as follows: -.Bd -literal -offset indent -SPLAY_HEAD(HEADNAME, TYPE) head; -.Ed -.Pp -where -.Fa HEADNAME -is the name of the structure to be defined, and struct -.Fa TYPE -is the type of the elements to be inserted into the tree. -.Pp -The -.Fn SPLAY_ENTRY -macro declares a structure that allows elements to be connected in the tree. -.Pp -In order to use the functions that manipulate the tree structure, -their prototypes need to be declared with the -.Fn SPLAY_PROTOTYPE -macro, -where -.Fa NAME -is a unique identifier for this particular tree. -The -.Fa TYPE -argument is the type of the structure that is being managed -by the tree. -The -.Fa FIELD -argument is the name of the element defined by -.Fn SPLAY_ENTRY . -.Pp -The function bodies are generated with the -.Fn SPLAY_GENERATE -macro. It takes the same arguments as the -.Fn SPLAY_PROTOTYPE -macro, but should be used only once. -.Pp -Finally, -the -.Fa CMP -argument is the name of a function used to compare tree noded -with each other. The function takes two arguments of type -.Fa "struct TYPE *" . -If the first argument is smaller than the second, the function returns a -value smaller than zero. If they are equal, the function returns zero. -Otherwise, it should return a value greater than zero. The compare -function defines the order of the tree elements. -.Pp -The -.Fn SPLAY_INIT -macro initializes the tree referenced by -.Fa head . -.Pp -The splay tree can also be initialized statically by using the -.Fn SPLAY_INITIALIZER -macro like this: -.Bd -literal -offset indent -SPLAY_HEAD(HEADNAME, TYPE) head = SPLAY_INITIALIZER(&head); -.Ed -.Pp -The -.Fn SPLAY_INSERT -macro inserts the new element -.Fa elm -into the tree. -.Pp -The -.Fn SPLAY_REMOVE -macro removes the element -.Fa elm -from the tree pointed by -.Fa head . -.Pp -The -.Fn SPLAY_FIND -macro can be used to find a particular element in the tree. -.Bd -literal -offset indent -struct TYPE find, *res; -find.key = 30; -res = SPLAY_FIND(NAME, head, &find); -.Ed -.Pp -The -.Fn SPLAY_ROOT , -.Fn SPLAY_MIN , -.Fn SPLAY_MAX , -and -.Fn SPLAY_NEXT -macros can be used to traverse the tree: -.Bd -literal -offset indent -for (np = SPLAY_MIN(NAME, &head); np != NULL; np = SPLAY_NEXT(NAME, &head, np)) -.Ed -.Pp -Or, for simplicity, one can use the -.Fn SPLAY_FOREACH -macro: -.Bd -literal -offset indent -SPLAY_FOREACH(np, NAME, head) -.Ed -.Pp -The -.Fn SPLAY_EMPTY -macro should be used to check whether a splay tree is empty. -.Pp -.Sh RED-BLACK TREES -A red-black tree is a binary search tree with the node color as an -extra attribute. It fulfills a set of conditions: -.Bl -enum -compact -offset indent -.It -every search path from the root to a leaf consists of the same number of -black nodes, -.It -each red node (except for the root) has a black parent, -.It -each leaf node is black. -.El -.Pp -Every operation on a red-black tree is bounded as O(lg n). -The maximum height of a red-black tree is 2lg (n+1). -.Pp -A red-black tree is headed by a structure defined by the -.Fn RB_HEAD -macro. -A -.Fa RB_HEAD -structure is declared as follows: -.Bd -literal -offset indent -RB_HEAD(HEADNAME, TYPE) head; -.Ed -.Pp -where -.Fa HEADNAME -is the name of the structure to be defined, and struct -.Fa TYPE -is the type of the elements to be inserted into the tree. -.Pp -The -.Fn RB_ENTRY -macro declares a structure that allows elements to be connected in the tree. -.Pp -In order to use the functions that manipulate the tree structure, -their prototypes need to be declared with the -.Fn RB_PROTOTYPE -macro, -where -.Fa NAME -is a unique identifier for this particular tree. -The -.Fa TYPE -argument is the type of the structure that is being managed -by the tree. -The -.Fa FIELD -argument is the name of the element defined by -.Fn RB_ENTRY . -.Pp -The function bodies are generated with the -.Fn RB_GENERATE -macro. It takes the same arguments as the -.Fn RB_PROTOTYPE -macro, but should be used only once. -.Pp -Finally, -the -.Fa CMP -argument is the name of a function used to compare tree noded -with each other. The function takes two arguments of type -.Fa "struct TYPE *" . -If the first argument is smaller than the second, the function returns a -value smaller than zero. If they are equal, the function returns zero. -Otherwise, it should return a value greater than zero. The compare -function defines the order of the tree elements. -.Pp -The -.Fn RB_INIT -macro initializes the tree referenced by -.Fa head . -.Pp -The redblack tree can also be initialized statically by using the -.Fn RB_INITIALIZER -macro like this: -.Bd -literal -offset indent -RB_HEAD(HEADNAME, TYPE) head = RB_INITIALIZER(&head); -.Ed -.Pp -The -.Fn RB_INSERT -macro inserts the new element -.Fa elm -into the tree. -.Pp -The -.Fn RB_REMOVE -macro removes the element -.Fa elm -from the tree pointed by -.Fa head . -.Pp -The -.Fn RB_FIND -macro can be used to find a particular element in the tree. -.Bd -literal -offset indent -struct TYPE find, *res; -find.key = 30; -res = RB_FIND(NAME, head, &find); -.Ed -.Pp -The -.Fn RB_ROOT , -.Fn RB_MIN , -.Fn RB_MAX , -and -.Fn RB_NEXT -macros can be used to traverse the tree: -.Bd -literal -offset indent -for (np = RB_MIN(NAME, &head); np != NULL; np = RB_NEXT(NAME, &head, np)) -.Ed -.Pp -Or, for simplicity, one can use the -.Fn RB_FOREACH -macro: -.Bd -literal -offset indent -RB_FOREACH(np, NAME, head) -.Ed -.Pp -The -.Fn RB_EMPTY -macro should be used to check whether a splay tree is empty. -.Pp -.Sh NOTES -Trying to free a tree in the following way is a common error: -.Bd -literal -offset indent -SPLAY_FOREACH(var, NAME, head) { - SPLAY_REMOVE(NAME, head, var); - free(var); -} -free(head); -.Ed -.Pp -Since -.Va var -is free'd, the -.Fn FOREACH -macro refers to a pointer that may have been reallocated already. -Proper code needs a second variable. -.Bd -literal -offset indent -for (var = SPLAY_MIN(NAME, head); var != NULL; var = nxt) { - nxt = SPLAY_NEXT(NAME, head, var); - SPLAY_REMOVE(NAME, head, var); - free(var); -} -.Ed -.Pp -Both -.Fn RB_INSERT -and -.Fn SPLAY_INSERT -return -.Va NULL -if the element was inserted in the tree successfully, otherwise they -return a pointer to the element with the colliding key. -.Pp -Accordingly, -.Fn RB_REMOVE -and -.Fn SPLAY_REMOVE -return the pointer to the removed element otherwise they return -.Va NULL -to indicate an error. -.Sh AUTHORS -The author of the tree macros is Niels Provos. diff --git a/share/man/man5/moduli.5 b/share/man/man5/moduli.5 deleted file mode 100644 index 69d060c06bd6..000000000000 --- a/share/man/man5/moduli.5 +++ /dev/null @@ -1,157 +0,0 @@ -.\" $OpenBSD: moduli.5,v 1.3 2001/06/24 18:50:52 provos Exp $ -.\" -.\" Copyright 1997, 2000 William Allen Simpson <wsimpson@greendragon.com> -.\" 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 designed by William Allen Simpson. -.\" 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. -.\" -.\" Manual page, using -mandoc macros -.\" -.Dd July 28, 1997 -.Dt MODULI 5 -.Os -.Sh NAME -.Nm moduli -.Nd system moduli file -.Sh DESCRIPTION -The -.Pa /etc/moduli -file contains the system-wide Diffie-Hellman prime moduli for the -.Xr photurisd 8 -and -.Xr sshd 8 -programs. -.Pp -Each line in this file contains the following fields: -Time, Type, Tests, Tries, Size, Generator, Modulus. -The fields are separated by white space (tab or blank). -.Pp -.Fa Time : yyyymmddhhmmss . -Specifies the system time that the line was appended to the file. -The value 00000000000000 means unknown (historic). -.\"The file is sorted in ascending order. -.Pp -.Fa Type : decimal . -Specifies the internal structure of the prime modulus. -.Pp -.Bl -tag -width indent -offset indent -compact -.It 0 : -unknown; -often learned from peer during protocol operation, -and saved for later analysis. -.It 1 : -unstructured; -a common large number. -.It 2 : -safe (p = 2q + 1); -meets basic structural requirements. -.It 3 : -Schnorr. -.It 4 : -Sophie-Germaine (q = (p-1)/2); -usually generated in the process of testing safe or strong primes. -.It 5 : -strong; -useful for RSA public key generation. -.El -.Pp -.Fa Tests : decimal (bit field) . -Specifies the methods used in checking for primality. -Usually, more than one test is used. -.Pp -.Bl -tag -width indent -offset indent -compact -.It 0 : -not tested; -often learned from peer during protocol operation, -and saved for later analysis. -.It 1 : -composite; -failed one or more tests. -In this case, the highest bit specifies the test that failed. -.It 2 : -sieve; -checked for division by a range of smaller primes. -.It 4 : -Miller-Rabin. -.It 8 : -Jacobi. -.It 16 : -Elliptic Curve. -.El -.Pp -.Fa Tries : decimal . -Depends on the value of the highest valid Test bit, -where the method specified is: -.Pp -.Bl -tag -width indent -offset indent -compact -.It 0 : -not tested -(always zero). -.It 1 : -composite -(irrelevant). -.It 2 : -sieve; -number of primes sieved. -Commonly on the order of 32,000,000. -.It 4 : -Miller-Rabin; -number of M-R iterations. -Commonly on the order of 32 to 64. -.It 8 : -Jacobi; -unknown -(always zero). -.It 16 : -Elliptic Curve; -unused -(always zero). -.El -.Pp -.Fa Size : decimal . -Specifies the number of significant bits. -.Pp -.Fa Generator : hex string . -Specifies the best generator for a Diffie-Hellman exchange. -0 = unknown or variable, -2, 3, 5, etc. -.Pp -.Fa Modulus : hex string . -The prime modulus. -.Pp -The file is searched for moduli that meet the appropriate -Time, Size and Generator criteria. -When more than one meet the criteria, -the selection should be weighted toward newer moduli, -without completely disqualifying older moduli. -.Sh FILES -.Bl -tag -width /etc/moduli -compact -.It Pa /etc/moduli -.El -.Sh SEE ALSO -.Xr photurisd 8 , -.Xr sshd 8 - diff --git a/usr.bin/m4/Makefile b/usr.bin/m4/Makefile deleted file mode 100644 index ef065c05a428..000000000000 --- a/usr.bin/m4/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# $OpenBSD: Makefile,v 1.10 2002/04/26 13:13:41 espie Exp $ - -# -DEXTENDED -# if you want the paste & spaste macros. - -PROG= m4 -CFLAGS+=-DEXTENDED -CDIAGFLAGS=-W -Wall -Wstrict-prototypes -pedantic \ - -Wno-unused -Wno-char-subscripts -Wno-sign-compare - -SRCS= eval.c expr.c look.c main.c misc.c gnum4.c trace.c -MAN= m4.1 - -.include <bsd.prog.mk> diff --git a/usr.bin/m4/PSD.doc/Makefile b/usr.bin/m4/PSD.doc/Makefile deleted file mode 100644 index c60c912e15c2..000000000000 --- a/usr.bin/m4/PSD.doc/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $OpenBSD: Makefile,v 1.2 1996/06/26 05:36:17 deraadt Exp $ - - -DIR= psd/17.m4 -SRCS= m4.ms -MACROS= -msU - -paper.ps: ${SRCS} - ${ROFF} ${SRCS} > ${.TARGET} - -.include <bsd.doc.mk> diff --git a/usr.bin/m4/TEST/ack.m4 b/usr.bin/m4/TEST/ack.m4 deleted file mode 100644 index ef0b5ef51593..000000000000 --- a/usr.bin/m4/TEST/ack.m4 +++ /dev/null @@ -1,42 +0,0 @@ -# $OpenBSD: ack.m4,v 1.2 1996/06/26 05:36:18 deraadt Exp $ -# $NetBSD: ack.m4,v 1.4 1995/09/28 05:37:54 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)ack.m4 8.1 (Berkeley) 6/6/93 -# - -define(ack, `ifelse($1,0,incr($2),$2,0,`ack(DECR($1),1)', -`ack(DECR($1), ack($1,DECR($2)))')') diff --git a/usr.bin/m4/TEST/hanoi.m4 b/usr.bin/m4/TEST/hanoi.m4 deleted file mode 100644 index d16f922ad0d2..000000000000 --- a/usr.bin/m4/TEST/hanoi.m4 +++ /dev/null @@ -1,47 +0,0 @@ -# $OpenBSD: hanoi.m4,v 1.2 1996/06/26 05:36:19 deraadt Exp $ -# $NetBSD: hanoi.m4,v 1.4 1995/09/28 05:37:56 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)hanoi.m4 8.1 (Berkeley) 6/6/93 -# - -define(hanoi, `trans(A, B, C, $1)') - -define(moved,`move disk from $1 to $2 -') - -define(trans, `ifelse($4,1,`moved($1,$2)', - `trans($1,$3,$2,DECR($4))moved($1,$2)trans($3,$2,$1,DECR($4))')') diff --git a/usr.bin/m4/TEST/hash.m4 b/usr.bin/m4/TEST/hash.m4 deleted file mode 100644 index 21b40e140c2f..000000000000 --- a/usr.bin/m4/TEST/hash.m4 +++ /dev/null @@ -1,57 +0,0 @@ -# $OpenBSD: hash.m4,v 1.2 1996/06/26 05:36:19 deraadt Exp $ -# $NetBSD: hash.m4,v 1.4 1995/09/28 05:37:58 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)hash.m4 8.1 (Berkeley) 6/6/93 -# - -dnl This probably will not run on any m4 that cannot -dnl handle char constants in eval. -dnl -changequote(<,>) define(HASHVAL,99) dnl -define(hash,<eval(str(substr($1,1),0)%HASHVAL)>) dnl -define(str, - <ifelse($1,",$2, - <str(substr(<$1>,1),<eval($2+'substr($1,0,1)')>)>) - >) dnl -define(KEYWORD,<$1,hash($1),>) dnl -define(TSTART, -<struct prehash { - char *keyword; - int hashval; -} keytab[] = {>) dnl -define(TEND,< "",0 -};>) dnl diff --git a/usr.bin/m4/TEST/sqroot.m4 b/usr.bin/m4/TEST/sqroot.m4 deleted file mode 100644 index d01789bb4d0d..000000000000 --- a/usr.bin/m4/TEST/sqroot.m4 +++ /dev/null @@ -1,47 +0,0 @@ -# $OpenBSD: sqroot.m4,v 1.2 1996/06/26 05:36:20 deraadt Exp $ -# $NetBSD: sqroot.m4,v 1.4 1995/09/28 05:38:01 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)sqroot.m4 8.1 (Berkeley) 6/6/93 -# - -define(square_root, - `ifelse(eval($1<0),1,negative-square-root, - `square_root_aux($1, 1, eval(($1+1)/2))')') -define(square_root_aux, - `ifelse($3, $2, $3, - $3, eval($1/$2), $3, - `square_root_aux($1, $3, eval(($3+($1/$3))/2))')') diff --git a/usr.bin/m4/TEST/string.m4 b/usr.bin/m4/TEST/string.m4 deleted file mode 100644 index bb0bba4d1b67..000000000000 --- a/usr.bin/m4/TEST/string.m4 +++ /dev/null @@ -1,47 +0,0 @@ -# $OpenBSD: string.m4,v 1.2 1996/06/26 05:36:20 deraadt Exp $ -# $NetBSD: string.m4,v 1.4 1995/09/28 05:38:03 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)string.m4 8.1 (Berkeley) 6/6/93 -# - -define(string,`integer $1(len(substr($2,1))) -str($1,substr($2,1),0) -data $1(len(substr($2,1)))/EOS/ -') - -define(str,`ifelse($2,",,data $1(incr($3))/`LET'substr($2,0,1)/ -`str($1,substr($2,1),incr($3))')') diff --git a/usr.bin/m4/TEST/test.m4 b/usr.bin/m4/TEST/test.m4 deleted file mode 100644 index 1c77b9bdef9d..000000000000 --- a/usr.bin/m4/TEST/test.m4 +++ /dev/null @@ -1,245 +0,0 @@ -# $OpenBSD: test.m4,v 1.2 1996/06/26 05:36:21 deraadt Exp $ -# $NetBSD: test.m4,v 1.4 1995/09/28 05:38:05 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)test.m4 8.1 (Berkeley) 6/6/93 -# - -# test file for mp (not comprehensive) -# -# v7 m4 does not have `decr'. -# -define(DECR,`eval($1-1)') -# -# include string macros -# -include(string.m4) -# -# create some fortrash strings for an even uglier language -# -string(TEXT, "text") -string(DATA, "data") -string(BEGIN, "begin") -string(END, "end") -string(IF, "if") -string(THEN, "then") -string(ELSE, "else") -string(CASE, "case") -string(REPEAT, "repeat") -string(WHILE, "while") -string(DEFAULT, "default") -string(UNTIL, "until") -string(FUNCTION, "function") -string(PROCEDURE, "procedure") -string(EXTERNAL, "external") -string(FORWARD, "forward") -string(TYPE, "type") -string(VAR, "var") -string(CONST, "const") -string(PROGRAM, "program") -string(INPUT, "input") -string(OUTPUT, "output") -# -divert(2) -diversion #1 -divert(3) -diversion #2 -divert(4) -diversion #3 -divert(5) -diversion #4 -divert(0) -define(abc,xxx) -ifdef(`abc',defined,undefined) -# -# v7 m4 does this wrong. The right output is -# this is A vEry lon sEntEnCE -# see m4 documentation for translit. -# -translit(`this is a very long sentence', abcdefg, ABCDEF) -# -# include towers-of-hanoi -# -include(hanoi.m4) -# -# some reasonable set of disks -# -hanoi(6) -# -# include ackermann's function -# -include(ack.m4) -# -# something like (3,3) will blow away un*x m4. -# -ack(2,3) -# -# include a square_root function for fixed nums -# -include(sqroot.m4) -# -# some square roots. -# -square_root(15) -square_root(100) -square_root(-4) -square_root(21372) -# -# some textual material for enjoyment. -# -[taken from the 'Clemson University Computer Newsletter', - September 1981, pp. 6-7] - -I am a wizard in the magical Kingdom of Transformation and I -slay dragons for a living. Actually, I am a systems programmer. -One of the problems with systems programming is explaining to -non-computer enthusiasts what that is. All of the terms I use to -describe my job are totally meaningless to them. Usually my response -to questions about my work is to say as little as possible. For -instance, if someone asks what happened at work this week, I say -"Nothing much" and then I change the subject. - -With the assistance of my brother, a mechanical engineer, I have devised -an analogy that everyone can understand. The analogy describes the -"Kingdom of Transformation" where travelers wander and are magically -transformed. This kingdom is the computer and the travelers are information. -The purpose of the computer is to change information to a more meaningful -forma. The law of conservation applies here: The computer never creates -and never intentionally destroys data. With no further ado, let us travel -to the Kingdom of Transformation: - -In a land far, far away, there is a magical kingdom called the Kingdom of -Transformation. A king rules over this land and employs a Council of -Wizardry. The main purpose of this kingdom is to provide a way for -neighboring kingdoms to transform citizens into more useful citizens. This -is done by allowing the citizens to enter the kingdom at one of its ports -and to travel any of the many routes in the kingdom. They are magically -transformed along the way. The income of the Kingdom of Transformation -comes from the many toll roads within its boundaries. - -The Kingdom of Transformation was created when several kingdoms got -together and discovered a mutual need for new talents and abilities for -citizens. They employed CTK, Inc. (Creators of Transformation, Inc.) to -create this kingdom. CTK designed the country, its transportation routes, -and its laws of transformation, and created the major highway system. - -Hazards -======= - -Because magic is not truly controllable, CTK invariably, but unknowingly, -creates dragons. Dragons are huge fire-breathing beasts which sometimes -injure or kill travelers. Fortunately, they do not travel, but always -remain near their den. - -Other hazards also exist which are potentially harmful. As the roads -become older and more weatherbeaten, pot-holes will develop, trees will -fall on travelers, etc. CTK maintenance men are called to fix these -problems. - -Wizards -======= - -The wizards play a major role in creating and maintaining the kingdom but -get little credit for their work because it is performed secretly. The -wizards do not wan the workers or travelers to learn their incantations -because many laws would be broken and chaos would result. - -CTK's grand design is always general enough to be applicable in many -different situations. As a result, it is often difficult to use. The -first duty of the wizards is to tailor the transformation laws so as to be -more beneficial and easier to use in their particular environment. - -After creation of the kingdom, a major duty of the wizards is to search for -and kill dragons. If travelers do not return on time or if they return -injured, the ruler of the country contacts the wizards. If the wizards -determine that the injury or death occurred due to the traveler's -negligence, they provide the traveler's country with additional warnings. -If not, they must determine if the cause was a road hazard or a dragon. If -the suspect a road hazard, they call in a CTK maintenance man to locate the -hazard and to eliminate it, as in repairing the pothole in the road. If -they think that cause was a dragon, then they must find and slay it. - -The most difficult part of eliminating a dragon is finding it. Sometimes -the wizard magically knows where the dragon's lair it, but often the wizard -must send another traveler along the same route and watch to see where he -disappears. This sounds like a failsafe method for finding dragons (and a -suicide mission for thr traveler) but the second traveler does not always -disappear. Some dragons eat any traveler who comes too close; others are -very picky. - -The wizards may call in CTK who designed the highway system and -transformation laws to help devise a way to locate the dragon. CTK also -helps provide the right spell or incantation to slay the dragon. (There is -no general spell to slay dragons; each dragon must be eliminated with a -different spell.) - -Because neither CTK nor wizards are perfect, spells to not always work -correctly. At best, nothing happens when the wrong spell is uttered. At -worst, the dragon becomes a much larger dragon or multiplies into several -smaller ones. In either case, new spells must be found. - -If all existing dragons are quiet (i.e. have eaten sufficiently), wizards -have time to do other things. They hide in castles and practice spells and -incatations. They also devise shortcuts for travelers and new laws of -transformation. - -Changes in the Kingdom -====================== - -As new transformation kingdoms are created and old ones are maintained, -CTK, Inc. is constantly learning new things. It learns ways to avoid -creating some of the dragons that they have previously created. It also -discovers new and better laws of transformation. As a result, CTK will -periodically create a new grand design which is far better than the old. -The wizards determine when is a good time to implement this new design. -This is when the tourist season is slow or when no important travelers -(VIPs) are to arrive. The kingdom must be closed for the actual -implementation and is leter reopened as a new and better place to go. - -A final question you might ask is what happens when the number of tourists -becomes too great for the kingdom to handle in a reasonable period of time -(i.e., the tourist lines at the ports are too long). The Kingdom of -Transformation has three options: (1) shorten the paths that a tourist must -travel, or (2) convince CTK to develop a faster breed of horses so that the -travelers can finish sooner, or (3) annex more territories so that the -kingdom can handle more travelers. - -Thus ends the story of the Kingdom of Transformation. I hope this has -explained my job to you: I slay dragons for a living. - -# -#should do an automatic undivert.. -# diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c deleted file mode 100644 index 5af3c8774c41..000000000000 --- a/usr.bin/m4/eval.c +++ /dev/null @@ -1,1050 +0,0 @@ -/* $OpenBSD: eval.c,v 1.44 2002/04/26 16:15:16 espie Exp $ */ -/* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95"; -#else -static char rcsid[] = "$OpenBSD: eval.c,v 1.44 2002/04/26 16:15:16 espie Exp $"; -#endif -#endif /* not lint */ - -/* - * eval.c - * Facility: m4 macro processor - * by: oz - */ - -#include <sys/types.h> -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <stddef.h> -#include <string.h> -#include <fcntl.h> -#include <err.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" -#include "pathnames.h" - -#define BUILTIN_MARKER "__builtin_" - -static void dodefn(const char *); -static void dopushdef(const char *, const char *); -static void dodump(const char *[], int); -static void dotrace(const char *[], int, int); -static void doifelse(const char *[], int); -static int doincl(const char *); -static int dopaste(const char *); -static void gnu_dochq(const char *[], int); -static void dochq(const char *[], int); -static void gnu_dochc(const char *[], int); -static void dochc(const char *[], int); -static void dodiv(int); -static void doundiv(const char *[], int); -static void dosub(const char *[], int); -static void map(char *, const char *, const char *, const char *); -static const char *handledash(char *, char *, const char *); -static void expand_builtin(const char *[], int, int); -static void expand_macro(const char *[], int); -static void dump_one_def(ndptr); - -unsigned long expansion_id; - -/* - * eval - eval all macros and builtins calls - * argc - number of elements in argv. - * argv - element vector : - * argv[0] = definition of a user - * macro or nil if built-in. - * argv[1] = name of the macro or - * built-in. - * argv[2] = parameters to user-defined - * . macro or built-in. - * . - * - * A call in the form of macro-or-builtin() will result in: - * argv[0] = nullstr - * argv[1] = macro-or-builtin - * argv[2] = nullstr - * - * argc is 3 for macro-or-builtin() and 2 for macro-or-builtin - */ -void -eval(const char *argv[], int argc, int td) -{ - ssize_t mark = -1; - - expansion_id++; - if (td & RECDEF) - errx(1, "%s at line %lu: expanding recursive definition for %s", - CURRENT_NAME, CURRENT_LINE, argv[1]); - if (traced_macros && is_traced(argv[1])) - mark = trace(argv, argc, infile+ilevel); - if (td == MACRTYPE) - expand_macro(argv, argc); - else - expand_builtin(argv, argc, td); - if (mark != -1) - finish_trace(mark); -} - -/* - * expand_builtin - evaluate built-in macros. - */ -void -expand_builtin(const char *argv[], int argc, int td) -{ - int c, n; - int ac; - static int sysval = 0; - -#ifdef DEBUG - printf("argc = %d\n", argc); - for (n = 0; n < argc; n++) - printf("argv[%d] = %s\n", n, argv[n]); - fflush(stdout); -#endif - - /* - * if argc == 3 and argv[2] is null, then we - * have macro-or-builtin() type call. We adjust - * argc to avoid further checking.. - */ - ac = argc; - - if (argc == 3 && !*(argv[2])) - argc--; - - switch (td & TYPEMASK) { - - case DEFITYPE: - if (argc > 2) - dodefine(argv[2], (argc > 3) ? argv[3] : null); - break; - - case PUSDTYPE: - if (argc > 2) - dopushdef(argv[2], (argc > 3) ? argv[3] : null); - break; - - case DUMPTYPE: - dodump(argv, argc); - break; - - case TRACEONTYPE: - dotrace(argv, argc, 1); - break; - - case TRACEOFFTYPE: - dotrace(argv, argc, 0); - break; - - case EXPRTYPE: - /* - * doexpr - evaluate arithmetic - * expression - */ - if (argc > 2) - pbnum(expr(argv[2])); - break; - - case IFELTYPE: - if (argc > 4) - doifelse(argv, argc); - break; - - case IFDFTYPE: - /* - * doifdef - select one of two - * alternatives based on the existence of - * another definition - */ - if (argc > 3) { - if (lookup(argv[2]) != nil) - pbstr(argv[3]); - else if (argc > 4) - pbstr(argv[4]); - } - break; - - case LENGTYPE: - /* - * dolen - find the length of the - * argument - */ - pbnum((argc > 2) ? strlen(argv[2]) : 0); - break; - - case INCRTYPE: - /* - * doincr - increment the value of the - * argument - */ - if (argc > 2) - pbnum(atoi(argv[2]) + 1); - break; - - case DECRTYPE: - /* - * dodecr - decrement the value of the - * argument - */ - if (argc > 2) - pbnum(atoi(argv[2]) - 1); - break; - - case SYSCTYPE: - /* - * dosys - execute system command - */ - if (argc > 2) - sysval = system(argv[2]); - break; - - case SYSVTYPE: - /* - * dosysval - return value of the last - * system call. - * - */ - pbnum(sysval); - break; - - case ESYSCMDTYPE: - if (argc > 2) - doesyscmd(argv[2]); - break; - case INCLTYPE: - if (argc > 2) - if (!doincl(argv[2])) - err(1, "%s at line %lu: include(%s)", - CURRENT_NAME, CURRENT_LINE, argv[2]); - break; - - case SINCTYPE: - if (argc > 2) - (void) doincl(argv[2]); - break; -#ifdef EXTENDED - case PASTTYPE: - if (argc > 2) - if (!dopaste(argv[2])) - err(1, "%s at line %lu: paste(%s)", - CURRENT_NAME, CURRENT_LINE, argv[2]); - break; - - case SPASTYPE: - if (argc > 2) - (void) dopaste(argv[2]); - break; -#endif - case CHNQTYPE: - if (mimic_gnu) - gnu_dochq(argv, ac); - else - dochq(argv, argc); - break; - - case CHNCTYPE: - if (mimic_gnu) - gnu_dochc(argv, ac); - else - dochc(argv, argc); - break; - - case SUBSTYPE: - /* - * dosub - select substring - * - */ - if (argc > 3) - dosub(argv, argc); - break; - - case SHIFTYPE: - /* - * doshift - push back all arguments - * except the first one (i.e. skip - * argv[2]) - */ - if (argc > 3) { - for (n = argc - 1; n > 3; n--) { - pbstr(rquote); - pbstr(argv[n]); - pbstr(lquote); - putback(COMMA); - } - pbstr(rquote); - pbstr(argv[3]); - pbstr(lquote); - } - break; - - case DIVRTYPE: - if (argc > 2 && (n = atoi(argv[2])) != 0) - dodiv(n); - else { - active = stdout; - oindex = 0; - } - break; - - case UNDVTYPE: - doundiv(argv, argc); - break; - - case DIVNTYPE: - /* - * dodivnum - return the number of - * current output diversion - */ - pbnum(oindex); - break; - - case UNDFTYPE: - /* - * doundefine - undefine a previously - * defined macro(s) or m4 keyword(s). - */ - if (argc > 2) - for (n = 2; n < argc; n++) - remhash(argv[n], ALL); - break; - - case POPDTYPE: - /* - * dopopdef - remove the topmost - * definitions of macro(s) or m4 - * keyword(s). - */ - if (argc > 2) - for (n = 2; n < argc; n++) - remhash(argv[n], TOP); - break; - - case MKTMTYPE: - /* - * dotemp - create a temporary file - */ - if (argc > 2) { - int fd; - char *temp; - - temp = xstrdup(argv[2]); - - fd = mkstemp(temp); - if (fd == -1) - err(1, - "%s at line %lu: couldn't make temp file %s", - CURRENT_NAME, CURRENT_LINE, argv[2]); - close(fd); - pbstr(temp); - free(temp); - } - break; - - case TRNLTYPE: - /* - * dotranslit - replace all characters in - * the source string that appears in the - * "from" string with the corresponding - * characters in the "to" string. - */ - if (argc > 3) { - char *temp; - - temp = xalloc(strlen(argv[2])+1); - if (argc > 4) - map(temp, argv[2], argv[3], argv[4]); - else - map(temp, argv[2], argv[3], null); - pbstr(temp); - free(temp); - } else if (argc > 2) - pbstr(argv[2]); - break; - - case INDXTYPE: - /* - * doindex - find the index of the second - * argument string in the first argument - * string. -1 if not present. - */ - pbnum((argc > 3) ? indx(argv[2], argv[3]) : -1); - break; - - case ERRPTYPE: - /* - * doerrp - print the arguments to stderr - * file - */ - if (argc > 2) { - for (n = 2; n < argc; n++) - fprintf(stderr, "%s ", argv[n]); - fprintf(stderr, "\n"); - } - break; - - case DNLNTYPE: - /* - * dodnl - eat-up-to and including - * newline - */ - while ((c = gpbc()) != '\n' && c != EOF) - ; - break; - - case M4WRTYPE: - /* - * dom4wrap - set up for - * wrap-up/wind-down activity - */ - m4wraps = (argc > 2) ? xstrdup(argv[2]) : null; - break; - - case EXITTYPE: - /* - * doexit - immediate exit from m4. - */ - killdiv(); - exit((argc > 2) ? atoi(argv[2]) : 0); - break; - - case DEFNTYPE: - if (argc > 2) - for (n = 2; n < argc; n++) - dodefn(argv[n]); - break; - - case INDIRTYPE: /* Indirect call */ - if (argc > 2) - doindir(argv, argc); - break; - - case BUILTINTYPE: /* Builtins only */ - if (argc > 2) - dobuiltin(argv, argc); - break; - - case PATSTYPE: - if (argc > 2) - dopatsubst(argv, argc); - break; - case REGEXPTYPE: - if (argc > 2) - doregexp(argv, argc); - break; - case LINETYPE: - doprintlineno(infile+ilevel); - break; - case FILENAMETYPE: - doprintfilename(infile+ilevel); - break; - case SELFTYPE: - pbstr(rquote); - pbstr(argv[1]); - pbstr(lquote); - break; - default: - errx(1, "%s at line %lu: eval: major botch.", - CURRENT_NAME, CURRENT_LINE); - break; - } -} - -/* - * expand_macro - user-defined macro expansion - */ -void -expand_macro(const char *argv[], int argc) -{ - const char *t; - const char *p; - int n; - int argno; - - t = argv[0]; /* defn string as a whole */ - p = t; - while (*p) - p++; - p--; /* last character of defn */ - while (p > t) { - if (*(p - 1) != ARGFLAG) - PUTBACK(*p); - else { - switch (*p) { - - case '#': - pbnum(argc - 2); - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if ((argno = *p - '0') < argc - 1) - pbstr(argv[argno + 1]); - break; - case '*': - if (argc > 2) { - for (n = argc - 1; n > 2; n--) { - pbstr(argv[n]); - putback(COMMA); - } - pbstr(argv[2]); - } - break; - case '@': - if (argc > 2) { - for (n = argc - 1; n > 2; n--) { - pbstr(rquote); - pbstr(argv[n]); - pbstr(lquote); - putback(COMMA); - } - pbstr(rquote); - pbstr(argv[2]); - pbstr(lquote); - } - break; - default: - PUTBACK(*p); - PUTBACK('$'); - break; - } - p--; - } - p--; - } - if (p == t) /* do last character */ - PUTBACK(*p); -} - -/* - * dodefine - install definition in the table - */ -void -dodefine(const char *name, const char *defn) -{ - ndptr p; - int n; - - if (!*name) - errx(1, "%s at line %lu: null definition.", CURRENT_NAME, - CURRENT_LINE); - if ((p = lookup(name)) == nil) - p = addent(name); - else if (p->defn != null) - free((char *) p->defn); - if (strncmp(defn, BUILTIN_MARKER, sizeof(BUILTIN_MARKER)-1) == 0) { - n = builtin_type(defn+sizeof(BUILTIN_MARKER)-1); - if (n != -1) { - p->type = n & TYPEMASK; - if ((n & NOARGS) == 0) - p->type |= NEEDARGS; - p->defn = null; - return; - } - } - if (!*defn) - p->defn = null; - else - p->defn = xstrdup(defn); - p->type = MACRTYPE; - if (STREQ(name, defn)) - p->type |= RECDEF; -} - -/* - * dodefn - push back a quoted definition of - * the given name. - */ -static void -dodefn(const char *name) -{ - ndptr p; - char *real; - - if ((p = lookup(name)) != nil) { - if (p->defn != null) { - pbstr(rquote); - pbstr(p->defn); - pbstr(lquote); - } else if ((real = builtin_realname(p->type)) != NULL) { - pbstr(real); - pbstr(BUILTIN_MARKER); - } - } -} - -/* - * dopushdef - install a definition in the hash table - * without removing a previous definition. Since - * each new entry is entered in *front* of the - * hash bucket, it hides a previous definition from - * lookup. - */ -static void -dopushdef(const char *name, const char *defn) -{ - ndptr p; - - if (!*name) - errx(1, "%s at line %lu: null definition", CURRENT_NAME, - CURRENT_LINE); - p = addent(name); - if (!*defn) - p->defn = null; - else - p->defn = xstrdup(defn); - p->type = MACRTYPE; - if (STREQ(name, defn)) - p->type |= RECDEF; -} - -/* - * dump_one_def - dump the specified definition. - */ -static void -dump_one_def(ndptr p) -{ - char *real; - - if (mimic_gnu) { - if ((p->type & TYPEMASK) == MACRTYPE) - fprintf(traceout, "%s:\t%s\n", p->name, p->defn); - else { - real = builtin_realname(p->type); - if (real == NULL) - real = null; - fprintf(traceout, "%s:\t<%s>\n", p->name, real); - } - } else - fprintf(traceout, "`%s'\t`%s'\n", p->name, p->defn); -} - -/* - * dodumpdef - dump the specified definitions in the hash - * table to stderr. If nothing is specified, the entire - * hash table is dumped. - */ -static void -dodump(const char *argv[], int argc) -{ - int n; - ndptr p; - - if (argc > 2) { - for (n = 2; n < argc; n++) - if ((p = lookup(argv[n])) != nil) - dump_one_def(p); - } else { - for (n = 0; n < HASHSIZE; n++) - for (p = hashtab[n]; p != nil; p = p->nxtptr) - dump_one_def(p); - } -} - -/* - * dotrace - mark some macros as traced/untraced depending upon on. - */ -static void -dotrace(const char *argv[], int argc, int on) -{ - int n; - - if (argc > 2) { - for (n = 2; n < argc; n++) - mark_traced(argv[n], on); - } else - mark_traced(NULL, on); -} - -/* - * doifelse - select one of two alternatives - loop. - */ -static void -doifelse(const char *argv[], int argc) -{ - cycle { - if (STREQ(argv[2], argv[3])) - pbstr(argv[4]); - else if (argc == 6) - pbstr(argv[5]); - else if (argc > 6) { - argv += 3; - argc -= 3; - continue; - } - break; - } -} - -/* - * doinclude - include a given file. - */ -static int -doincl(const char *ifile) -{ - if (ilevel + 1 == MAXINP) - errx(1, "%s at line %lu: too many include files.", - CURRENT_NAME, CURRENT_LINE); - if (fopen_trypath(infile+ilevel+1, ifile) != NULL) { - ilevel++; - bbase[ilevel] = bufbase = bp; - return (1); - } else - return (0); -} - -#ifdef EXTENDED -/* - * dopaste - include a given file without any - * macro processing. - */ -static int -dopaste(const char *pfile) -{ - FILE *pf; - int c; - - if ((pf = fopen(pfile, "r")) != NULL) { - while ((c = getc(pf)) != EOF) - putc(c, active); - (void) fclose(pf); - return (1); - } else - return (0); -} -#endif - -static void -gnu_dochq(const char *argv[], int ac) -{ - /* In gnu-m4 mode, the only way to restore quotes is to have no - * arguments at all. */ - if (ac == 2) { - lquote[0] = LQUOTE, lquote[1] = EOS; - rquote[0] = RQUOTE, rquote[1] = EOS; - } else { - strlcpy(lquote, argv[2], sizeof(lquote)); - if(ac > 3) - strlcpy(rquote, argv[3], sizeof(rquote)); - else - rquote[0] = EOS; - } -} - -/* - * dochq - change quote characters - */ -static void -dochq(const char *argv[], int argc) -{ - if (argc > 2) { - if (*argv[2]) - strlcpy(lquote, argv[2], sizeof(lquote)); - else { - lquote[0] = LQUOTE; - lquote[1] = EOS; - } - if (argc > 3) { - if (*argv[3]) - strlcpy(rquote, argv[3], sizeof(rquote)); - } else - strcpy(rquote, lquote); - } else { - lquote[0] = LQUOTE, lquote[1] = EOS; - rquote[0] = RQUOTE, rquote[1] = EOS; - } -} - -static void -gnu_dochc(const char *argv[], int ac) -{ - /* In gnu-m4 mode, no arguments mean no comment - * arguments at all. */ - if (ac == 2) { - scommt[0] = EOS; - ecommt[0] = EOS; - } else { - if (*argv[2]) - strlcpy(scommt, argv[2], sizeof(scommt)); - else - scommt[0] = SCOMMT, scommt[1] = EOS; - if(ac > 3 && *argv[3]) - strlcpy(ecommt, argv[3], sizeof(ecommt)); - else - ecommt[0] = ECOMMT, ecommt[1] = EOS; - } -} -/* - * dochc - change comment characters - */ -static void -dochc(const char *argv[], int argc) -{ - if (argc > 2) { - if (*argv[2]) - strlcpy(scommt, argv[2], sizeof(scommt)); - if (argc > 3) { - if (*argv[3]) - strlcpy(ecommt, argv[3], sizeof(ecommt)); - } - else - ecommt[0] = ECOMMT, ecommt[1] = EOS; - } - else { - scommt[0] = SCOMMT, scommt[1] = EOS; - ecommt[0] = ECOMMT, ecommt[1] = EOS; - } -} - -/* - * dodivert - divert the output to a temporary file - */ -static void -dodiv(int n) -{ - int fd; - - oindex = n; - if (n >= maxout) { - if (mimic_gnu) - resizedivs(n + 10); - else - n = 0; /* bitbucket */ - } - - if (n < 0) - n = 0; /* bitbucket */ - if (outfile[n] == NULL) { - char fname[] = _PATH_DIVNAME; - - if ((fd = mkstemp(fname)) < 0 || - (outfile[n] = fdopen(fd, "w+")) == NULL) - err(1, "%s: cannot divert", fname); - if (unlink(fname) == -1) - err(1, "%s: cannot unlink", fname); - } - active = outfile[n]; -} - -/* - * doundivert - undivert a specified output, or all - * other outputs, in numerical order. - */ -static void -doundiv(const char *argv[], int argc) -{ - int ind; - int n; - - if (argc > 2) { - for (ind = 2; ind < argc; ind++) { - n = atoi(argv[ind]); - if (n > 0 && n < maxout && outfile[n] != NULL) - getdiv(n); - - } - } - else - for (n = 1; n < maxout; n++) - if (outfile[n] != NULL) - getdiv(n); -} - -/* - * dosub - select substring - */ -static void -dosub(const char *argv[], int argc) -{ - const char *ap, *fc, *k; - int nc; - - ap = argv[2]; /* target string */ -#ifdef EXPR - fc = ap + expr(argv[3]); /* first char */ -#else - fc = ap + atoi(argv[3]); /* first char */ -#endif - nc = strlen(fc); - if (argc >= 5) -#ifdef EXPR - nc = min(nc, expr(argv[4])); -#else - nc = min(nc, atoi(argv[4])); -#endif - if (fc >= ap && fc < ap + strlen(ap)) - for (k = fc + nc - 1; k >= fc; k--) - putback(*k); -} - -/* - * map: - * map every character of s1 that is specified in from - * into s3 and replace in s. (source s1 remains untouched) - * - * This is a standard implementation of map(s,from,to) function of ICON - * language. Within mapvec, we replace every character of "from" with - * the corresponding character in "to". If "to" is shorter than "from", - * than the corresponding entries are null, which means that those - * characters dissapear altogether. Furthermore, imagine - * map(dest, "sourcestring", "srtin", "rn..*") type call. In this case, - * `s' maps to `r', `r' maps to `n' and `n' maps to `*'. Thus, `s' - * ultimately maps to `*'. In order to achieve this effect in an efficient - * manner (i.e. without multiple passes over the destination string), we - * loop over mapvec, starting with the initial source character. if the - * character value (dch) in this location is different than the source - * character (sch), sch becomes dch, once again to index into mapvec, until - * the character value stabilizes (i.e. sch = dch, in other words - * mapvec[n] == n). Even if the entry in the mapvec is null for an ordinary - * character, it will stabilize, since mapvec[0] == 0 at all times. At the - * end, we restore mapvec* back to normal where mapvec[n] == n for - * 0 <= n <= 127. This strategy, along with the restoration of mapvec, is - * about 5 times faster than any algorithm that makes multiple passes over - * destination string. - */ -static void -map(char *dest, const char *src, const char *from, const char *to) -{ - const char *tmp; - unsigned char sch, dch; - static char frombis[257]; - static char tobis[257]; - static unsigned char mapvec[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, - 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, - 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, - 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, - 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, - 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, - 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, - 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, - 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 - }; - - if (*src) { - if (mimic_gnu) { - /* - * expand character ranges on the fly - */ - from = handledash(frombis, frombis + 256, from); - to = handledash(tobis, tobis + 256, to); - } - tmp = from; - /* - * create a mapping between "from" and - * "to" - */ - while (*from) - mapvec[(unsigned char)(*from++)] = (*to) ? - (unsigned char)(*to++) : 0; - - while (*src) { - sch = (unsigned char)(*src++); - dch = mapvec[sch]; - while (dch != sch) { - sch = dch; - dch = mapvec[sch]; - } - if ((*dest = (char)dch)) - dest++; - } - /* - * restore all the changed characters - */ - while (*tmp) { - mapvec[(unsigned char)(*tmp)] = (unsigned char)(*tmp); - tmp++; - } - } - *dest = '\0'; -} - - -/* - * handledash: - * use buffer to copy the src string, expanding character ranges - * on the way. - */ -static const char * -handledash(char *buffer, char *end, const char *src) -{ - char *p; - - p = buffer; - while(*src) { - if (src[1] == '-' && src[2]) { - unsigned char i; - for (i = (unsigned char)src[0]; - i <= (unsigned char)src[2]; i++) { - *p++ = i; - if (p == end) { - *p = '\0'; - return buffer; - } - } - src += 3; - } else - *p++ = *src++; - if (p == end) - break; - } - *p = '\0'; - return buffer; -} diff --git a/usr.bin/m4/expr.c b/usr.bin/m4/expr.c deleted file mode 100644 index 10eacc91bd1e..000000000000 --- a/usr.bin/m4/expr.c +++ /dev/null @@ -1,621 +0,0 @@ -/* $OpenBSD: expr.c,v 1.14 2002/04/26 16:15:16 espie Exp $ */ -/* $NetBSD: expr.c,v 1.7 1995/09/28 05:37:31 tls Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)expr.c 8.2 (Berkeley) 4/29/95"; -#else -static char rcsid[] = "$OpenBSD: expr.c,v 1.14 2002/04/26 16:15:16 espie Exp $"; -#endif -#endif /* not lint */ - -#include <sys/cdefs.h> -#include <ctype.h> -#include <err.h> -#include <stddef.h> -#include <stdio.h> -#include "mdef.h" -#include "extern.h" - -/* - * expression evaluator: performs a standard recursive - * descent parse to evaluate any expression permissible - * within the following grammar: - * - * expr : query EOS - * query : lor - * | lor "?" query ":" query - * lor : land { "||" land } - * land : not { "&&" not } - * not : eqrel - * | '!' not - * eqrel : shift { eqrelop shift } - * shift : primary { shop primary } - * primary : term { addop term } - * term : exp { mulop exp } - * exp : unary { expop unary } - * unary : factor - * | unop unary - * factor : constant - * | "(" query ")" - * constant: num - * | "'" CHAR "'" - * num : DIGIT - * | DIGIT num - * shop : "<<" - * | ">>" - * eqrel : "=" - * | "==" - * | "!=" - * | "<" - * | ">" - * | "<=" - * | ">=" - * - * - * This expression evaluator is lifted from a public-domain - * C Pre-Processor included with the DECUS C Compiler distribution. - * It is hacked somewhat to be suitable for m4. - * - * Originally by: Mike Lutz - * Bob Harper - */ - -#define EQL 0 -#define NEQ 1 -#define LSS 2 -#define LEQ 3 -#define GTR 4 -#define GEQ 5 -#define OCTAL 8 -#define DECIMAL 10 -#define HEX 16 - -static const char *nxtch; /* Parser scan pointer */ -static const char *where; - -static int query(void); -static int lor(void); -static int land(void); -static int not(void); -static int eqrel(void); -static int shift(void); -static int primary(void); -static int term(void); -static int exp(void); -static int unary(void); -static int factor(void); -static int constant(void); -static int num(void); -static int geteqrel(void); -static int skipws(void); -static void experr(const char *); - -/* - * For longjmp - */ -#include <setjmp.h> -static jmp_buf expjump; - -/* - * macros: - * ungetch - Put back the last character examined. - * getch - return the next character from expr string. - */ -#define ungetch() nxtch-- -#define getch() *nxtch++ - -int -expr(const char *expbuf) -{ - int rval; - - nxtch = expbuf; - where = expbuf; - if (setjmp(expjump) != 0) - return FALSE; - - rval = query(); - if (skipws() == EOS) - return rval; - - printf("m4: ill-formed expression.\n"); - return FALSE; -} - -/* - * query : lor | lor '?' query ':' query - */ -static int -query() -{ - int result, true_val, false_val; - - result = lor(); - if (skipws() != '?') { - ungetch(); - return result; - } - - true_val = query(); - if (skipws() != ':') - experr("bad query"); - - false_val = query(); - return result ? true_val : false_val; -} - -/* - * lor : land { '||' land } - */ -static int -lor() -{ - int c, vl, vr; - - vl = land(); - while ((c = skipws()) == '|') { - if (getch() != '|') - ungetch(); - vr = land(); - vl = vl || vr; - } - - ungetch(); - return vl; -} - -/* - * land : not { '&&' not } - */ -static int -land() -{ - int c, vl, vr; - - vl = not(); - while ((c = skipws()) == '&') { - if (getch() != '&') - ungetch(); - vr = not(); - vl = vl && vr; - } - - ungetch(); - return vl; -} - -/* - * not : eqrel | '!' not - */ -static int -not() -{ - int val, c; - - if ((c = skipws()) == '!' && getch() != '=') { - ungetch(); - val = not(); - return !val; - } - - if (c == '!') - ungetch(); - ungetch(); - return eqrel(); -} - -/* - * eqrel : shift { eqrelop shift } - */ -static int -eqrel() -{ - int vl, vr, eqrel; - - vl = shift(); - while ((eqrel = geteqrel()) != -1) { - vr = shift(); - - switch (eqrel) { - - case EQL: - vl = (vl == vr); - break; - case NEQ: - vl = (vl != vr); - break; - - case LEQ: - vl = (vl <= vr); - break; - case LSS: - vl = (vl < vr); - break; - case GTR: - vl = (vl > vr); - break; - case GEQ: - vl = (vl >= vr); - break; - } - } - return vl; -} - -/* - * shift : primary { shop primary } - */ -static int -shift() -{ - int vl, vr, c; - - vl = primary(); - while (((c = skipws()) == '<' || c == '>') && getch() == c) { - vr = primary(); - - if (c == '<') - vl <<= vr; - else - vl >>= vr; - } - - if (c == '<' || c == '>') - ungetch(); - ungetch(); - return vl; -} - -/* - * primary : term { addop term } - */ -static int -primary() -{ - int c, vl, vr; - - vl = term(); - while ((c = skipws()) == '+' || c == '-') { - vr = term(); - - if (c == '+') - vl += vr; - else - vl -= vr; - } - - ungetch(); - return vl; -} - -/* - * <term> := <exp> { <mulop> <exp> } - */ -static int -term() -{ - int c, vl, vr; - - vl = exp(); - while ((c = skipws()) == '*' || c == '/' || c == '%') { - vr = exp(); - - switch (c) { - case '*': - vl *= vr; - break; - case '/': - if (vr == 0) - errx(1, "division by zero in eval."); - else - vl /= vr; - break; - case '%': - if (vr == 0) - errx(1, "modulo zero in eval."); - else - vl %= vr; - break; - } - } - ungetch(); - return vl; -} - -/* - * <term> := <unary> { <expop> <unary> } - */ -static int -exp() -{ - int c, vl, vr, n; - - vl = unary(); - switch (c = skipws()) { - - case '*': - if (getch() != '*') { - ungetch(); - break; - } - - case '^': - vr = exp(); - n = 1; - while (vr-- > 0) - n *= vl; - return n; - } - - ungetch(); - return vl; -} - -/* - * unary : factor | unop unary - */ -static int -unary() -{ - int val, c; - - if ((c = skipws()) == '+' || c == '-' || c == '~') { - val = unary(); - - switch (c) { - case '+': - return val; - case '-': - return -val; - case '~': - return ~val; - } - } - - ungetch(); - return factor(); -} - -/* - * factor : constant | '(' query ')' - */ -static int -factor() -{ - int val; - - if (skipws() == '(') { - val = query(); - if (skipws() != ')') - experr("bad factor"); - return val; - } - - ungetch(); - return constant(); -} - -/* - * constant: num | 'char' - * Note: constant() handles multi-byte constants - */ -static int -constant() -{ - int i; - int value; - int c; - int v[sizeof(int)]; - - if (skipws() != '\'') { - ungetch(); - return num(); - } - for (i = 0; i < sizeof(int); i++) { - if ((c = getch()) == '\'') { - ungetch(); - break; - } - if (c == '\\') { - switch (c = getch()) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - ungetch(); - c = num(); - break; - case 'n': - c = 012; - break; - case 'r': - c = 015; - break; - case 't': - c = 011; - break; - case 'b': - c = 010; - break; - case 'f': - c = 014; - break; - } - } - v[i] = c; - } - if (i == 0 || getch() != '\'') - experr("illegal character constant"); - for (value = 0; --i >= 0;) { - value <<= 8; - value += v[i]; - } - return value; -} - -/* - * num : digit | num digit - */ -static int -num() -{ - int rval, c, base; - int ndig; - - rval = 0; - ndig = 0; - c = skipws(); - if (c == '0') { - c = skipws(); - if (c == 'x' || c == 'X') { - base = HEX; - c = skipws(); - } else { - base = OCTAL; - ndig++; - } - } else - base = DECIMAL; - for(;;) { - switch(c) { - case '8': case '9': - if (base == OCTAL) - goto bad_digit; - /*FALLTHRU*/ - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - rval *= base; - rval += c - '0'; - break; - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - c = tolower(c); - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - if (base == HEX) { - rval *= base; - rval += c - 'a' + 10; - break; - } - /*FALLTHRU*/ - default: - goto bad_digit; - } - c = getch(); - ndig++; - } -bad_digit: - ungetch(); - - if (ndig == 0) - experr("bad constant"); - - return rval; -} - -/* - * eqrel : '=' | '==' | '!=' | '<' | '>' | '<=' | '>=' - */ -static int -geteqrel() -{ - int c1, c2; - - c1 = skipws(); - c2 = getch(); - - switch (c1) { - - case '=': - if (c2 != '=') - ungetch(); - return EQL; - - case '!': - if (c2 == '=') - return NEQ; - ungetch(); - ungetch(); - return -1; - - case '<': - if (c2 == '=') - return LEQ; - ungetch(); - return LSS; - - case '>': - if (c2 == '=') - return GEQ; - ungetch(); - return GTR; - - default: - ungetch(); - ungetch(); - return -1; - } -} - -/* - * Skip over any white space and return terminating char. - */ -static int -skipws() -{ - int c; - - while ((c = getch()) <= ' ' && c > EOS) - ; - return c; -} - -/* - * resets environment to eval(), prints an error - * and forces eval to return FALSE. - */ -static void -experr(const char *msg) -{ - printf("m4: %s in expr %s.\n", msg, where); - longjmp(expjump, -1); -} diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h deleted file mode 100644 index 9170fa89c046..000000000000 --- a/usr.bin/m4/extern.h +++ /dev/null @@ -1,152 +0,0 @@ -/* $OpenBSD: extern.h,v 1.29 2002/02/16 21:27:48 millert Exp $ */ -/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */ - -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)extern.h 8.1 (Berkeley) 6/6/93 - */ - -/* eval.c */ -extern void eval(const char *[], int, int); -extern void dodefine(const char *, const char *); -extern unsigned long expansion_id; - -/* expr.c */ -extern int expr(const char *); - -/* gnum4.c */ -extern void addtoincludepath(const char *); -extern struct input_file *fopen_trypath(struct input_file *, const char *); -extern void doindir(const char *[], int); -extern void dobuiltin(const char *[], int); -extern void dopatsubst(const char *[], int); -extern void doregexp(const char *[], int); - -extern void doprintlineno(struct input_file *); -extern void doprintfilename(struct input_file *); - -extern void doesyscmd(const char *); - - -/* look.c */ -extern ndptr addent(const char *); -extern unsigned hash(const char *); -extern ndptr lookup(const char *); -extern void remhash(const char *, int); - -/* main.c */ -extern void outputstr(const char *); -extern int builtin_type(const char *); -extern char *builtin_realname(int); - -/* misc.c */ -extern void chrsave(int); -extern char *compute_prevep(void); -extern void getdiv(int); -extern ptrdiff_t indx(const char *, const char *); -extern void initspaces(void); -extern void killdiv(void); -extern void onintr(int); -extern void pbnum(int); -extern void pbunsigned(unsigned long); -extern void pbstr(const char *); -extern void putback(int); -extern void *xalloc(size_t); -extern char *xstrdup(const char *); -extern void usage(void); -extern void resizedivs(int); -extern size_t buffer_mark(void); -extern void dump_buffer(FILE *, size_t); - -extern int obtain_char(struct input_file *); -extern void set_input(struct input_file *, FILE *, const char *); -extern void release_input(struct input_file *); - -/* speeded-up versions of chrsave/putback */ -#define PUTBACK(c) \ - do { \ - if (bp >= endpbb) \ - enlarge_bufspace(); \ - *bp++ = (c); \ - } while(0) - -#define CHRSAVE(c) \ - do { \ - if (ep >= endest) \ - enlarge_strspace(); \ - *ep++ = (c); \ - } while(0) - -/* and corresponding exposure for local symbols */ -extern void enlarge_bufspace(void); -extern void enlarge_strspace(void); -extern char *endpbb; -extern char *endest; - -/* trace.c */ -extern void mark_traced(const char *, int); -extern int is_traced(const char *); -extern void trace_file(const char *); -extern ssize_t trace(const char **, int, struct input_file *); -extern void finish_trace(size_t); -extern int traced_macros; -extern void set_trace_flags(const char *); -extern FILE *traceout; - -extern ndptr hashtab[]; /* hash table for macros etc. */ -extern stae *mstack; /* stack of m4 machine */ -extern char *sstack; /* shadow stack, for string space extension */ -extern FILE *active; /* active output file pointer */ -extern struct input_file infile[];/* input file stack (0=stdin) */ -extern FILE **outfile; /* diversion array(0=bitbucket) */ -extern int maxout; /* maximum number of diversions */ -extern int fp; /* m4 call frame pointer */ -extern int ilevel; /* input file stack pointer */ -extern int oindex; /* diversion index. */ -extern int sp; /* current m4 stack pointer */ -extern char *bp; /* first available character */ -extern char *buf; /* push-back buffer */ -extern char *bufbase; /* buffer base for this ilevel */ -extern char *bbase[]; /* buffer base per ilevel */ -extern char ecommt[MAXCCHARS+1];/* end character for comment */ -extern char *ep; /* first free char in strspace */ -extern char lquote[MAXCCHARS+1];/* left quote character (`) */ -extern char *m4wraps; /* m4wrap string default. */ -extern char *null; /* as it says.. just a null. */ -extern char rquote[MAXCCHARS+1];/* right quote character (') */ -extern char scommt[MAXCCHARS+1];/* start character for comment */ - -extern int mimic_gnu; /* behaves like gnu-m4 */ diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c deleted file mode 100644 index 0383ef4c745b..000000000000 --- a/usr.bin/m4/gnum4.c +++ /dev/null @@ -1,523 +0,0 @@ -/* $OpenBSD: gnum4.c,v 1.18 2002/04/26 16:15:16 espie Exp $ */ - -/* - * Copyright (c) 1999 Marc Espie - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * functions needed to support gnu-m4 extensions, including a fake freezing - */ - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <ctype.h> -#include <paths.h> -#include <regex.h> -#include <stddef.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <err.h> -#include <errno.h> -#include <unistd.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" - - -int mimic_gnu = 0; - -/* - * Support for include path search - * First search in the the current directory. - * If not found, and the path is not absolute, include path kicks in. - * First, -I options, in the order found on the command line. - * Then M4PATH env variable - */ - -struct path_entry { - char *name; - struct path_entry *next; -} *first, *last; - -static struct path_entry *new_path_entry(const char *); -static void ensure_m4path(void); -static struct input_file *dopath(struct input_file *, const char *); - -static struct path_entry * -new_path_entry(const char *dirname) -{ - struct path_entry *n; - - n = malloc(sizeof(struct path_entry)); - if (!n) - errx(1, "out of memory"); - n->name = strdup(dirname); - if (!n->name) - errx(1, "out of memory"); - n->next = 0; - return n; -} - -void -addtoincludepath(const char *dirname) -{ - struct path_entry *n; - - n = new_path_entry(dirname); - - if (last) { - last->next = n; - last = n; - } - else - last = first = n; -} - -static void -ensure_m4path() -{ - static int envpathdone = 0; - char *envpath; - char *sweep; - char *path; - - if (envpathdone) - return; - envpathdone = TRUE; - envpath = getenv("M4PATH"); - if (!envpath) - return; - /* for portability: getenv result is read-only */ - envpath = strdup(envpath); - if (!envpath) - errx(1, "out of memory"); - for (sweep = envpath; - (path = strsep(&sweep, ":")) != NULL;) - addtoincludepath(path); - free(envpath); -} - -static -struct input_file * -dopath(struct input_file *i, const char *filename) -{ - char path[MAXPATHLEN]; - struct path_entry *pe; - FILE *f; - - for (pe = first; pe; pe = pe->next) { - snprintf(path, sizeof(path), "%s/%s", pe->name, filename); - if ((f = fopen(path, "r")) != 0) { - set_input(i, f, path); - return i; - } - } - return NULL; -} - -struct input_file * -fopen_trypath(struct input_file *i, const char *filename) -{ - FILE *f; - - f = fopen(filename, "r"); - if (f != NULL) { - set_input(i, f, filename); - return i; - } - if (filename[0] == '/') - return NULL; - - ensure_m4path(); - - return dopath(i, filename); -} - -void -doindir(const char *argv[], int argc) -{ - ndptr p; - - p = lookup(argv[2]); - if (p == NULL) - errx(1, "undefined macro %s", argv[2]); - argv[1] = p->defn; - eval(argv+1, argc-1, p->type); -} - -void -dobuiltin(const char *argv[], int argc) -{ - int n; - argv[1] = NULL; - n = builtin_type(argv[2]); - if (n != -1) - eval(argv+1, argc-1, n); - else - errx(1, "unknown builtin %s", argv[2]); -} - - -/* We need some temporary buffer space, as pb pushes BACK and substitution - * proceeds forward... */ -static char *buffer; -static size_t bufsize = 0; -static size_t current = 0; - -static void addchars(const char *, size_t); -static void addchar(int); -static char *twiddle(const char *); -static char *getstring(void); -static void exit_regerror(int, regex_t *); -static void do_subst(const char *, regex_t *, const char *, regmatch_t *); -static void do_regexpindex(const char *, regex_t *, regmatch_t *); -static void do_regexp(const char *, regex_t *, const char *, regmatch_t *); -static void add_sub(int, const char *, regex_t *, regmatch_t *); -static void add_replace(const char *, regex_t *, const char *, regmatch_t *); -#define addconstantstring(s) addchars((s), sizeof(s)-1) - -static void -addchars(const char *c, size_t n) -{ - if (n == 0) - return; - while (current + n > bufsize) { - if (bufsize == 0) - bufsize = 1024; - else - bufsize *= 2; - buffer = realloc(buffer, bufsize); - if (buffer == NULL) - errx(1, "out of memory"); - } - memcpy(buffer+current, c, n); - current += n; -} - -static void -addchar(int c) -{ - if (current +1 > bufsize) { - if (bufsize == 0) - bufsize = 1024; - else - bufsize *= 2; - buffer = realloc(buffer, bufsize); - if (buffer == NULL) - errx(1, "out of memory"); - } - buffer[current++] = c; -} - -static char * -getstring() -{ - addchar('\0'); - current = 0; - return buffer; -} - - -static void -exit_regerror(int er, regex_t *re) -{ - size_t errlen; - char *errbuf; - - errlen = regerror(er, re, NULL, 0); - errbuf = xalloc(errlen); - regerror(er, re, errbuf, errlen); - errx(1, "regular expression error: %s", errbuf); -} - -static void -add_sub(int n, const char *string, regex_t *re, regmatch_t *pm) -{ - if (n > re->re_nsub) - warnx("No subexpression %d", n); - /* Subexpressions that did not match are - * not an error. */ - else if (pm[n].rm_so != -1 && - pm[n].rm_eo != -1) { - addchars(string + pm[n].rm_so, - pm[n].rm_eo - pm[n].rm_so); - } -} - -/* Add replacement string to the output buffer, recognizing special - * constructs and replacing them with substrings of the original string. - */ -static void -add_replace(const char *string, regex_t *re, const char *replace, regmatch_t *pm) -{ - const char *p; - - for (p = replace; *p != '\0'; p++) { - if (*p == '&' && !mimic_gnu) { - add_sub(0, string, re, pm); - continue; - } - if (*p == '\\') { - if (p[1] == '\\') { - addchar(p[1]); - p++; - continue; - } - if (p[1] == '&') { - if (mimic_gnu) - add_sub(0, string, re, pm); - else - addchar(p[1]); - p++; - continue; - } - if (isdigit(p[1])) { - add_sub(*(++p) - '0', string, re, pm); - continue; - } - } - addchar(*p); - } -} - -static void -do_subst(const char *string, regex_t *re, const char *replace, regmatch_t *pm) -{ - int error; - int flags = 0; - const char *last_match = NULL; - - while ((error = regexec(re, string, re->re_nsub+1, pm, flags)) == 0) { - if (pm[0].rm_eo != 0) { - if (string[pm[0].rm_eo-1] == '\n') - flags = 0; - else - flags = REG_NOTBOL; - } - - /* NULL length matches are special... We use the `vi-mode' - * rule: don't allow a NULL-match at the last match - * position. - */ - if (pm[0].rm_so == pm[0].rm_eo && - string + pm[0].rm_so == last_match) { - if (*string == '\0') - return; - addchar(*string); - if (*string++ == '\n') - flags = 0; - else - flags = REG_NOTBOL; - continue; - } - last_match = string + pm[0].rm_so; - addchars(string, pm[0].rm_so); - add_replace(string, re, replace, pm); - string += pm[0].rm_eo; - } - if (error != REG_NOMATCH) - exit_regerror(error, re); - pbstr(string); -} - -static void -do_regexp(const char *string, regex_t *re, const char *replace, regmatch_t *pm) -{ - int error; - - switch(error = regexec(re, string, re->re_nsub+1, pm, 0)) { - case 0: - add_replace(string, re, replace, pm); - pbstr(getstring()); - break; - case REG_NOMATCH: - break; - default: - exit_regerror(error, re); - } -} - -static void -do_regexpindex(const char *string, regex_t *re, regmatch_t *pm) -{ - int error; - - switch(error = regexec(re, string, re->re_nsub+1, pm, 0)) { - case 0: - pbunsigned(pm[0].rm_so); - break; - case REG_NOMATCH: - pbnum(-1); - break; - default: - exit_regerror(error, re); - } -} - -/* In Gnu m4 mode, parentheses for backmatch don't work like POSIX 1003.2 - * says. So we twiddle with the regexp before passing it to regcomp. - */ -static char * -twiddle(const char *p) -{ - /* This could use strcspn for speed... */ - while (*p != '\0') { - if (*p == '\\') { - switch(p[1]) { - case '(': - case ')': - case '|': - addchar(p[1]); - break; - case 'w': - addconstantstring("[_a-zA-Z0-9]"); - break; - case 'W': - addconstantstring("[^_a-zA-Z0-9]"); - break; - case '<': - addconstantstring("[[:<:]]"); - break; - case '>': - addconstantstring("[[:>:]]"); - break; - default: - addchars(p, 2); - break; - } - p+=2; - continue; - } - if (*p == '(' || *p == ')' || *p == '|') - addchar('\\'); - - addchar(*p); - p++; - } - return getstring(); -} - -/* patsubst(string, regexp, opt replacement) */ -/* argv[2]: string - * argv[3]: regexp - * argv[4]: opt rep - */ -void -dopatsubst(const char *argv[], int argc) -{ - int error; - regex_t re; - regmatch_t *pmatch; - - if (argc <= 3) { - warnx("Too few arguments to patsubst"); - return; - } - error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3], - REG_NEWLINE | REG_EXTENDED); - if (error != 0) - exit_regerror(error, &re); - - pmatch = xalloc(sizeof(regmatch_t) * (re.re_nsub+1)); - do_subst(argv[2], &re, - argc != 4 && argv[4] != NULL ? argv[4] : "", pmatch); - pbstr(getstring()); - free(pmatch); - regfree(&re); -} - -void -doregexp(const char *argv[], int argc) -{ - int error; - regex_t re; - regmatch_t *pmatch; - - if (argc <= 3) { - warnx("Too few arguments to regexp"); - return; - } - error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3], - REG_EXTENDED); - if (error != 0) - exit_regerror(error, &re); - - pmatch = xalloc(sizeof(regmatch_t) * (re.re_nsub+1)); - if (argv[4] == NULL || argc == 4) - do_regexpindex(argv[2], &re, pmatch); - else - do_regexp(argv[2], &re, argv[4], pmatch); - free(pmatch); - regfree(&re); -} - -void -doesyscmd(const char *cmd) -{ - int p[2]; - pid_t pid, cpid; - char *argv[4]; - int cc; - int status; - - /* Follow gnu m4 documentation: first flush buffers. */ - fflush(NULL); - - argv[0] = "sh"; - argv[1] = "-c"; - argv[2] = (char *)cmd; - argv[3] = NULL; - - /* Just set up standard output, share stderr and stdin with m4 */ - if (pipe(p) == -1) - err(1, "bad pipe"); - switch(cpid = fork()) { - case -1: - err(1, "bad fork"); - /* NOTREACHED */ - case 0: - (void) close(p[0]); - (void) dup2(p[1], 1); - (void) close(p[1]); - execv(_PATH_BSHELL, argv); - exit(1); - default: - /* Read result in two stages, since m4's buffer is - * pushback-only. */ - (void) close(p[1]); - do { - char result[BUFSIZE]; - cc = read(p[0], result, sizeof result); - if (cc > 0) - addchars(result, cc); - } while (cc > 0 || (cc == -1 && errno == EINTR)); - - (void) close(p[0]); - while ((pid = wait(&status)) != cpid && pid >= 0) - continue; - pbstr(getstring()); - } -} diff --git a/usr.bin/m4/look.c b/usr.bin/m4/look.c deleted file mode 100644 index ba76e805fda7..000000000000 --- a/usr.bin/m4/look.c +++ /dev/null @@ -1,145 +0,0 @@ -/* $OpenBSD: look.c,v 1.10 2002/04/26 16:15:16 espie Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char sccsid[] = "@(#)look.c 8.1 (Berkeley) 6/6/93"; -#endif /* not lint */ - -/* - * look.c - * Facility: m4 macro processor - * by: oz - */ - -#include <sys/types.h> -#include <stdio.h> -#include <stdlib.h> -#include <stddef.h> -#include <string.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" - -static void freent(ndptr); - -unsigned int -hash(const char *name) -{ - unsigned int h = 0; - while (*name) - h = (h << 5) + h + *name++; - return (h); -} - -/* - * find name in the hash table - */ -ndptr -lookup(const char *name) -{ - ndptr p; - unsigned int h; - - h = hash(name); - for (p = hashtab[h % HASHSIZE]; p != nil; p = p->nxtptr) - if (h == p->hv && STREQ(name, p->name)) - break; - return (p); -} - -/* - * hash and create an entry in the hash table. - * The new entry is added in front of a hash bucket. - */ -ndptr -addent(const char *name) -{ - unsigned int h; - ndptr p; - - h = hash(name); - p = (ndptr) xalloc(sizeof(struct ndblock)); - p->nxtptr = hashtab[h % HASHSIZE]; - hashtab[h % HASHSIZE] = p; - p->name = xstrdup(name); - p->hv = h; - return p; -} - -static void -freent(ndptr p) -{ - free((char *) p->name); - if (p->defn != null) - free((char *) p->defn); - free((char *) p); -} - -/* - * remove an entry from the hashtable - */ -void -remhash(const char *name, int all) -{ - unsigned int h; - ndptr xp, tp, mp; - - h = hash(name); - mp = hashtab[h % HASHSIZE]; - tp = nil; - while (mp != nil) { - if (mp->hv == h && STREQ(mp->name, name)) { - mp = mp->nxtptr; - if (tp == nil) { - freent(hashtab[h % HASHSIZE]); - hashtab[h % HASHSIZE] = mp; - } - else { - xp = tp->nxtptr; - tp->nxtptr = mp; - freent(xp); - } - if (!all) - break; - } - else { - tp = mp; - mp = mp->nxtptr; - } - } -} diff --git a/usr.bin/m4/m4.1 b/usr.bin/m4/m4.1 deleted file mode 100644 index ccd793d6e2a3..000000000000 --- a/usr.bin/m4/m4.1 +++ /dev/null @@ -1,381 +0,0 @@ -.\" @(#) $OpenBSD: m4.1,v 1.24 2002/04/18 18:57:23 espie Exp $ -.\" -.\" -.Dd January 26, 1993 -.Dt M4 1 -.Os -.Sh NAME -.Nm m4 -.Nd macro language processor -.Sh SYNOPSIS -.Nm m4 -.Op Fl d Ar flags -.Op Fl t Ar name -.Op Fl g -.Oo -.Fl D Ns Ar name Ns Op Ar =value -.Oc -.Op Fl U Ns Ar name -.Op Fl I Ar dirname -.Sh DESCRIPTION -The -.Nm m4 -utility is a macro processor that can be used as a front end to any -language (e.g., C, ratfor, fortran, lex, and yacc). -.Nm m4 -reads from the standard input and writes -the processed text to the standard output. -.Pp -Macro calls have the form name(argument1[, argument2, ..., argumentN]). -.Pp -There cannot be any space following the macro name and the open -parenthesis -.Pq Ql ( . -If the macro name is not followed by an open -parenthesis it is processed with no arguments. -.Pp -Macro names consist of a leading alphabetic or underscore -possibly followed by alphanumeric or underscore characters, e.g., -valid macro names match the pattern -.Dq [a-zA-Z_][a-zA-Z0-9_]* . -.Pp -In arguments to macros, leading unquoted space, tab, and newline -.Pq Ql \en -characters are ignored. -To quote strings, use left and right single -quotes (e.g., -.Sq \ this is a string with a leading space ) . -You can change the quote characters with the -.Ic changequote -built-in macro. -.Pp -Most built-ins don't make any sense without arguments, and hence are not -recognized as special when not followed by an open parenthesis. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl D Ns Ar name Ns Oo -.Ar =value -.Oc -Define the symbol -.Ar name -to have some value (or -.Dv NULL ) . -.It Fl "U" Ns Ar "name" -Undefine the symbol -.Ar name . -.It Fl I Ar "dirname" -Add directory -.Ar dirname -to the include path. -.It Fl d Ar "flags" -Set trace flags. -.Ar flags -may hold the following: -.Bl -tag -width Ds -.It Ar a -print macro arguments. -.It Ar c -print macro expansion over several lines. -.It Ar e -print result of macro expansion. -.It Ar f -print filename location. -.It Ar l -print line number. -.It Ar q -quote arguments and expansion with the current quotes. -.It Ar t -start with all macros traced. -.It Ar x -number macro expansions. -.It Ar V -turn on all options. -.El -.Pp -By default, trace is set to -.Qq eq . -.It Fl t Ar macro -Turn tracing on for -.Ar macro . -.It Fl g -Activate GNU-m4 compatibility mode. -In this mode, changequote with -two empty parameters deactivates quotes, translit handles simple character -ranges (e.g., a-z), regular expressions mimic emacs behavior, -and the number of diversions is unlimited. -.El -.Sh SYNTAX -.Nm m4 -provides the following built-in macros. -They may be redefined, losing their original meaning. -Return values are null unless otherwise stated. -.Bl -tag -width changequotexxx -.It Ic builtin -Calls a built-in by its name, overriding possible redefinitions. -.It Ic changecom -Change the start and end comment sequences. -The default is the pound sign -.Pq Ql # -and the newline character. -With no arguments comments are turned off. -The maximum length for a comment marker is five characters. -.It Ic changequote -Defines the quote symbols to be the first and second arguments. -The symbols may be up to five characters long. -If no arguments are -given it restores the default open and close single quotes. -.It Ic decr -Decrements the argument by 1. -The argument must be a valid numeric string. -.It Ic define -Define a new macro named by the first argument to have the -value of the second argument. -Each occurrence of -.Ql $n -(where -.Ar n -is 0 through 9) is replaced by the -.Ar n Ns 'th -argument. -.Ql $0 -is the name of the calling macro. -Undefined arguments are replaced by a null string. -.Ql $# -is replaced by the number of arguments; -.Ql $* -is replaced by all arguments comma separated; -.Ql $@ -is the same as -.Ql $* -but all arguments are quoted against further expansion. -.It Ic defn -Returns the quoted definition for each argument. -This can be used to rename -macro definitions (even for built-in macros). -.It Ic divert -There are 10 output queues (numbered 0-9). -At the end of processing -.Nm m4 -concatenates all the queues in numerical order to produce the -final output. -Initially the output queue is 0. -The divert -macro allows you to select a new output queue (an invalid argument -passed to divert causes output to be discarded). -.It Ic divnum -Returns the current output queue number. -.It Ic dnl -Discard input characters up to and including the next newline. -.It Ic dumpdef -Prints the names and definitions for the named items, or for everything -if no arguments are passed. -.It Ic errprint -Prints the first argument on the standard error output stream. -.It Ic esyscmd -Pass its first argument to a shell and returns the shell's standard output. -Note that the shell shares its standard input and standard error with -.Nm -.It Ic eval -Computes the first argument as an arithmetic expression using 32-bit -arithmetic. -Operators are the standard C ternary, arithmetic, logical, -shift, relational, bitwise, and parentheses operators. -You can specify -octal, decimal, and hexadecimal numbers as in C. -The second argument (if any) -specifies the radix for the result and the third argument (if any) -specifies the minimum number of digits in the result. -.It Ic expr -This is an alias for -.Ic eval . -.It Ic ifdef -If the macro named by the first argument is defined then return the second -argument, otherwise the third. -If there is no third argument, the value is -.Dv NULL . -The word -.Qq unix -is predefined. -.It Ic ifelse -If the first argument matches the second argument then -.Ic ifelse -returns -the third argument. -If the match fails the three arguments are -discarded and the next three arguments are used until there is -zero or one arguments left, either this last argument or -.Dv NULL -is returned if no other matches were found. -.It Ic include -Returns the contents of the file specified in the first argument. -If the file is not found as is, look through the include path: -first the directories specified with -.Fl I -on the command line, then the environment variable -.Ev M4PATH , -as a colon-separated list of directories. -Include aborts with an error message if the file cannot be included. -.It Ic incr -Increments the argument by 1. -The argument must be a valid numeric string. -.It Ic index -Returns the index of the second argument in the first argument (e.g., -.Ic index(the quick brown fox jumped, fox) -returns 16). -If the second -argument is not found index returns \-1. -.It Ic indir -Indirectly calls the macro whose name is passed as the first arguments, -with the remaining arguments passed as first, ... arguments. -.It Ic len -Returns the number of characters in the first argument. -Extra arguments -are ignored. -.It Ic m4exit -Immediately exits with the return value specified by the first argument, -0 if none. -.It Ic m4wrap -Allows you to define what happens at the final -.Dv EOF , -usually for cleanup purposes (e.g., -.Ic m4wrap("cleanup(tempfile)") -causes the macro cleanup to be -invoked after all other processing is done). -.It Ic maketemp -Translates the string -.Dq XXXXX -in the first argument with the current process -ID leaving other characters alone. -This can be used to create unique -temporary file names. -.It Ic paste -Includes the contents of the file specified by the first argument without -any macro processing. -Aborts with an error message if the file cannot be -included. -.It Ic patsubst -Substitutes a regular expression in a string with a replacement string. -Usual substitution patterns apply: an ampersand -.Pq Ql & -is replaced by the string matching the regular expression. -The string -.Ql \e# , -where -.Ql # -is a digit, is replaced by the corresponding back-reference. -.It Ic popdef -Restores the -.Ic pushdef Ns ed -definition for each argument. -.It Ic pushdef -Takes the same arguments as -.Ic define , -but it saves the definition on a -stack for later retrieval by -.Ic popdef . -.It Ic regexp -Finds a regular expression in a string. -If no further arguments are given, -it returns the first match position or \-1 if no match. -If a third argument -is provided, it returns the replacement string, with sub-patterns replaced. -.It Ic shift -Returns all but the first argument, the remaining arguments are -quoted and pushed back with commas in between. -The quoting -nullifies the effect of the extra scan that will subsequently be -performed. -.It Ic sinclude -Similar to -.Ic include , -except it ignores any errors. -.It Ic spaste -Similar to -.Ic paste , -except it ignores any errors. -.It Ic substr -Returns a substring of the first argument starting at the offset specified -by the second argument and the length specified by the third argument. -If no third argument is present it returns the rest of the string. -.It Ic syscmd -Passes the first argument to the shell. -Nothing is returned. -.It Ic sysval -Returns the return value from the last -.Ic syscmd . -.It Ic traceon -Enables tracing of macro expansions for the given arguments, or for all -macros if no argument is given. -.It Ic traceoff -Disables tracing of macro expansions for the given arguments, or for all -macros if no argument is given. -.It Ic translit -Transliterate the characters in the first argument from the set -given by the second argument to the set given by the third. -You cannot use -.Xr tr 1 -style abbreviations. -.It Ic undefine -Removes the definition for the macros specified by its arguments. -.It Ic undivert -Flushes the named output queues (or all queues if no arguments). -.It Ic unix -A pre-defined macro for testing the OS platform. -.It Ic __line__ -Returns the current file's line number. -.It Ic __file__ -Returns the current file's name. -.El -.Sh COMPATIBILITY -.Nm -follows the Single Unix 2 specification, along with a few extensions taken -from -.Nm gnu-m4 . -.Pp -The -.Fl s -option -.Po -.Xr cpp 1 's -#line directives -.Pc -is currently not supported. -Flags -.Fl I , -.Fl d , -.Fl t -are non-standard. -.Pp -The output format of tracing and of -.Ic dumpdef -are not specified in any standard, -are likely to change and should not be relied upon. -The current format of tracing is closely modelled on -.Nm gnu-m4 , -to allow -.Nm autoconf -to work. -.Pp -For portability, one should not use the macros -.Ic builtin , -.Ic esycmd , -.Ic expr , -.Ic indir , -.Ic paste , -.Ic patsubst , -.Ic regexp , -.Ic spaste , -.Ic unix , -.Ic __line__ , -.Ic __file__ . -.Pp -All builtins do expand without arguments in many other -.Nm m4 . -.Pp -Many other -.Nm -have dire size limitations with respect to buffer sizes. -.Sh AUTHORS -Ozan Yigit <oz@sis.yorku.ca> and Richard A. O'Keefe (ok@goanna.cs.rmit.OZ.AU). -GNU-m4 compatibility extensions by Marc Espie <espie@cvs.openbsd.org>. diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c deleted file mode 100644 index 9e29700fcb75..000000000000 --- a/usr.bin/m4/main.c +++ /dev/null @@ -1,623 +0,0 @@ -/* $OpenBSD: main.c,v 1.53 2002/04/26 16:15:16 espie Exp $ */ -/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ - -/*- - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1989, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; -#else -static char rcsid[] = "$OpenBSD: main.c,v 1.53 2002/04/26 16:15:16 espie Exp $"; -#endif -#endif /* not lint */ - -/* - * main.c - * Facility: m4 macro processor - * by: oz - */ - -#include <sys/types.h> -#include <assert.h> -#include <signal.h> -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include <stddef.h> -#include <stdlib.h> -#include <err.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" -#include "pathnames.h" - -ndptr hashtab[HASHSIZE]; /* hash table for macros etc. */ -stae *mstack; /* stack of m4 machine */ -char *sstack; /* shadow stack, for string space extension */ -static size_t STACKMAX; /* current maximum size of stack */ -int sp; /* current m4 stack pointer */ -int fp; /* m4 call frame pointer */ -struct input_file infile[MAXINP];/* input file stack (0=stdin) */ -FILE **outfile; /* diversion array(0=bitbucket)*/ -int maxout; -FILE *active; /* active output file pointer */ -int ilevel = 0; /* input file stack pointer */ -int oindex = 0; /* diversion index.. */ -char *null = ""; /* as it says.. just a null.. */ -char *m4wraps = ""; /* m4wrap string default.. */ -char lquote[MAXCCHARS+1] = {LQUOTE}; /* left quote character (`) */ -char rquote[MAXCCHARS+1] = {RQUOTE}; /* right quote character (') */ -char scommt[MAXCCHARS+1] = {SCOMMT}; /* start character for comment */ -char ecommt[MAXCCHARS+1] = {ECOMMT}; /* end character for comment */ - -struct keyblk keywrds[] = { /* m4 keywords to be installed */ - { "include", INCLTYPE }, - { "sinclude", SINCTYPE }, - { "define", DEFITYPE }, - { "defn", DEFNTYPE }, - { "divert", DIVRTYPE | NOARGS }, - { "expr", EXPRTYPE }, - { "eval", EXPRTYPE }, - { "substr", SUBSTYPE }, - { "ifelse", IFELTYPE }, - { "ifdef", IFDFTYPE }, - { "len", LENGTYPE }, - { "incr", INCRTYPE }, - { "decr", DECRTYPE }, - { "dnl", DNLNTYPE | NOARGS }, - { "changequote", CHNQTYPE | NOARGS }, - { "changecom", CHNCTYPE | NOARGS }, - { "index", INDXTYPE }, -#ifdef EXTENDED - { "paste", PASTTYPE }, - { "spaste", SPASTYPE }, - /* Newer extensions, needed to handle gnu-m4 scripts */ - { "indir", INDIRTYPE}, - { "builtin", BUILTINTYPE}, - { "patsubst", PATSTYPE}, - { "regexp", REGEXPTYPE}, - { "esyscmd", ESYSCMDTYPE}, - { "__file__", FILENAMETYPE | NOARGS}, - { "__line__", LINETYPE | NOARGS}, -#endif - { "popdef", POPDTYPE }, - { "pushdef", PUSDTYPE }, - { "dumpdef", DUMPTYPE | NOARGS }, - { "shift", SHIFTYPE | NOARGS }, - { "translit", TRNLTYPE }, - { "undefine", UNDFTYPE }, - { "undivert", UNDVTYPE | NOARGS }, - { "divnum", DIVNTYPE | NOARGS }, - { "maketemp", MKTMTYPE }, - { "errprint", ERRPTYPE | NOARGS }, - { "m4wrap", M4WRTYPE | NOARGS }, - { "m4exit", EXITTYPE | NOARGS }, - { "syscmd", SYSCTYPE }, - { "sysval", SYSVTYPE | NOARGS }, - { "traceon", TRACEONTYPE | NOARGS }, - { "traceoff", TRACEOFFTYPE | NOARGS }, - -#if defined(unix) || defined(__unix__) - { "unix", SELFTYPE | NOARGS }, -#else -#ifdef vms - { "vms", SELFTYPE | NOARGS }, -#endif -#endif -}; - -#define MAXKEYS (sizeof(keywrds)/sizeof(struct keyblk)) - -extern int optind; -extern char *optarg; - -#define MAXRECORD 50 -static struct position { - char *name; - unsigned long line; -} quotes[MAXRECORD], paren[MAXRECORD]; - -static void record(struct position *, int); -static void dump_stack(struct position *, int); - -static void macro(void); -static void initkwds(void); -static ndptr inspect(int, char *); -static int do_look_ahead(int, const char *); - -static void enlarge_stack(void); - -int main(int, char *[]); - -int -main(int argc, char *argv[]) -{ - int c; - int n; - char *p; - - if (signal(SIGINT, SIG_IGN) != SIG_IGN) - signal(SIGINT, onintr); - - initkwds(); - initspaces(); - STACKMAX = INITSTACKMAX; - - mstack = (stae *)xalloc(sizeof(stae) * STACKMAX); - sstack = (char *)xalloc(STACKMAX); - - maxout = 0; - outfile = NULL; - resizedivs(MAXOUT); - - while ((c = getopt(argc, argv, "gt:d:D:U:o:I:")) != -1) - switch(c) { - - case 'D': /* define something..*/ - for (p = optarg; *p; p++) - if (*p == '=') - break; - if (*p) - *p++ = EOS; - dodefine(optarg, p); - break; - case 'I': - addtoincludepath(optarg); - break; - case 'U': /* undefine... */ - remhash(optarg, TOP); - break; - case 'g': - mimic_gnu = 1; - break; - case 'd': - set_trace_flags(optarg); - break; - case 't': - mark_traced(optarg, 1); - break; - case 'o': - trace_file(optarg); - break; - case '?': - usage(); - } - - argc -= optind; - argv += optind; - - active = stdout; /* default active output */ - bbase[0] = bufbase; - if (!argc) { - sp = -1; /* stack pointer initialized */ - fp = 0; /* frame pointer initialized */ - set_input(infile+0, stdin, "stdin"); - /* default input (naturally) */ - macro(); - } else - for (; argc--; ++argv) { - p = *argv; - if (p[0] == '-' && p[1] == EOS) - set_input(infile, stdin, "stdin"); - else if (fopen_trypath(infile, p) == NULL) - err(1, "%s", p); - sp = -1; - fp = 0; - macro(); - release_input(infile); - } - - if (*m4wraps) { /* anything for rundown ?? */ - ilevel = 0; /* in case m4wrap includes.. */ - bufbase = bp = buf; /* use the entire buffer */ - pbstr(m4wraps); /* user-defined wrapup act */ - macro(); /* last will and testament */ - } - - if (active != stdout) - active = stdout; /* reset output just in case */ - for (n = 1; n < maxout; n++) /* default wrap-up: undivert */ - if (outfile[n] != NULL) - getdiv(n); - /* remove bitbucket if used */ - if (outfile[0] != NULL) { - (void) fclose(outfile[0]); - } - - return 0; -} - -/* - * Look ahead for `token'. - * (on input `t == token[0]') - * Used for comment and quoting delimiters. - * Returns 1 if `token' present; copied to output. - * 0 if `token' not found; all characters pushed back - */ -static int -do_look_ahead(int t, const char *token) -{ - int i; - - assert((unsigned char)t == (unsigned char)token[0]); - - for (i = 1; *++token; i++) { - t = gpbc(); - if (t == EOF || (unsigned char)t != (unsigned char)*token) { - putback(t); - while (--i) - putback(*--token); - return 0; - } - } - return 1; -} - -#define LOOK_AHEAD(t, token) (t != EOF && \ - (unsigned char)(t)==(unsigned char)(token)[0] && \ - do_look_ahead(t,token)) - -/* - * macro - the work horse.. - */ -static void -macro() -{ - char token[MAXTOK+1]; - int t, l; - ndptr p; - int nlpar; - - cycle { - t = gpbc(); - if (t == '_' || isalpha(t)) { - p = inspect(t, token); - if (p != nil) - putback(l = gpbc()); - if (p == nil || (l != LPAREN && - (p->type & NEEDARGS) != 0)) - outputstr(token); - else { - /* - * real thing.. First build a call frame: - */ - pushf(fp); /* previous call frm */ - pushf(p->type); /* type of the call */ - pushf(0); /* parenthesis level */ - fp = sp; /* new frame pointer */ - /* - * now push the string arguments: - */ - pushs1(p->defn); /* defn string */ - pushs1(p->name); /* macro name */ - pushs(ep); /* start next..*/ - - if (l != LPAREN && PARLEV == 0) { - /* no bracks */ - chrsave(EOS); - - if (sp == STACKMAX) - errx(1, "internal stack overflow"); - eval((const char **) mstack+fp+1, 2, - CALTYP); - - ep = PREVEP; /* flush strspace */ - sp = PREVSP; /* previous sp.. */ - fp = PREVFP; /* rewind stack...*/ - } - } - } else if (t == EOF) { - if (sp > -1) { - warnx( "unexpected end of input, unclosed parenthesis:"); - dump_stack(paren, PARLEV); - exit(1); - } - if (ilevel <= 0) - break; /* all done thanks.. */ - release_input(infile+ilevel--); - bufbase = bbase[ilevel]; - continue; - } - /* - * non-alpha token possibly seen.. - * [the order of else if .. stmts is important.] - */ - else if (LOOK_AHEAD(t,lquote)) { /* strip quotes */ - nlpar = 0; - record(quotes, nlpar++); - /* - * Opening quote: scan forward until matching - * closing quote has been found. - */ - do { - - l = gpbc(); - if (LOOK_AHEAD(l,rquote)) { - if (--nlpar > 0) - outputstr(rquote); - } else if (LOOK_AHEAD(l,lquote)) { - record(quotes, nlpar++); - outputstr(lquote); - } else if (l == EOF) { - if (nlpar == 1) - warnx("unclosed quote:"); - else - warnx("%d unclosed quotes:", nlpar); - dump_stack(quotes, nlpar); - exit(1); - } else { - if (nlpar > 0) { - if (sp < 0) - putc(l, active); - else - CHRSAVE(l); - } - } - } - while (nlpar != 0); - } - - else if (sp < 0 && LOOK_AHEAD(t, scommt)) { - fputs(scommt, active); - - for(;;) { - t = gpbc(); - if (LOOK_AHEAD(t, ecommt)) { - fputs(ecommt, active); - break; - } - if (t == EOF) - break; - putc(t, active); - } - } - - else if (sp < 0) { /* not in a macro at all */ - putc(t, active); /* output directly.. */ - } - - else switch(t) { - - case LPAREN: - if (PARLEV > 0) - chrsave(t); - while (isspace(l = gpbc())) - ; /* skip blank, tab, nl.. */ - putback(l); - record(paren, PARLEV++); - break; - - case RPAREN: - if (--PARLEV > 0) - chrsave(t); - else { /* end of argument list */ - chrsave(EOS); - - if (sp == STACKMAX) - errx(1, "internal stack overflow"); - - eval((const char **) mstack+fp+1, sp-fp, - CALTYP); - - ep = PREVEP; /* flush strspace */ - sp = PREVSP; /* previous sp.. */ - fp = PREVFP; /* rewind stack...*/ - } - break; - - case COMMA: - if (PARLEV == 1) { - chrsave(EOS); /* new argument */ - while (isspace(l = gpbc())) - ; - putback(l); - pushs(ep); - } else - chrsave(t); - break; - - default: - if (LOOK_AHEAD(t, scommt)) { - char *p; - for (p = scommt; *p; p++) - chrsave(*p); - for(;;) { - t = gpbc(); - if (LOOK_AHEAD(t, ecommt)) { - for (p = ecommt; *p; p++) - chrsave(*p); - break; - } - if (t == EOF) - break; - CHRSAVE(t); - } - } else - CHRSAVE(t); /* stack the char */ - break; - } - } -} - -/* - * output string directly, without pushing it for reparses. - */ -void -outputstr(const char *s) -{ - if (sp < 0) - while (*s) - putc(*s++, active); - else - while (*s) - CHRSAVE(*s++); -} - -/* - * build an input token.. - * consider only those starting with _ or A-Za-z. This is a - * combo with lookup to speed things up. - */ -static ndptr -inspect(int c, char *tp) -{ - char *name = tp; - char *etp = tp+MAXTOK; - ndptr p; - unsigned int h; - - h = *tp++ = c; - - while ((isalnum(c = gpbc()) || c == '_') && tp < etp) - h = (h << 5) + h + (*tp++ = c); - if (c != EOF) - PUTBACK(c); - *tp = EOS; - /* token is too long, it won't match anything, but it can still - * be output. */ - if (tp == ep) { - outputstr(name); - while (isalnum(c = gpbc()) || c == '_') { - if (sp < 0) - putc(c, active); - else - CHRSAVE(c); - } - *name = EOS; - return nil; - } - - for (p = hashtab[h % HASHSIZE]; p != nil; p = p->nxtptr) - if (h == p->hv && STREQ(name, p->name)) - break; - return p; -} - -/* - * initkwds - initialise m4 keywords as fast as possible. - * This very similar to install, but without certain overheads, - * such as calling lookup. Malloc is not used for storing the - * keyword strings, since we simply use the static pointers - * within keywrds block. - */ -static void -initkwds() -{ - size_t i; - unsigned int h; - ndptr p; - - for (i = 0; i < MAXKEYS; i++) { - h = hash(keywrds[i].knam); - p = (ndptr) xalloc(sizeof(struct ndblock)); - p->nxtptr = hashtab[h % HASHSIZE]; - hashtab[h % HASHSIZE] = p; - p->name = xstrdup(keywrds[i].knam); - p->defn = null; - p->hv = h; - p->type = keywrds[i].ktyp & TYPEMASK; - if ((keywrds[i].ktyp & NOARGS) == 0) - p->type |= NEEDARGS; - } -} - -/* Look up a builtin type, even if overridden by the user */ -int -builtin_type(const char *key) -{ - int i; - - for (i = 0; i != MAXKEYS; i++) - if (STREQ(keywrds[i].knam, key)) - return keywrds[i].ktyp; - return -1; -} - -char * -builtin_realname(int n) -{ - int i; - - for (i = 0; i != MAXKEYS; i++) - if (((keywrds[i].ktyp ^ n) & TYPEMASK) == 0) - return keywrds[i].knam; - return NULL; -} - -static void -record(struct position *t, int lev) -{ - if (lev < MAXRECORD) { - t[lev].name = CURRENT_NAME; - t[lev].line = CURRENT_LINE; - } -} - -static void -dump_stack(struct position *t, int lev) -{ - int i; - - for (i = 0; i < lev; i++) { - if (i == MAXRECORD) { - fprintf(stderr, " ...\n"); - break; - } - fprintf(stderr, " %s at line %lu\n", - t[i].name, t[i].line); - } -} - - -static void -enlarge_stack() -{ - STACKMAX *= 2; - mstack = realloc(mstack, sizeof(stae) * STACKMAX); - sstack = realloc(sstack, STACKMAX); - if (mstack == NULL || sstack == NULL) - errx(1, "Evaluation stack overflow (%lu)", - (unsigned long)STACKMAX); -} diff --git a/usr.bin/m4/mdef.h b/usr.bin/m4/mdef.h deleted file mode 100644 index 4a10500be28e..000000000000 --- a/usr.bin/m4/mdef.h +++ /dev/null @@ -1,224 +0,0 @@ -/* $OpenBSD: mdef.h,v 1.21 2001/09/27 11:40:33 espie Exp $ */ -/* $NetBSD: mdef.h,v 1.7 1996/01/13 23:25:27 pk Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mdef.h 8.1 (Berkeley) 6/6/93 - */ - -#define MACRTYPE 1 -#define DEFITYPE 2 -#define EXPRTYPE 3 -#define SUBSTYPE 4 -#define IFELTYPE 5 -#define LENGTYPE 6 -#define CHNQTYPE 7 -#define SYSCTYPE 8 -#define UNDFTYPE 9 -#define INCLTYPE 10 -#define SINCTYPE 11 -#define PASTTYPE 12 -#define SPASTYPE 13 -#define INCRTYPE 14 -#define IFDFTYPE 15 -#define PUSDTYPE 16 -#define POPDTYPE 17 -#define SHIFTYPE 18 -#define DECRTYPE 19 -#define DIVRTYPE 20 -#define UNDVTYPE 21 -#define DIVNTYPE 22 -#define MKTMTYPE 23 -#define ERRPTYPE 24 -#define M4WRTYPE 25 -#define TRNLTYPE 26 -#define DNLNTYPE 27 -#define DUMPTYPE 28 -#define CHNCTYPE 29 -#define INDXTYPE 30 -#define SYSVTYPE 31 -#define EXITTYPE 32 -#define DEFNTYPE 33 -#define SELFTYPE 34 -#define INDIRTYPE 35 -#define BUILTINTYPE 36 -#define PATSTYPE 37 -#define FILENAMETYPE 38 -#define LINETYPE 39 -#define REGEXPTYPE 40 -#define ESYSCMDTYPE 41 -#define TRACEONTYPE 42 -#define TRACEOFFTYPE 43 - - -#define TYPEMASK 63 /* Keep bits really corresponding to a type. */ -#define RECDEF 256 /* Pure recursive def, don't expand it */ -#define NOARGS 512 /* builtin needs no args */ -#define NEEDARGS 1024 /* mark builtin that need args with this */ - -/* - * m4 special characters - */ - -#define ARGFLAG '$' -#define LPAREN '(' -#define RPAREN ')' -#define LQUOTE '`' -#define RQUOTE '\'' -#define COMMA ',' -#define SCOMMT '#' -#define ECOMMT '\n' - -#ifdef msdos -#define system(str) (-1) -#endif - -/* - * other important constants - */ - -#define EOS '\0' -#define MAXINP 10 /* maximum include files */ -#define MAXOUT 10 /* maximum # of diversions */ -#define BUFSIZE 4096 /* starting size of pushback buffer */ -#define INITSTACKMAX 4096 /* starting size of call stack */ -#define STRSPMAX 4096 /* starting size of string space */ -#define MAXTOK 512 /* maximum chars in a tokn */ -#define HASHSIZE 199 /* maximum size of hashtab */ -#define MAXCCHARS 5 /* max size of comment/quote delim */ - -#define ALL 1 -#define TOP 0 - -#define TRUE 1 -#define FALSE 0 -#define cycle for(;;) - -/* - * m4 data structures - */ - -typedef struct ndblock *ndptr; - -struct ndblock { /* hastable structure */ - char *name; /* entry name.. */ - char *defn; /* definition.. */ - unsigned int type; /* type of the entry.. */ - unsigned int hv; /* hash function value.. */ - ndptr nxtptr; /* link to next entry.. */ -}; - -#define nil ((ndptr) 0) - -struct keyblk { - char *knam; /* keyword name */ - int ktyp; /* keyword type */ -}; - -typedef union { /* stack structure */ - int sfra; /* frame entry */ - char *sstr; /* string entry */ -} stae; - -struct input_file { - FILE *file; - char *name; - unsigned long lineno; - int c; -}; - -#define CURRENT_NAME (infile[ilevel].name) -#define CURRENT_LINE (infile[ilevel].lineno) -/* - * macros for readibility and/or speed - * - * gpbc() - get a possibly pushed-back character - * pushf() - push a call frame entry onto stack - * pushs() - push a string pointer onto stack - */ -#define gpbc() (bp > bufbase) ? *--bp : obtain_char(infile+ilevel) -#define pushf(x) \ - do { \ - if (++sp == STACKMAX) \ - enlarge_stack();\ - mstack[sp].sfra = (x); \ - sstack[sp] = 0; \ - } while (0) - -#define pushs(x) \ - do { \ - if (++sp == STACKMAX) \ - enlarge_stack();\ - mstack[sp].sstr = (x); \ - sstack[sp] = 1; \ - } while (0) - -#define pushs1(x) \ - do { \ - if (++sp == STACKMAX) \ - enlarge_stack();\ - mstack[sp].sstr = (x); \ - sstack[sp] = 0; \ - } while (0) - -/* - * . . - * | . | <-- sp | . | - * +-------+ +-----+ - * | arg 3 ----------------------->| str | - * +-------+ | . | - * | arg 2 ---PREVEP-----+ . - * +-------+ | - * . | | | - * +-------+ | +-----+ - * | plev | PARLEV +-------->| str | - * +-------+ | . | - * | type | CALTYP . - * +-------+ - * | prcf ---PREVFP--+ - * +-------+ | - * | . | PREVSP | - * . | - * +-------+ | - * | <----------+ - * +-------+ - * - */ -#define PARLEV (mstack[fp].sfra) -#define CALTYP (mstack[fp-1].sfra) -#define PREVEP (mstack[fp+3].sstr) -#define PREVSP (fp-3) -#define PREVFP (mstack[fp-2].sfra) diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c deleted file mode 100644 index 291c2192fde5..000000000000 --- a/usr.bin/m4/misc.c +++ /dev/null @@ -1,360 +0,0 @@ -/* $OpenBSD: misc.c,v 1.27 2002/04/26 16:15:16 espie Exp $ */ -/* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93"; -#else -static char rcsid[] = "$OpenBSD: misc.c,v 1.27 2002/04/26 16:15:16 espie Exp $"; -#endif -#endif /* not lint */ - -#include <sys/types.h> -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <stddef.h> -#include <string.h> -#include <err.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" -#include "pathnames.h" - - -char *ep; /* first free char in strspace */ -static char *strspace; /* string space for evaluation */ -char *endest; /* end of string space */ -static size_t strsize = STRSPMAX; -static size_t bufsize = BUFSIZE; - -char *buf; /* push-back buffer */ -char *bufbase; /* the base for current ilevel */ -char *bbase[MAXINP]; /* the base for each ilevel */ -char *bp; /* first available character */ -char *endpbb; /* end of push-back buffer */ - - -/* - * find the index of second str in the first str. - */ -ptrdiff_t -indx(const char *s1, const char *s2) -{ - char *t; - - t = strstr(s1, s2); - if (t == NULL) - return (-1); - else - return (t - s1); -} -/* - * putback - push character back onto input - */ -void -putback(int c) -{ - if (c == EOF) - return; - if (bp >= endpbb) - enlarge_bufspace(); - *bp++ = c; -} - -/* - * pbstr - push string back onto input - * putback is replicated to improve - * performance. - */ -void -pbstr(const char *s) -{ - size_t n; - - n = strlen(s); - while (endpbb - bp <= n) - enlarge_bufspace(); - while (n > 0) - *bp++ = s[--n]; -} - -/* - * pbnum - convert number to string, push back on input. - */ -void -pbnum(int n) -{ - int num; - - num = (n < 0) ? -n : n; - do { - putback(num % 10 + '0'); - } - while ((num /= 10) > 0); - - if (n < 0) - putback('-'); -} - -/* - * pbunsigned - convert unsigned long to string, push back on input. - */ -void -pbunsigned(unsigned long n) -{ - do { - putback(n % 10 + '0'); - } - while ((n /= 10) > 0); -} - -void -initspaces() -{ - int i; - - strspace = xalloc(strsize+1); - ep = strspace; - endest = strspace+strsize; - buf = (char *)xalloc(bufsize); - bufbase = buf; - bp = buf; - endpbb = buf + bufsize; - for (i = 0; i < MAXINP; i++) - bbase[i] = buf; -} - -void -enlarge_strspace() -{ - char *newstrspace; - int i; - - strsize *= 2; - newstrspace = malloc(strsize + 1); - if (!newstrspace) - errx(1, "string space overflow"); - memcpy(newstrspace, strspace, strsize/2); - for (i = 0; i <= sp; i++) - if (sstack[i]) - mstack[i].sstr = (mstack[i].sstr - strspace) - + newstrspace; - ep = (ep-strspace) + newstrspace; - free(strspace); - strspace = newstrspace; - endest = strspace + strsize; -} - -void -enlarge_bufspace() -{ - char *newbuf; - int i; - - bufsize *= 2; - newbuf = realloc(buf, bufsize); - if (!newbuf) - errx(1, "too many characters pushed back"); - for (i = 0; i < MAXINP; i++) - bbase[i] = (bbase[i]-buf)+newbuf; - bp = (bp-buf)+newbuf; - bufbase = (bufbase-buf)+newbuf; - buf = newbuf; - endpbb = buf+bufsize; -} - -/* - * chrsave - put single char on string space - */ -void -chrsave(int c) -{ - if (ep >= endest) - enlarge_strspace(); - *ep++ = c; -} - -/* - * read in a diversion file, and dispose it. - */ -void -getdiv(int n) -{ - int c; - - if (active == outfile[n]) - errx(1, "undivert: diversion still active"); - rewind(outfile[n]); - while ((c = getc(outfile[n])) != EOF) - putc(c, active); - (void) fclose(outfile[n]); - outfile[n] = NULL; -} - -void -onintr(int signo) -{ -#define intrmessage "m4: interrupted.\n" - write(STDERR_FILENO, intrmessage, sizeof(intrmessage)-1); - _exit(1); -} - -/* - * killdiv - get rid of the diversion files - */ -void -killdiv() -{ - int n; - - for (n = 0; n < maxout; n++) - if (outfile[n] != NULL) { - (void) fclose(outfile[n]); - } -} - -/* - * resizedivs: allocate more diversion files */ -void -resizedivs(int n) -{ - int i; - - outfile = (FILE **)realloc(outfile, sizeof(FILE *) * n); - if (outfile == NULL) - errx(1, "too many diverts %d", n); - for (i = maxout; i < n; i++) - outfile[i] = NULL; - maxout = n; -} - -void * -xalloc(size_t n) -{ - char *p = malloc(n); - - if (p == NULL) - err(1, "malloc"); - return p; -} - -char * -xstrdup(const char *s) -{ - char *p = strdup(s); - if (p == NULL) - err(1, "strdup"); - return p; -} - -void -usage() -{ - fprintf(stderr, "usage: m4 [-Dname[=val]] [-Uname] [-I dirname...]\n"); - exit(1); -} - -int -obtain_char(struct input_file *f) -{ - if (f->c == EOF) - return EOF; - else if (f->c == '\n') - f->lineno++; - - f->c = fgetc(f->file); - return f->c; -} - -void -set_input(struct input_file *f, FILE *real, const char *name) -{ - f->file = real; - f->lineno = 1; - f->c = 0; - f->name = xstrdup(name); -} - -void -release_input(struct input_file *f) -{ - if (f->file != stdin) - fclose(f->file); - f->c = EOF; - /* - * XXX can't free filename, as there might still be - * error information pointing to it. - */ -} - -void -doprintlineno(struct input_file *f) -{ - pbunsigned(f->lineno); -} - -void -doprintfilename(struct input_file *f) -{ - pbstr(rquote); - pbstr(f->name); - pbstr(lquote); -} - -/* - * buffer_mark/dump_buffer: allows one to save a mark in a buffer, - * and later dump everything that was added since then to a file. - */ -size_t -buffer_mark() -{ - return bp - buf; -} - - -void -dump_buffer(FILE *f, size_t m) -{ - char *s; - - for (s = bp; s-buf > m;) - fputc(*--s, f); -} diff --git a/usr.bin/m4/pathnames.h b/usr.bin/m4/pathnames.h deleted file mode 100644 index dc7f0d3dff54..000000000000 --- a/usr.bin/m4/pathnames.h +++ /dev/null @@ -1,60 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.4 1997/04/04 18:41:29 deraadt Exp $ */ -/* $NetBSD: pathnames.h,v 1.6 1995/09/29 00:27:55 cgd Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 - */ - -/* - * Definitions of diversion files. If the name of the file is changed, - * adjust UNIQUE to point to the wildcard (*) character in the filename. - */ - -#ifdef msdos -#define _PATH_DIVNAME "\\M4*XXXXXX" /* msdos diversion files */ -#define UNIQUE 3 /* unique char location */ -#endif - -#if defined(unix) || defined(__NetBSD__) || defined(__OpenBSD__) -#define _PATH_DIVNAME "/tmp/m4.0XXXXXXXXXX" /* unix diversion files */ -#define UNIQUE 8 /* unique char location */ -#endif - -#ifdef vms -#define _PATH_DIVNAME "sys$login:m4*XXXXXX" /* vms diversion files */ -#define UNIQUE 12 /* unique char location */ -#endif diff --git a/usr.bin/m4/stdd.h b/usr.bin/m4/stdd.h deleted file mode 100644 index 5c869b7f77d3..000000000000 --- a/usr.bin/m4/stdd.h +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: stdd.h,v 1.4 1999/11/09 18:16:18 deraadt Exp $ */ -/* $NetBSD: stdd.h,v 1.2 1995/09/28 05:37:50 tls Exp $ */ - -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)stdd.h 8.1 (Berkeley) 6/6/93 - */ - -/* - * standard defines - */ - -#define max(a,b) ((a) > (b)? (a): (b)) -#define min(a,b) ((a) < (b)? (a): (b)) - -#define iswhite(c) ((c) == ' ' || (c) == '\t') - -/* - * STREQ is an optimised strcmp(a,b)==0 - * STREQN is an optimised strncmp(a,b,n)==0; assumes n > 0 - */ -#define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0) -#define STREQN(a, b, n) ((a)[0] == (b)[0] && strncmp(a, b, n) == 0) - -#define YES 1 -#define NO 0 diff --git a/usr.bin/m4/trace.c b/usr.bin/m4/trace.c deleted file mode 100644 index 99c72aba2db2..000000000000 --- a/usr.bin/m4/trace.c +++ /dev/null @@ -1,260 +0,0 @@ -/* $OpenBSD: trace.c,v 1.6 2002/04/26 16:15:16 espie Exp $ */ -/* - * Copyright (c) 2001 Marc Espie. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE OPENBSD 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 OPENBSD - * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <stddef.h> -#include <stdio.h> -#include <err.h> -#include <stdlib.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" - -FILE *traceout = stderr; - -int traced_macros = 0; - -#define TRACE_ARGS 1 -#define TRACE_EXPANSION 2 -#define TRACE_QUOTE 4 -#define TRACE_FILENAME 8 -#define TRACE_LINENO 16 -#define TRACE_CONT 32 -#define TRACE_ID 64 -#define TRACE_NEWFILE 128 /* not implemented yet */ -#define TRACE_INPUT 256 /* not implemented yet */ -#define TRACE_ALL 512 - -static struct t { - struct t *next; - char *name; - int on; -} *l; - -static unsigned int letter_to_flag(int); -static void print_header(struct input_file *); -static struct t *find_trace_entry(const char *); -static int frame_level(void); - -static unsigned int flags = TRACE_QUOTE | TRACE_EXPANSION; - -static struct t * -find_trace_entry(const char *name) -{ - struct t *n; - - for (n = l; n != NULL; n = n->next) - if (STREQ(n->name, name)) - return n; - return NULL; -} - - -void -mark_traced(const char *name, int on) -{ - struct t *n, *n2; - - traced_macros = 1; - - if (name == NULL) { - if (on) - flags |= TRACE_ALL; - else { - flags &= ~TRACE_ALL; - traced_macros = 0; - } - for (n = l; n != NULL; n = n2) { - n2 = n->next; - free(n->name); - free(n); - } - l = NULL; - } else { - n = find_trace_entry(name); - if (n == NULL) { - n = xalloc(sizeof(struct t)); - n->name = xstrdup(name); - n->next = l; - l = n; - } - n->on = on; - } -} - -int -is_traced(const char *name) -{ - struct t *n; - - for (n = l; n != NULL; n = n->next) - if (STREQ(n->name, name)) - return n->on; - return (flags & TRACE_ALL) ? 1 : 0; -} - -void -trace_file(const char *name) -{ - - if (traceout != stderr) - fclose(traceout); - traceout = fopen(name, "w"); - if (!traceout) - err(1, "can't open %s", name); -} - -static unsigned int -letter_to_flag(int c) -{ - switch(c) { - case 'a': - return TRACE_ARGS; - case 'e': - return TRACE_EXPANSION; - case 'q': - return TRACE_QUOTE; - case 'c': - return TRACE_CONT; - case 'x': - return TRACE_ID; - case 'f': - return TRACE_FILENAME; - case 'l': - return TRACE_LINENO; - case 'p': - return TRACE_NEWFILE; - case 'i': - return TRACE_INPUT; - case 't': - return TRACE_ALL; - case 'V': - return ~0; - default: - return 0; - } -} - -void -set_trace_flags(const char *s) -{ - char mode = 0; - unsigned int f = 0; - - traced_macros = 1; - - if (*s == '+' || *s == '-') - mode = *s++; - while (*s) - f |= letter_to_flag(*s++); - switch(mode) { - case 0: - flags = f; - break; - case '+': - flags |= f; - break; - case '-': - flags &= ~f; - break; - } -} - -static int -frame_level() -{ - int level; - int framep; - - for (framep = fp, level = 0; framep != 0; - level++,framep = mstack[framep-2].sfra) - ; - return level; -} - -static void -print_header(struct input_file *inp) -{ - fprintf(traceout, "m4trace:"); - if (flags & TRACE_FILENAME) - fprintf(traceout, "%s:", inp->name); - if (flags & TRACE_LINENO) - fprintf(traceout, "%lu:", inp->lineno); - fprintf(traceout, " -%d- ", frame_level()); - if (flags & TRACE_ID) - fprintf(traceout, "id %lu: ", expansion_id); -} - -ssize_t -trace(const char *argv[], int argc, struct input_file *inp) -{ - print_header(inp); - if (flags & TRACE_CONT) { - fprintf(traceout, "%s ...\n", argv[1]); - print_header(inp); - } - fprintf(traceout, "%s", argv[1]); - if ((flags & TRACE_ARGS) && argc > 2) { - char delim[3]; - int i; - - delim[0] = LPAREN; - delim[1] = EOS; - for (i = 2; i < argc; i++) { - fprintf(traceout, "%s%s%s%s", delim, - (flags & TRACE_QUOTE) ? lquote : "", - argv[i], - (flags & TRACE_QUOTE) ? rquote : ""); - delim[0] = COMMA; - delim[1] = ' '; - delim[2] = EOS; - } - fprintf(traceout, "%c", RPAREN); - } - if (flags & TRACE_CONT) { - fprintf(traceout, " -> ???\n"); - print_header(inp); - fprintf(traceout, argc > 2 ? "%s(...)" : "%s", argv[1]); - } - if (flags & TRACE_EXPANSION) - return buffer_mark(); - else { - fprintf(traceout, "\n"); - return -1; - } -} - -void -finish_trace(size_t mark) -{ - fprintf(traceout, " -> "); - if (flags & TRACE_QUOTE) - fprintf(traceout, "%s", lquote); - dump_buffer(traceout, mark); - if (flags & TRACE_QUOTE) - fprintf(traceout, "%s", rquote); - fprintf(traceout, "\n"); -} diff --git a/usr.bin/patch/Makefile b/usr.bin/patch/Makefile deleted file mode 100644 index 9c54a925f50d..000000000000 --- a/usr.bin/patch/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $OpenBSD: Makefile,v 1.3 2003/07/18 02:00:09 deraadt Exp $ - -PROG= patch -SRCS= patch.c pch.c inp.c util.c backupfile.c - -.include <bsd.prog.mk> diff --git a/usr.bin/patch/README b/usr.bin/patch/README deleted file mode 100644 index 72c10644d17a..000000000000 --- a/usr.bin/patch/README +++ /dev/null @@ -1,123 +0,0 @@ -this version modified to fit in with the 386bsd release. -this isn't gnu software, so we're not obligated to give -you the original sources -- if you want them, get them -from prep.ai.mit.edu:pub/gnu/patch-2.0.12u8.tar.z - - -- cgd - -####################################################################### - - -This version of patch contains modifications made by the Free Software -Foundation, summarized in the file ChangeLog. Primarily they are to -support the unified context diff format that GNU diff can produce, and -to support making GNU Emacs-style backup files. They also include -fixes for some bugs. - -There are two GNU variants of patch: this one, which retains Larry -Wall's interactive Configure script and has patchlevels starting with -`12u'; and another one that has a GNU-style non-interactive configure -script and accepts long-named options, and has patchlevels starting -with `12g'. Unlike the 12g variant, the 12u variant contains no -copylefted code, for the paranoid. The two variants are otherwise the -same. They should be available from the same places. - -The FSF is distributing this version of patch independently because as -of this writing, Larry Wall has not released a new version of patch -since mid-1988. I have heard that he has been too busy working on -other things, like Perl. - -Here is a wish list of some projects to improve patch: - -1. Correctly handle files and patchfiles that contain NUL characters. -This is hard to do straightforwardly; it would be less work to -adopt a kind of escape encoding internally. -Let ESC be a "control prefix". ESC @ stands for NUL. ESC [ stands for ESC. -You need to crunch this when reading input (replace fgets), -and when writing the output file (replace fputs), -but otherwise everything can go along as it does now. -Be careful to handle reject files correctly; -I think they are currently created using `write', not `fputs'. - -2. Correctly handle patches produced by GNU diff for files that do -not end with a newline. - -Please send bug reports for this version of patch to -bug-gnu-utils@prep.ai.mit.edu as well as to Larry Wall (lwall@netlabs.com). - --djm@gnu.ai.mit.edu (David MacKenzie) - - Patch Kit, Version 2.0 - - Copyright (c) 1988, Larry Wall - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following condition -is met: - 1. Redistributions of source code must retain the above copyright - notice, this condition and the following disclaimer. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. --------------------------------------------------------------------------- - -Please read all the directions below before you proceed any further, and -then follow them carefully. Failure to do so may void your warranty. :-) - -After you have unpacked your kit, you should have all the files listed -in MANIFEST. - -Installation - -1) Run Configure. This will figure out various things about your system. - Some things Configure will figure out for itself, other things it will - ask you about. It will then proceed to make config.h, config.sh, and - Makefile. - - You might possibly have to trim # comments from the front of Configure - if your sh doesn't handle them, but all other # comments will be taken - care of. - - If you don't have sh, you'll have to rip the prototype of config.h out - of Configure and generate the defines by hand. - -2) Glance through config.h to make sure system dependencies are correct. - Most of them should have been taken care of by running the - Configure script. - - If you have any additional changes to make to the C definitions, they - can be done in the Makefile, or in config.h. Bear in mind that they may - get undone next time you run Configure. - -3) make - - This will attempt to make patch in the current directory. - -4) make install - - This will put patch into a public directory (normally /usr/local/bin). - It will also try to put the man pages in a reasonable place. It will not - nroff the man page, however. - -5) Read the manual entry before running patch. - -6) IMPORTANT! Help save the world! Communicate any problems and - suggested patches to me, lwall@netlabs.com (Larry Wall), - so we can keep the world in sync. If you have a problem, there's - someone else out there who either has had or will have the same problem. - - If possible, send in patches such that the patch program will apply them. - Context diffs are the best, then normal diffs. Don't send ed scripts-- - I've probably changed my copy since the version you have. - - Watch for patch patches in comp.sources.bugs. Patches will generally be - in a form usable by the patch program. Your current patch level - is shown in patchlevel.h. diff --git a/usr.bin/patch/backupfile.c b/usr.bin/patch/backupfile.c deleted file mode 100644 index 5863e9b1b147..000000000000 --- a/usr.bin/patch/backupfile.c +++ /dev/null @@ -1,238 +0,0 @@ -/* $OpenBSD: backupfile.c,v 1.17 2003/08/01 20:30:48 otto Exp $ */ - -/* - * backupfile.c -- make Emacs style backup file names Copyright (C) 1990 Free - * Software Foundation, Inc. - * - * This program is free software; you can redistribute it and/or modify it - * without restriction. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - */ - -/* - * David MacKenzie <djm@ai.mit.edu>. Some algorithms adapted from GNU Emacs. - */ - -#ifndef lint -static const char rcsid[] = "$OpenBSD: backupfile.c,v 1.17 2003/08/01 20:30:48 otto Exp $"; -#endif /* not lint */ - -#include <ctype.h> -#include <dirent.h> -#include <libgen.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "backupfile.h" - - -#define ISDIGIT(c) (isascii (c) && isdigit (c)) - -/* Which type of backup file names are generated. */ -enum backup_type backup_type = none; - -/* - * The extension added to file names to produce a simple (as opposed to - * numbered) backup file name. - */ -char *simple_backup_suffix = "~"; - -static char *concat(const char *, const char *); -static char *make_version_name(const char *, int); -static int max_backup_version(const char *, const char *); -static int version_number(const char *, const char *, int); -static int argmatch(const char *, const char **); -static void invalid_arg(const char *, const char *, int); - -/* - * Return the name of the new backup file for file FILE, allocated with - * malloc. Return 0 if out of memory. FILE must not end with a '/' unless it - * is the root directory. Do not call this function if backup_type == none. - */ -char * -find_backup_file_name(const char *file) -{ - char *dir, *base_versions; - int highest_backup; - - if (backup_type == simple) - return concat(file, simple_backup_suffix); - base_versions = concat(basename(file), ".~"); - if (base_versions == NULL) - return NULL; - dir = dirname(file); - if (dir == NULL) { - free(base_versions); - return NULL; - } - highest_backup = max_backup_version(base_versions, dir); - free(base_versions); - if (backup_type == numbered_existing && highest_backup == 0) - return concat(file, simple_backup_suffix); - return make_version_name(file, highest_backup + 1); -} - -/* - * Return the number of the highest-numbered backup file for file FILE in - * directory DIR. If there are no numbered backups of FILE in DIR, or an - * error occurs reading DIR, return 0. FILE should already have ".~" appended - * to it. - */ -static int -max_backup_version(const char *file, const char *dir) -{ - DIR *dirp; - struct dirent *dp; - int highest_version, this_version, file_name_length; - - dirp = opendir(dir); - if (dirp == NULL) - return 0; - - highest_version = 0; - file_name_length = strlen(file); - - while ((dp = readdir(dirp)) != NULL) { - if (dp->d_namlen <= file_name_length) - continue; - - this_version = version_number(file, dp->d_name, file_name_length); - if (this_version > highest_version) - highest_version = this_version; - } - closedir(dirp); - return highest_version; -} - -/* - * Return a string, allocated with malloc, containing "FILE.~VERSION~". - * Return 0 if out of memory. - */ -static char * -make_version_name(const char *file, int version) -{ - char *backup_name; - - if (asprintf(&backup_name, "%s.~%d~", file, version) == -1) - return NULL; - return backup_name; -} - -/* - * If BACKUP is a numbered backup of BASE, return its version number; - * otherwise return 0. BASE_LENGTH is the length of BASE. BASE should - * already have ".~" appended to it. - */ -static int -version_number(const char *base, const char *backup, int base_length) -{ - int version; - const char *p; - - version = 0; - if (!strncmp(base, backup, base_length) && ISDIGIT(backup[base_length])) { - for (p = &backup[base_length]; ISDIGIT(*p); ++p) - version = version * 10 + *p - '0'; - if (p[0] != '~' || p[1]) - version = 0; - } - return version; -} - -/* - * Return the newly-allocated concatenation of STR1 and STR2. If out of - * memory, return 0. - */ -static char * -concat(const char *str1, const char *str2) -{ - char *newstr; - - if (asprintf(&newstr, "%s%s", str1, str2) == -1) - return NULL; - return newstr; -} - -/* - * If ARG is an unambiguous match for an element of the null-terminated array - * OPTLIST, return the index in OPTLIST of the matched element, else -1 if it - * does not match any element or -2 if it is ambiguous (is a prefix of more - * than one element). - */ -static int -argmatch(const char *arg, const char **optlist) -{ - int i; /* Temporary index in OPTLIST. */ - size_t arglen; /* Length of ARG. */ - int matchind = -1; /* Index of first nonexact match. */ - int ambiguous = 0; /* If nonzero, multiple nonexact match(es). */ - - arglen = strlen(arg); - - /* Test all elements for either exact match or abbreviated matches. */ - for (i = 0; optlist[i]; i++) { - if (!strncmp(optlist[i], arg, arglen)) { - if (strlen(optlist[i]) == arglen) - /* Exact match found. */ - return i; - else if (matchind == -1) - /* First nonexact match found. */ - matchind = i; - else - /* Second nonexact match found. */ - ambiguous = 1; - } - } - if (ambiguous) - return -2; - else - return matchind; -} - -/* - * Error reporting for argmatch. KIND is a description of the type of entity - * that was being matched. VALUE is the invalid value that was given. PROBLEM - * is the return value from argmatch. - */ -static void -invalid_arg(const char *kind, const char *value, int problem) -{ - fprintf(stderr, "patch: "); - if (problem == -1) - fprintf(stderr, "invalid"); - else /* Assume -2. */ - fprintf(stderr, "ambiguous"); - fprintf(stderr, " %s `%s'\n", kind, value); -} - -static const char *backup_args[] = { - "never", "simple", "nil", "existing", "t", "numbered", 0 -}; - -static enum backup_type backup_types[] = { - simple, simple, numbered_existing, - numbered_existing, numbered, numbered -}; - -/* - * Return the type of backup indicated by VERSION. Unique abbreviations are - * accepted. - */ -enum backup_type -get_version(const char *version) -{ - int i; - - if (version == NULL || *version == '\0') - return numbered_existing; - i = argmatch(version, backup_args); - if (i >= 0) - return backup_types[i]; - invalid_arg("version control type", version, i); - exit(2); -} diff --git a/usr.bin/patch/backupfile.h b/usr.bin/patch/backupfile.h deleted file mode 100644 index 7c20ddb4bc55..000000000000 --- a/usr.bin/patch/backupfile.h +++ /dev/null @@ -1,38 +0,0 @@ -/* $OpenBSD: backupfile.h,v 1.6 2003/07/28 18:35:36 otto Exp $ */ - -/* - * backupfile.h -- declarations for making Emacs style backup file names - * Copyright (C) 1990 Free Software Foundation, Inc. - * - * This program is free software; you can redistribute it and/or modify it - * without restriction. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - */ - -/* When to make backup files. */ -enum backup_type { - /* Never make backups. */ - none, - - /* Make simple backups of every file. */ - simple, - - /* - * Make numbered backups of files that already have numbered backups, - * and simple backups of the others. - */ - numbered_existing, - - /* Make numbered backups of every file. */ - numbered -}; - -extern enum backup_type backup_type; -extern char *simple_backup_suffix; - -char *find_backup_file_name(const char *file); -enum backup_type get_version(const char *version); diff --git a/usr.bin/patch/common.h b/usr.bin/patch/common.h deleted file mode 100644 index 4101a5757470..000000000000 --- a/usr.bin/patch/common.h +++ /dev/null @@ -1,114 +0,0 @@ -/* $OpenBSD: common.h,v 1.25 2003/10/31 20:20:45 millert Exp $ */ - -/* - * patch - a program to apply diffs to original files - * - * Copyright 1986, Larry Wall - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following condition is met: - * 1. Redistributions of source code must retain the above copyright notice, - * this condition and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * -C option added in 1998, original code by Marc Espie, based on FreeBSD - * behaviour - */ - -#include <stdbool.h> - -#define DEBUGGING - -/* constants */ - -#define MAXHUNKSIZE 100000 /* is this enough lines? */ -#define INITHUNKMAX 125 /* initial dynamic allocation size */ -#define MAXLINELEN 8192 -#define BUFFERSIZE 1024 - -#define SCCSPREFIX "s." -#define GET "get -e %s" -#define SCCSDIFF "get -p %s | diff - %s >/dev/null" - -#define RCSSUFFIX ",v" -#define CHECKOUT "co -l %s" -#define RCSDIFF "rcsdiff %s > /dev/null" - -#define ORIGEXT ".orig" -#define REJEXT ".rej" - -/* handy definitions */ - -#define strNE(s1,s2) (strcmp(s1, s2)) -#define strEQ(s1,s2) (!strcmp(s1, s2)) -#define strnNE(s1,s2,l) (strncmp(s1, s2, l)) -#define strnEQ(s1,s2,l) (!strncmp(s1, s2, l)) - -/* typedefs */ - -typedef long LINENUM; /* must be signed */ - -/* globals */ - -extern int filemode; - -extern char buf[MAXLINELEN];/* general purpose buffer */ - -extern bool using_plan_a; /* try to keep everything in memory */ -extern bool out_of_mem; /* ran out of memory in plan a */ - -#define MAXFILEC 2 - -extern char *filearg[MAXFILEC]; -extern bool ok_to_create_file; -extern char *outname; -extern char *origprae; - -extern char *TMPOUTNAME; -extern char *TMPINNAME; -extern char *TMPREJNAME; -extern char *TMPPATNAME; -extern bool toutkeep; -extern bool trejkeep; - -#ifdef DEBUGGING -extern int debug; -#endif - -extern bool force; -extern bool batch; -extern bool verbose; -extern bool reverse; -extern bool noreverse; -extern bool skip_rest_of_patch; -extern int strippath; -extern bool canonicalize; -/* TRUE if -C was specified on command line. */ -extern bool check_only; -extern bool warn_on_invalid_line; -extern bool last_line_missing_eol; - - -#define CONTEXT_DIFF 1 -#define NORMAL_DIFF 2 -#define ED_DIFF 3 -#define NEW_CONTEXT_DIFF 4 -#define UNI_DIFF 5 - -extern int diff_type; -extern char *revision; /* prerequisite revision, if any */ -extern LINENUM input_lines; /* how long is input file in lines */ - -extern int posix; - diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c deleted file mode 100644 index 3326843ad008..000000000000 --- a/usr.bin/patch/inp.c +++ /dev/null @@ -1,473 +0,0 @@ -/* $OpenBSD: inp.c,v 1.31 2003/12/08 22:44:18 mickey Exp $ */ - -/* - * patch - a program to apply diffs to original files - * - * Copyright 1986, Larry Wall - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following condition is met: - * 1. Redistributions of source code must retain the above copyright notice, - * this condition and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * -C option added in 1998, original code by Marc Espie, based on FreeBSD - * behaviour - */ - -#ifndef lint -static const char rcsid[] = "$OpenBSD: inp.c,v 1.31 2003/12/08 22:44:18 mickey Exp $"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/file.h> -#include <sys/stat.h> -#include <sys/mman.h> - -#include <ctype.h> -#include <libgen.h> -#include <limits.h> -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "common.h" -#include "util.h" -#include "pch.h" -#include "inp.h" - - -/* Input-file-with-indexable-lines abstract type */ - -static off_t i_size; /* size of the input file */ -static char *i_womp; /* plan a buffer for entire file */ -static char **i_ptr; /* pointers to lines in i_womp */ - -static int tifd = -1; /* plan b virtual string array */ -static char *tibuf[2]; /* plan b buffers */ -static LINENUM tiline[2] = {-1, -1}; /* 1st line in each buffer */ -static LINENUM lines_per_buf; /* how many lines per buffer */ -static int tireclen; /* length of records in tmp file */ - -static bool rev_in_string(const char *); -static bool reallocate_lines(size_t *); - -/* returns false if insufficient memory */ -static bool plan_a(const char *); - -static void plan_b(const char *); - -/* New patch--prepare to edit another file. */ - -void -re_input(void) -{ - if (using_plan_a) { - i_size = 0; - free(i_ptr); - i_ptr = NULL; - if (i_womp != NULL) { - munmap(i_womp, i_size); - i_womp = NULL; - } - } else { - using_plan_a = true; /* maybe the next one is smaller */ - close(tifd); - tifd = -1; - free(tibuf[0]); - free(tibuf[1]); - tibuf[0] = tibuf[1] = NULL; - tiline[0] = tiline[1] = -1; - tireclen = 0; - } -} - -/* Constuct the line index, somehow or other. */ - -void -scan_input(const char *filename) -{ - if (!plan_a(filename)) - plan_b(filename); - if (verbose) { - say("Patching file %s using Plan %s...\n", filename, - (using_plan_a ? "A" : "B")); - } -} - -static bool -reallocate_lines(size_t *lines_allocated) -{ - char **p; - size_t new_size; - - new_size = *lines_allocated * 3 / 2; - p = realloc(i_ptr, (new_size + 2) * sizeof(char *)); - if (p == NULL) { /* shucks, it was a near thing */ - munmap(i_womp, i_size); - i_womp = NULL; - free(i_ptr); - i_ptr = NULL; - *lines_allocated = 0; - return false; - } - *lines_allocated = new_size; - i_ptr = p; - return true; -} - -/* Try keeping everything in memory. */ - -static bool -plan_a(const char *filename) -{ - int ifd, statfailed; - char *p, *s, lbuf[MAXLINELEN]; - LINENUM iline; - struct stat filestat; - off_t i; - ptrdiff_t sz; - size_t lines_allocated; - -#ifdef DEBUGGING - if (debug & 8) - return false; -#endif - - if (filename == NULL || *filename == '\0') - return false; - - statfailed = stat(filename, &filestat); - if (statfailed && ok_to_create_file) { - if (verbose) - say("(Creating file %s...)\n", filename); - - /* - * in check_patch case, we still display `Creating file' even - * though we're not. The rule is that -C should be as similar - * to normal patch behavior as possible - */ - if (check_only) - return true; - makedirs(filename, true); - close(creat(filename, 0666)); - statfailed = stat(filename, &filestat); - } - if (statfailed && check_only) - fatal("%s not found, -C mode, can't probe further\n", filename); - /* For nonexistent or read-only files, look for RCS or SCCS versions. */ - if (statfailed || - /* No one can write to it. */ - (filestat.st_mode & 0222) == 0 || - /* I can't write to it. */ - ((filestat.st_mode & 0022) == 0 && filestat.st_uid != getuid())) { - char *cs = NULL, *filebase, *filedir; - struct stat cstat; - - filebase = basename(filename); - filedir = dirname(filename); - - /* Leave room in lbuf for the diff command. */ - s = lbuf + 20; - -#define try(f, a1, a2, a3) \ - (snprintf(s, sizeof lbuf - 20, f, a1, a2, a3), stat(s, &cstat) == 0) - - if (try("%s/RCS/%s%s", filedir, filebase, RCSSUFFIX) || - try("%s/RCS/%s%s", filedir, filebase, "") || - try("%s/%s%s", filedir, filebase, RCSSUFFIX)) { - snprintf(buf, sizeof buf, CHECKOUT, filename); - snprintf(lbuf, sizeof lbuf, RCSDIFF, filename); - cs = "RCS"; - } else if (try("%s/SCCS/%s%s", filedir, SCCSPREFIX, filebase) || - try("%s/%s%s", filedir, SCCSPREFIX, filebase)) { - snprintf(buf, sizeof buf, GET, s); - snprintf(lbuf, sizeof lbuf, SCCSDIFF, s, filename); - cs = "SCCS"; - } else if (statfailed) - fatal("can't find %s\n", filename); - /* - * else we can't write to it but it's not under a version - * control system, so just proceed. - */ - if (cs) { - if (!statfailed) { - if ((filestat.st_mode & 0222) != 0) - /* The owner can write to it. */ - fatal("file %s seems to be locked " - "by somebody else under %s\n", - filename, cs); - /* - * It might be checked out unlocked. See if - * it's safe to check out the default version - * locked. - */ - if (verbose) - say("Comparing file %s to default " - "%s version...\n", - filename, cs); - if (system(lbuf)) - fatal("can't check out file %s: " - "differs from default %s version\n", - filename, cs); - } - if (verbose) - say("Checking out file %s from %s...\n", - filename, cs); - if (system(buf) || stat(filename, &filestat)) - fatal("can't check out file %s from %s\n", - filename, cs); - } - } - filemode = filestat.st_mode; - if (!S_ISREG(filemode)) - fatal("%s is not a normal file--can't patch\n", filename); - i_size = filestat.st_size; - if (out_of_mem) { - set_hunkmax(); /* make sure dynamic arrays are allocated */ - out_of_mem = false; - return false; /* force plan b because plan a bombed */ - } - if (i_size > SIZE_MAX) { - say("block too large to mmap\n"); - return false; - } - if ((ifd = open(filename, O_RDONLY)) < 0) - pfatal("can't open file %s", filename); - - i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0); - if (i_womp == MAP_FAILED) { - perror("mmap failed"); - i_womp = NULL; - close(ifd); - return false; - } - - close(ifd); - if (i_size) - madvise(i_womp, i_size, MADV_SEQUENTIAL); - - /* estimate the number of lines */ - lines_allocated = i_size / 25; - if (lines_allocated < 100) - lines_allocated = 100; - - if (!reallocate_lines(&lines_allocated)) - return false; - - /* now scan the buffer and build pointer array */ - iline = 1; - i_ptr[iline] = i_womp; - /* test for NUL too, to maintain the behavior of the original code */ - for (s = i_womp, i = 0; i < i_size && *s != '\0'; s++, i++) { - if (*s == '\n') { - if (iline == lines_allocated) { - if (!reallocate_lines(&lines_allocated)) - return false; - } - /* these are NOT NUL terminated */ - i_ptr[++iline] = s + 1; - } - } - /* if the last line contains no EOL, append one */ - if (i_size > 0 && i_womp[i_size - 1] != '\n') { - last_line_missing_eol = true; - /* fix last line */ - sz = s - i_ptr[iline]; - p = malloc(sz + 1); - if (p == NULL) { - free(i_ptr); - i_ptr = NULL; - munmap(i_womp, i_size); - i_womp = NULL; - return false; - } - - memcpy(p, i_ptr[iline], sz); - p[sz] = '\n'; - i_ptr[iline] = p; - /* count the extra line and make it point to some valid mem */ - i_ptr[++iline] = ""; - } else - last_line_missing_eol = false; - - input_lines = iline - 1; - - /* now check for revision, if any */ - - if (revision != NULL) { - if (!rev_in_string(i_womp)) { - if (force) { - if (verbose) - say("Warning: this file doesn't appear " - "to be the %s version--patching anyway.\n", - revision); - } else if (batch) { - fatal("this file doesn't appear to be the " - "%s version--aborting.\n", - revision); - } else { - ask("This file doesn't appear to be the " - "%s version--patch anyway? [n] ", - revision); - if (*buf != 'y') - fatal("aborted\n"); - } - } else if (verbose) - say("Good. This file appears to be the %s version.\n", - revision); - } - return true; /* plan a will work */ -} - -/* Keep (virtually) nothing in memory. */ - -static void -plan_b(const char *filename) -{ - FILE *ifp; - int i = 0, j, maxlen = 1; - char *p; - bool found_revision = (revision == NULL); - - using_plan_a = false; - if ((ifp = fopen(filename, "r")) == NULL) - pfatal("can't open file %s", filename); - (void) unlink(TMPINNAME); - if ((tifd = open(TMPINNAME, O_EXCL | O_CREAT | O_WRONLY, 0666)) < 0) - pfatal("can't open file %s", TMPINNAME); - while (fgets(buf, sizeof buf, ifp) != NULL) { - if (revision != NULL && !found_revision && rev_in_string(buf)) - found_revision = true; - if ((i = strlen(buf)) > maxlen) - maxlen = i; /* find longest line */ - } - last_line_missing_eol = i > 0 && buf[i - 1] != '\n'; - if (last_line_missing_eol && maxlen == i) - maxlen++; - - if (revision != NULL) { - if (!found_revision) { - if (force) { - if (verbose) - say("Warning: this file doesn't appear " - "to be the %s version--patching anyway.\n", - revision); - } else if (batch) { - fatal("this file doesn't appear to be the " - "%s version--aborting.\n", - revision); - } else { - ask("This file doesn't appear to be the %s " - "version--patch anyway? [n] ", - revision); - if (*buf != 'y') - fatal("aborted\n"); - } - } else if (verbose) - say("Good. This file appears to be the %s version.\n", - revision); - } - fseek(ifp, 0L, SEEK_SET); /* rewind file */ - lines_per_buf = BUFFERSIZE / maxlen; - tireclen = maxlen; - tibuf[0] = malloc(BUFFERSIZE + 1); - if (tibuf[0] == NULL) - fatal("out of memory\n"); - tibuf[1] = malloc(BUFFERSIZE + 1); - if (tibuf[1] == NULL) - fatal("out of memory\n"); - for (i = 1;; i++) { - p = tibuf[0] + maxlen * (i % lines_per_buf); - if (i % lines_per_buf == 0) /* new block */ - if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE) - pfatal("can't write temp file"); - if (fgets(p, maxlen + 1, ifp) == NULL) { - input_lines = i - 1; - if (i % lines_per_buf != 0) - if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE) - pfatal("can't write temp file"); - break; - } - j = strlen(p); - /* These are '\n' terminated strings, so no need to add a NUL */ - if (j == 0 || p[j - 1] != '\n') - p[j] = '\n'; - } - fclose(ifp); - close(tifd); - if ((tifd = open(TMPINNAME, O_RDONLY)) < 0) - pfatal("can't reopen file %s", TMPINNAME); -} - -/* - * Fetch a line from the input file, \n terminated, not necessarily \0. - */ -char * -ifetch(LINENUM line, int whichbuf) -{ - if (line < 1 || line > input_lines) { - if (warn_on_invalid_line) { - say("No such line %ld in input file, ignoring\n", line); - warn_on_invalid_line = false; - } - return NULL; - } - if (using_plan_a) - return i_ptr[line]; - else { - LINENUM offline = line % lines_per_buf; - LINENUM baseline = line - offline; - - if (tiline[0] == baseline) - whichbuf = 0; - else if (tiline[1] == baseline) - whichbuf = 1; - else { - tiline[whichbuf] = baseline; - - lseek(tifd, (off_t) (baseline / lines_per_buf * - BUFFERSIZE), SEEK_SET); - - if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0) - pfatal("error reading tmp file %s", TMPINNAME); - } - return tibuf[whichbuf] + (tireclen * offline); - } -} - -/* - * True if the string argument contains the revision number we want. - */ -static bool -rev_in_string(const char *string) -{ - const char *s; - int patlen; - - if (revision == NULL) - return true; - patlen = strlen(revision); - if (strnEQ(string, revision, patlen) && isspace(string[patlen])) - return true; - for (s = string; *s; s++) { - if (isspace(*s) && strnEQ(s + 1, revision, patlen) && - isspace(s[patlen + 1])) { - return true; - } - } - return false; -} diff --git a/usr.bin/patch/inp.h b/usr.bin/patch/inp.h deleted file mode 100644 index aa66208fdc8b..000000000000 --- a/usr.bin/patch/inp.h +++ /dev/null @@ -1,31 +0,0 @@ -/* $OpenBSD: inp.h,v 1.8 2003/08/15 08:00:51 otto Exp $ */ - -/* - * patch - a program to apply diffs to original files - * - * Copyright 1986, Larry Wall - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following condition is met: - * 1. Redistributions of source code must retain the above copyright notice, - * this condition and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * -C option added in 1998, original code by Marc Espie, based on FreeBSD - * behaviour - */ - -void re_input(void); -void scan_input(const char *); -char *ifetch(LINENUM, int); diff --git a/usr.bin/patch/patch.1 b/usr.bin/patch/patch.1 deleted file mode 100644 index 9d12b8b12bd7..000000000000 --- a/usr.bin/patch/patch.1 +++ /dev/null @@ -1,641 +0,0 @@ -.\" $OpenBSD: patch.1,v 1.17 2003/10/31 20:20:45 millert Exp $ -.\" Copyright 1986, Larry Wall -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following condition -.\" is met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this condition and the following disclaimer. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. -.\" -.Dd July 23, 2003 -.Dt PATCH 1 -.Os -.Sh NAME -.Nm patch -.Nd apply a diff file to an original -.Sh SYNOPSIS -.Nm patch -.Op Cm options -.Op Ar origfile Op Ar patchfile -.Nm patch -.Pf \*(Lt Ar patchfile -.Sh DESCRIPTION -.Nm -will take a patch file containing any of the four forms of difference -listing produced by the -.Xr diff 1 -program and apply those differences to an original file, -producing a patched version. -If -.Ar patchfile -is omitted, or is a hyphen, the patch will be read from the standard input. -.Pp -.Nm -will attempt to determine the type of the diff listing, unless over-ruled by a -.Fl c , -.Fl e , -.Fl n , -or -.Fl u -option. -Context diffs (old-style, new-style, and unified) and -normal diffs are applied directly by the -.Nm -program itself, whereas ed diffs are simply fed to the -.Xr ed 1 -editor via a pipe. -.Pp -If the -.Ar patchfile -contains more than one patch, -.Nm -will try to apply each of them as if they came from separate patch files. -This means, among other things, that it is assumed that the name of the file -to patch must be determined for each diff listing, and that the garbage before -each diff listing will be examined for interesting things such as file names -and revision level (see the section on -.Sx Filename Determination -below). -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl b , Fl Fl backup -Save a backup copy of the file before it is modified. -By default the original file is saved with a backup extension of -.Qq .orig -unless the file already has a numbered backup, in which case a numbered -backup is made. -This is equivalent to specifying -.Qo Fl V Ar existing Qc . -This option is currently the default but that will change in a future release. -.It Fl B , Fl Fl prefix -Causes the next argument to be interpreted as a prefix to the backup file -name. -If this argument is specified, any argument to -.Fl z -will be ignored. -.It Fl c , Fl Fl context -Forces -.Nm -to interpret the patch file as a context diff. -.It Fl C , Fl Fl check -Checks that the patch would apply cleanly, but does not modify anything. -.It Fl d , Fl Fl directory -Causes -.Nm -to interpret the next argument as a directory, and -.Xr cd 1 -to it before doing anything else. -.It Fl D , Fl Fl ifdef -Causes -.Nm -to use the -.Qq #ifdef...#endif -construct to mark changes. -The argument following will be used as the differentiating symbol. -Note that, unlike the C compiler, there must be a space between the -.Fl D -and the argument. -.It Fl e , Fl Fl ed -Forces -.Nm -to interpret the patch file as an -.Xr ed 1 -script. -.It Fl E , Fl Fl remove-empty-files -Causes -.Nm -to remove output files that are empty after the patches have been applied. -This option is useful when applying patches that create or remove files. -.It Fl f , Fl Fl force -Forces -.Nm -to assume that the user knows exactly what he or she is doing, and to not -ask any questions. -It assumes the following: -skip patches for which a file to patch can't be found; -patch files even though they have the wrong version for the -.Qq Prereq: -line in the patch; -and assume that patches are not reversed even if they look like they are. -This option does not suppress commentary; use -.Fl s -for that. -.It Xo -.Fl F Ns Aq Ar number , -.Fl Fl fuzz Aq Ar number -.Xc -Sets the maximum fuzz factor. -This option only applies to context diffs, and causes -.Nm -to ignore up to that many lines in looking for places to install a hunk. -Note that a larger fuzz factor increases the odds of a faulty patch. -The default fuzz factor is 2, and it may not be set to more than -the number of lines of context in the context diff, ordinarily 3. -.It Fl i , Fl Fl input -Causes the next argument to be interpreted as the input file name -(i.e. a patchfile). -This option may be specified multiple times. -.It Fl l , Fl Fl ignore-whitespace -Causes the pattern matching to be done loosely, in case the tabs and -spaces have been munged in your input file. -Any sequence of whitespace in the pattern line will match any sequence -in the input file. -Normal characters must still match exactly. -Each line of the context must still match a line in the input file. -.It Fl n , Fl Fl normal -Forces -.Nm -to interpret the patch file as a normal diff. -.It Fl N , Fl Fl forward -Causes -.Nm -to ignore patches that it thinks are reversed or already applied. -See also -.Fl R . -.It Fl o , Fl Fl output -Causes the next argument to be interpreted as the output file name. -.It Xo -.Fl p Ns Aq Ar number , -.Fl Fl strip Aq Ar number -.Xc -Sets the pathname strip count, -which controls how pathnames found in the patch file are treated, -in case you keep your files in a different directory than the person who sent -out the patch. -The strip count specifies how many slashes are to be stripped from -the front of the pathname. -(Any intervening directory names also go away.) -For example, supposing the file name in the patch file was -.Pa /u/howard/src/blurfl/blurfl.c : -.Pp -Setting -.Fl p Ns Ar 0 -gives the entire pathname unmodified. -.Pp -.Fl p Ns Ar 1 -gives -.Pp -.D1 Pa u/howard/src/blurfl/blurfl.c -.Pp -without the leading slash. -.Pp -.Fl p Ns Ar 4 -gives -.Pp -.D1 Pa blurfl/blurfl.c -.Pp -Not specifying -.Fl p -at all just gives you -.Pa blurfl.c , -unless all of the directories in the leading path -.Pq Pa u/howard/src/blurfl -exist and that path is relative, -in which case you get the entire pathname unmodified. -Whatever you end up with is looked for either in the current directory, -or the directory specified by the -.Fl d -option. -.It Fl r , Fl Fl reject-file -Causes the next argument to be interpreted as the reject file name. -.It Fl R , Fl Fl reverse -Tells -.Nm -that this patch was created with the old and new files swapped. -(Yes, I'm afraid that does happen occasionally, human nature being what it -is.) -.Nm -will attempt to swap each hunk around before applying it. -Rejects will come out in the swapped format. -The -.Fl R -option will not work with ed diff scripts because there is too little -information to reconstruct the reverse operation. -.Pp -If the first hunk of a patch fails, -.Nm -will reverse the hunk to see if it can be applied that way. -If it can, you will be asked if you want to have the -.Fl R -option set. -If it can't, the patch will continue to be applied normally. -(Note: this method cannot detect a reversed patch if it is a normal diff -and if the first command is an append (i.e. it should have been a delete) -since appends always succeed, due to the fact that a null context will match -anywhere. -Luckily, most patches add or change lines rather than delete them, so most -reversed normal diffs will begin with a delete, which will fail, triggering -the heuristic.) -.It Xo -.Fl s , Fl Fl quiet , -.Fl Fl silent -.Xc -Makes -.Nm -do its work silently, unless an error occurs. -.It Fl t , Fl Fl batch -Similar to -.Fl f , -in that it suppresses questions, but makes some different assumptions: -skip patches for which a file to patch can't be found (the same as -.Fl f ) ; -skip patches for which the file has the wrong version for the -.Qq Prereq: -line in the patch; -and assume that patches are reversed if they look like they are. -.It Fl u , Fl Fl unified -Forces -.Nm -to interpret the patch file as a unified context diff (a unidiff). -.It Fl v , Fl Fl version -Causes -.Nm -to print out its revision header and patch level. -.It Fl V , Fl Fl version-control -Causes the next argument to be interpreted as a method for creating -backup file names. -The type of backups made can also be given in the -.Ev PATCH_VERSION_CONTROL -or -.Ev VERSION_CONTROL -environment variables, which are overridden by this option. -The -.Fl B -option overrides this option, causing the prefix to always be used for -making backup file names. -The values of the -.Ev PATCH_VERSION_CONTROL -and -.Ev VERSION_CONTROL -environment variables and the argument to the -.Fl V -option are like the GNU Emacs -.Dq version-control -variable; they also recognize synonyms that are more descriptive. -The valid values are (unique abbreviations are accepted): -.Bl -tag -width Ds -offset indent -.It t , numbered -Always make numbered backups. -.It nil , existing -Make numbered backups of files that already have them, -simple backups of the others. -.It never , simple -Always make simple backups. -.El -.It Xo -.Fl x Ns Aq Ar number , -.Fl Fl debug Aq Ar number -.Xc -Sets internal debugging flags, and is of interest only to -.Nm -patchers. -.It Fl z , Fl Fl suffix -Causes the next argument to be interpreted as the backup extension, to be -used in place of -.Qq .orig . -.It Fl Fl posix -Enables strict -.St -p1003.2 -conformance, specifically: -.Bl -enum -.It -Backup files are not created unless the -.Fl b -option is specified. -.It -If unspecified, the file name used is the first of the old, new and -index files that exists. -.El -.El -.Ss Patch Application -.Nm -will try to skip any leading garbage, apply the diff, -and then skip any trailing garbage. -Thus you could feed an article or message containing a -diff listing to -.Nm patch , -and it should work. -If the entire diff is indented by a consistent amount, -this will be taken into account. -.Pp -With context diffs, and to a lesser extent with normal diffs, -.Nm -can detect when the line numbers mentioned in the patch are incorrect, -and will attempt to find the correct place to apply each hunk of the patch. -As a first guess, it takes the line number mentioned for the hunk, plus or -minus any offset used in applying the previous hunk. -If that is not the correct place, -.Nm -will scan both forwards and backwards for a set of lines matching the context -given in the hunk. -First -.Nm -looks for a place where all lines of the context match. -If no such place is found, and it's a context diff, and the maximum fuzz factor -is set to 1 or more, then another scan takes place ignoring the first and last -line of context. -If that fails, and the maximum fuzz factor is set to 2 or more, -the first two and last two lines of context are ignored, -and another scan is made. -.Pq The default maximum fuzz factor is 2. -.Pp -If -.Nm -cannot find a place to install that hunk of the patch, it will put the hunk -out to a reject file, which normally is the name of the output file plus -.Qq .rej . -(Note that the rejected hunk will come out in context diff form whether the -input patch was a context diff or a normal diff. -If the input was a normal diff, many of the contexts will simply be null.) -The line numbers on the hunks in the reject file may be different than -in the patch file: they reflect the approximate location patch thinks the -failed hunks belong in the new file rather than the old one. -.Pp -As each hunk is completed, you will be told whether the hunk succeeded or -failed, and which line (in the new file) -.Nm -thought the hunk should go on. -If this is different from the line number specified in the diff, -you will be told the offset. -A single large offset MAY be an indication that a hunk was installed in the -wrong place. -You will also be told if a fuzz factor was used to make the match, in which -case you should also be slightly suspicious. -.Ss Filename Determination -If no original file is specified on the command line, -.Nm -will try to figure out from the leading garbage what the name of the file -to edit is. -When checking a prospective file name, pathname components are stripped -as specified by the -.Fl p -option and the file's existence and writability are checked relative -to the current working directory (or the directory specified by the -.Fl d -option). -.Pp -If the diff is a context or unified diff, -.Nm -is able to determine the old and new file names from the diff header. -For context diffs, the -.Dq old -file is specified in the line beginning with -.Qq *** -and the -.Dq new -file is specified in the line beginning with -.Qq --- . -For a unified diff, the -.Dq old -file is specified in the line beginning with -.Qq --- -and the -.Dq new -file is specified in the line beginning with -.Qq +++ . -If there is an -.Qq Index: -line in the leading garbage (regardless of the diff type), -.Nm -will use the file name from that line as the -.Dq index -file. -.Pp -.Nm -will choose the file name by performing the following steps, with the first -match used: -.Bl -enum -.It -If -.Nm -is operating in strict -.St -p1003.2 -mode, the first of the -.Dq old , -.Dq new -and -.Dq index -file names that exist is used. -Otherwise, -.Nm -will examine either the -.Dq old -and -.Dq new -file names or, for a non-context diff, the -.Dq index -file name, and choose the file name with the fewest path components, -the shortest basename, and the shortest total file name length (in that order). -.It -If no file exists, -.Nm -checks for the existence of the files in an SCCS or RCS directory -(using the appropriate prefix or suffix) using the criteria specified -above. -If found, -.Nm -will attempt to get or check out the file. -.It -If no suitable file was found to patch, the patch file is a context or -unified diff, and the old file was zero length, the new file name is -created and used. -.It -If the file name still cannot be determined, -.Nm -will prompt the user for the file name to use. -.El -.Pp -Additionally, if the leading garbage contains a -.Qq Prereq:\ \& -line, -.Nm -will take the first word from the prerequisites line (normally a version -number) and check the input file to see if that word can be found. -If not, -.Nm -will ask for confirmation before proceeding. -.Pp -The upshot of all this is that you should be able to say, while in a news -interface, the following: -.Pp -.Dl | patch -d /usr/src/local/blurfl -.Pp -and patch a file in the blurfl directory directly from the article containing -the patch. -.Ss Backup Files -By default, the patched version is put in place of the original, with -the original file backed up to the same name with the extension -.Qq .orig , -or as specified by the -.Fl B , -.Fl V , -or -.Fl z -options. -The extension used for making backup files may also be specified in the -.Ev SIMPLE_BACKUP_SUFFIX -environment variable, which is overridden by the options above. -.Pp -If the backup file is a symbolic or hard link to the original file, -.Nm -creates a new backup file name by changing the first lowercase letter -in the last component of the file's name into uppercase. -If there are no more lowercase letters in the name, -it removes the first character from the name. -It repeats this process until it comes up with a -backup file that does not already exist or is not linked to the original file. -.Pp -You may also specify where you want the output to go with the -.Fl o -option; if that file already exists, it is backed up first. -.Ss Notes For Patch Senders -There are several things you should bear in mind if you are going to -be sending out patches: -.Pp -First, you can save people a lot of grief by keeping a -.Pa patchlevel.h -file which is patched to increment the patch level as the first diff in the -patch file you send out. -If you put a -.Qq Prereq: -line in with the patch, it won't let them apply -patches out of order without some warning. -.Pp -Second, make sure you've specified the file names right, either in a -context diff header, or with an -.Qq Index: -line. -If you are patching something in a subdirectory, be sure to tell the patch -user to specify a -.Fl p -option as needed. -.Pp -Third, you can create a file by sending out a diff that compares a -null file to the file you want to create. -This will only work if the file you want to create doesn't exist already in -the target directory. -.Pp -Fourth, take care not to send out reversed patches, since it makes people wonder -whether they already applied the patch. -.Pp -Fifth, while you may be able to get away with putting 582 diff listings into -one file, it is probably wiser to group related patches into separate files in -case something goes haywire. -.Sh ENVIRONMENT -.Bl -tag -width "PATCH_VERSION_CONTROL" -compact -.It Ev POSIXLY_CORRECT -When set, -.Nm -behaves as if the -.Fl Fl posix -option has been specified. -.It Ev SIMPLE_BACKUP_SUFFIX -Extension to use for backup file names instead of -.Qq .orig . -.It Ev TMPDIR -Directory to put temporary files in; default is -.Pa /tmp . -.It Ev PATCH_VERSION_CONTROL -Selects when numbered backup files are made. -.It Ev VERSION_CONTROL -Same as -.Ev PATCH_VERSION_CONTROL . -.El -.Sh FILES -.Bl -tag -width "$TMPDIR/patch*" -compact -.It Pa $TMPDIR/patch* -.Nm -temporary files -.It Pa /dev/tty -used to read input when -.Nm -prompts the user -.El -.Sh DIAGNOSTICS -Too many to list here, but generally indicative that -.Nm -couldn't parse your patch file. -.Pp -The message -.Qq Hmm... -indicates that there is unprocessed text in the patch file and that -.Nm -is attempting to intuit whether there is a patch in that text and, if so, -what kind of patch it is. -.Pp -The -.Nm -utility exits with one of the following values: -.Pp -.Bl -tag -width Ds -compact -offset indent -.It \&0 -Successful completion. -.It \&1 -One or more lines were written to a reject file. -.It \*[Gt]\&1 -An error occurred. -.El -.Pp -When applying a set of patches in a loop it behooves you to check this -exit status so you don't apply a later patch to a partially patched file. -.Sh SEE ALSO -.Xr diff 1 -.Sh AUTHORS -.An Larry Wall -with many other contributors. -.Sh CAVEATS -.Nm -cannot tell if the line numbers are off in an ed script, and can only detect -bad line numbers in a normal diff when it finds a -.Qq change -or a -.Qq delete -command. -A context diff using fuzz factor 3 may have the same problem. -Until a suitable interactive interface is added, you should probably do -a context diff in these cases to see if the changes made sense. -Of course, compiling without errors is a pretty good indication that the patch -worked, but not always. -.Pp -.Nm -usually produces the correct results, even when it has to do a lot of -guessing. -However, the results are guaranteed to be correct only when the patch is -applied to exactly the same version of the file that the patch was -generated from. -.Sh BUGS -Could be smarter about partial matches, excessively deviant offsets and -swapped code, but that would take an extra pass. -.Pp -Check patch mode -.Pq Fl C -will fail if you try to check several patches in succession that build on -each other. -The entire -.Nm -code would have to be restructured to keep temporary files around so that it -can handle this situation. -.Pp -If code has been duplicated (for instance with #ifdef OLDCODE ... #else ... -#endif), -.Nm -is incapable of patching both versions, and, if it works at all, will likely -patch the wrong one, and tell you that it succeeded to boot. -.Pp -If you apply a patch you've already applied, -.Nm -will think it is a reversed patch, and offer to un-apply the patch. -This could be construed as a feature. diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c deleted file mode 100644 index 7b754871ba9b..000000000000 --- a/usr.bin/patch/patch.c +++ /dev/null @@ -1,974 +0,0 @@ -/* $OpenBSD: patch.c,v 1.41 2004/07/09 19:13:46 otto Exp $ */ - -/* - * patch - a program to apply diffs to original files - * - * Copyright 1986, Larry Wall - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following condition is met: - * 1. Redistributions of source code must retain the above copyright notice, - * this condition and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * -C option added in 1998, original code by Marc Espie, based on FreeBSD - * behaviour - */ - -#ifndef lint -static const char rcsid[] = "$OpenBSD: patch.c,v 1.41 2004/07/09 19:13:46 otto Exp $"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - -#include <ctype.h> -#include <getopt.h> -#include <limits.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#include "common.h" -#include "util.h" -#include "pch.h" -#include "inp.h" -#include "backupfile.h" -#include "pathnames.h" - -int filemode = 0644; - -char buf[MAXLINELEN]; /* general purpose buffer */ - -bool using_plan_a = true; /* try to keep everything in memory */ -bool out_of_mem = false; /* ran out of memory in plan a */ - -#define MAXFILEC 2 - -char *filearg[MAXFILEC]; -bool ok_to_create_file = false; -char *outname = NULL; -char *origprae = NULL; -char *TMPOUTNAME; -char *TMPINNAME; -char *TMPREJNAME; -char *TMPPATNAME; -bool toutkeep = false; -bool trejkeep = false; -bool warn_on_invalid_line; -bool last_line_missing_eol; - -#ifdef DEBUGGING -int debug = 0; -#endif - -bool force = false; -bool batch = false; -bool verbose = true; -bool reverse = false; -bool noreverse = false; -bool skip_rest_of_patch = false; -int strippath = 957; -bool canonicalize = false; -bool check_only = false; -int diff_type = 0; -char *revision = NULL; /* prerequisite revision, if any */ -LINENUM input_lines = 0; /* how long is input file in lines */ -int posix = 0; /* strict POSIX mode? */ - -static void reinitialize_almost_everything(void); -static void get_some_switches(void); -static LINENUM locate_hunk(LINENUM); -static void abort_hunk(void); -static void apply_hunk(LINENUM); -static void init_output(const char *); -static void init_reject(const char *); -static void copy_till(LINENUM, bool); -static void spew_output(void); -static void dump_line(LINENUM, bool); -static bool patch_match(LINENUM, LINENUM, LINENUM); -static bool similar(const char *, const char *, int); -static __dead void usage(void); - -/* true if -E was specified on command line. */ -static bool remove_empty_files = false; - -/* true if -R was specified on command line. */ -static bool reverse_flag_specified = false; - -/* buffer holding the name of the rejected patch file. */ -static char rejname[NAME_MAX + 1]; - -/* buffer for stderr */ -static char serrbuf[BUFSIZ]; - -/* how many input lines have been irretractibly output */ -static LINENUM last_frozen_line = 0; - -static int Argc; /* guess */ -static char **Argv; -static int Argc_last; /* for restarting plan_b */ -static char **Argv_last; - -static FILE *ofp = NULL; /* output file pointer */ -static FILE *rejfp = NULL; /* reject file pointer */ - -static int filec = 0; /* how many file arguments? */ -static LINENUM last_offset = 0; -static LINENUM maxfuzz = 2; - -/* patch using ifdef, ifndef, etc. */ -static bool do_defines = false; -/* #ifdef xyzzy */ -static char if_defined[128]; -/* #ifndef xyzzy */ -static char not_defined[128]; -/* #else */ -static const char else_defined[] = "#else\n"; -/* #endif xyzzy */ -static char end_defined[128]; - - -/* Apply a set of diffs as appropriate. */ - -int -main(int argc, char *argv[]) -{ - int error = 0, hunk, failed, patch_seen = 0, i, fd; - LINENUM where = 0, newwhere, fuzz, mymaxfuzz; - const char *tmpdir; - char *v; - - setbuf(stderr, serrbuf); - for (i = 0; i < MAXFILEC; i++) - filearg[i] = NULL; - - /* Cons up the names of the temporary files. */ - if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') - tmpdir = _PATH_TMP; - for (i = strlen(tmpdir) - 1; i > 0 && tmpdir[i] == '/'; i--) - ; - i++; - if (asprintf(&TMPOUTNAME, "%.*s/patchoXXXXXXXXXX", i, tmpdir) == -1) - fatal("cannot allocate memory"); - if ((fd = mkstemp(TMPOUTNAME)) < 0) - pfatal("can't create %s", TMPOUTNAME); - close(fd); - - if (asprintf(&TMPINNAME, "%.*s/patchiXXXXXXXXXX", i, tmpdir) == -1) - fatal("cannot allocate memory"); - if ((fd = mkstemp(TMPINNAME)) < 0) - pfatal("can't create %s", TMPINNAME); - close(fd); - - if (asprintf(&TMPREJNAME, "%.*s/patchrXXXXXXXXXX", i, tmpdir) == -1) - fatal("cannot allocate memory"); - if ((fd = mkstemp(TMPREJNAME)) < 0) - pfatal("can't create %s", TMPREJNAME); - close(fd); - - if (asprintf(&TMPPATNAME, "%.*s/patchpXXXXXXXXXX", i, tmpdir) == -1) - fatal("cannot allocate memory"); - if ((fd = mkstemp(TMPPATNAME)) < 0) - pfatal("can't create %s", TMPPATNAME); - close(fd); - - v = getenv("SIMPLE_BACKUP_SUFFIX"); - if (v) - simple_backup_suffix = v; - else - simple_backup_suffix = ORIGEXT; - - /* parse switches */ - Argc = argc; - Argv = argv; - get_some_switches(); - - if (backup_type == none) { - if ((v = getenv("PATCH_VERSION_CONTROL")) == NULL) - v = getenv("VERSION_CONTROL"); - if (v != NULL || !posix) - backup_type = get_version(v); /* OK to pass NULL. */ - } - - /* make sure we clean up /tmp in case of disaster */ - set_signals(0); - - for (open_patch_file(filearg[1]); there_is_another_patch(); - reinitialize_almost_everything()) { - /* for each patch in patch file */ - - patch_seen = true; - warn_on_invalid_line = true; - - if (outname == NULL) - outname = savestr(filearg[0]); - - /* for ed script just up and do it and exit */ - if (diff_type == ED_DIFF) { - do_ed_script(); - continue; - } - /* initialize the patched file */ - if (!skip_rest_of_patch) - init_output(TMPOUTNAME); - - /* initialize reject file */ - init_reject(TMPREJNAME); - - /* find out where all the lines are */ - if (!skip_rest_of_patch) - scan_input(filearg[0]); - - /* from here on, open no standard i/o files, because malloc */ - /* might misfire and we can't catch it easily */ - - /* apply each hunk of patch */ - hunk = 0; - failed = 0; - out_of_mem = false; - while (another_hunk()) { - hunk++; - fuzz = 0; - mymaxfuzz = pch_context(); - if (maxfuzz < mymaxfuzz) - mymaxfuzz = maxfuzz; - if (!skip_rest_of_patch) { - do { - where = locate_hunk(fuzz); - if (hunk == 1 && where == 0 && !force) { - /* dwim for reversed patch? */ - if (!pch_swap()) { - if (fuzz == 0) - say("Not enough memory to try swapped hunk! Assuming unswapped.\n"); - continue; - } - reverse = !reverse; - /* try again */ - where = locate_hunk(fuzz); - if (where == 0) { - /* didn't find it swapped */ - if (!pch_swap()) - /* put it back to normal */ - fatal("lost hunk on alloc error!\n"); - reverse = !reverse; - } else if (noreverse) { - if (!pch_swap()) - /* put it back to normal */ - fatal("lost hunk on alloc error!\n"); - reverse = !reverse; - say("Ignoring previously applied (or reversed) patch.\n"); - skip_rest_of_patch = true; - } else if (batch) { - if (verbose) - say("%seversed (or previously applied) patch detected! %s -R.", - reverse ? "R" : "Unr", - reverse ? "Assuming" : "Ignoring"); - } else { - ask("%seversed (or previously applied) patch detected! %s -R? [y] ", - reverse ? "R" : "Unr", - reverse ? "Assume" : "Ignore"); - if (*buf == 'n') { - ask("Apply anyway? [n] "); - if (*buf != 'y') - skip_rest_of_patch = true; - where = 0; - reverse = !reverse; - if (!pch_swap()) - /* put it back to normal */ - fatal("lost hunk on alloc error!\n"); - } - } - } - } while (!skip_rest_of_patch && where == 0 && - ++fuzz <= mymaxfuzz); - - if (skip_rest_of_patch) { /* just got decided */ - fclose(ofp); - ofp = NULL; - } - } - newwhere = pch_newfirst() + last_offset; - if (skip_rest_of_patch) { - abort_hunk(); - failed++; - if (verbose) - say("Hunk #%d ignored at %ld.\n", - hunk, newwhere); - } else if (where == 0) { - abort_hunk(); - failed++; - if (verbose) - say("Hunk #%d failed at %ld.\n", - hunk, newwhere); - } else { - apply_hunk(where); - if (verbose) { - say("Hunk #%d succeeded at %ld", - hunk, newwhere); - if (fuzz != 0) - say(" with fuzz %ld", fuzz); - if (last_offset) - say(" (offset %ld line%s)", - last_offset, - last_offset == 1L ? "" : "s"); - say(".\n"); - } - } - } - - if (out_of_mem && using_plan_a) { - Argc = Argc_last; - Argv = Argv_last; - say("\n\nRan out of memory using Plan A--trying again...\n\n"); - if (ofp) - fclose(ofp); - ofp = NULL; - if (rejfp) - fclose(rejfp); - rejfp = NULL; - continue; - } - if (hunk == 0) - fatal("Internal error: hunk should not be 0\n"); - - /* finish spewing out the new file */ - if (!skip_rest_of_patch) - spew_output(); - - /* and put the output where desired */ - ignore_signals(); - if (!skip_rest_of_patch) { - struct stat statbuf; - char *realout = outname; - - if (!check_only) { - if (move_file(TMPOUTNAME, outname) < 0) { - toutkeep = true; - realout = TMPOUTNAME; - chmod(TMPOUTNAME, filemode); - } else - chmod(outname, filemode); - - if (remove_empty_files && - stat(realout, &statbuf) == 0 && - statbuf.st_size == 0) { - if (verbose) - say("Removing %s (empty after patching).\n", - realout); - unlink(realout); - } - } - } - fclose(rejfp); - rejfp = NULL; - if (failed) { - error = 1; - if (*rejname == '\0') { - if (strlcpy(rejname, outname, - sizeof(rejname)) >= sizeof(rejname)) - fatal("filename %s is too long\n", outname); - if (strlcat(rejname, REJEXT, - sizeof(rejname)) >= sizeof(rejname)) - fatal("filename %s is too long\n", outname); - } - if (skip_rest_of_patch) { - say("%d out of %d hunks ignored--saving rejects to %s\n", - failed, hunk, rejname); - } else { - say("%d out of %d hunks failed--saving rejects to %s\n", - failed, hunk, rejname); - } - if (!check_only && move_file(TMPREJNAME, rejname) < 0) - trejkeep = true; - } - set_signals(1); - } - my_exit(error); - /* NOTREACHED */ -} - -/* Prepare to find the next patch to do in the patch file. */ - -static void -reinitialize_almost_everything(void) -{ - re_patch(); - re_input(); - - input_lines = 0; - last_frozen_line = 0; - - filec = 0; - if (!out_of_mem) { - free(filearg[0]); - filearg[0] = NULL; - } - - free(outname); - outname = NULL; - - last_offset = 0; - diff_type = 0; - - free(revision); - revision = NULL; - - reverse = reverse_flag_specified; - skip_rest_of_patch = false; - - get_some_switches(); -} - -/* Process switches and filenames. */ - -static void -get_some_switches(void) -{ - const char *options = "b::B:cCd:D:eEfF:i:lnNo:p:r:RstuvV:x:z:"; - static struct option longopts[] = { - {"backup", no_argument, 0, 'b'}, - {"batch", no_argument, 0, 't'}, - {"check", no_argument, 0, 'C'}, - {"context", no_argument, 0, 'c'}, - {"debug", required_argument, 0, 'x'}, - {"directory", required_argument, 0, 'd'}, - {"ed", no_argument, 0, 'e'}, - {"force", no_argument, 0, 'f'}, - {"forward", no_argument, 0, 'N'}, - {"fuzz", required_argument, 0, 'F'}, - {"ifdef", required_argument, 0, 'D'}, - {"input", required_argument, 0, 'i'}, - {"ignore-whitespace", no_argument, 0, 'l'}, - {"normal", no_argument, 0, 'n'}, - {"output", required_argument, 0, 'o'}, - {"prefix", required_argument, 0, 'B'}, - {"quiet", no_argument, 0, 's'}, - {"reject-file", required_argument, 0, 'r'}, - {"remove-empty-files", no_argument, 0, 'E'}, - {"reverse", no_argument, 0, 'R'}, - {"silent", no_argument, 0, 's'}, - {"strip", required_argument, 0, 'p'}, - {"suffix", required_argument, 0, 'z'}, - {"unified", no_argument, 0, 'u'}, - {"version", no_argument, 0, 'v'}, - {"version-control", required_argument, 0, 'V'}, - {"posix", no_argument, &posix, 1}, - {NULL, 0, 0, 0} - }; - int ch; - - rejname[0] = '\0'; - Argc_last = Argc; - Argv_last = Argv; - if (!Argc) - return; - optreset = optind = 1; - while ((ch = getopt_long(Argc, Argv, options, longopts, NULL)) != -1) { - switch (ch) { - case 'b': - if (backup_type == none) - backup_type = numbered_existing; - if (optarg == NULL) - break; - if (verbose) - say("Warning, the ``-b suffix'' option has been" - " obsoleted by the -z option.\n"); - /* FALLTHROUGH */ - case 'z': - /* must directly follow 'b' case for backwards compat */ - simple_backup_suffix = savestr(optarg); - break; - case 'B': - origprae = savestr(optarg); - break; - case 'c': - diff_type = CONTEXT_DIFF; - break; - case 'C': - check_only = true; - break; - case 'd': - if (chdir(optarg) < 0) - pfatal("can't cd to %s", optarg); - break; - case 'D': - do_defines = true; - if (!isalpha(*optarg) && *optarg != '_') - fatal("argument to -D is not an identifier\n"); - snprintf(if_defined, sizeof if_defined, - "#ifdef %s\n", optarg); - snprintf(not_defined, sizeof not_defined, - "#ifndef %s\n", optarg); - snprintf(end_defined, sizeof end_defined, - "#endif /* %s */\n", optarg); - break; - case 'e': - diff_type = ED_DIFF; - break; - case 'E': - remove_empty_files = true; - break; - case 'f': - force = true; - break; - case 'F': - maxfuzz = atoi(optarg); - break; - case 'i': - if (++filec == MAXFILEC) - fatal("too many file arguments\n"); - filearg[filec] = savestr(optarg); - break; - case 'l': - canonicalize = true; - break; - case 'n': - diff_type = NORMAL_DIFF; - break; - case 'N': - noreverse = true; - break; - case 'o': - outname = savestr(optarg); - break; - case 'p': - strippath = atoi(optarg); - break; - case 'r': - if (strlcpy(rejname, optarg, - sizeof(rejname)) >= sizeof(rejname)) - fatal("argument for -r is too long\n"); - break; - case 'R': - reverse = true; - reverse_flag_specified = true; - break; - case 's': - verbose = false; - break; - case 't': - batch = true; - break; - case 'u': - diff_type = UNI_DIFF; - break; - case 'v': - version(); - break; - case 'V': - backup_type = get_version(optarg); - break; -#ifdef DEBUGGING - case 'x': - debug = atoi(optarg); - break; -#endif - default: - if (ch != '\0') - usage(); - break; - } - } - Argc -= optind; - Argv += optind; - - if (Argc > 0) { - filearg[0] = savestr(*Argv++); - Argc--; - while (Argc > 0) { - if (++filec == MAXFILEC) - fatal("too many file arguments\n"); - filearg[filec] = savestr(*Argv++); - Argc--; - } - } - - if (getenv("POSIXLY_CORRECT") != NULL) - posix = 1; -} - -static __dead void -usage(void) -{ - fprintf(stderr, -"usage: patch [-bcCeEflnNRstuv] [-B backup-prefix] [-d directory] [-D symbol]\n" -" [-F max-fuzz] [-i patchfile] [-o out-file] [-p strip-count]\n" -" [-r rej-name] [-V {numbered,existing,simple}] [-z backup-ext]\n" -" [origfile [patchfile]]\n"); - my_exit(EXIT_SUCCESS); -} - -/* - * Attempt to find the right place to apply this hunk of patch. - */ -static LINENUM -locate_hunk(LINENUM fuzz) -{ - LINENUM first_guess = pch_first() + last_offset; - LINENUM offset; - LINENUM pat_lines = pch_ptrn_lines(); - LINENUM max_pos_offset = input_lines - first_guess - pat_lines + 1; - LINENUM max_neg_offset = first_guess - last_frozen_line - 1 + pch_context(); - - if (pat_lines == 0) { /* null range matches always */ - if (verbose && fuzz == 0 && (diff_type == CONTEXT_DIFF - || diff_type == NEW_CONTEXT_DIFF - || diff_type == UNI_DIFF)) { - say("Empty context always matches.\n"); - } - if (diff_type == CONTEXT_DIFF - || diff_type == NEW_CONTEXT_DIFF - || diff_type == UNI_DIFF) { - if (fuzz == 0) - return (input_lines == 0 ? first_guess : 0); - } else - return (first_guess); - } - if (max_neg_offset >= first_guess) /* do not try lines < 0 */ - max_neg_offset = first_guess - 1; - if (first_guess <= input_lines && patch_match(first_guess, 0, fuzz)) - return first_guess; - for (offset = 1; ; offset++) { - bool check_after = (offset <= max_pos_offset); - bool check_before = (offset <= max_neg_offset); - - if (check_after && patch_match(first_guess, offset, fuzz)) { -#ifdef DEBUGGING - if (debug & 1) - say("Offset changing from %ld to %ld\n", - last_offset, offset); -#endif - last_offset = offset; - return first_guess + offset; - } else if (check_before && patch_match(first_guess, -offset, fuzz)) { -#ifdef DEBUGGING - if (debug & 1) - say("Offset changing from %ld to %ld\n", - last_offset, -offset); -#endif - last_offset = -offset; - return first_guess - offset; - } else if (!check_before && !check_after) - return 0; - } -} - -/* We did not find the pattern, dump out the hunk so they can handle it. */ - -static void -abort_hunk(void) -{ - LINENUM i; - const LINENUM pat_end = pch_end(); - /* - * add in last_offset to guess the same as the previous successful - * hunk - */ - const LINENUM oldfirst = pch_first() + last_offset; - const LINENUM newfirst = pch_newfirst() + last_offset; - const LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1; - const LINENUM newlast = newfirst + pch_repl_lines() - 1; - const char *stars = (diff_type >= NEW_CONTEXT_DIFF ? " ****" : ""); - const char *minuses = (diff_type >= NEW_CONTEXT_DIFF ? " ----" : " -----"); - - fprintf(rejfp, "***************\n"); - for (i = 0; i <= pat_end; i++) { - switch (pch_char(i)) { - case '*': - if (oldlast < oldfirst) - fprintf(rejfp, "*** 0%s\n", stars); - else if (oldlast == oldfirst) - fprintf(rejfp, "*** %ld%s\n", oldfirst, stars); - else - fprintf(rejfp, "*** %ld,%ld%s\n", oldfirst, - oldlast, stars); - break; - case '=': - if (newlast < newfirst) - fprintf(rejfp, "--- 0%s\n", minuses); - else if (newlast == newfirst) - fprintf(rejfp, "--- %ld%s\n", newfirst, minuses); - else - fprintf(rejfp, "--- %ld,%ld%s\n", newfirst, - newlast, minuses); - break; - case '\n': - fprintf(rejfp, "%s", pfetch(i)); - break; - case ' ': - case '-': - case '+': - case '!': - fprintf(rejfp, "%c %s", pch_char(i), pfetch(i)); - break; - default: - fatal("fatal internal error in abort_hunk\n"); - } - } -} - -/* We found where to apply it (we hope), so do it. */ - -static void -apply_hunk(LINENUM where) -{ - LINENUM old = 1; - const LINENUM lastline = pch_ptrn_lines(); - LINENUM new = lastline + 1; -#define OUTSIDE 0 -#define IN_IFNDEF 1 -#define IN_IFDEF 2 -#define IN_ELSE 3 - int def_state = OUTSIDE; - const LINENUM pat_end = pch_end(); - - where--; - while (pch_char(new) == '=' || pch_char(new) == '\n') - new++; - - while (old <= lastline) { - if (pch_char(old) == '-') { - copy_till(where + old - 1, false); - if (do_defines) { - if (def_state == OUTSIDE) { - fputs(not_defined, ofp); - def_state = IN_IFNDEF; - } else if (def_state == IN_IFDEF) { - fputs(else_defined, ofp); - def_state = IN_ELSE; - } - fputs(pfetch(old), ofp); - } - last_frozen_line++; - old++; - } else if (new > pat_end) { - break; - } else if (pch_char(new) == '+') { - copy_till(where + old - 1, false); - if (do_defines) { - if (def_state == IN_IFNDEF) { - fputs(else_defined, ofp); - def_state = IN_ELSE; - } else if (def_state == OUTSIDE) { - fputs(if_defined, ofp); - def_state = IN_IFDEF; - } - } - fputs(pfetch(new), ofp); - new++; - } else if (pch_char(new) != pch_char(old)) { - say("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n", - pch_hunk_beg() + old, - pch_hunk_beg() + new); -#ifdef DEBUGGING - say("oldchar = '%c', newchar = '%c'\n", - pch_char(old), pch_char(new)); -#endif - my_exit(2); - } else if (pch_char(new) == '!') { - copy_till(where + old - 1, false); - if (do_defines) { - fputs(not_defined, ofp); - def_state = IN_IFNDEF; - } - while (pch_char(old) == '!') { - if (do_defines) { - fputs(pfetch(old), ofp); - } - last_frozen_line++; - old++; - } - if (do_defines) { - fputs(else_defined, ofp); - def_state = IN_ELSE; - } - while (pch_char(new) == '!') { - fputs(pfetch(new), ofp); - new++; - } - } else { - if (pch_char(new) != ' ') - fatal("Internal error: expected ' '\n"); - old++; - new++; - if (do_defines && def_state != OUTSIDE) { - fputs(end_defined, ofp); - def_state = OUTSIDE; - } - } - } - if (new <= pat_end && pch_char(new) == '+') { - copy_till(where + old - 1, false); - if (do_defines) { - if (def_state == OUTSIDE) { - fputs(if_defined, ofp); - def_state = IN_IFDEF; - } else if (def_state == IN_IFNDEF) { - fputs(else_defined, ofp); - def_state = IN_ELSE; - } - } - while (new <= pat_end && pch_char(new) == '+') { - fputs(pfetch(new), ofp); - new++; - } - } - if (do_defines && def_state != OUTSIDE) { - fputs(end_defined, ofp); - } -} - -/* - * Open the new file. - */ -static void -init_output(const char *name) -{ - ofp = fopen(name, "w"); - if (ofp == NULL) - pfatal("can't create %s", name); -} - -/* - * Open a file to put hunks we can't locate. - */ -static void -init_reject(const char *name) -{ - rejfp = fopen(name, "w"); - if (rejfp == NULL) - pfatal("can't create %s", name); -} - -/* - * Copy input file to output, up to wherever hunk is to be applied. - * If endoffile is true, treat the last line specially since it may - * lack a newline. - */ -static void -copy_till(LINENUM lastline, bool endoffile) -{ - if (last_frozen_line > lastline) - fatal("misordered hunks! output would be garbled\n"); - while (last_frozen_line < lastline) { - if (++last_frozen_line == lastline && endoffile) - dump_line(last_frozen_line, !last_line_missing_eol); - else - dump_line(last_frozen_line, true); - } -} - -/* - * Finish copying the input file to the output file. - */ -static void -spew_output(void) -{ -#ifdef DEBUGGING - if (debug & 256) - say("il=%ld lfl=%ld\n", input_lines, last_frozen_line); -#endif - if (input_lines) - copy_till(input_lines, true); /* dump remainder of file */ - fclose(ofp); - ofp = NULL; -} - -/* - * Copy one line from input to output. - */ -static void -dump_line(LINENUM line, bool write_newline) -{ - char *s; - - s = ifetch(line, 0); - if (s == NULL) - return; - /* Note: string is not NUL terminated. */ - for (; *s != '\n'; s++) - putc(*s, ofp); - if (write_newline) - putc('\n', ofp); -} - -/* - * Does the patch pattern match at line base+offset? - */ -static bool -patch_match(LINENUM base, LINENUM offset, LINENUM fuzz) -{ - LINENUM pline = 1 + fuzz; - LINENUM iline; - LINENUM pat_lines = pch_ptrn_lines() - fuzz; - const char *ilineptr; - const char *plineptr; - short plinelen; - - for (iline = base + offset + fuzz; pline <= pat_lines; pline++, iline++) { - ilineptr = ifetch(iline, offset >= 0); - if (ilineptr == NULL) - return false; - plineptr = pfetch(pline); - plinelen = pch_line_len(pline); - if (canonicalize) { - if (!similar(ilineptr, plineptr, plinelen)) - return false; - } else if (strnNE(ilineptr, plineptr, plinelen)) - return false; - if (iline == input_lines) { - /* - * We are looking at the last line of the file. - * If the file has no eol, the patch line should - * not have one either and vice-versa. Note that - * plinelen > 0. - */ - if (last_line_missing_eol) { - if (plineptr[plinelen - 1] == '\n') - return false; - } else { - if (plineptr[plinelen - 1] != '\n') - return false; - } - } - } - return true; -} - -/* - * Do two lines match with canonicalized white space? - */ -static bool -similar(const char *a, const char *b, int len) -{ - while (len) { - if (isspace(*b)) { /* whitespace (or \n) to match? */ - if (!isspace(*a)) /* no corresponding whitespace? */ - return false; - while (len && isspace(*b) && *b != '\n') - b++, len--; /* skip pattern whitespace */ - while (isspace(*a) && *a != '\n') - a++; /* skip target whitespace */ - if (*a == '\n' || *b == '\n') - return (*a == *b); /* should end in sync */ - } else if (*a++ != *b++) /* match non-whitespace chars */ - return false; - else - len--; /* probably not necessary */ - } - return true; /* actually, this is not reached */ - /* since there is always a \n */ -} diff --git a/usr.bin/patch/pathnames.h b/usr.bin/patch/pathnames.h deleted file mode 100644 index 397e3fabe372..000000000000 --- a/usr.bin/patch/pathnames.h +++ /dev/null @@ -1,11 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.1 2003/07/29 20:10:17 millert Exp $ */ - -/* - * Placed in the public domain by Todd C. Miller <Todd.Miller@courtesan.com> - * on July 29, 2003. - */ - -#include <paths.h> - -#define _PATH_ED "/bin/ed" -#define _PATH_MKDIR "/bin/mkdir" diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c deleted file mode 100644 index bfdb17630100..000000000000 --- a/usr.bin/patch/pch.c +++ /dev/null @@ -1,1549 +0,0 @@ -/* $OpenBSD: pch.c,v 1.34 2004/07/09 19:13:46 otto Exp $ */ - -/* - * patch - a program to apply diffs to original files - * - * Copyright 1986, Larry Wall - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following condition is met: - * 1. Redistributions of source code must retain the above copyright notice, - * this condition and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * -C option added in 1998, original code by Marc Espie, based on FreeBSD - * behaviour - */ - -#ifndef lint -static const char rcsid[] = "$OpenBSD: pch.c,v 1.34 2004/07/09 19:13:46 otto Exp $"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/stat.h> - -#include <ctype.h> -#include <libgen.h> -#include <limits.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "common.h" -#include "util.h" -#include "pch.h" -#include "pathnames.h" - -/* Patch (diff listing) abstract type. */ - -static long p_filesize; /* size of the patch file */ -static LINENUM p_first; /* 1st line number */ -static LINENUM p_newfirst; /* 1st line number of replacement */ -static LINENUM p_ptrn_lines; /* # lines in pattern */ -static LINENUM p_repl_lines; /* # lines in replacement text */ -static LINENUM p_end = -1; /* last line in hunk */ -static LINENUM p_max; /* max allowed value of p_end */ -static LINENUM p_context = 3; /* # of context lines */ -static LINENUM p_input_line = 0; /* current line # from patch file */ -static char **p_line = NULL;/* the text of the hunk */ -static short *p_len = NULL; /* length of each line */ -static char *p_char = NULL; /* +, -, and ! */ -static int hunkmax = INITHUNKMAX; /* size of above arrays to begin with */ -static int p_indent; /* indent to patch */ -static LINENUM p_base; /* where to intuit this time */ -static LINENUM p_bline; /* line # of p_base */ -static LINENUM p_start; /* where intuit found a patch */ -static LINENUM p_sline; /* and the line number for it */ -static LINENUM p_hunk_beg; /* line number of current hunk */ -static LINENUM p_efake = -1; /* end of faked up lines--don't free */ -static LINENUM p_bfake = -1; /* beg of faked up lines */ -static FILE *pfp = NULL; /* patch file pointer */ -static char *bestguess = NULL; /* guess at correct filename */ - -static void grow_hunkmax(void); -static int intuit_diff_type(void); -static void next_intuit_at(LINENUM, LINENUM); -static void skip_to(LINENUM, LINENUM); -static char *pgets(char *, int, FILE *); -static char *best_name(const struct file_name *, bool); -static char *posix_name(const struct file_name *, bool); -static size_t num_components(const char *); - -/* - * Prepare to look for the next patch in the patch file. - */ -void -re_patch(void) -{ - p_first = 0; - p_newfirst = 0; - p_ptrn_lines = 0; - p_repl_lines = 0; - p_end = (LINENUM) - 1; - p_max = 0; - p_indent = 0; -} - -/* - * Open the patch file at the beginning of time. - */ -void -open_patch_file(const char *filename) -{ - struct stat filestat; - - if (filename == NULL || *filename == '\0' || strEQ(filename, "-")) { - pfp = fopen(TMPPATNAME, "w"); - if (pfp == NULL) - pfatal("can't create %s", TMPPATNAME); - while (fgets(buf, sizeof buf, stdin) != NULL) - fputs(buf, pfp); - fclose(pfp); - filename = TMPPATNAME; - } - pfp = fopen(filename, "r"); - if (pfp == NULL) - pfatal("patch file %s not found", filename); - fstat(fileno(pfp), &filestat); - p_filesize = filestat.st_size; - next_intuit_at(0L, 1L); /* start at the beginning */ - set_hunkmax(); -} - -/* - * Make sure our dynamically realloced tables are malloced to begin with. - */ -void -set_hunkmax(void) -{ - if (p_line == NULL) - p_line = malloc((size_t) hunkmax * sizeof(char *)); - if (p_len == NULL) - p_len = malloc((size_t) hunkmax * sizeof(short)); - if (p_char == NULL) - p_char = malloc((size_t) hunkmax * sizeof(char)); -} - -/* - * Enlarge the arrays containing the current hunk of patch. - */ -static void -grow_hunkmax(void) -{ - int new_hunkmax; - char **new_p_line; - short *new_p_len; - char *new_p_char; - - new_hunkmax = hunkmax * 2; - - if (p_line == NULL || p_len == NULL || p_char == NULL) - fatal("Internal memory allocation error\n"); - - new_p_line = realloc(p_line, new_hunkmax * sizeof(char *)); - if (new_p_line == NULL) - free(p_line); - - new_p_len = realloc(p_len, new_hunkmax * sizeof(short)); - if (new_p_len == NULL) - free(p_len); - - new_p_char = realloc(p_char, new_hunkmax * sizeof(char)); - if (new_p_char == NULL) - free(p_char); - - p_char = new_p_char; - p_len = new_p_len; - p_line = new_p_line; - - if (p_line != NULL && p_len != NULL && p_char != NULL) { - hunkmax = new_hunkmax; - return; - } - - if (!using_plan_a) - fatal("out of memory\n"); - out_of_mem = true; /* whatever is null will be allocated again */ - /* from within plan_a(), of all places */ -} - -/* True if the remainder of the patch file contains a diff of some sort. */ - -bool -there_is_another_patch(void) -{ - bool exists = false; - - if (p_base != 0L && p_base >= p_filesize) { - if (verbose) - say("done\n"); - return false; - } - if (verbose) - say("Hmm..."); - diff_type = intuit_diff_type(); - if (!diff_type) { - if (p_base != 0L) { - if (verbose) - say(" Ignoring the trailing garbage.\ndone\n"); - } else - say(" I can't seem to find a patch in there anywhere.\n"); - return false; - } - if (verbose) - say(" %sooks like %s to me...\n", - (p_base == 0L ? "L" : "The next patch l"), - diff_type == UNI_DIFF ? "a unified diff" : - diff_type == CONTEXT_DIFF ? "a context diff" : - diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" : - diff_type == NORMAL_DIFF ? "a normal diff" : - "an ed script"); - if (p_indent && verbose) - say("(Patch is indented %d space%s.)\n", p_indent, - p_indent == 1 ? "" : "s"); - skip_to(p_start, p_sline); - while (filearg[0] == NULL) { - if (force || batch) { - say("No file to patch. Skipping...\n"); - filearg[0] = savestr(bestguess); - skip_rest_of_patch = true; - return true; - } - ask("File to patch: "); - if (*buf != '\n') { - free(bestguess); - bestguess = savestr(buf); - filearg[0] = fetchname(buf, &exists, 0); - } - if (!exists) { - ask("No file found--skip this patch? [n] "); - if (*buf != 'y') - continue; - if (verbose) - say("Skipping patch...\n"); - free(filearg[0]); - filearg[0] = fetchname(bestguess, &exists, 0); - skip_rest_of_patch = true; - return true; - } - } - return true; -} - -/* Determine what kind of diff is in the remaining part of the patch file. */ - -static int -intuit_diff_type(void) -{ - long this_line = 0, previous_line; - long first_command_line = -1; - LINENUM fcl_line = -1; - bool last_line_was_command = false, this_is_a_command = false; - bool stars_last_line = false, stars_this_line = false; - char *s, *t; - int indent, retval; - struct file_name names[MAX_FILE]; - - memset(names, 0, sizeof(names)); - ok_to_create_file = false; - fseek(pfp, p_base, SEEK_SET); - p_input_line = p_bline - 1; - for (;;) { - previous_line = this_line; - last_line_was_command = this_is_a_command; - stars_last_line = stars_this_line; - this_line = ftell(pfp); - indent = 0; - p_input_line++; - if (fgets(buf, sizeof buf, pfp) == NULL) { - if (first_command_line >= 0L) { - /* nothing but deletes!? */ - p_start = first_command_line; - p_sline = fcl_line; - retval = ED_DIFF; - goto scan_exit; - } else { - p_start = this_line; - p_sline = p_input_line; - retval = 0; - goto scan_exit; - } - } - for (s = buf; *s == ' ' || *s == '\t' || *s == 'X'; s++) { - if (*s == '\t') - indent += 8 - (indent % 8); - else - indent++; - } - for (t = s; isdigit(*t) || *t == ','; t++) - ; - this_is_a_command = (isdigit(*s) && - (*t == 'd' || *t == 'c' || *t == 'a')); - if (first_command_line < 0L && this_is_a_command) { - first_command_line = this_line; - fcl_line = p_input_line; - p_indent = indent; /* assume this for now */ - } - if (!stars_last_line && strnEQ(s, "*** ", 4)) - names[OLD_FILE].path = fetchname(s + 4, - &names[OLD_FILE].exists, strippath); - else if (strnEQ(s, "--- ", 4)) - names[NEW_FILE].path = fetchname(s + 4, - &names[NEW_FILE].exists, strippath); - else if (strnEQ(s, "+++ ", 4)) - /* pretend it is the old name */ - names[OLD_FILE].path = fetchname(s + 4, - &names[OLD_FILE].exists, strippath); - else if (strnEQ(s, "Index:", 6)) - names[INDEX_FILE].path = fetchname(s + 6, - &names[INDEX_FILE].exists, strippath); - else if (strnEQ(s, "Prereq:", 7)) { - for (t = s + 7; isspace(*t); t++) - ; - revision = savestr(t); - for (t = revision; *t && !isspace(*t); t++) - ; - *t = '\0'; - if (*revision == '\0') { - free(revision); - revision = NULL; - } - } - if ((!diff_type || diff_type == ED_DIFF) && - first_command_line >= 0L && - strEQ(s, ".\n")) { - p_indent = indent; - p_start = first_command_line; - p_sline = fcl_line; - retval = ED_DIFF; - goto scan_exit; - } - if ((!diff_type || diff_type == UNI_DIFF) && strnEQ(s, "@@ -", 4)) { - if (strnEQ(s + 4, "0,0", 3)) - ok_to_create_file = true; - p_indent = indent; - p_start = this_line; - p_sline = p_input_line; - retval = UNI_DIFF; - goto scan_exit; - } - stars_this_line = strnEQ(s, "********", 8); - if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line && - strnEQ(s, "*** ", 4)) { - if (atol(s + 4) == 0) - ok_to_create_file = true; - /* - * If this is a new context diff the character just - * before the newline is a '*'. - */ - while (*s != '\n') - s++; - p_indent = indent; - p_start = previous_line; - p_sline = p_input_line - 1; - retval = (*(s - 1) == '*' ? NEW_CONTEXT_DIFF : CONTEXT_DIFF); - goto scan_exit; - } - if ((!diff_type || diff_type == NORMAL_DIFF) && - last_line_was_command && - (strnEQ(s, "< ", 2) || strnEQ(s, "> ", 2))) { - p_start = previous_line; - p_sline = p_input_line - 1; - p_indent = indent; - retval = NORMAL_DIFF; - goto scan_exit; - } - } -scan_exit: - if (retval == UNI_DIFF) { - /* unswap old and new */ - struct file_name tmp = names[OLD_FILE]; - names[OLD_FILE] = names[NEW_FILE]; - names[NEW_FILE] = tmp; - } - if (filearg[0] == NULL) { - if (posix) - filearg[0] = posix_name(names, ok_to_create_file); - else { - /* Ignore the Index: name for context diffs, like GNU */ - if (names[OLD_FILE].path != NULL || - names[NEW_FILE].path != NULL) { - free(names[INDEX_FILE].path); - names[INDEX_FILE].path = NULL; - } - filearg[0] = best_name(names, ok_to_create_file); - } - } - - free(bestguess); - bestguess = NULL; - if (filearg[0] != NULL) - bestguess = savestr(filearg[0]); - else if (!ok_to_create_file) { - /* - * We don't want to create a new file but we need a - * filename to set bestguess. Avoid setting filearg[0] - * so the file is not created automatically. - */ - if (posix) - bestguess = posix_name(names, true); - else - bestguess = best_name(names, true); - } - free(names[OLD_FILE].path); - free(names[NEW_FILE].path); - free(names[INDEX_FILE].path); - return retval; -} - -/* - * Remember where this patch ends so we know where to start up again. - */ -static void -next_intuit_at(LINENUM file_pos, LINENUM file_line) -{ - p_base = file_pos; - p_bline = file_line; -} - -/* - * Basically a verbose fseek() to the actual diff listing. - */ -static void -skip_to(LINENUM file_pos, LINENUM file_line) -{ - char *ret; - - if (p_base > file_pos) - fatal("Internal error: seek %ld>%ld\n", p_base, file_pos); - if (verbose && p_base < file_pos) { - fseek(pfp, p_base, SEEK_SET); - say("The text leading up to this was:\n--------------------------\n"); - while (ftell(pfp) < file_pos) { - ret = fgets(buf, sizeof buf, pfp); - if (ret == NULL) - fatal("Unexpected end of file\n"); - say("|%s", buf); - } - say("--------------------------\n"); - } else - fseek(pfp, file_pos, SEEK_SET); - p_input_line = file_line - 1; -} - -/* Make this a function for better debugging. */ -static void -malformed(void) -{ - fatal("malformed patch at line %ld: %s", p_input_line, buf); - /* about as informative as "Syntax error" in C */ -} - -/* - * True if the line has been discarded (i.e. it is a line saying - * "\ No newline at end of file".) - */ -static bool -remove_special_line(void) -{ - int c; - - c = fgetc(pfp); - if (c == '\\') { - do { - c = fgetc(pfp); - } while (c != EOF && c != '\n'); - - return true; - } - if (c != EOF) - fseek(pfp, -1L, SEEK_CUR); - - return false; -} - -/* - * True if there is more of the current diff listing to process. - */ -bool -another_hunk(void) -{ - long line_beginning; /* file pos of the current line */ - LINENUM repl_beginning; /* index of --- line */ - LINENUM fillcnt; /* #lines of missing ptrn or repl */ - LINENUM fillsrc; /* index of first line to copy */ - LINENUM filldst; /* index of first missing line */ - bool ptrn_spaces_eaten; /* ptrn was slightly misformed */ - bool repl_could_be_missing; /* no + or ! lines in this hunk */ - bool repl_missing; /* we are now backtracking */ - long repl_backtrack_position; /* file pos of first repl line */ - LINENUM repl_patch_line; /* input line number for same */ - LINENUM ptrn_copiable; /* # of copiable lines in ptrn */ - char *s, *ret; - int context = 0; - - while (p_end >= 0) { - if (p_end == p_efake) - p_end = p_bfake; /* don't free twice */ - else - free(p_line[p_end]); - p_end--; - } - p_efake = -1; - - p_max = hunkmax; /* gets reduced when --- found */ - if (diff_type == CONTEXT_DIFF || diff_type == NEW_CONTEXT_DIFF) { - line_beginning = ftell(pfp); - repl_beginning = 0; - fillcnt = 0; - ptrn_spaces_eaten = false; - repl_could_be_missing = true; - repl_missing = false; - repl_backtrack_position = 0; - ptrn_copiable = 0; - - ret = pgets(buf, sizeof buf, pfp); - p_input_line++; - if (ret == NULL || strnNE(buf, "********", 8)) { - next_intuit_at(line_beginning, p_input_line); - return false; - } - p_context = 100; - p_hunk_beg = p_input_line + 1; - while (p_end < p_max) { - line_beginning = ftell(pfp); - ret = pgets(buf, sizeof buf, pfp); - p_input_line++; - if (ret == NULL) { - if (p_max - p_end < 4) { - /* assume blank lines got chopped */ - strlcpy(buf, " \n", sizeof buf); - } else { - if (repl_beginning && repl_could_be_missing) { - repl_missing = true; - goto hunk_done; - } - fatal("unexpected end of file in patch\n"); - } - } - p_end++; - if (p_end >= hunkmax) - fatal("Internal error: hunk larger than hunk " - "buffer size"); - p_char[p_end] = *buf; - p_line[p_end] = NULL; - switch (*buf) { - case '*': - if (strnEQ(buf, "********", 8)) { - if (repl_beginning && repl_could_be_missing) { - repl_missing = true; - goto hunk_done; - } else - fatal("unexpected end of hunk " - "at line %ld\n", - p_input_line); - } - if (p_end != 0) { - if (repl_beginning && repl_could_be_missing) { - repl_missing = true; - goto hunk_done; - } - fatal("unexpected *** at line %ld: %s", - p_input_line, buf); - } - context = 0; - p_line[p_end] = savestr(buf); - if (out_of_mem) { - p_end--; - return false; - } - for (s = buf; *s && !isdigit(*s); s++) - ; - if (!*s) - malformed(); - if (strnEQ(s, "0,0", 3)) - memmove(s, s + 2, strlen(s + 2) + 1); - p_first = (LINENUM) atol(s); - while (isdigit(*s)) - s++; - if (*s == ',') { - for (; *s && !isdigit(*s); s++) - ; - if (!*s) - malformed(); - p_ptrn_lines = ((LINENUM) atol(s)) - p_first + 1; - } else if (p_first) - p_ptrn_lines = 1; - else { - p_ptrn_lines = 0; - p_first = 1; - } - - /* we need this much at least */ - p_max = p_ptrn_lines + 6; - while (p_max >= hunkmax) - grow_hunkmax(); - p_max = hunkmax; - break; - case '-': - if (buf[1] == '-') { - if (repl_beginning || - (p_end != p_ptrn_lines + 1 + - (p_char[p_end - 1] == '\n'))) { - if (p_end == 1) { - /* - * `old' lines were omitted; - * set up to fill them in - * from 'new' context lines. - */ - p_end = p_ptrn_lines + 1; - fillsrc = p_end + 1; - filldst = 1; - fillcnt = p_ptrn_lines; - } else { - if (repl_beginning) { - if (repl_could_be_missing) { - repl_missing = true; - goto hunk_done; - } - fatal("duplicate \"---\" at line %ld--check line numbers at line %ld\n", - p_input_line, p_hunk_beg + repl_beginning); - } else { - fatal("%s \"---\" at line %ld--check line numbers at line %ld\n", - (p_end <= p_ptrn_lines - ? "Premature" - : "Overdue"), - p_input_line, p_hunk_beg); - } - } - } - repl_beginning = p_end; - repl_backtrack_position = ftell(pfp); - repl_patch_line = p_input_line; - p_line[p_end] = savestr(buf); - if (out_of_mem) { - p_end--; - return false; - } - p_char[p_end] = '='; - for (s = buf; *s && !isdigit(*s); s++) - ; - if (!*s) - malformed(); - p_newfirst = (LINENUM) atol(s); - while (isdigit(*s)) - s++; - if (*s == ',') { - for (; *s && !isdigit(*s); s++) - ; - if (!*s) - malformed(); - p_repl_lines = ((LINENUM) atol(s)) - - p_newfirst + 1; - } else if (p_newfirst) - p_repl_lines = 1; - else { - p_repl_lines = 0; - p_newfirst = 1; - } - p_max = p_repl_lines + p_end; - if (p_max > MAXHUNKSIZE) - fatal("hunk too large (%ld lines) at line %ld: %s", - p_max, p_input_line, buf); - while (p_max >= hunkmax) - grow_hunkmax(); - if (p_repl_lines != ptrn_copiable && - (p_context != 0 || p_repl_lines != 1)) - repl_could_be_missing = false; - break; - } - goto change_line; - case '+': - case '!': - repl_could_be_missing = false; - change_line: - if (buf[1] == '\n' && canonicalize) - strlcpy(buf + 1, " \n", sizeof buf - 1); - if (!isspace(buf[1]) && buf[1] != '>' && - buf[1] != '<' && - repl_beginning && repl_could_be_missing) { - repl_missing = true; - goto hunk_done; - } - if (context >= 0) { - if (context < p_context) - p_context = context; - context = -1000; - } - p_line[p_end] = savestr(buf + 2); - if (out_of_mem) { - p_end--; - return false; - } - if (p_end == p_ptrn_lines) { - if (remove_special_line()) { - int len; - - len = strlen(p_line[p_end]) - 1; - (p_line[p_end])[len] = 0; - } - } - break; - case '\t': - case '\n': /* assume the 2 spaces got eaten */ - if (repl_beginning && repl_could_be_missing && - (!ptrn_spaces_eaten || - diff_type == NEW_CONTEXT_DIFF)) { - repl_missing = true; - goto hunk_done; - } - p_line[p_end] = savestr(buf); - if (out_of_mem) { - p_end--; - return false; - } - if (p_end != p_ptrn_lines + 1) { - ptrn_spaces_eaten |= (repl_beginning != 0); - context++; - if (!repl_beginning) - ptrn_copiable++; - p_char[p_end] = ' '; - } - break; - case ' ': - if (!isspace(buf[1]) && - repl_beginning && repl_could_be_missing) { - repl_missing = true; - goto hunk_done; - } - context++; - if (!repl_beginning) - ptrn_copiable++; - p_line[p_end] = savestr(buf + 2); - if (out_of_mem) { - p_end--; - return false; - } - break; - default: - if (repl_beginning && repl_could_be_missing) { - repl_missing = true; - goto hunk_done; - } - malformed(); - } - /* set up p_len for strncmp() so we don't have to */ - /* assume null termination */ - if (p_line[p_end]) - p_len[p_end] = strlen(p_line[p_end]); - else - p_len[p_end] = 0; - } - -hunk_done: - if (p_end >= 0 && !repl_beginning) - fatal("no --- found in patch at line %ld\n", pch_hunk_beg()); - - if (repl_missing) { - - /* reset state back to just after --- */ - p_input_line = repl_patch_line; - for (p_end--; p_end > repl_beginning; p_end--) - free(p_line[p_end]); - fseek(pfp, repl_backtrack_position, SEEK_SET); - - /* redundant 'new' context lines were omitted - set */ - /* up to fill them in from the old file context */ - if (!p_context && p_repl_lines == 1) { - p_repl_lines = 0; - p_max--; - } - fillsrc = 1; - filldst = repl_beginning + 1; - fillcnt = p_repl_lines; - p_end = p_max; - } else if (!p_context && fillcnt == 1) { - /* the first hunk was a null hunk with no context */ - /* and we were expecting one line -- fix it up. */ - while (filldst < p_end) { - p_line[filldst] = p_line[filldst + 1]; - p_char[filldst] = p_char[filldst + 1]; - p_len[filldst] = p_len[filldst + 1]; - filldst++; - } -#if 0 - repl_beginning--; /* this doesn't need to be fixed */ -#endif - p_end--; - p_first++; /* do append rather than insert */ - fillcnt = 0; - p_ptrn_lines = 0; - } - if (diff_type == CONTEXT_DIFF && - (fillcnt || (p_first > 1 && ptrn_copiable > 2 * p_context))) { - if (verbose) - say("%s\n%s\n%s\n", - "(Fascinating--this is really a new-style context diff but without", - "the telltale extra asterisks on the *** line that usually indicate", - "the new style...)"); - diff_type = NEW_CONTEXT_DIFF; - } - /* if there were omitted context lines, fill them in now */ - if (fillcnt) { - p_bfake = filldst; /* remember where not to free() */ - p_efake = filldst + fillcnt - 1; - while (fillcnt-- > 0) { - while (fillsrc <= p_end && p_char[fillsrc] != ' ') - fillsrc++; - if (fillsrc > p_end) - fatal("replacement text or line numbers mangled in hunk at line %ld\n", - p_hunk_beg); - p_line[filldst] = p_line[fillsrc]; - p_char[filldst] = p_char[fillsrc]; - p_len[filldst] = p_len[fillsrc]; - fillsrc++; - filldst++; - } - while (fillsrc <= p_end && fillsrc != repl_beginning && - p_char[fillsrc] != ' ') - fillsrc++; -#ifdef DEBUGGING - if (debug & 64) - printf("fillsrc %ld, filldst %ld, rb %ld, e+1 %ld\n", - fillsrc, filldst, repl_beginning, p_end + 1); -#endif - if (fillsrc != p_end + 1 && fillsrc != repl_beginning) - malformed(); - if (filldst != p_end + 1 && filldst != repl_beginning) - malformed(); - } - if (p_line[p_end] != NULL) { - if (remove_special_line()) { - p_len[p_end] -= 1; - (p_line[p_end])[p_len[p_end]] = 0; - } - } - } else if (diff_type == UNI_DIFF) { - long line_beginning = ftell(pfp); /* file pos of the current line */ - LINENUM fillsrc; /* index of old lines */ - LINENUM filldst; /* index of new lines */ - char ch; - - ret = pgets(buf, sizeof buf, pfp); - p_input_line++; - if (ret == NULL || strnNE(buf, "@@ -", 4)) { - next_intuit_at(line_beginning, p_input_line); - return false; - } - s = buf + 4; - if (!*s) - malformed(); - p_first = (LINENUM) atol(s); - while (isdigit(*s)) - s++; - if (*s == ',') { - p_ptrn_lines = (LINENUM) atol(++s); - while (isdigit(*s)) - s++; - } else - p_ptrn_lines = 1; - if (*s == ' ') - s++; - if (*s != '+' || !*++s) - malformed(); - p_newfirst = (LINENUM) atol(s); - while (isdigit(*s)) - s++; - if (*s == ',') { - p_repl_lines = (LINENUM) atol(++s); - while (isdigit(*s)) - s++; - } else - p_repl_lines = 1; - if (*s == ' ') - s++; - if (*s != '@') - malformed(); - if (!p_ptrn_lines) - p_first++; /* do append rather than insert */ - p_max = p_ptrn_lines + p_repl_lines + 1; - while (p_max >= hunkmax) - grow_hunkmax(); - fillsrc = 1; - filldst = fillsrc + p_ptrn_lines; - p_end = filldst + p_repl_lines; - snprintf(buf, sizeof buf, "*** %ld,%ld ****\n", p_first, - p_first + p_ptrn_lines - 1); - p_line[0] = savestr(buf); - if (out_of_mem) { - p_end = -1; - return false; - } - p_char[0] = '*'; - snprintf(buf, sizeof buf, "--- %ld,%ld ----\n", p_newfirst, - p_newfirst + p_repl_lines - 1); - p_line[filldst] = savestr(buf); - if (out_of_mem) { - p_end = 0; - return false; - } - p_char[filldst++] = '='; - p_context = 100; - context = 0; - p_hunk_beg = p_input_line + 1; - while (fillsrc <= p_ptrn_lines || filldst <= p_end) { - line_beginning = ftell(pfp); - ret = pgets(buf, sizeof buf, pfp); - p_input_line++; - if (ret == NULL) { - if (p_max - filldst < 3) { - /* assume blank lines got chopped */ - strlcpy(buf, " \n", sizeof buf); - } else { - fatal("unexpected end of file in patch\n"); - } - } - if (*buf == '\t' || *buf == '\n') { - ch = ' '; /* assume the space got eaten */ - s = savestr(buf); - } else { - ch = *buf; - s = savestr(buf + 1); - } - if (out_of_mem) { - while (--filldst > p_ptrn_lines) - free(p_line[filldst]); - p_end = fillsrc - 1; - return false; - } - switch (ch) { - case '-': - if (fillsrc > p_ptrn_lines) { - free(s); - p_end = filldst - 1; - malformed(); - } - p_char[fillsrc] = ch; - p_line[fillsrc] = s; - p_len[fillsrc++] = strlen(s); - if (fillsrc > p_ptrn_lines) { - if (remove_special_line()) { - p_len[fillsrc - 1] -= 1; - s[p_len[fillsrc - 1]] = 0; - } - } - break; - case '=': - ch = ' '; - /* FALL THROUGH */ - case ' ': - if (fillsrc > p_ptrn_lines) { - free(s); - while (--filldst > p_ptrn_lines) - free(p_line[filldst]); - p_end = fillsrc - 1; - malformed(); - } - context++; - p_char[fillsrc] = ch; - p_line[fillsrc] = s; - p_len[fillsrc++] = strlen(s); - s = savestr(s); - if (out_of_mem) { - while (--filldst > p_ptrn_lines) - free(p_line[filldst]); - p_end = fillsrc - 1; - return false; - } - if (fillsrc > p_ptrn_lines) { - if (remove_special_line()) { - p_len[fillsrc - 1] -= 1; - s[p_len[fillsrc - 1]] = 0; - } - } - /* FALL THROUGH */ - case '+': - if (filldst > p_end) { - free(s); - while (--filldst > p_ptrn_lines) - free(p_line[filldst]); - p_end = fillsrc - 1; - malformed(); - } - p_char[filldst] = ch; - p_line[filldst] = s; - p_len[filldst++] = strlen(s); - if (fillsrc > p_ptrn_lines) { - if (remove_special_line()) { - p_len[filldst - 1] -= 1; - s[p_len[filldst - 1]] = 0; - } - } - break; - default: - p_end = filldst; - malformed(); - } - if (ch != ' ' && context > 0) { - if (context < p_context) - p_context = context; - context = -1000; - } - } /* while */ - } else { /* normal diff--fake it up */ - char hunk_type; - int i; - LINENUM min, max; - long line_beginning = ftell(pfp); - - p_context = 0; - ret = pgets(buf, sizeof buf, pfp); - p_input_line++; - if (ret == NULL || !isdigit(*buf)) { - next_intuit_at(line_beginning, p_input_line); - return false; - } - p_first = (LINENUM) atol(buf); - for (s = buf; isdigit(*s); s++) - ; - if (*s == ',') { - p_ptrn_lines = (LINENUM) atol(++s) - p_first + 1; - while (isdigit(*s)) - s++; - } else - p_ptrn_lines = (*s != 'a'); - hunk_type = *s; - if (hunk_type == 'a') - p_first++; /* do append rather than insert */ - min = (LINENUM) atol(++s); - for (; isdigit(*s); s++) - ; - if (*s == ',') - max = (LINENUM) atol(++s); - else - max = min; - if (hunk_type == 'd') - min++; - p_end = p_ptrn_lines + 1 + max - min + 1; - if (p_end > MAXHUNKSIZE) - fatal("hunk too large (%ld lines) at line %ld: %s", - p_end, p_input_line, buf); - while (p_end >= hunkmax) - grow_hunkmax(); - p_newfirst = min; - p_repl_lines = max - min + 1; - snprintf(buf, sizeof buf, "*** %ld,%ld\n", p_first, - p_first + p_ptrn_lines - 1); - p_line[0] = savestr(buf); - if (out_of_mem) { - p_end = -1; - return false; - } - p_char[0] = '*'; - for (i = 1; i <= p_ptrn_lines; i++) { - ret = pgets(buf, sizeof buf, pfp); - p_input_line++; - if (ret == NULL) - fatal("unexpected end of file in patch at line %ld\n", - p_input_line); - if (*buf != '<') - fatal("< expected at line %ld of patch\n", - p_input_line); - p_line[i] = savestr(buf + 2); - if (out_of_mem) { - p_end = i - 1; - return false; - } - p_len[i] = strlen(p_line[i]); - p_char[i] = '-'; - } - - if (remove_special_line()) { - p_len[i - 1] -= 1; - (p_line[i - 1])[p_len[i - 1]] = 0; - } - if (hunk_type == 'c') { - ret = pgets(buf, sizeof buf, pfp); - p_input_line++; - if (ret == NULL) - fatal("unexpected end of file in patch at line %ld\n", - p_input_line); - if (*buf != '-') - fatal("--- expected at line %ld of patch\n", - p_input_line); - } - snprintf(buf, sizeof(buf), "--- %ld,%ld\n", min, max); - p_line[i] = savestr(buf); - if (out_of_mem) { - p_end = i - 1; - return false; - } - p_char[i] = '='; - for (i++; i <= p_end; i++) { - ret = pgets(buf, sizeof buf, pfp); - p_input_line++; - if (ret == NULL) - fatal("unexpected end of file in patch at line %ld\n", - p_input_line); - if (*buf != '>') - fatal("> expected at line %ld of patch\n", - p_input_line); - p_line[i] = savestr(buf + 2); - if (out_of_mem) { - p_end = i - 1; - return false; - } - p_len[i] = strlen(p_line[i]); - p_char[i] = '+'; - } - - if (remove_special_line()) { - p_len[i - 1] -= 1; - (p_line[i - 1])[p_len[i - 1]] = 0; - } - } - if (reverse) /* backwards patch? */ - if (!pch_swap()) - say("Not enough memory to swap next hunk!\n"); -#ifdef DEBUGGING - if (debug & 2) { - int i; - char special; - - for (i = 0; i <= p_end; i++) { - if (i == p_ptrn_lines) - special = '^'; - else - special = ' '; - fprintf(stderr, "%3d %c %c %s", i, p_char[i], - special, p_line[i]); - fflush(stderr); - } - } -#endif - if (p_end + 1 < hunkmax)/* paranoia reigns supreme... */ - p_char[p_end + 1] = '^'; /* add a stopper for apply_hunk */ - return true; -} - -/* - * Input a line from the patch file, worrying about indentation. - */ -static char * -pgets(char *bf, int sz, FILE *fp) -{ - char *s, *ret = fgets(bf, sz, fp); - int indent = 0; - - if (p_indent && ret != NULL) { - for (s = buf; - indent < p_indent && (*s == ' ' || *s == '\t' || *s == 'X'); - s++) { - if (*s == '\t') - indent += 8 - (indent % 7); - else - indent++; - } - if (buf != s && strlcpy(buf, s, sizeof(buf)) >= sizeof(buf)) - fatal("buffer too small in pgets()\n"); - } - return ret; -} - -/* - * Reverse the old and new portions of the current hunk. - */ -bool -pch_swap(void) -{ - char **tp_line; /* the text of the hunk */ - short *tp_len; /* length of each line */ - char *tp_char; /* +, -, and ! */ - LINENUM i; - LINENUM n; - bool blankline = false; - char *s; - - i = p_first; - p_first = p_newfirst; - p_newfirst = i; - - /* make a scratch copy */ - - tp_line = p_line; - tp_len = p_len; - tp_char = p_char; - p_line = NULL; /* force set_hunkmax to allocate again */ - p_len = NULL; - p_char = NULL; - set_hunkmax(); - if (p_line == NULL || p_len == NULL || p_char == NULL) { - - free(p_line); - p_line = tp_line; - free(p_len); - p_len = tp_len; - free(p_char); - p_char = tp_char; - return false; /* not enough memory to swap hunk! */ - } - /* now turn the new into the old */ - - i = p_ptrn_lines + 1; - if (tp_char[i] == '\n') { /* account for possible blank line */ - blankline = true; - i++; - } - if (p_efake >= 0) { /* fix non-freeable ptr range */ - if (p_efake <= i) - n = p_end - i + 1; - else - n = -i; - p_efake += n; - p_bfake += n; - } - for (n = 0; i <= p_end; i++, n++) { - p_line[n] = tp_line[i]; - p_char[n] = tp_char[i]; - if (p_char[n] == '+') - p_char[n] = '-'; - p_len[n] = tp_len[i]; - } - if (blankline) { - i = p_ptrn_lines + 1; - p_line[n] = tp_line[i]; - p_char[n] = tp_char[i]; - p_len[n] = tp_len[i]; - n++; - } - if (p_char[0] != '=') - fatal("Malformed patch at line %ld: expected '=' found '%c'\n", - p_input_line, p_char[0]); - p_char[0] = '*'; - for (s = p_line[0]; *s; s++) - if (*s == '-') - *s = '*'; - - /* now turn the old into the new */ - - if (p_char[0] != '*') - fatal("Malformed patch at line %ld: expected '*' found '%c'\n", - p_input_line, p_char[0]); - tp_char[0] = '='; - for (s = tp_line[0]; *s; s++) - if (*s == '*') - *s = '-'; - for (i = 0; n <= p_end; i++, n++) { - p_line[n] = tp_line[i]; - p_char[n] = tp_char[i]; - if (p_char[n] == '-') - p_char[n] = '+'; - p_len[n] = tp_len[i]; - } - - if (i != p_ptrn_lines + 1) - fatal("Malformed patch at line %ld: expected %ld lines, " - "got %ld\n", - p_input_line, p_ptrn_lines + 1, i); - - i = p_ptrn_lines; - p_ptrn_lines = p_repl_lines; - p_repl_lines = i; - - free(tp_line); - free(tp_len); - free(tp_char); - - return true; -} - -/* - * Return the specified line position in the old file of the old context. - */ -LINENUM -pch_first(void) -{ - return p_first; -} - -/* - * Return the number of lines of old context. - */ -LINENUM -pch_ptrn_lines(void) -{ - return p_ptrn_lines; -} - -/* - * Return the probable line position in the new file of the first line. - */ -LINENUM -pch_newfirst(void) -{ - return p_newfirst; -} - -/* - * Return the number of lines in the replacement text including context. - */ -LINENUM -pch_repl_lines(void) -{ - return p_repl_lines; -} - -/* - * Return the number of lines in the whole hunk. - */ -LINENUM -pch_end(void) -{ - return p_end; -} - -/* - * Return the number of context lines before the first changed line. - */ -LINENUM -pch_context(void) -{ - return p_context; -} - -/* - * Return the length of a particular patch line. - */ -short -pch_line_len(LINENUM line) -{ - return p_len[line]; -} - -/* - * Return the control character (+, -, *, !, etc) for a patch line. - */ -char -pch_char(LINENUM line) -{ - return p_char[line]; -} - -/* - * Return a pointer to a particular patch line. - */ -char * -pfetch(LINENUM line) -{ - return p_line[line]; -} - -/* - * Return where in the patch file this hunk began, for error messages. - */ -LINENUM -pch_hunk_beg(void) -{ - return p_hunk_beg; -} - -/* - * Apply an ed script by feeding ed itself. - */ -void -do_ed_script(void) -{ - char *t; - long beginning_of_this_line; - FILE *pipefp; - - pipefp = NULL; - if (!skip_rest_of_patch) { - if (copy_file(filearg[0], TMPOUTNAME) < 0) { - unlink(TMPOUTNAME); - fatal("can't create temp file %s", TMPOUTNAME); - } - snprintf(buf, sizeof buf, "%s%s%s", _PATH_ED, - verbose ? " " : " -s ", TMPOUTNAME); - pipefp = popen(buf, "w"); - } - for (;;) { - beginning_of_this_line = ftell(pfp); - if (pgets(buf, sizeof buf, pfp) == NULL) { - next_intuit_at(beginning_of_this_line, p_input_line); - break; - } - p_input_line++; - for (t = buf; isdigit(*t) || *t == ','; t++) - ; - /* POSIX defines allowed commands as {a,c,d,i,s} */ - if (isdigit(*buf) && (*t == 'a' || *t == 'c' || *t == 'd' || - *t == 'i' || *t == 's')) { - if (pipefp != NULL) - fputs(buf, pipefp); - if (*t != 'd') { - while (pgets(buf, sizeof buf, pfp) != NULL) { - p_input_line++; - if (pipefp != NULL) - fputs(buf, pipefp); - if (strEQ(buf, ".\n")) - break; - } - } - } else { - next_intuit_at(beginning_of_this_line, p_input_line); - break; - } - } - if (pipefp == NULL) - return; - fprintf(pipefp, "w\n"); - fprintf(pipefp, "q\n"); - fflush(pipefp); - pclose(pipefp); - ignore_signals(); - if (!check_only) { - if (move_file(TMPOUTNAME, outname) < 0) { - toutkeep = true; - chmod(TMPOUTNAME, filemode); - } else - chmod(outname, filemode); - } - set_signals(1); -} - -/* - * Choose the name of the file to be patched based on POSIX rules. - * NOTE: the POSIX rules are amazingly stupid and we only follow them - * if the user specified --posix or set POSIXLY_CORRECT. - */ -static char * -posix_name(const struct file_name *names, bool assume_exists) -{ - char *path = NULL; - int i; - - /* - * POSIX states that the filename will be chosen from one - * of the old, new and index names (in that order) if - * the file exists relative to CWD after -p stripping. - */ - for (i = 0; i < MAX_FILE; i++) { - if (names[i].path != NULL && names[i].exists) { - path = names[i].path; - break; - } - } - if (path == NULL && !assume_exists) { - /* - * No files found, look for something we can checkout from - * RCS/SCCS dirs. Same order as above. - */ - for (i = 0; i < MAX_FILE; i++) { - if (names[i].path != NULL && - (path = checked_in(names[i].path)) != NULL) - break; - } - /* - * Still no match? Check to see if the diff could be creating - * a new file. - */ - if (path == NULL && ok_to_create_file && - names[NEW_FILE].path != NULL) - path = names[NEW_FILE].path; - } - - return path ? savestr(path) : NULL; -} - -/* - * Choose the name of the file to be patched based the "best" one - * available. - */ -static char * -best_name(const struct file_name *names, bool assume_exists) -{ - size_t min_components, min_baselen, min_len, tmp; - char *best = NULL; - int i; - - /* - * The "best" name is the one with the fewest number of path - * components, the shortest basename length, and the shortest - * overall length (in that order). We only use the Index: file - * if neither of the old or new files could be intuited from - * the diff header. - */ - min_components = min_baselen = min_len = SIZE_MAX; - for (i = INDEX_FILE; i >= OLD_FILE; i--) { - if (names[i].path == NULL || - (!names[i].exists && !assume_exists)) - continue; - if ((tmp = num_components(names[i].path)) > min_components) - continue; - min_components = tmp; - if ((tmp = strlen(basename(names[i].path))) > min_baselen) - continue; - min_baselen = tmp; - if ((tmp = strlen(names[i].path)) > min_len) - continue; - min_len = tmp; - best = names[i].path; - } - if (best == NULL) { - /* - * No files found, look for something we can checkout from - * RCS/SCCS dirs. Logic is identical to that above... - */ - min_components = min_baselen = min_len = SIZE_MAX; - for (i = INDEX_FILE; i >= OLD_FILE; i--) { - if (names[i].path == NULL || - checked_in(names[i].path) == NULL) - continue; - if ((tmp = num_components(names[i].path)) > min_components) - continue; - min_components = tmp; - if ((tmp = strlen(basename(names[i].path))) > min_baselen) - continue; - min_baselen = tmp; - if ((tmp = strlen(names[i].path)) > min_len) - continue; - min_len = tmp; - best = names[i].path; - } - /* - * Still no match? Check to see if the diff could be creating - * a new file. - */ - if (best == NULL && ok_to_create_file && - names[NEW_FILE].path != NULL) - best = names[NEW_FILE].path; - } - - return best ? savestr(best) : NULL; -} - -static size_t -num_components(const char *path) -{ - size_t n; - const char *cp; - - for (n = 0, cp = path; (cp = strchr(cp, '/')) != NULL; n++, cp++) { - while (*cp == '/') - cp++; /* skip consecutive slashes */ - } - return n; -} diff --git a/usr.bin/patch/pch.h b/usr.bin/patch/pch.h deleted file mode 100644 index b7bf8e8a224e..000000000000 --- a/usr.bin/patch/pch.h +++ /dev/null @@ -1,56 +0,0 @@ -/* $OpenBSD: pch.h,v 1.9 2003/10/31 20:20:45 millert Exp $ */ - -/* - * patch - a program to apply diffs to original files - * - * Copyright 1986, Larry Wall - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following condition is met: - * 1. Redistributions of source code must retain the above copyright notice, - * this condition and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * -C option added in 1998, original code by Marc Espie, based on FreeBSD - * behaviour - */ - -#define OLD_FILE 0 -#define NEW_FILE 1 -#define INDEX_FILE 2 -#define MAX_FILE 3 - -struct file_name { - char *path; - bool exists; -}; - -void re_patch(void); -void open_patch_file(const char *); -void set_hunkmax(void); -bool there_is_another_patch(void); -bool another_hunk(void); -bool pch_swap(void); -char *pfetch(LINENUM); -short pch_line_len(LINENUM); -LINENUM pch_first(void); -LINENUM pch_ptrn_lines(void); -LINENUM pch_newfirst(void); -LINENUM pch_repl_lines(void); -LINENUM pch_end(void); -LINENUM pch_context(void); -LINENUM pch_hunk_beg(void); -char pch_char(LINENUM); -char *pfetch(LINENUM); -void do_ed_script(void); diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c deleted file mode 100644 index 23a22b17078f..000000000000 --- a/usr.bin/patch/util.c +++ /dev/null @@ -1,425 +0,0 @@ -/* $OpenBSD: util.c,v 1.27 2003/10/31 20:20:45 millert Exp $ */ - -/* - * patch - a program to apply diffs to original files - * - * Copyright 1986, Larry Wall - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following condition is met: - * 1. Redistributions of source code must retain the above copyright notice, - * this condition and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * -C option added in 1998, original code by Marc Espie, based on FreeBSD - * behaviour - */ - -#ifndef lint -static const char rcsid[] = "$OpenBSD: util.c,v 1.27 2003/10/31 20:20:45 millert Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/stat.h> - -#include <ctype.h> -#include <errno.h> -#include <fcntl.h> -#include <libgen.h> -#include <paths.h> -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -#include "common.h" -#include "util.h" -#include "backupfile.h" -#include "pathnames.h" - - -/* Rename a file, copying it if necessary. */ - -int -move_file(const char *from, const char *to) -{ - int fromfd; - ssize_t i; - - /* to stdout? */ - - if (strEQ(to, "-")) { -#ifdef DEBUGGING - if (debug & 4) - say("Moving %s to stdout.\n", from); -#endif - fromfd = open(from, O_RDONLY); - if (fromfd < 0) - pfatal("internal error, can't reopen %s", from); - while ((i = read(fromfd, buf, sizeof buf)) > 0) - if (write(STDOUT_FILENO, buf, i) != i) - pfatal("write failed"); - close(fromfd); - return 0; - } - if (backup_file(to) < 0) { - say("Can't backup %s, output is in %s: %s\n", to, from, - strerror(errno)); - return -1; - } -#ifdef DEBUGGING - if (debug & 4) - say("Moving %s to %s.\n", from, to); -#endif - if (rename(from, to) < 0) { - if (errno != EXDEV || copy_file(from, to) < 0) { - say("Can't create %s, output is in %s: %s\n", - to, from, strerror(errno)); - return -1; - } - } - return 0; -} - -/* Backup the original file. */ - -int -backup_file(const char *orig) -{ - struct stat filestat; - char bakname[MAXPATHLEN], *s, *simplename; - dev_t orig_device; - ino_t orig_inode; - - if (backup_type == none || stat(orig, &filestat) != 0) - return 0; /* nothing to do */ - orig_device = filestat.st_dev; - orig_inode = filestat.st_ino; - - if (origprae) { - if (strlcpy(bakname, origprae, sizeof(bakname)) >= sizeof(bakname) || - strlcat(bakname, orig, sizeof(bakname)) >= sizeof(bakname)) - fatal("filename %s too long for buffer\n", origprae); - } else { - if ((s = find_backup_file_name(orig)) == NULL) - fatal("out of memory\n"); - if (strlcpy(bakname, s, sizeof(bakname)) >= sizeof(bakname)) - fatal("filename %s too long for buffer\n", s); - free(s); - } - - if ((simplename = strrchr(bakname, '/')) != NULL) - simplename = simplename + 1; - else - simplename = bakname; - - /* - * Find a backup name that is not the same file. Change the - * first lowercase char into uppercase; if that isn't - * sufficient, chop off the first char and try again. - */ - while (stat(bakname, &filestat) == 0 && - orig_device == filestat.st_dev && orig_inode == filestat.st_ino) { - /* Skip initial non-lowercase chars. */ - for (s = simplename; *s && !islower(*s); s++) - ; - if (*s) - *s = toupper(*s); - else - memmove(simplename, simplename + 1, - strlen(simplename + 1) + 1); - } -#ifdef DEBUGGING - if (debug & 4) - say("Moving %s to %s.\n", orig, bakname); -#endif - if (rename(orig, bakname) < 0) { - if (errno != EXDEV || copy_file(orig, bakname) < 0) - return -1; - } - return 0; -} - -/* - * Copy a file. - */ -int -copy_file(const char *from, const char *to) -{ - int tofd, fromfd; - ssize_t i; - - tofd = open(to, O_CREAT|O_TRUNC|O_WRONLY, 0666); - if (tofd < 0) - return -1; - fromfd = open(from, O_RDONLY, 0); - if (fromfd < 0) - pfatal("internal error, can't reopen %s", from); - while ((i = read(fromfd, buf, sizeof buf)) > 0) - if (write(tofd, buf, i) != i) - pfatal("write to %s failed", to); - close(fromfd); - close(tofd); - return 0; -} - -/* - * Allocate a unique area for a string. - */ -char * -savestr(const char *s) -{ - char *rv; - - if (!s) - s = "Oops"; - rv = strdup(s); - if (rv == NULL) { - if (using_plan_a) - out_of_mem = true; - else - fatal("out of memory\n"); - } - return rv; -} - -/* - * Vanilla terminal output (buffered). - */ -void -say(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fflush(stderr); -} - -/* - * Terminal output, pun intended. - */ -void -fatal(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - fprintf(stderr, "patch: **** "); - vfprintf(stderr, fmt, ap); - va_end(ap); - my_exit(2); -} - -/* - * Say something from patch, something from the system, then silence . . . - */ -void -pfatal(const char *fmt, ...) -{ - va_list ap; - int errnum = errno; - - fprintf(stderr, "patch: **** "); - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, ": %s\n", strerror(errnum)); - my_exit(2); -} - -/* - * Get a response from the user via /dev/tty - */ -void -ask(const char *fmt, ...) -{ - va_list ap; - ssize_t nr; - static int ttyfd = -1; - - va_start(ap, fmt); - vfprintf(stdout, fmt, ap); - va_end(ap); - fflush(stdout); - if (ttyfd < 0) - ttyfd = open(_PATH_TTY, O_RDONLY); - if (ttyfd >= 0) { - if ((nr = read(ttyfd, buf, sizeof(buf))) > 0 && - buf[nr - 1] == '\n') - buf[nr - 1] = '\0'; - } - if (ttyfd < 0 || nr <= 0) { - /* no tty or error reading, pretend user entered 'return' */ - putchar('\n'); - buf[0] = '\0'; - } -} - -/* - * How to handle certain events when not in a critical region. - */ -void -set_signals(int reset) -{ - static sig_t hupval, intval; - - if (!reset) { - hupval = signal(SIGHUP, SIG_IGN); - if (hupval != SIG_IGN) - hupval = (sig_t) my_exit; - intval = signal(SIGINT, SIG_IGN); - if (intval != SIG_IGN) - intval = (sig_t) my_exit; - } - signal(SIGHUP, hupval); - signal(SIGINT, intval); -} - -/* - * How to handle certain events when in a critical region. - */ -void -ignore_signals(void) -{ - signal(SIGHUP, SIG_IGN); - signal(SIGINT, SIG_IGN); -} - -/* - * Make sure we'll have the directories to create a file. If `striplast' is - * true, ignore the last element of `filename'. - */ - -void -makedirs(const char *filename, bool striplast) -{ - char *tmpbuf; - - if ((tmpbuf = strdup(filename)) == NULL) - fatal("out of memory\n"); - - if (striplast) { - char *s = strrchr(tmpbuf, '/'); - if (s == NULL) - return; /* nothing to be done */ - *s = '\0'; - } - if (snprintf(buf, sizeof(buf), "%s -p %s", _PATH_MKDIR, tmpbuf) - >= sizeof(buf)) - fatal("buffer too small to hold %.20s...\n", tmpbuf); - - if (system(buf)) - pfatal("%.40s failed", buf); -} - -/* - * Make filenames more reasonable. - */ -char * -fetchname(const char *at, bool *exists, int strip_leading) -{ - char *fullname, *name, *t; - int sleading; - struct stat filestat; - - if (at == NULL || *at == '\0') - return NULL; - while (isspace(*at)) - at++; -#ifdef DEBUGGING - if (debug & 128) - say("fetchname %s %d\n", at, strip_leading); -#endif - /* So files can be created by diffing against /dev/null. */ - if (strnEQ(at, _PATH_DEVNULL, sizeof(_PATH_DEVNULL) - 1)) - return NULL; - name = fullname = t = savestr(at); - - /* Strip off up to `strip_leading' path components and NUL terminate. */ - for (sleading = strip_leading; *t != '\0' && !isspace(*t); t++) { - if (t[0] == '/' && t[1] != '/' && t[1] != '\0') - if (--sleading >= 0) - name = t + 1; - } - *t = '\0'; - - /* - * If no -p option was given (957 is the default value!), we were - * given a relative pathname, and the leading directories that we - * just stripped off all exist, put them back on. - */ - if (strip_leading == 957 && name != fullname && *fullname != '/') { - name[-1] = '\0'; - if (stat(fullname, &filestat) == 0 && S_ISDIR(filestat.st_mode)) { - name[-1] = '/'; - name = fullname; - } - } - name = savestr(name); - free(fullname); - - *exists = stat(name, &filestat) == 0; - return name; -} - -/* - * Takes the name returned by fetchname and looks in RCS/SCCS directories - * for a checked in version. - */ -char * -checked_in(char *file) -{ - char *filebase, *filedir, tmpbuf[MAXPATHLEN]; - struct stat filestat; - - filebase = basename(file); - filedir = dirname(file); - -#define try(f, a1, a2, a3) \ -(snprintf(tmpbuf, sizeof tmpbuf, f, a1, a2, a3), stat(tmpbuf, &filestat) == 0) - - if (try("%s/RCS/%s%s", filedir, filebase, RCSSUFFIX) || - try("%s/RCS/%s%s", filedir, filebase, "") || - try("%s/%s%s", filedir, filebase, RCSSUFFIX) || - try("%s/SCCS/%s%s", filedir, SCCSPREFIX, filebase) || - try("%s/%s%s", filedir, SCCSPREFIX, filebase)) - return file; - - return NULL; -} - -void -version(void) -{ - fprintf(stderr, "Patch version 2.0-12u8-OpenBSD\n"); - my_exit(EXIT_SUCCESS); -} - -/* - * Exit with cleanup. - */ -void -my_exit(int status) -{ - unlink(TMPINNAME); - if (!toutkeep) - unlink(TMPOUTNAME); - if (!trejkeep) - unlink(TMPREJNAME); - unlink(TMPPATNAME); - exit(status); -} diff --git a/usr.bin/patch/util.h b/usr.bin/patch/util.h deleted file mode 100644 index 0ec187028b9b..000000000000 --- a/usr.bin/patch/util.h +++ /dev/null @@ -1,47 +0,0 @@ -/* $OpenBSD: util.h,v 1.12 2003/10/31 20:20:45 millert Exp $ */ - -/* - * patch - a program to apply diffs to original files - * - * Copyright 1986, Larry Wall - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following condition is met: - * 1. Redistributions of source code must retain the above copyright notice, - * this condition and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * -C option added in 1998, original code by Marc Espie, based on FreeBSD - * behaviour - */ - -char *fetchname(const char *, bool *, int); -char *checked_in(char *); -int backup_file(const char *); -int move_file(const char *, const char *); -int copy_file(const char *, const char *); -void say(const char *, ...) - __attribute__((__format__(__printf__, 1, 2))); -void fatal(const char *, ...) - __attribute__((__format__(__printf__, 1, 2))); -void pfatal(const char *, ...) - __attribute__((__format__(__printf__, 1, 2))); -void ask(const char *, ...) - __attribute__((__format__(__printf__, 1, 2))); -char *savestr(const char *); -void set_signals(int); -void ignore_signals(void); -void makedirs(const char *, bool); -void version(void); -void my_exit(int) __attribute__((noreturn)); diff --git a/usr.bin/tip/libacu/biz22.c b/usr.bin/tip/libacu/biz22.c deleted file mode 100644 index cd5ca4acfcc8..000000000000 --- a/usr.bin/tip/libacu/biz22.c +++ /dev/null @@ -1,195 +0,0 @@ -/* $OpenBSD: biz22.c,v 1.7 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: biz22.c,v 1.6 1997/02/11 09:24:11 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)biz22.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: biz22.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -#define DISCONNECT_CMD "\20\04" /* disconnection string */ - -static void sigALRM(); -static int timeout = 0; -static jmp_buf timeoutbuf; - -static int cmd(), detect(); -void biz22_disconnect(); - -/* - * Dial up on a BIZCOMP Model 1022 with either - * tone dialing (mod = "V") - * pulse dialing (mod = "W") - */ -static int -biz_dialer(num, mod) - char *num, *mod; -{ - int connected = 0; - char cbuf[40]; - - if (boolean(value(VERBOSE))) - printf("\nstarting call..."); - /* - * Disable auto-answer and configure for tone/pulse - * dialing - */ - if (cmd("\02K\r")) { - printf("can't initialize bizcomp..."); - return (0); - } - (void)strcpy(cbuf, "\02.\r"); - cbuf[1] = *mod; - if (cmd(cbuf)) { - printf("can't set dialing mode..."); - return (0); - } - (void)snprintf(cbuf, sizeof(cbuf), "\02D%s\r", num); - write(FD, cbuf, strlen(cbuf)); - if (!detect("7\r")) { - printf("can't get dial tone..."); - return (0); - } - if (boolean(value(VERBOSE))) - printf("ringing..."); - /* - * The reply from the BIZCOMP should be: - * 2 \r or 7 \r failure - * 1 \r success - */ - connected = detect("1\r"); -#ifdef ACULOG - if (timeout) { - char line[80]; - - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "biz1022", line); - } -#endif - if (timeout) - biz22_disconnect(); /* insurance */ - return (connected); -} - -int -biz22w_dialer(num, acu) - char *num, *acu; -{ - - return (biz_dialer(num, "W")); -} - -int -biz22f_dialer(num, acu) - char *num, *acu; -{ - - return (biz_dialer(num, "V")); -} - -void -biz22_disconnect() -{ - write(FD, DISCONNECT_CMD, 4); - sleep(2); - tcflush(FD, TCIOFLUSH); -} - -void -biz22_abort() -{ - - write(FD, "\02", 1); -} - -static void -sigALRM() -{ - - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int -cmd(s) - char *s; -{ - sig_t f; - char c; - - write(FD, s, strlen(s)); - f = signal(SIGALRM, sigALRM); - if (setjmp(timeoutbuf)) { - biz22_abort(); - signal(SIGALRM, f); - return (1); - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - signal(SIGALRM, f); - c &= 0177; - return (c != '\r'); -} - -static int -detect(s) - char *s; -{ - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - timeout = 0; - while (*s) { - if (setjmp(timeoutbuf)) { - biz22_abort(); - break; - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - c &= 0177; - if (c != *s++) - return (0); - } - signal(SIGALRM, f); - return (timeout == 0); -} diff --git a/usr.bin/tip/libacu/biz31.c b/usr.bin/tip/libacu/biz31.c deleted file mode 100644 index 5522d652aed0..000000000000 --- a/usr.bin/tip/libacu/biz31.c +++ /dev/null @@ -1,254 +0,0 @@ -/* $OpenBSD: biz31.c,v 1.6 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: biz31.c,v 1.5 1997/02/11 09:24:14 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)biz31.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: biz31.c,v 1.6 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -#define MAXRETRY 3 /* sync up retry count */ -#define DISCONNECT_CMD "\21\25\11\24" /* disconnection string */ - -static void sigALRM(); -static int timeout = 0; -static jmp_buf timeoutbuf; - -/* - * Dial up on a BIZCOMP Model 1031 with either - * tone dialing (mod = "f") - * pulse dialing (mod = "w") - */ -static int -biz_dialer(num, mod) - char *num, *mod; -{ - int connected = 0; - - if (!bizsync(FD)) { - logent(value(HOST), "", "biz", "out of sync"); - printf("bizcomp out of sync\n"); - delock(uucplock); - exit(0); - } - if (boolean(value(VERBOSE))) - printf("\nstarting call..."); - echo("#\rk$\r$\n"); /* disable auto-answer */ - echo("$>$.$ #\r"); /* tone/pulse dialing */ - echo(mod); - echo("$\r$\n"); - echo("$>$.$ #\re$ "); /* disconnection sequence */ - echo(DISCONNECT_CMD); - echo("\r$\n$\r$\n"); - echo("$>$.$ #\rr$ "); /* repeat dial */ - echo(num); - echo("\r$\n"); - if (boolean(value(VERBOSE))) - printf("ringing..."); - /* - * The reply from the BIZCOMP should be: - * `^G NO CONNECTION\r\n^G\r\n' failure - * ` CONNECTION\r\n^G' success - */ - connected = detect(" "); -#ifdef ACULOG - if (timeout) { - char line[80]; - - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "biz", line); - } -#endif - if (!connected) - flush(" NO CONNECTION\r\n\07\r\n"); - else - flush("CONNECTION\r\n\07"); - if (timeout) - biz31_disconnect(); /* insurance */ - return (connected); -} - -biz31w_dialer(num, acu) - char *num, *acu; -{ - - return (biz_dialer(num, "w")); -} - -biz31f_dialer(num, acu) - char *num, *acu; -{ - - return (biz_dialer(num, "f")); -} - -biz31_disconnect() -{ - - write(FD, DISCONNECT_CMD, 4); - sleep(2); - tcflush(FD, TCIOFLUSH); -} - -biz31_abort() -{ - - write(FD, "\33", 1); -} - -static int -echo(s) - char *s; -{ - char c; - - while (c = *s++) switch (c) { - - case '$': - read(FD, &c, 1); - s++; - break; - - case '#': - c = *s++; - write(FD, &c, 1); - break; - - default: - write(FD, &c, 1); - read(FD, &c, 1); - } -} - -static void -sigALRM() -{ - - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int -detect(s) - char *s; -{ - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - timeout = 0; - while (*s) { - if (setjmp(timeoutbuf)) { - printf("\07timeout waiting for reply\n"); - biz31_abort(); - break; - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - if (c != *s++) - break; - } - signal(SIGALRM, f); - return (timeout == 0); -} - -static int -flush(s) - char *s; -{ - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - while (*s++) { - if (setjmp(timeoutbuf)) - break; - alarm(10); - read(FD, &c, 1); - alarm(0); - } - signal(SIGALRM, f); - timeout = 0; /* guard against disconnection */ -} - -/* - * This convoluted piece of code attempts to get - * the bizcomp in sync. If you don't have the capacity or nread - * call there are gory ways to simulate this. - */ -static int -bizsync(fd) -{ -#ifdef FIOCAPACITY - struct capacity b; -# define chars(b) ((b).cp_nbytes) -# define IOCTL FIOCAPACITY -#endif -#ifdef FIONREAD - long b; -# define chars(b) (b) -# define IOCTL FIONREAD -#endif - int already = 0; - char buf[10]; - -retry: - if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0 && chars(b) > 0) - tcflush(FD, TCIOFLUSH); - write(fd, "\rp>\r", 4); - sleep(1); - if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0) { - if (chars(b) != 10) { - nono: - if (already > MAXRETRY) - return (0); - write(fd, DISCONNECT_CMD, 4); - sleep(2); - already++; - goto retry; - } else { - read(fd, buf, 10); - if (strncmp(buf, "p >\r\n\r\n>", 8)) - goto nono; - } - } - return (1); -} diff --git a/usr.bin/tip/libacu/courier.c b/usr.bin/tip/libacu/courier.c deleted file mode 100644 index 728ccc9f4377..000000000000 --- a/usr.bin/tip/libacu/courier.c +++ /dev/null @@ -1,354 +0,0 @@ -/* $OpenBSD: courier.c,v 1.9 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: courier.c,v 1.7 1997/02/11 09:24:16 mrg Exp $ */ - -/* - * Copyright (c) 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)courier.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: courier.c,v 1.9 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * Routines for calling up on a Courier modem. - * Derived from Hayes driver. - */ -#include "tip.h" -#include <sys/ioctl.h> -#include <stdio.h> - -#define MAXRETRY 5 - -static void sigALRM(); -static int timeout = 0; -static int connected = 0; -static jmp_buf timeoutbuf, intbuf; -static int coursync(), cour_connect(), cour_swallow(); -void cour_nap(); - -void cour_disconnect __P((void)); - -int -cour_dialer(num, acu) - char *num; - char *acu; -{ - char *cp; -#ifdef ACULOG - char line[80]; -#endif - struct termios cntrl; - - if (boolean(value(VERBOSE))) - printf("Using \"%s\"\n", acu); - - tcgetattr(FD, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(FD, TCSAFLUSH, &cntrl); - /* - * Get in synch. - */ - if (!coursync()) { -badsynch: - printf("can't synchronize with courier\n"); -#ifdef ACULOG - logent(value(HOST), num, "courier", "can't synch up"); -#endif - return (0); - } - cour_write(FD, "AT E0\r", 6); /* turn off echoing */ - sleep(1); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - cour_verbose_read(); -#endif - tcflush(FD, TCIOFLUSH); - cour_write(FD, "AT C1 E0 H0 Q0 X6 V1\r", 21); - if (!cour_swallow("\r\nOK\r\n")) - goto badsynch; - fflush(stdout); - cour_write(FD, "AT D", 4); - for (cp = num; *cp; cp++) - if (*cp == '=') - *cp = ','; - cour_write(FD, num, strlen(num)); - cour_write(FD, "\r", 1); - connected = cour_connect(); -#ifdef ACULOG - if (timeout) { - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "cour", line); - } -#endif - if (timeout) - cour_disconnect(); - return (connected); -} - -void -cour_disconnect() -{ - /* first hang up the modem*/ - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - coursync(); /* reset */ - close(FD); -} - -void -cour_abort() -{ - cour_write(FD, "\r", 1); /* send anything to abort the call */ - cour_disconnect(); -} - -static void -sigALRM() -{ - printf("\07timeout waiting for reply\n"); - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int -cour_swallow(match) - char *match; -{ - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - timeout = 0; - do { - if (*match =='\0') { - signal(SIGALRM, f); - return (1); - } - if (setjmp(timeoutbuf)) { - signal(SIGALRM, f); - return (0); - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - c &= 0177; -#ifdef DEBUG - if (boolean(value(VERBOSE))) - putchar(c); -#endif - } while (c == *match++); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - fflush(stdout); -#endif - signal(SIGALRM, SIG_DFL); - return (0); -} - -struct baud_msg { - char *msg; - int baud; -} baud_msg[] = { - "", B300, - " 1200", B1200, - " 2400", B2400, - " 9600", B9600, - " 9600/ARQ", B9600, - 0, 0, -}; - -static int -cour_connect() -{ - char c; - int nc, nl, n; - char dialer_buf[64]; - struct baud_msg *bm; - sig_t f; - - if (cour_swallow("\r\n") == 0) - return (0); - f = signal(SIGALRM, sigALRM); -again: - nc = 0; nl = sizeof(dialer_buf)-1; - bzero(dialer_buf, sizeof(dialer_buf)); - timeout = 0; - for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) { - if (setjmp(timeoutbuf)) - break; - alarm(number(value(DIALTIMEOUT))); - n = read(FD, &c, 1); - alarm(0); - if (n <= 0) - break; - c &= 0x7f; - if (c == '\r') { - if (cour_swallow("\n") == 0) - break; - if (!dialer_buf[0]) - goto again; - if (strcmp(dialer_buf, "RINGING") == 0 && - boolean(value(VERBOSE))) { -#ifdef DEBUG - printf("%s\r\n", dialer_buf); -#endif - goto again; - } - if (strncmp(dialer_buf, "CONNECT", - sizeof("CONNECT")-1) != 0) - break; - for (bm = baud_msg ; bm->msg ; bm++) - if (strcmp(bm->msg, - dialer_buf+sizeof("CONNECT")-1) == 0) { - struct termios cntrl; - - tcgetattr(FD, &cntrl); - cfsetospeed(&cntrl, bm->baud); - cfsetispeed(&cntrl, bm->baud); - tcsetattr(FD, TCSAFLUSH, &cntrl); - signal(SIGALRM, f); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - printf("%s\r\n", dialer_buf); -#endif - return (1); - } - break; - } - dialer_buf[nc] = c; -#ifdef notdef - if (boolean(value(VERBOSE))) - putchar(c); -#endif - } - printf("%s\r\n", dialer_buf); - signal(SIGALRM, f); - return (0); -} - -/* - * This convoluted piece of code attempts to get - * the courier in sync. - */ -static int -coursync() -{ - int already = 0; - int len; - char buf[40]; - - while (already++ < MAXRETRY) { - tcflush(FD, TCIOFLUSH); - cour_write(FD, "\rAT Z\r", 6); /* reset modem */ - bzero(buf, sizeof(buf)); - sleep(1); - ioctl(FD, FIONREAD, &len); - if (len) { - len = read(FD, buf, sizeof(buf)); -#ifdef DEBUG - buf[len] = '\0'; - printf("coursync: (\"%s\")\n\r", buf); -#endif - if (strchr(buf, '0') || - (strchr(buf, 'O') && strchr(buf, 'K'))) - return(1); - } - /* - * If not strapped for DTR control, - * try to get command mode. - */ - sleep(1); - cour_write(FD, "+++", 3); - sleep(1); - /* - * Toggle DTR to force anyone off that might have left - * the modem connected. - */ - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - } - cour_write(FD, "\rAT Z\r", 6); - return (0); -} - -static void -cour_write(fd, cp, n) -int fd; -char *cp; -int n; -{ -#ifdef notdef - if (boolean(value(VERBOSE))) - write(1, cp, n); -#endif - tcdrain(fd); - cour_nap(); - for ( ; n-- ; cp++) { - write(fd, cp, 1); - tcdrain(fd); - cour_nap(); - } -} - -#ifdef DEBUG -cour_verbose_read() -{ - int n = 0; - char buf[BUFSIZ]; - - if (ioctl(FD, FIONREAD, &n) < 0) - return; - if (n <= 0) - return; - if (read(FD, buf, n) != n) - return; - write(1, buf, n); -} -#endif - -/* Give the courier 50 milliseconds between characters */ -void -cour_nap() -{ - struct timespec ts; - - ts.tv_sec = 0; - ts.tv_nsec = 50 * 1000000; - - nanosleep(&ts, NULL); -} diff --git a/usr.bin/tip/libacu/df.c b/usr.bin/tip/libacu/df.c deleted file mode 100644 index 2fa0a0b320a1..000000000000 --- a/usr.bin/tip/libacu/df.c +++ /dev/null @@ -1,145 +0,0 @@ -/* $OpenBSD: df.c,v 1.5 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: df.c,v 1.4 1995/10/29 00:49:51 pk Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)df.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: df.c,v 1.5 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * Dial the DF02-AC or DF03-AC - */ - -#include "tip.h" - -static jmp_buf Sjbuf; -static void timeout(); - -int -df02_dialer(num, acu) - char *num, *acu; -{ - - return (df_dialer(num, acu, 0)); -} - -int -df03_dialer(num, acu) - char *num, *acu; -{ - - return (df_dialer(num, acu, 1)); -} - -int -df_dialer(num, acu, df03) - char *num, *acu; - int df03; -{ - int f = FD; - struct termios cntrl; - int speed = 0; - char c = '\0'; - - tcgetattr(f, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(f, TCSANOW, &cntrl); - if (setjmp(Sjbuf)) { - printf("connection timed out\r\n"); - df_disconnect(); - return (0); - } - if (boolean(value(VERBOSE))) - printf("\ndialing..."); - fflush(stdout); -#ifdef TIOCMSET - if (df03) { - int st = TIOCM_ST; /* secondary Transmit flag */ - - tcgetattr(f, &cntrl); - speed = cfgetospeed(&cntrl); - if (speed != B1200) { /* must dial at 1200 baud */ - cfsetospeed(&cntrl, B1200); - cfsetispeed(&cntrl, B1200); - tcsetattr(f, TCSAFLUSH, &cntrl); - ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */ - } else - ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */ - } -#endif - signal(SIGALRM, timeout); - alarm(5 * strlen(num) + 10); - tcflush(f, TCIOFLUSH); - write(f, "\001", 1); - sleep(1); - write(f, "\002", 1); - write(f, num, strlen(num)); - read(f, &c, 1); -#ifdef TIOCMSET - if (df03 && speed != B1200) { - cfsetospeed(&cntrl, speed); - cfsetispeed(&cntrl, speed); - tcsetattr(f, TCSAFLUSH, &cntrl); - } -#endif - return (c == 'A'); -} - -void -df_disconnect() -{ - write(FD, "\001", 1); - sleep(1); - tcflush(FD, TCIOFLUSH); -} - - -void -df_abort() -{ - - df_disconnect(); -} - - -static void -timeout() -{ - - longjmp(Sjbuf, 1); -} diff --git a/usr.bin/tip/libacu/dn11.c b/usr.bin/tip/libacu/dn11.c deleted file mode 100644 index 3f3461594296..000000000000 --- a/usr.bin/tip/libacu/dn11.c +++ /dev/null @@ -1,152 +0,0 @@ -/* $OpenBSD: dn11.c,v 1.5 2001/11/19 19:02:16 mpech Exp $ */ -/* $NetBSD: dn11.c,v 1.4 1995/10/29 00:49:53 pk Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)dn11.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: dn11.c,v 1.5 2001/11/19 19:02:16 mpech Exp $"; -#endif /* not lint */ - -/* - * Routines for dialing up on DN-11 - */ -#include "tip.h" - -void dn_abort(); -void alarmtr(); -static jmp_buf jmpbuf; -static int child = -1, dn; - -int -dn_dialer(num, acu) - char *num, *acu; -{ - int lt, nw; - int timelim; - struct termios cntrl; - - if (boolean(value(VERBOSE))) - printf("\nstarting call..."); - if ((dn = open(acu, 1)) < 0) { - if (errno == EBUSY) - printf("line busy..."); - else - printf("acu open error..."); - return (0); - } - if (setjmp(jmpbuf)) { - kill(child, SIGKILL); - close(dn); - return (0); - } - signal(SIGALRM, alarmtr); - timelim = 5 * strlen(num); - alarm(timelim < 30 ? 30 : timelim); - if ((child = fork()) == 0) { - /* - * ignore this stuff for aborts - */ - signal(SIGALRM, SIG_IGN); - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - sleep(2); - nw = write(dn, num, lt = strlen(num)); - exit(nw != lt); - } - /* - * open line - will return on carrier - */ - if ((FD = open(DV, 2)) < 0) { - if (errno == EIO) - printf("lost carrier..."); - else - printf("dialup line open failed..."); - alarm(0); - kill(child, SIGKILL); - close(dn); - return (0); - } - alarm(0); - tcgetattr(dn, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(dn, TCSANOW, &cntrl); - signal(SIGALRM, SIG_DFL); - while ((nw = wait(<)) != child && nw != -1) - ; - fflush(stdout); - close(dn); - if (lt != 0) { - close(FD); - return (0); - } - return (1); -} - -void -alarmtr() -{ - alarm(0); - longjmp(jmpbuf, 1); -} - -/* - * Insurance, for some reason we don't seem to be - * hanging up... - */ -void -dn_disconnect() -{ - - sleep(2); - if (FD > 0) - ioctl(FD, TIOCCDTR, 0); - close(FD); -} - -void -dn_abort() -{ - - sleep(2); - if (child > 0) - kill(child, SIGKILL); - if (dn > 0) - close(dn); - if (FD > 0) - ioctl(FD, TIOCCDTR, 0); - close(FD); -} diff --git a/usr.bin/tip/libacu/hayes.c b/usr.bin/tip/libacu/hayes.c deleted file mode 100644 index 19ee8f80abe6..000000000000 --- a/usr.bin/tip/libacu/hayes.c +++ /dev/null @@ -1,321 +0,0 @@ -/* $OpenBSD: hayes.c,v 1.8 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: hayes.c,v 1.6 1997/02/11 09:24:17 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)hayes.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: hayes.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * Routines for calling up on a Hayes Modem - * (based on the old VenTel driver). - * The modem is expected to be strapped for "echo". - * Also, the switches enabling the DTR and CD lines - * must be set correctly. - * NOTICE: - * The easy way to hang up a modem is always simply to - * clear the DTR signal. However, if the +++ sequence - * (which switches the modem back to local mode) is sent - * before modem is hung up, removal of the DTR signal - * has no effect (except that it prevents the modem from - * recognizing commands). - * (by Helge Skrivervik, Calma Company, Sunnyvale, CA. 1984) - */ -/* - * TODO: - * It is probably not a good idea to switch the modem - * state between 'verbose' and terse (status messages). - * This should be kicked out and we should use verbose - * mode only. This would make it consistent with normal - * interactive use thru the command 'tip dialer'. - */ -#include "tip.h" - -#include <termios.h> -#include <sys/ioctl.h> - -#define min(a,b) ((a < b) ? a : b) - -static void sigALRM(); -static int timeout = 0; -static jmp_buf timeoutbuf; -static char gobble(); -#define DUMBUFLEN 40 -static char dumbuf[DUMBUFLEN]; - -#define DIALING 1 -#define IDLE 2 -#define CONNECTED 3 -#define FAILED 4 -static int state = IDLE; - -int -hay_dialer(num, acu) - char *num; - char *acu; -{ - char *cp; - int connected = 0; - char dummy; - struct termios cntrl; -#ifdef ACULOG - char line[80]; -#endif - if (hay_sync() == 0) /* make sure we can talk to the modem */ - return(0); - if (boolean(value(VERBOSE))) - printf("\ndialing..."); - fflush(stdout); - tcgetattr(FD, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(FD, TCSANOW, &cntrl); - tcflush(FD, TCIOFLUSH); - write(FD, "ATv0\r", 5); /* tell modem to use short status codes */ - gobble("\r"); - gobble("\r"); - write(FD, "ATTD", 4); /* send dial command */ - for (cp = num; *cp; cp++) - if (*cp == '=') - *cp = ','; - write(FD, num, strlen(num)); - state = DIALING; - write(FD, "\r", 1); - connected = 0; - if (gobble("\r")) { - if ((dummy = gobble("01234")) != '1') - error_rep(dummy); - else - connected = 1; - } - if (connected) - state = CONNECTED; - else { - state = FAILED; - return (connected); /* lets get out of here.. */ - } - tcflush(FD, TCIOFLUSH); -#ifdef ACULOG - if (timeout) { - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "hayes", line); - } -#endif - if (timeout) - hay_disconnect(); /* insurance */ - return (connected); -} - - -void -hay_disconnect() -{ - /* first hang up the modem*/ -#ifdef DEBUG - printf("\rdisconnecting modem....\n\r"); -#endif - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - goodbye(); -} - -void -hay_abort() -{ - - write(FD, "\r", 1); /* send anything to abort the call */ - hay_disconnect(); -} - -static void -sigALRM() -{ - - printf("\07timeout waiting for reply\n\r"); - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static char -gobble(match) - char *match; -{ - char c; - sig_t f; - int i, status = 0; - - f = signal(SIGALRM, sigALRM); - timeout = 0; -#ifdef DEBUG - printf("\ngobble: waiting for %s\n", match); -#endif - do { - if (setjmp(timeoutbuf)) { - signal(SIGALRM, f); - return (0); - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - c &= 0177; -#ifdef DEBUG - printf("%c 0x%x ", c, c); -#endif - for (i = 0; i < strlen(match); i++) - if (c == match[i]) - status = c; - } while (status == 0); - signal(SIGALRM, SIG_DFL); -#ifdef DEBUG - printf("\n"); -#endif - return (status); -} - -static void -error_rep(c) - char c; -{ - printf("\n\r"); - switch (c) { - - case '0': - printf("OK"); - break; - - case '1': - printf("CONNECT"); - break; - - case '2': - printf("RING"); - break; - - case '3': - printf("NO CARRIER"); - break; - - case '4': - printf("ERROR in input"); - break; - - case '5': - printf("CONNECT 1200"); - break; - - default: - printf("Unknown Modem error: %c (0x%x)", c, c); - } - printf("\n\r"); - return; -} - -/* - * set modem back to normal verbose status codes. - */ -void -goodbye() -{ - int len; - char c; - - tcflush(FD, TCIOFLUSH); - if (hay_sync()) { - sleep(1); -#ifndef DEBUG - tcflush(FD, TCIOFLUSH); -#endif - write(FD, "ATH0\r", 5); /* insurance */ -#ifndef DEBUG - c = gobble("03"); - if (c != '0' && c != '3') { - printf("cannot hang up modem\n\r"); - printf("please use 'tip dialer' to make sure the line is hung up\n\r"); - } -#endif - sleep(1); - ioctl(FD, FIONREAD, &len); -#ifdef DEBUG - printf("goodbye1: len=%d -- ", len); - rlen = read(FD, dumbuf, min(len, DUMBUFLEN)); - dumbuf[rlen] = '\0'; - printf("read (%d): %s\r\n", rlen, dumbuf); -#endif - write(FD, "ATv1\r", 5); - sleep(1); -#ifdef DEBUG - ioctl(FD, FIONREAD, &len); - printf("goodbye2: len=%d -- ", len); - rlen = read(FD, dumbuf, min(len, DUMBUFLEN)); - dumbuf[rlen] = '\0'; - printf("read (%d): %s\r\n", rlen, dumbuf); -#endif - } - tcflush(FD, TCIOFLUSH); - ioctl(FD, TIOCCDTR, 0); /* clear DTR (insurance) */ - close(FD); -} - -#define MAXRETRY 5 - -int -hay_sync() -{ - int len, retry = 0; - - while (retry++ <= MAXRETRY) { - write(FD, "AT\r", 3); - sleep(1); - ioctl(FD, FIONREAD, &len); - if (len) { - len = read(FD, dumbuf, min(len, DUMBUFLEN)); - if (strchr(dumbuf, '0') || - (strchr(dumbuf, 'O') && strchr(dumbuf, 'K'))) - return(1); -#ifdef DEBUG - dumbuf[len] = '\0'; - printf("hay_sync: (\"%s\") %d\n\r", dumbuf, retry); -#endif - } - ioctl(FD, TIOCCDTR, 0); - ioctl(FD, TIOCSDTR, 0); - } - printf("Cannot synchronize with hayes...\n\r"); - return(0); -} diff --git a/usr.bin/tip/libacu/t3000.c b/usr.bin/tip/libacu/t3000.c deleted file mode 100644 index 1f0509104475..000000000000 --- a/usr.bin/tip/libacu/t3000.c +++ /dev/null @@ -1,370 +0,0 @@ -/* $OpenBSD: t3000.c,v 1.9 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: t3000.c,v 1.5 1997/02/11 09:24:18 mrg Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)t3000.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: t3000.c,v 1.9 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * Routines for calling up on a Telebit T3000 modem. - * Derived from Courier driver. - */ -#include "tip.h" - -#include <sys/ioctl.h> -#include <stdio.h> - -#define MAXRETRY 5 - -static void sigALRM(); -static int timeout = 0; -static int connected = 0; -static jmp_buf timeoutbuf, intbuf; -static int t3000_sync(), t3000_connect(), t3000_swallow(); -static void t3000_nap(); - -int -t3000_dialer(num, acu) - char *num; - char *acu; -{ - char *cp; - struct termios cntrl; -#ifdef ACULOG - char line[80]; -#endif - - if (boolean(value(VERBOSE))) - printf("Using \"%s\"\n", acu); - - tcgetattr(FD, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(FD, TCSANOW, &cntrl); - /* - * Get in synch. - */ - if (!t3000_sync()) { -badsynch: - printf("can't synchronize with t3000\n"); -#ifdef ACULOG - logent(value(HOST), num, "t3000", "can't synch up"); -#endif - return (0); - } - t3000_write(FD, "AT E0\r", 6); /* turn off echoing */ - sleep(1); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - t3000_verbose_read(); -#endif - tcflush(FD, TCIOFLUSH); - t3000_write(FD, "AT E0 H0 Q0 X4 V1\r", 18); - if (!t3000_swallow("\r\nOK\r\n")) - goto badsynch; - fflush(stdout); - t3000_write(FD, "AT D", 4); - for (cp = num; *cp; cp++) - if (*cp == '=') - *cp = ','; - t3000_write(FD, num, strlen(num)); - t3000_write(FD, "\r", 1); - connected = t3000_connect(); -#ifdef ACULOG - if (timeout) { - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "t3000", line); - } -#endif - if (timeout) - t3000_disconnect(); - return (connected); -} - -void -t3000_disconnect() -{ - /* first hang up the modem*/ - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - t3000_sync(); /* reset */ - close(FD); -} - -void -t3000_abort() -{ - t3000_write(FD, "\r", 1); /* send anything to abort the call */ - t3000_disconnect(); -} - -static void -sigALRM() -{ - printf("\07timeout waiting for reply\n"); - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int -t3000_swallow(match) - char *match; -{ - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - timeout = 0; - do { - if (*match =='\0') { - signal(SIGALRM, f); - return (1); - } - if (setjmp(timeoutbuf)) { - signal(SIGALRM, f); - return (0); - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - c &= 0177; -#ifdef DEBUG - if (boolean(value(VERBOSE))) - putchar(c); -#endif - } while (c == *match++); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - fflush(stdout); -#endif - signal(SIGALRM, SIG_DFL); - return (0); -} - -#ifndef B19200 /* XXX */ -#define B19200 EXTA -#define B38400 EXTB -#endif - -struct tbaud_msg { - char *msg; - int baud; - int baud2; -} tbaud_msg[] = { - "", B300, 0, - " 1200", B1200, 0, - " 2400", B2400, 0, - " 4800", B4800, 0, - " 9600", B9600, 0, - " 14400", B19200, B9600, - " 19200", B19200, B9600, - " 38400", B38400, B9600, - " 57600", B38400, B9600, - " 7512", B9600, 0, - " 1275", B2400, 0, - " 7200", B9600, 0, - " 12000", B19200, B9600, - 0, 0, 0, -}; - -static int -t3000_connect() -{ - char c; - int nc, nl, n; - char dialer_buf[64]; - struct tbaud_msg *bm; - sig_t f; - - if (t3000_swallow("\r\n") == 0) - return (0); - f = signal(SIGALRM, sigALRM); -again: - nc = 0; nl = sizeof(dialer_buf)-1; - bzero(dialer_buf, sizeof(dialer_buf)); - timeout = 0; - for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) { - if (setjmp(timeoutbuf)) - break; - alarm(number(value(DIALTIMEOUT))); - n = read(FD, &c, 1); - alarm(0); - if (n <= 0) - break; - c &= 0x7f; - if (c == '\r') { - if (t3000_swallow("\n") == 0) - break; - if (!dialer_buf[0]) - goto again; - if (strcmp(dialer_buf, "RINGING") == 0 && - boolean(value(VERBOSE))) { -#ifdef DEBUG - printf("%s\r\n", dialer_buf); -#endif - goto again; - } - if (strncmp(dialer_buf, "CONNECT", - sizeof("CONNECT")-1) != 0) - break; - for (bm = tbaud_msg ; bm->msg ; bm++) - if (strcmp(bm->msg, - dialer_buf+sizeof("CONNECT")-1) == 0) { - struct termios cntrl; - - tcgetattr(FD, &cntrl); - cfsetospeed(&cntrl, bm->baud); - cfsetispeed(&cntrl, bm->baud); - tcsetattr(FD, TCSAFLUSH, &cntrl); - signal(SIGALRM, f); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - printf("%s\r\n", dialer_buf); -#endif - return (1); - } - break; - } - dialer_buf[nc] = c; -#ifdef notdef - if (boolean(value(VERBOSE))) - putchar(c); -#endif - } - printf("%s\r\n", dialer_buf); - signal(SIGALRM, f); - return (0); -} - -/* - * This convoluted piece of code attempts to get - * the t3000 in sync. - */ -static int -t3000_sync() -{ - int already = 0; - int len; - char buf[40]; - - while (already++ < MAXRETRY) { - tcflush(FD, TCIOFLUSH); - t3000_write(FD, "\rAT Z\r", 6); /* reset modem */ - bzero(buf, sizeof(buf)); - sleep(2); - ioctl(FD, FIONREAD, &len); -#if 1 -if (len == 0) len = 1; -#endif - if (len) { - len = read(FD, buf, sizeof(buf)); -#ifdef DEBUG - buf[len] = '\0'; - printf("t3000_sync: (\"%s\")\n\r", buf); -#endif - if (strchr(buf, '0') || - (strchr(buf, 'O') && strchr(buf, 'K'))) - return(1); - } - /* - * If not strapped for DTR control, - * try to get command mode. - */ - sleep(1); - t3000_write(FD, "+++", 3); - sleep(1); - /* - * Toggle DTR to force anyone off that might have left - * the modem connected. - */ - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - } - t3000_write(FD, "\rAT Z\r", 6); - return (0); -} - -static int -t3000_write(fd, cp, n) -int fd; -char *cp; -int n; -{ -#ifdef notdef - if (boolean(value(VERBOSE))) - write(1, cp, n); -#endif - tcdrain(fd); - t3000_nap(); - for ( ; n-- ; cp++) { - write(fd, cp, 1); - tcdrain(fd); - t3000_nap(); - } -} - -#ifdef DEBUG -t3000_verbose_read() -{ - int n = 0; - char buf[BUFSIZ]; - - if (ioctl(FD, FIONREAD, &n) < 0) - return; - if (n <= 0) - return; - if (read(FD, buf, n) != n) - return; - write(1, buf, n); -} -#endif - -/* Give the t3000 50 milliseconds between characters */ -void -t3000_nap() -{ - struct timespec ts; - - ts.tv_sec = 0; - ts.tv_nsec = 50 * 1000000; - - nanosleep(&ts, NULL); -} diff --git a/usr.bin/tip/libacu/v3451.c b/usr.bin/tip/libacu/v3451.c deleted file mode 100644 index 1440c551e0e0..000000000000 --- a/usr.bin/tip/libacu/v3451.c +++ /dev/null @@ -1,220 +0,0 @@ -/* $OpenBSD: v3451.c,v 1.6 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: v3451.c,v 1.6 1997/02/11 09:24:20 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)v3451.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: v3451.c,v 1.6 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * Routines for calling up on a Vadic 3451 Modem - */ -#include "tip.h" - -static jmp_buf Sjbuf; - -static int expect(), notin(), prefix(); -static void vawrite(), alarmtr(); - -int -v3451_dialer(num, acu) - char *num; - char *acu; -{ - sig_t func; - int ok; - int slow = number(value(BAUDRATE)) < 1200; - char phone[50]; - struct termios cntrl; - - /* - * Get in synch - */ - vawrite("I\r", 1 + slow); - vawrite("I\r", 1 + slow); - vawrite("I\r", 1 + slow); - vawrite("\005\r", 2 + slow); - if (!expect("READY")) { - printf("can't synchronize with vadic 3451\n"); -#ifdef ACULOG - logent(value(HOST), num, "vadic", "can't synch up"); -#endif - return (0); - } - tcgetattr(FD, &cntrl); - term.c_cflag |= HUPCL; - tcsetattr(FD, TCSANOW, &cntrl); - sleep(1); - vawrite("D\r", 2 + slow); - if (!expect("NUMBER?")) { - printf("Vadic will not accept dial command\n"); -#ifdef ACULOG - logent(value(HOST), num, "vadic", "will not accept dial"); -#endif - return (0); - } - (void)snprintf(phone, sizeof phone, "%s\r", num); - vawrite(phone, 1 + slow); - if (!expect(phone)) { - printf("Vadic will not accept phone number\n"); -#ifdef ACULOG - logent(value(HOST), num, "vadic", "will not accept number"); -#endif - return (0); - } - func = signal(SIGINT,SIG_IGN); - /* - * You cannot interrupt the Vadic when its dialing; - * even dropping DTR does not work (definitely a - * brain damaged design). - */ - vawrite("\r", 1 + slow); - vawrite("\r", 1 + slow); - if (!expect("DIALING:")) { - printf("Vadic failed to dial\n"); -#ifdef ACULOG - logent(value(HOST), num, "vadic", "failed to dial"); -#endif - return (0); - } - if (boolean(value(VERBOSE))) - printf("\ndialing..."); - ok = expect("ON LINE"); - signal(SIGINT, func); - if (!ok) { - printf("call failed\n"); -#ifdef ACULOG - logent(value(HOST), num, "vadic", "call failed"); -#endif - return (0); - } - tcflush(FD, TCIOFLUSH); - return (1); -} - -void -v3451_disconnect() -{ - - close(FD); -} - -void -v3451_abort() -{ - - close(FD); -} - -static void -vawrite(cp, delay) - char *cp; - int delay; -{ - - for (; *cp; sleep(delay), cp++) - write(FD, cp, 1); -} - -static int -expect(cp) - char *cp; -{ - char buf[300]; - char *rp = buf; - int timeout = 30, online = 0; - - if (strcmp(cp, "\"\"") == 0) - return (1); - *rp = 0; - /* - * If we are waiting for the Vadic to complete - * dialing and get a connection, allow more time - * Unfortunately, the Vadic times out 24 seconds after - * the last digit is dialed - */ - online = strcmp(cp, "ON LINE") == 0; - if (online) - timeout = number(value(DIALTIMEOUT)); - signal(SIGALRM, alarmtr); - if (setjmp(Sjbuf)) - return (0); - alarm(timeout); - while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) { - if (online && notin("FAILED CALL", buf) == 0) - return (0); - if (read(FD, rp, 1) < 0) { - alarm(0); - return (0); - } - if (*rp &= 0177) - rp++; - *rp = '\0'; - } - alarm(0); - return (1); -} - -static void -alarmtr() -{ - longjmp(Sjbuf, 1); -} - -static int -notin(sh, lg) - char *sh, *lg; -{ - - for (; *lg; lg++) - if (prefix(sh, lg)) - return (0); - return (1); -} - -static int -prefix(s1, s2) - char *s1, *s2; -{ - char c; - - while ((c = *s1++) == *s2++) - if (c == '\0') - return (1); - return (c == '\0'); -} diff --git a/usr.bin/tip/libacu/v831.c b/usr.bin/tip/libacu/v831.c deleted file mode 100644 index 005e5d931e52..000000000000 --- a/usr.bin/tip/libacu/v831.c +++ /dev/null @@ -1,268 +0,0 @@ -/* $OpenBSD: v831.c,v 1.6 2001/11/19 19:02:16 mpech Exp $ */ -/* $NetBSD: v831.c,v 1.5 1996/12/29 10:42:01 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)v831.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: v831.c,v 1.6 2001/11/19 19:02:16 mpech Exp $"; -#endif /* not lint */ - -/* - * Routines for dialing up on Vadic 831 - */ -#include "tip.h" -#include <termios.h> - -void v831_abort(); -static void alarmtr(); -static int dialit(); -static char *sanitize(); - -static jmp_buf jmpbuf; -static int child = -1; - -int -v831_dialer(num, acu) - char *num, *acu; -{ - int status, pid; - int timelim; - - if (boolean(value(VERBOSE))) - printf("\nstarting call..."); -#ifdef DEBUG - printf ("(acu=%s)\n", acu); -#endif - if ((AC = open(acu, O_RDWR)) < 0) { - if (errno == EBUSY) - printf("line busy..."); - else - printf("acu open error..."); - return (0); - } - if (setjmp(jmpbuf)) { - kill(child, SIGKILL); - close(AC); - return (0); - } - signal(SIGALRM, alarmtr); - timelim = 5 * strlen(num); - alarm(timelim < 30 ? 30 : timelim); - if ((child = fork()) == 0) { - /* - * ignore this stuff for aborts - */ - signal(SIGALRM, SIG_IGN); - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - sleep(2); - exit(dialit(num, acu) != 'A'); - } - /* - * open line - will return on carrier - */ - if ((FD = open(DV, O_RDWR)) < 0) { -#ifdef DEBUG - printf("(after open, errno=%d)\n", errno); -#endif - if (errno == EIO) - printf("lost carrier..."); - else - printf("dialup line open failed..."); - alarm(0); - kill(child, SIGKILL); - close(AC); - return (0); - } - alarm(0); - signal(SIGALRM, SIG_DFL); - while ((pid = wait(&status)) != child && pid != -1) - ; - if (status) { - close(AC); - return (0); - } - return (1); -} - -static void -alarmtr() -{ - alarm(0); - longjmp(jmpbuf, 1); -} - -/* - * Insurance, for some reason we don't seem to be - * hanging up... - */ -void -v831_disconnect() -{ - struct termios cntrl; - - sleep(2); -#ifdef DEBUG - printf("[disconnect: FD=%d]\n", FD); -#endif - if (FD > 0) { - ioctl(FD, TIOCCDTR, 0); - tcgetattr(FD, &cntrl); - cfsetospeed(&cntrl, 0); - cfsetispeed(&cntrl, 0); - tcsetattr(FD, TCSAFLUSH, &cntrl); - ioctl(FD, TIOCNXCL, NULL); - } - close(FD); -} - -void -v831_abort() -{ - -#ifdef DEBUG - printf("[abort: AC=%d]\n", AC); -#endif - sleep(2); - if (child > 0) - kill(child, SIGKILL); - if (AC > 0) - ioctl(FD, TIOCNXCL, NULL); - close(AC); - if (FD > 0) - ioctl(FD, TIOCCDTR, 0); - close(FD); -} - -/* - * Sigh, this probably must be changed at each site. - */ -struct vaconfig { - char *vc_name; - char vc_rack; - char vc_modem; -} vaconfig[] = { - { "/dev/cua0",'4','0' }, - { "/dev/cua1",'4','1' }, - { 0 } -}; - -#define pc(x) (c = x, write(AC,&c,1)) -#define ABORT 01 -#define SI 017 -#define STX 02 -#define ETX 03 - -static int -dialit(phonenum, acu) - char *phonenum; - char *acu; -{ - struct vaconfig *vp; - struct termios cntrl; - char c; - int i; - - phonenum = sanitize(phonenum); -#ifdef DEBUG - printf ("(dial phonenum=%s)\n", phonenum); -#endif - if (*phonenum == '<' && phonenum[1] == 0) - return ('Z'); - for (vp = vaconfig; vp->vc_name; vp++) - if (strcmp(vp->vc_name, acu) == 0) - break; - if (vp->vc_name == 0) { - printf("Unable to locate dialer (%s)\n", acu); - return ('K'); - } - tcgetattr(AC, &cntrl); - cfsetospeed(&cntrl, B2400); - cfsetispeed(&cntrl, B2400); - cntrl.c_cflag |= PARODD | PARENB; - cntrl.c_lflag &= ~(ISIG | ICANON); - tcsetattr(AC, TCSANOW, &cntrl); - tcflush(AC, TCIOFLUSH); - pc(STX); - pc(vp->vc_rack); - pc(vp->vc_modem); - while (*phonenum && *phonenum != '<') - pc(*phonenum++); - pc(SI); - pc(ETX); - sleep(1); - i = read(AC, &c, 1); -#ifdef DEBUG - printf("read %d chars, char=%c, errno %d\n", i, c, errno); -#endif - if (i != 1) - c = 'M'; - if (c == 'B' || c == 'G') { - char cc, oc = c; - - pc(ABORT); - read(AC, &cc, 1); -#ifdef DEBUG - printf("abort response=%c\n", cc); -#endif - c = oc; - v831_disconnect(); - } - close(AC); -#ifdef DEBUG - printf("dialit: returns %c\n", c); -#endif - return (c); -} - -static char * -sanitize(s) - char *s; -{ - static char buf[128]; - char *cp; - - for (cp = buf; *s; s++) { - if (!isdigit(*s) && *s == '<' && *s != '_') - continue; - if (*s == '_') - *s = '='; - *cp++ = *s; - } - *cp++ = 0; - return (buf); -} diff --git a/usr.bin/tip/libacu/ventel.c b/usr.bin/tip/libacu/ventel.c deleted file mode 100644 index 48035c177d2d..000000000000 --- a/usr.bin/tip/libacu/ventel.c +++ /dev/null @@ -1,266 +0,0 @@ -/* $OpenBSD: ventel.c,v 1.7 2001/11/19 19:02:16 mpech Exp $ */ -/* $NetBSD: ventel.c,v 1.6 1997/02/11 09:24:21 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)ventel.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: ventel.c,v 1.7 2001/11/19 19:02:16 mpech Exp $"; -#endif /* not lint */ - -/* - * Routines for calling up on a Ventel Modem - * The Ventel is expected to be strapped for local echo (just like uucp) - */ -#include "tip.h" -#include <termios.h> -#include <sys/ioctl.h> - -#define MAXRETRY 5 - -static void sigALRM(); -static int timeout = 0; -static jmp_buf timeoutbuf; - -static int gobble(), vensync(); -static void echo(); - -/* - * some sleep calls have been replaced by this macro - * because some ventel modems require two <cr>s in less than - * a second in order to 'wake up'... yes, it is dirty... - */ -#define delay(num,denom) busyloop(CPUSPEED*num/denom) -#define CPUSPEED 1000000 /* VAX 780 is 1MIPS */ -#define DELAY(n) do { long N = (n); while (--N > 0); } while (0) -#define busyloop(n) do { DELAY(n); } while (0) - -int -ven_dialer(num, acu) - char *num; - char *acu; -{ - char *cp; - int connected = 0; - char *msg, line[80]; - struct termios cntrl; - - /* - * Get in synch with a couple of carriage returns - */ - if (!vensync(FD)) { - printf("can't synchronize with ventel\n"); -#ifdef ACULOG - logent(value(HOST), num, "ventel", "can't synch up"); -#endif - return (0); - } - if (boolean(value(VERBOSE))) - printf("\ndialing..."); - fflush(stdout); - tcgetattr(FD, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(FD, TCSANOW, &cntrl); - echo("#k$\r$\n$D$I$A$L$:$ "); - for (cp = num; *cp; cp++) { - delay(1, 10); - write(FD, cp, 1); - } - delay(1, 10); - write(FD, "\r", 1); - gobble('\n', line); - if (gobble('\n', line)) - connected = gobble('!', line); - tcflush(FD, TCIOFLUSH); -#ifdef ACULOG - if (timeout) { - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "ventel", line); - } -#endif - if (timeout) - ven_disconnect(); /* insurance */ - if (connected || timeout || !boolean(value(VERBOSE))) - return (connected); - /* call failed, parse response for user */ - cp = strchr(line, '\r'); - if (cp) - *cp = '\0'; - for (cp = line; cp = strchr(cp, ' '); cp++) - if (cp[1] == ' ') - break; - if (cp) { - while (*cp == ' ') - cp++; - msg = cp; - while (*cp) { - if (isupper(*cp)) - *cp = tolower(*cp); - cp++; - } - printf("%s...", msg); - } - return (connected); -} - -void -ven_disconnect() -{ - - close(FD); -} - -void -ven_abort() -{ - - write(FD, "\03", 1); - close(FD); -} - -static void -echo(s) - char *s; -{ - char c; - - while (c = *s++) switch (c) { - - case '$': - read(FD, &c, 1); - s++; - break; - - case '#': - c = *s++; - write(FD, &c, 1); - break; - - default: - write(FD, &c, 1); - read(FD, &c, 1); - } -} - -static void -sigALRM() -{ - printf("\07timeout waiting for reply\n"); - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int -gobble(match, response) - char match; - char response[]; -{ - char *cp = response; - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - timeout = 0; - do { - if (setjmp(timeoutbuf)) { - signal(SIGALRM, f); - *cp = '\0'; - return (0); - } - alarm(number(value(DIALTIMEOUT))); - read(FD, cp, 1); - alarm(0); - c = (*cp++ &= 0177); -#ifdef notdef - if (boolean(value(VERBOSE))) - putchar(c); -#endif - } while (c != '\n' && c != match); - signal(SIGALRM, SIG_DFL); - *cp = '\0'; - return (c == match); -} - -#define min(a,b) ((a)>(b)?(b):(a)) -/* - * This convoluted piece of code attempts to get - * the ventel in sync. If you don't have FIONREAD - * there are gory ways to simulate this. - */ -static int -vensync(fd) -{ - int already = 0, nread; - char buf[60]; - - /* - * Toggle DTR to force anyone off that might have left - * the modem connected, and insure a consistent state - * to start from. - * - * If you don't have the ioctl calls to diddle directly - * with DTR, you can always try setting the baud rate to 0. - */ - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - while (already < MAXRETRY) { - /* - * After reseting the modem, send it two \r's to - * autobaud on. Make sure to delay between them - * so the modem can frame the incoming characters. - */ - write(fd, "\r", 1); - delay(1,10); - write(fd, "\r", 1); - sleep(2); - if (ioctl(fd, FIONREAD, (caddr_t)&nread) < 0) { - perror("tip: ioctl"); - continue; - } - while (nread > 0) { - read(fd, buf, min(nread, 60)); - if ((buf[nread - 1] & 0177) == '$') - return (1); - nread -= min(nread, 60); - } - sleep(1); - already++; - } - return (0); -} - diff --git a/usr.bin/tip/tip/Makefile b/usr.bin/tip/tip/Makefile deleted file mode 100644 index 8d269d65cbd3..000000000000 --- a/usr.bin/tip/tip/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# $OpenBSD: Makefile,v 1.9 2001/09/23 06:15:30 pvalchev Exp $ -# -# Files are: -# /etc/remote remote host description file -# /etc/phones phone number file, owned by ${OWNER} and -# mode 6?? -# /var/log/aculog ACU accounting file, owned by ${OWNER} and -# mode 6?? {if ACULOG defined} -# Presently supports: -# BIZCOMP -# DEC DF02-AC, DF03-AC -# DEC DN-11/Able Quadracall -# HAYES and Hayes emulators -# USR COURIER (2400 baud) -# VENTEL 212+ -# VADIC 831 RS232 adaptor -# VADIC 3451 -# TELEBIT T3000 -# -# Configuration defines: -# DF02, DF03, DN11 ACU's supported -# BIZ1031, BIZ1022, VENTEL, V831, V3451, HAYES, COURIER, T3000 -# ACULOG turn on tip logging of ACU use -# PRISTINE no phone #'s put in ACU log file -# CONNECT worthless command -# DEFBR default baud rate to make connection at -# DEFFS default frame size for FTP buffering of -# writes on local side -# BUFSIZ buffer sizing from stdio, must be fed -# explicitly to remcap.c if not 1024 -# CONNECT enable ~C command (connect pgm to remote) - -PROG= tip -LINKS= ${BINDIR}/tip ${BINDIR}/cu -MLINKS= tip.1 cu.1 -CFLAGS+=-I${.CURDIR} -ansi -pedantic \ - -DDEFBR=9600 -DDEFFS=BUFSIZ -DACULOG -DPRISTINE -DCONNECT \ - -DV831 -DVENTEL -DHAYES -DCOURIER -DT3000 -.PATH: ${.CURDIR}/aculib -SRCS= acu.c acutab.c cmds.c cmdtab.c cu.c hunt.c log.c partab.c \ - remote.c tip.c tipout.c uucplock.c value.c vars.c \ - biz22.c courier.c df.c dn11.c hayes.c t3000.c v3451.c v831.c ventel.c - -# -- acutab is configuration dependent, and so depends on the Makefile -# -- remote.o depends on the Makefile because of DEFBR and DEFFS -# -- log.o depends on the Makefile because of ACULOG -acutab.o log.o remote.o: Makefile - -.include <bsd.prog.mk> diff --git a/usr.bin/tip/tip/acu.c b/usr.bin/tip/tip/acu.c deleted file mode 100644 index 91549e917417..000000000000 --- a/usr.bin/tip/tip/acu.c +++ /dev/null @@ -1,198 +0,0 @@ -/* $OpenBSD: acu.c,v 1.7 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: acu.c,v 1.4 1996/12/29 10:34:03 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)acu.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: acu.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -static acu_t *acu = NOACU; -static int conflag; -static void acuabort(); -static acu_t *acutype(); -static jmp_buf jmpbuf; -/* - * Establish connection for tip - * - * If DU is true, we should dial an ACU whose type is AT. - * The phone numbers are in PN, and the call unit is in CU. - * - * If the PN is an '@', then we consult the PHONES file for - * the phone numbers. This file is /etc/phones, unless overriden - * by an exported shell variable. - * - * The data base files must be in the format: - * host-name[ \t]*phone-number - * with the possibility of multiple phone numbers - * for a single host acting as a rotary (in the order - * found in the file). - */ -char * -connect() -{ - char *cp = PN; - char *phnum, string[256]; - FILE *fd; - volatile int tried = 0; - - if (!DU) { /* regular connect message */ - if (CM != NOSTR) - parwrite(FD, CM, size(CM)); - logent(value(HOST), "", DV, "call completed"); - return (NOSTR); - } - /* - * @ =>'s use data base in PHONES environment variable - * otherwise, use /etc/phones - */ - signal(SIGINT, acuabort); - signal(SIGQUIT, acuabort); - if (setjmp(jmpbuf)) { - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - printf("\ncall aborted\n"); - logent(value(HOST), "", "", "call aborted"); - if (acu != NOACU) { - setboolean(value(VERBOSE), FALSE); - if (conflag) - disconnect(NOSTR); - else - (*acu->acu_abort)(); - } - return ("interrupt"); - } - if ((acu = acutype(AT)) == NOACU) - return ("unknown ACU type"); - if (*cp != '@') { - while (*cp) { - phnum = cp; - cp = strpbrk(cp, ","); - if (*cp != '\0') - *cp++ = '\0'; - - if (strlen(phnum) == 0) - continue; - - conflag = (*acu->acu_dialer)(phnum, CU); - if (conflag) - break; - - logent(value(HOST), phnum, acu->acu_name, "call failed"); - tried++; - } - } else { - if ((fd = fopen(PH, "r")) == NOFILE) { - printf("%s: ", PH); - return ("can't open phone number file"); - } - while (fgets(string, sizeof(string), fd) != NOSTR) { - cp = &string[strcspn(string, " \t\n")]; - if (*cp != '\0') - *cp++ = '\0'; - - if (strcmp(string, value(HOST)) != 0) - continue; - - cp += strspn(cp, " \t\n"); - phnum = cp; - *(cp + strcspn(cp, ",\n")) = '\0'; - - if (strlen(phnum) == 0) - continue; - - conflag = (*acu->acu_dialer)(phnum, CU); - if (conflag) - break; - - logent(value(HOST), phnum, acu->acu_name, "call failed"); - tried++; - } - fclose(fd); - } - if (conflag) { - if (CM != NOSTR) - parwrite(FD, CM, size(CM)); - logent(value(HOST), phnum, acu->acu_name, "call completed"); - return (NOSTR); - } else if (!tried) { - logent(value(HOST), "", acu->acu_name, "missing phone number"); - return ("missing phone number"); - } else { - (*acu->acu_abort)(); - return ("call failed"); - } -} - -void -disconnect(reason) - char *reason; -{ - if (!conflag) { - logent(value(HOST), "", DV, "call terminated"); - return; - } - if (reason == NOSTR) { - logent(value(HOST), "", acu->acu_name, "call terminated"); - if (boolean(value(VERBOSE))) - printf("\r\ndisconnecting..."); - } else - logent(value(HOST), "", acu->acu_name, reason); - (*acu->acu_disconnect)(); -} - -static void -acuabort(s) -{ - signal(s, SIG_IGN); - longjmp(jmpbuf, 1); -} - -static acu_t * -acutype(s) - char *s; -{ - acu_t *p; - extern acu_t acutable[]; - - for (p = acutable; p->acu_name != '\0'; p++) - if (!strcmp(s, p->acu_name)) - return (p); - return (NOACU); -} diff --git a/usr.bin/tip/tip/acutab.c b/usr.bin/tip/tip/acutab.c deleted file mode 100644 index 193b8cc70cac..000000000000 --- a/usr.bin/tip/tip/acutab.c +++ /dev/null @@ -1,103 +0,0 @@ -/* $OpenBSD: acutab.c,v 1.2 1996/06/26 05:40:41 deraadt Exp $ */ -/* $NetBSD: acutab.c,v 1.3 1994/12/08 09:30:41 jtc Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)acutab.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: acutab.c,v 1.2 1996/06/26 05:40:41 deraadt Exp $"; -#endif /* not lint */ - -#include "tip.h" - -extern int df02_dialer(), df03_dialer(), df_disconnect(), df_abort(), - biz31f_dialer(), biz31_disconnect(), biz31_abort(), - biz31w_dialer(), - biz22f_dialer(), biz22_disconnect(), biz22_abort(), - biz22w_dialer(), - ven_dialer(), ven_disconnect(), ven_abort(), - hay_dialer(), hay_disconnect(), hay_abort(), - cour_dialer(), cour_disconnect(), cour_abort(), - t3000_dialer(), t3000_disconnect(), t3000_abort(), - v3451_dialer(), v3451_disconnect(), v3451_abort(), - v831_dialer(), v831_disconnect(), v831_abort(), - dn_dialer(), dn_disconnect(), dn_abort(); - -acu_t acutable[] = { -#if BIZ1031 - "biz31f", biz31f_dialer, biz31_disconnect, biz31_abort, - "biz31w", biz31w_dialer, biz31_disconnect, biz31_abort, -#endif -#if BIZ1022 - "biz22f", biz22f_dialer, biz22_disconnect, biz22_abort, - "biz22w", biz22w_dialer, biz22_disconnect, biz22_abort, -#endif -#if DF02 - "df02", df02_dialer, df_disconnect, df_abort, -#endif -#if DF03 - "df03", df03_dialer, df_disconnect, df_abort, -#endif -#if DN11 - "dn11", dn_dialer, dn_disconnect, dn_abort, -#endif -#ifdef VENTEL - "ventel",ven_dialer, ven_disconnect, ven_abort, -#endif -#ifdef HAYES - "hayes",hay_dialer, hay_disconnect, hay_abort, -#endif -#ifdef COURIER - "courier",cour_dialer, cour_disconnect, cour_abort, -#endif -#ifdef T3000 - "t3000",t3000_dialer, t3000_disconnect, t3000_abort, -#endif -#ifdef V3451 -#ifndef V831 - "vadic",v3451_dialer, v3451_disconnect, v3451_abort, -#endif - "v3451",v3451_dialer, v3451_disconnect, v3451_abort, -#endif -#ifdef V831 -#ifndef V3451 - "vadic",v831_dialer, v831_disconnect, v831_abort, -#endif - "v831",v831_dialer, v831_disconnect, v831_abort, -#endif - 0, 0, 0, 0 -}; - diff --git a/usr.bin/tip/tip/cmds.c b/usr.bin/tip/tip/cmds.c deleted file mode 100644 index 07d7f51f08d0..000000000000 --- a/usr.bin/tip/tip/cmds.c +++ /dev/null @@ -1,952 +0,0 @@ -/* $OpenBSD: cmds.c,v 1.13 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: cmds.c,v 1.7 1997/02/11 09:24:03 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: cmds.c,v 1.13 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" -#include "pathnames.h" - -#include <vis.h> - -/* - * tip - * - * miscellaneous commands - */ - -int quant[] = { 60, 60, 24 }; - -char null = '\0'; -char *sep[] = { "second", "minute", "hour" }; -static char *argv[10]; /* argument vector for take and put */ - -void timeout(); /* timeout function called on alarm */ -void stopsnd(); /* SIGINT handler during file transfers */ -void intcopy(); /* interrupt routine for file transfers */ - -/* - * FTP - remote ==> local - * get a file from the remote host - */ -void -getfl(c) - char c; -{ - char buf[256], *cp, *expand(); - - putchar(c); - /* - * get the UNIX receiving file's name - */ - if (prompt("Local file name? ", copyname, sizeof(copyname))) - return; - cp = expand(copyname); - if ((sfd = creat(cp, 0666)) < 0) { - printf("\r\n%s: cannot creat\r\n", copyname); - return; - } - - /* - * collect parameters - */ - if (prompt("List command for remote system? ", buf, sizeof(buf))) { - unlink(copyname); - return; - } - transfer(buf, sfd, value(EOFREAD)); -} - -/* - * Cu-like take command - */ -void -cu_take(cc) - char cc; -{ - int fd, argc; - char line[BUFSIZ], *expand(), *cp; - - if (prompt("[take] ", copyname, sizeof(copyname))) - return; - if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || - argc > 2) { - printf("usage: <take> from [to]\r\n"); - return; - } - if (argc == 1) - argv[1] = argv[0]; - cp = expand(argv[1]); - if ((fd = creat(cp, 0666)) < 0) { - printf("\r\n%s: cannot create\r\n", argv[1]); - return; - } - (void)snprintf(line, sizeof(line), "cat %s;echo \01", argv[0]); - transfer(line, fd, "\01"); -} - -static jmp_buf intbuf; - -/* - * Bulk transfer routine -- - * used by getfl(), cu_take(), and pipefile() - */ -void -transfer(buf, fd, eofchars) - char *buf, *eofchars; - int fd; -{ - int ct; - char c, buffer[BUFSIZ]; - char *p = buffer; - int cnt, eof; - time_t start; - sig_t f; - char r; - - parwrite(FD, buf, size(buf)); - quit = 0; - kill(pid, SIGIOT); - read(repdes[0], (char *)&ccc, 1); /* Wait until read process stops */ - - /* - * finish command - */ - r = '\r'; - parwrite(FD, &r, 1); - do - read(FD, &c, 1); - while ((c&STRIP_PAR) != '\n'); - tcsetattr(0, TCSAFLUSH, &defchars); - - (void) setjmp(intbuf); - f = signal(SIGINT, intcopy); - start = time(0); - for (ct = 0; !quit;) { - eof = read(FD, &c, 1) <= 0; - c &= STRIP_PAR; - if (quit) - continue; - if (eof || any(c, eofchars)) - break; - if (c == 0) - continue; /* ignore nulls */ - if (c == '\r') - continue; - *p++ = c; - - if (c == '\n' && boolean(value(VERBOSE))) - printf("\r%d", ++ct); - if ((cnt = (p-buffer)) == number(value(FRAMESIZE))) { - if (write(fd, buffer, cnt) != cnt) { - printf("\r\nwrite error\r\n"); - quit = 1; - } - p = buffer; - } - } - if ((cnt = (p-buffer))) - if (write(fd, buffer, cnt) != cnt) - printf("\r\nwrite error\r\n"); - - if (boolean(value(VERBOSE))) - prtime(" lines transferred in ", time(0)-start); - tcsetattr(0, TCSAFLUSH, &term); - write(fildes[1], (char *)&ccc, 1); - signal(SIGINT, f); - close(fd); -} - -/* - * FTP - remote ==> local process - * send remote input to local process via pipe - */ -void -pipefile() -{ - int cpid, pdes[2]; - char buf[256]; - int status, p; - - if (prompt("Local command? ", buf, sizeof(buf))) - return; - - if (pipe(pdes)) { - printf("can't establish pipe\r\n"); - return; - } - - if ((cpid = fork()) < 0) { - printf("can't fork!\r\n"); - return; - } else if (cpid) { - if (prompt("List command for remote system? ", buf, sizeof(buf))) { - close(pdes[0]), close(pdes[1]); - kill (cpid, SIGKILL); - } else { - close(pdes[0]); - signal(SIGPIPE, intcopy); - transfer(buf, pdes[1], value(EOFREAD)); - signal(SIGPIPE, SIG_DFL); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } - } else { - int f; - - dup2(pdes[0], 0); - close(pdes[0]); - for (f = 3; f < 20; f++) - close(f); - execute(buf); - printf("can't execl!\r\n"); - exit(0); - } -} - -/* - * Interrupt service routine for FTP - */ -void -stopsnd() -{ - - stop = 1; - signal(SIGINT, SIG_IGN); -} - -/* - * FTP - local ==> remote - * send local file to remote host - * terminate transmission with pseudo EOF sequence - */ -void -sendfile(cc) - char cc; -{ - FILE *fd; - char *fnamex; - char *expand(); - - putchar(cc); - /* - * get file name - */ - if (prompt("Local file name? ", fname, sizeof(fname))) - return; - - /* - * look up file - */ - fnamex = expand(fname); - if ((fd = fopen(fnamex, "r")) == NULL) { - printf("%s: cannot open\r\n", fname); - return; - } - transmit(fd, value(EOFWRITE), NULL); - if (!boolean(value(ECHOCHECK))) - tcdrain(FD); -} - -/* - * Bulk transfer routine to remote host -- - * used by sendfile() and cu_put() - */ -void -transmit(fd, eofchars, command) - FILE *fd; - char *eofchars, *command; -{ - char *pc, lastc; - int c, ccount, lcount; - time_t start_t, stop_t; - sig_t f; - - kill(pid, SIGIOT); /* put TIPOUT into a wait state */ - stop = 0; - f = signal(SIGINT, stopsnd); - tcsetattr(0, TCSAFLUSH, &defchars); - read(repdes[0], (char *)&ccc, 1); - if (command != NULL) { - for (pc = command; *pc; pc++) - send(*pc); - if (boolean(value(ECHOCHECK))) - read(FD, (char *)&c, 1); /* trailing \n */ - else { - tcdrain(FD); - sleep(5); /* wait for remote stty to take effect */ - } - } - lcount = 0; - lastc = '\0'; - start_t = time(0); - while (1) { - ccount = 0; - do { - c = getc(fd); - if (stop) - goto out; - if (c == EOF) - goto out; - if (c == 0177 && !boolean(value(RAWFTP))) - continue; - lastc = c; - if (c < 040) { - if (c == '\n') { - if (!boolean(value(RAWFTP))) - c = '\r'; - } - else if (c == '\t') { - if (!boolean(value(RAWFTP))) { - if (boolean(value(TABEXPAND))) { - send(' '); - while ((++ccount % 8) != 0) - send(' '); - continue; - } - } - } else - if (!boolean(value(RAWFTP))) - continue; - } - send(c); - } while (c != '\r' && !boolean(value(RAWFTP))); - if (boolean(value(VERBOSE))) - printf("\r%d", ++lcount); - if (boolean(value(ECHOCHECK))) { - timedout = 0; - alarm((long)value(ETIMEOUT)); - do { /* wait for prompt */ - read(FD, (char *)&c, 1); - if (timedout || stop) { - if (timedout) - printf("\r\ntimed out at eol\r\n"); - alarm(0); - goto out; - } - } while ((c&STRIP_PAR) != character(value(PROMPT))); - alarm(0); - } - } -out: - if (lastc != '\n' && !boolean(value(RAWFTP))) - send('\r'); - if (eofchars) { - for (pc = eofchars; *pc; pc++) - send(*pc); - } - stop_t = time(0); - fclose(fd); - signal(SIGINT, f); - if (boolean(value(VERBOSE))) { - if (boolean(value(RAWFTP))) - prtime(" chars transferred in ", stop_t-start_t); - else - prtime(" lines transferred in ", stop_t-start_t); - } - write(fildes[1], (char *)&ccc, 1); - tcsetattr(0, TCSAFLUSH, &term); -} - -/* - * Cu-like put command - */ -void -cu_put(cc) - char cc; -{ - FILE *fd; - char line[BUFSIZ]; - int argc; - char *expand(); - char *copynamex; - - if (prompt("[put] ", copyname, sizeof(copyname))) - return; - if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || - argc > 2) { - printf("usage: <put> from [to]\r\n"); - return; - } - if (argc == 1) - argv[1] = argv[0]; - copynamex = expand(argv[0]); - if ((fd = fopen(copynamex, "r")) == NULL) { - printf("%s: cannot open\r\n", copynamex); - return; - } - if (boolean(value(ECHOCHECK))) - (void)snprintf(line, sizeof(line), "cat>%s\r", argv[1]); - else - (void)snprintf(line, sizeof(line), - "stty -echo;cat>%s;stty echo\r", argv[1]); - transmit(fd, "\04", line); -} - -/* - * FTP - send single character - * wait for echo & handle timeout - */ -void -send(c) - int c; -{ - char cc; - int retry = 0; - - cc = c; - parwrite(FD, &cc, 1); -#ifdef notdef - if (number(value(CDELAY)) > 0 && c != '\r') - nap(number(value(CDELAY))); -#endif - if (!boolean(value(ECHOCHECK))) { -#ifdef notdef - if (number(value(LDELAY)) > 0 && c == '\r') - nap(number(value(LDELAY))); -#endif - return; - } -tryagain: - timedout = 0; - alarm((long)value(ETIMEOUT)); - read(FD, &cc, 1); - alarm(0); - if (timedout) { - printf("\r\ntimeout error (%s)\r\n", ctrl(c)); - if (retry++ > 3) - return; - parwrite(FD, &null, 1); /* poke it */ - goto tryagain; - } -} - -void -timeout() -{ - signal(SIGALRM, timeout); - timedout = 1; -} - -/* - * Stolen from consh() -- puts a remote file on the output of a local command. - * Identical to consh() except for where stdout goes. - */ -void -pipeout(c) -{ - char buf[256]; - int cpid, status, p; - time_t start = time(NULL); - - putchar(c); - if (prompt("Local command? ", buf, sizeof(buf))) - return; - kill(pid, SIGIOT); /* put TIPOUT into a wait state */ - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - tcsetattr(0, TCSAFLUSH, &defchars); - read(repdes[0], (char *)&ccc, 1); - /* - * Set up file descriptors in the child and - * let it go... - */ - if ((cpid = fork()) < 0) - printf("can't fork!\r\n"); - else if (cpid) { - start = time(NULL); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } else { - int i; - - dup2(FD, 1); - for (i = 3; i < 20; i++) - close(i); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - execute(buf); - printf("can't find `%s'\r\n", buf); - exit(0); - } - if (boolean(value(VERBOSE))) - prtime("away for ", time(0)-start); - write(fildes[1], (char *)&ccc, 1); - tcsetattr(0, TCSAFLUSH, &term); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); -} - -#ifdef CONNECT -/* - * Fork a program with: - * 0 <-> remote tty in - * 1 <-> remote tty out - * 2 <-> local tty out - */ -void -consh(c) -{ - char buf[256]; - int cpid, status, p; - time_t start = time(NULL); - - putchar(c); - if (prompt("Local command? ", buf, sizeof(buf))) - return; - kill(pid, SIGIOT); /* put TIPOUT into a wait state */ - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - tcsetattr(0, TCSAFLUSH, &defchars); - read(repdes[0], (char *)&ccc, 1); - /* - * Set up file descriptors in the child and - * let it go... - */ - if ((cpid = fork()) < 0) - printf("can't fork!\r\n"); - else if (cpid) { - start = time(0); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } else { - int i; - - dup2(FD, 0); - dup2(3, 1); - for (i = 3; i < 20; i++) - close(i); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - execute(buf); - printf("can't find `%s'\r\n", buf); - exit(0); - } - if (boolean(value(VERBOSE))) - prtime("away for ", time(0)-start); - write(fildes[1], (char *)&ccc, 1); - tcsetattr(0, TCSAFLUSH, &term); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); -} -#endif - -/* - * Escape to local shell - */ -void -shell() -{ - int shpid, status; - char *cp; - - printf("[sh]\r\n"); - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - unraw(); - if ((shpid = fork())) { - while (shpid != wait(&status)); - raw(); - printf("\r\n!\r\n"); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - return; - } else { - signal(SIGQUIT, SIG_DFL); - signal(SIGINT, SIG_DFL); - if ((cp = strrchr(value(SHELL), '/')) == NULL) - cp = value(SHELL); - else - cp++; - shell_uid(); - execl(value(SHELL), cp, (char *)NULL); - printf("\r\ncan't execl!\r\n"); - exit(1); - } -} - -/* - * TIPIN portion of scripting - * initiate the conversation with TIPOUT - */ -void -setscript() -{ - char c; - /* - * enable TIPOUT side for dialogue - */ - kill(pid, SIGEMT); - if (boolean(value(SCRIPT))) - write(fildes[1], value(RECORD), size(value(RECORD))); - write(fildes[1], "\n", 1); - /* - * wait for TIPOUT to finish - */ - read(repdes[0], &c, 1); - if (c == 'n') - printf("can't create %s\r\n", value(RECORD)); -} - -/* - * Change current working directory of - * local portion of tip - */ -void -chdirectory() -{ - char dirname[PATH_MAX]; - char *cp = dirname; - - if (prompt("[cd] ", dirname, sizeof(dirname))) { - if (stoprompt) - return; - cp = value(HOME); - } - if (chdir(cp) < 0) - printf("%s: bad directory\r\n", cp); - printf("!\r\n"); -} - -void -tipabort(msg) - char *msg; -{ - - kill(pid, SIGTERM); - disconnect(msg); - if (msg != NOSTR) - printf("\r\n%s", msg); - printf("\r\n[EOT]\r\n"); - daemon_uid(); - (void)uu_unlock(uucplock); - unraw(); - exit(0); -} - -void -finish() -{ - char *dismsg; - - if ((dismsg = value(DISCONNECT)) != NOSTR) { - write(FD, dismsg, strlen(dismsg)); - sleep(5); - } - tipabort(NOSTR); -} - -void -intcopy() -{ - raw(); - quit = 1; - longjmp(intbuf, 1); -} - -void -execute(s) - char *s; -{ - char *cp; - - if ((cp = strrchr(value(SHELL), '/')) == NULL) - cp = value(SHELL); - else - cp++; - shell_uid(); - execl(value(SHELL), cp, "-c", s, (char *)NULL); -} - -int -args(buf, a, num) - char *buf, *a[]; - int num; -{ - char *p = buf, *start; - char **parg = a; - int n = 0; - - do { - while (*p && (*p == ' ' || *p == '\t')) - p++; - start = p; - if (*p) - *parg = p; - while (*p && (*p != ' ' && *p != '\t')) - p++; - if (p != start) - parg++, n++; - if (*p) - *p++ = '\0'; - } while (*p && n < num); - - return(n); -} - -void -prtime(s, a) - char *s; - time_t a; -{ - int i; - int nums[3]; - - for (i = 0; i < 3; i++) { - nums[i] = (int)(a % quant[i]); - a /= quant[i]; - } - printf("%s", s); - while (--i >= 0) - if (nums[i] || i == 0 && nums[1] == 0 && nums[2] == 0) - printf("%d %s%c ", nums[i], sep[i], - nums[i] == 1 ? '\0' : 's'); - printf("\r\n!\r\n"); -} - -void -variable() -{ - char buf[256]; - - if (prompt("[set] ", buf, sizeof(buf))) - return; - vlex(buf); - if (vtable[BEAUTIFY].v_access&CHANGED) { - vtable[BEAUTIFY].v_access &= ~CHANGED; - kill(pid, SIGSYS); - } - if (vtable[SCRIPT].v_access&CHANGED) { - vtable[SCRIPT].v_access &= ~CHANGED; - setscript(); - /* - * So that "set record=blah script" doesn't - * cause two transactions to occur. - */ - if (vtable[RECORD].v_access&CHANGED) - vtable[RECORD].v_access &= ~CHANGED; - } - if (vtable[RECORD].v_access&CHANGED) { - vtable[RECORD].v_access &= ~CHANGED; - if (boolean(value(SCRIPT))) - setscript(); - } - if (vtable[TAND].v_access&CHANGED) { - vtable[TAND].v_access &= ~CHANGED; - if (boolean(value(TAND))) - tandem("on"); - else - tandem("off"); - } - if (vtable[LECHO].v_access&CHANGED) { - vtable[LECHO].v_access &= ~CHANGED; - HD = boolean(value(LECHO)); - } - if (vtable[PARITY].v_access&CHANGED) { - vtable[PARITY].v_access &= ~CHANGED; - setparity(NOSTR); - } -} - -void -listvariables() -{ - value_t *p; - char buf[BUFSIZ]; - - puts("v\r"); - for (p = vtable; p->v_name; p++) { - fputs(p->v_name, stdout); - switch (p->v_type&TMASK) { - case STRING: - if (p->v_value) { - strnvis(buf, p->v_value, sizeof(buf), - VIS_WHITE|VIS_OCTAL); - printf(" %s", buf); - } - putchar('\r'); - putchar('\n'); - break; - case NUMBER: - printf(" %ld\r\n", number(p->v_value)); - break; - case BOOL: - printf(" %s\r\n", - boolean(p->v_value) == '!' ? "false" : "true"); - break; - case CHAR: - vis(buf, character(p->v_value), VIS_WHITE|VIS_OCTAL, 0); - printf(" %s\r\n", buf); - break; - } - } -} - -/* - * Turn tandem mode on or off for remote tty. - */ -void -tandem(option) - char *option; -{ - struct termios rmtty; - - tcgetattr(FD, &rmtty); - if (strcmp(option, "on") == 0) { - rmtty.c_iflag |= IXOFF; - term.c_iflag |= IXOFF; - } else { - rmtty.c_iflag &= ~IXOFF; - term.c_iflag &= ~IXOFF; - } - tcsetattr(FD, TCSADRAIN, &rmtty); - tcsetattr(0, TCSADRAIN, &term); -} - -/* - * Send a break. - */ -void -genbrk() -{ - - ioctl(FD, TIOCSBRK, NULL); - sleep(1); - ioctl(FD, TIOCCBRK, NULL); -} - -/* - * Suspend tip - */ -void -suspend(c) - char c; -{ - - unraw(); - kill(c == CTRL('y') ? getpid() : 0, SIGTSTP); - raw(); -} - -/* - * expand a file name if it includes shell meta characters - */ - -char * -expand(name) - char name[]; -{ - static char xname[BUFSIZ]; - char cmdbuf[BUFSIZ]; - int pid, l; - char *cp, *Shell; - int s, pivec[2]; - - if (!anyof(name, "~{[*?$`'\"\\")) - return(name); - /* sigint = signal(SIGINT, SIG_IGN); */ - if (pipe(pivec) < 0) { - perror("pipe"); - /* signal(SIGINT, sigint) */ - return(name); - } - (void)snprintf(cmdbuf, sizeof(cmdbuf), "echo %s", name); - if ((pid = vfork()) == 0) { - Shell = value(SHELL); - if (Shell == NOSTR) - Shell = _PATH_BSHELL; - close(pivec[0]); - close(1); - dup(pivec[1]); - close(pivec[1]); - close(2); - shell_uid(); - execl(Shell, Shell, "-c", cmdbuf, (char *)NULL); - _exit(1); - } - if (pid == -1) { - perror("fork"); - close(pivec[0]); - close(pivec[1]); - return(NOSTR); - } - close(pivec[1]); - l = read(pivec[0], xname, BUFSIZ); - close(pivec[0]); - while (wait(&s) != pid); - ; - s &= 0377; - if (s != 0 && s != SIGPIPE) { - fprintf(stderr, "\"Echo\" failed\n"); - return(NOSTR); - } - if (l < 0) { - perror("read"); - return(NOSTR); - } - if (l == 0) { - fprintf(stderr, "\"%s\": No match\n", name); - return(NOSTR); - } - if (l == BUFSIZ) { - fprintf(stderr, "Buffer overflow expanding \"%s\"\n", name); - return(NOSTR); - } - xname[l] = 0; - for (cp = &xname[l-1]; *cp == '\n' && cp > xname; cp--) - ; - *++cp = '\0'; - return(xname); -} - -/* - * Are any of the characters in the two strings the same? - */ -int -anyof(s1, s2) - char *s1, *s2; -{ - int c; - - while ((c = *s1++)) - if (any(c, s2)) - return(1); - return(0); -} diff --git a/usr.bin/tip/tip/cmdtab.c b/usr.bin/tip/tip/cmdtab.c deleted file mode 100644 index 7f77e2777749..000000000000 --- a/usr.bin/tip/tip/cmdtab.c +++ /dev/null @@ -1,71 +0,0 @@ -/* $OpenBSD: cmdtab.c,v 1.3 2001/09/09 17:58:41 millert Exp $ */ -/* $NetBSD: cmdtab.c,v 1.3 1994/12/08 09:30:46 jtc Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.3 2001/09/09 17:58:41 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -extern int shell(), getfl(), sendfile(), chdirectory(); -extern int finish(), help(), pipefile(), pipeout(), consh(), variable(); -extern int cu_take(), cu_put(), dollar(), genbrk(), suspend(), listvariables(); - -esctable_t etable[] = { - { '!', NORM, "shell", shell }, - { '<', NORM, "receive file from remote host", getfl }, - { '>', NORM, "send file to remote host", sendfile }, - { 't', NORM, "take file from remote UNIX", cu_take }, - { 'p', NORM, "put file to remote UNIX", cu_put }, - { '|', NORM, "pipe remote file", pipefile }, - { '$', NORM, "pipe local command to remote host", pipeout }, -#ifdef CONNECT - { 'C', NORM, "connect program to remote host",consh }, -#endif - { 'c', NORM, "change directory", chdirectory }, - { '.', NORM, "exit from tip", finish }, - {CTRL('d'),NORM,"exit from tip", finish }, - {CTRL('y'),NORM,"suspend tip (local+remote)", suspend }, - {CTRL('z'),NORM,"suspend tip (local only)", suspend }, - { 's', NORM, "set variable", variable }, - { 'v', NORM, "list variables", listvariables }, - { '?', NORM, "get this summary", help }, - { '#', NORM, "send break", genbrk }, - { 0, 0, 0 } -}; diff --git a/usr.bin/tip/tip/cu.c b/usr.bin/tip/tip/cu.c deleted file mode 100644 index 8a44845b4269..000000000000 --- a/usr.bin/tip/tip/cu.c +++ /dev/null @@ -1,175 +0,0 @@ -/* $OpenBSD: cu.c,v 1.10 2001/09/26 06:07:28 pvalchev Exp $ */ -/* $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: cu.c,v 1.10 2001/09/26 06:07:28 pvalchev Exp $"; -#endif /* not lint */ - -#include "tip.h" - -void cleanup(); -void cuusage(); - -/* - * Botch the interface to look like cu's - */ -void -cumain(argc, argv) - int argc; - char *argv[]; -{ - int ch, i; - long l; - char *cp; - static char sbuf[12]; - - if (argc < 2) - cuusage(); - CU = DV = NOSTR; - BR = DEFBR; - while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) { - switch(ch) { - case 'a': - CU = optarg; - break; - case 'l': - if (DV != NULL) { - fprintf(stderr, - "%s: cannot specificy multiple -l options\n", - __progname); - exit(3); - } - if (strchr(optarg, '/')) - DV = optarg; - else - asprintf(&DV, "/dev/%s", optarg); - break; - case 's': - l = strtol(optarg, &cp, 10); - if (*cp != '\0' || l < 0 || l >= INT_MAX || - speed((int)l) == 0) { - fprintf(stderr, "%s: unsupported speed %s\n", - __progname, optarg); - exit(3); - } - BR = (int)l; - break; - case 'h': - setboolean(value(LECHO), TRUE); - HD = TRUE; - break; - case 't': - HW = 1, DU = -1; - break; - case 'o': - setparity("odd"); - break; - case 'e': - setparity("even"); - break; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - if (CU) - CU[strlen(CU)-1] = ch; - if (DV) - DV[strlen(DV)-1] = ch; - break; - default: - cuusage(); - break; - } - } - argc -= optind; - argv += optind; - - switch (argc) { - case 1: - PN = argv[0]; - break; - case 0: - break; - default: - cuusage(); - break; - } - - signal(SIGINT, cleanup); - signal(SIGQUIT, cleanup); - signal(SIGHUP, cleanup); - signal(SIGTERM, cleanup); - - /* - * The "cu" host name is used to define the - * attributes of the generic dialer. - */ - (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR); - if ((i = hunt(sbuf)) == 0) { - printf("all ports busy\n"); - exit(3); - } - if (i == -1) { - printf("link down\n"); - (void)uu_unlock(uucplock); - exit(3); - } - setbuf(stdout, NULL); - loginit(); - user_uid(); - vinit(); - setparity("none"); - setboolean(value(VERBOSE), FALSE); - if (HW) - ttysetup(speed(BR)); - if (connect()) { - printf("Connect failed\n"); - daemon_uid(); - (void)uu_unlock(uucplock); - exit(1); - } - if (!HW) - ttysetup(speed(BR)); -} - -void -cuusage() -{ - fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] [-s speed] [-#] " - "[phone-number]\n"); - exit(8); -} diff --git a/usr.bin/tip/tip/hunt.c b/usr.bin/tip/tip/hunt.c deleted file mode 100644 index 60aaa2350957..000000000000 --- a/usr.bin/tip/tip/hunt.c +++ /dev/null @@ -1,110 +0,0 @@ -/* $OpenBSD: hunt.c,v 1.8 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: hunt.c,v 1.6 1997/04/20 00:02:10 mellon Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)hunt.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: hunt.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -extern char *getremote(); - -static jmp_buf deadline; -static int deadfl; - -void -dead() -{ - deadfl = 1; - longjmp(deadline, 1); -} - -long -hunt(name) - char *name; -{ - char *cp; - sig_t f; - - f = signal(SIGALRM, dead); - while ((cp = getremote(name))) { - deadfl = 0; - uucplock = strrchr(cp, '/'); - if (uucplock == NULL) - uucplock = cp; - else - uucplock++; - - if (uu_lock(uucplock) < 0) - continue; - /* - * Straight through call units, such as the BIZCOMP, - * VADIC and the DF, must indicate they're hardwired in - * order to get an open file descriptor placed in FD. - * Otherwise, as for a DN-11, the open will have to - * be done in the "open" routine. - */ - if (!HW) - break; - if (setjmp(deadline) == 0) { - alarm(10); - FD = open(cp, (O_RDWR | - (boolean(value(DC)) ? O_NONBLOCK : 0))); - } - alarm(0); - if (FD < 0) { - perror(cp); - deadfl = 1; - } - if (!deadfl) { - struct termios cntrl; - - tcgetattr(FD, &cntrl); - if (!boolean(value(DC))) - cntrl.c_cflag |= HUPCL; - tcsetattr(FD, TCSAFLUSH, &cntrl); - ioctl(FD, TIOCEXCL, 0); - signal(SIGALRM, SIG_DFL); - return ((long)cp); - } - (void)uu_unlock(uucplock); - } - signal(SIGALRM, f); - return (deadfl ? -1 : (long)cp); -} diff --git a/usr.bin/tip/tip/log.c b/usr.bin/tip/tip/log.c deleted file mode 100644 index 1a715c0d5f52..000000000000 --- a/usr.bin/tip/tip/log.c +++ /dev/null @@ -1,94 +0,0 @@ -/* $OpenBSD: log.c,v 1.5 2001/09/09 19:30:49 millert Exp $ */ -/* $NetBSD: log.c,v 1.4 1994/12/24 17:56:28 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: log.c,v 1.5 2001/09/09 19:30:49 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -#ifdef ACULOG -static FILE *flog = NULL; - -/* - * Log file maintenance routines - */ -void -logent(group, num, acu, message) - char *group, *num, *acu, *message; -{ - char *user, *timestamp; - struct passwd *pwd; - time_t t; - - if (flog == NULL) - return; - if (flock(fileno(flog), LOCK_EX) < 0) { - perror("flock"); - return; - } - if ((user = getlogin()) == NOSTR) { - if ((pwd = getpwuid(getuid())) == NOPWD) - user = "???"; - else - user = pwd->pw_name; - } - t = time(0); - timestamp = ctime(&t); - timestamp[24] = '\0'; - fprintf(flog, "%s (%s) <%s, %s, %s> %s\n", - user, timestamp, group, -#ifdef PRISTINE - "", -#else - num, -#endif - acu, message); - (void) fflush(flog); - (void) flock(fileno(flog), LOCK_UN); -} - -void -loginit() -{ - flog = fopen(value(LOG), "a"); - if (flog == NULL) - fprintf(stderr, "can't open log file %s.\r\n", value(LOG)); -} -#endif diff --git a/usr.bin/tip/tip/partab.c b/usr.bin/tip/tip/partab.c deleted file mode 100644 index b0e4dc2f732e..000000000000 --- a/usr.bin/tip/tip/partab.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: partab.c,v 1.3 1997/04/02 01:47:02 millert Exp $ */ -/* $NetBSD: partab.c,v 1.4 1996/12/29 10:38:21 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)partab.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: partab.c,v 1.3 1997/04/02 01:47:02 millert Exp $"; -#endif /* not lint */ - -/* - * Even parity table for 0-0177 - */ -const unsigned char evenpartab[] = { - 0000,0201,0202,0003,0204,0005,0006,0207, - 0210,0011,0012,0213,0014,0215,0216,0017, - 0220,0021,0022,0223,0024,0225,0226,0027, - 0030,0231,0232,0033,0234,0035,0036,0237, - 0240,0041,0042,0243,0044,0245,0246,0047, - 0050,0251,0252,0053,0254,0055,0056,0257, - 0060,0261,0262,0063,0264,0065,0066,0267, - 0270,0071,0072,0273,0074,0275,0276,0077, - 0300,0101,0102,0303,0104,0305,0306,0107, - 0110,0311,0312,0113,0314,0115,0116,0317, - 0120,0321,0322,0123,0324,0125,0126,0327, - 0330,0131,0132,0333,0134,0335,0336,0137, - 0140,0341,0342,0143,0344,0145,0146,0347, - 0350,0151,0152,0353,0154,0355,0356,0157, - 0360,0161,0162,0363,0164,0365,0366,0167, - 0170,0371,0372,0173,0374,0175,0176,0377, -}; diff --git a/usr.bin/tip/tip/pathnames.h b/usr.bin/tip/tip/pathnames.h deleted file mode 100644 index cc7cbf4a7a2a..000000000000 --- a/usr.bin/tip/tip/pathnames.h +++ /dev/null @@ -1,44 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.2 1996/06/26 05:40:45 deraadt Exp $ */ -/* $NetBSD: pathnames.h,v 1.3 1994/12/08 09:30:59 jtc Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 - */ - -#include <paths.h> - -#define _PATH_ACULOG "/var/log/aculog" -#define _PATH_LOCKDIRNAME "/var/spool/lock/LCK..%s" -#define _PATH_PHONES "/etc/phones" -#define _PATH_REMOTE "/etc/remote" diff --git a/usr.bin/tip/tip/remote.c b/usr.bin/tip/tip/remote.c deleted file mode 100644 index f2aaeb243523..000000000000 --- a/usr.bin/tip/tip/remote.c +++ /dev/null @@ -1,241 +0,0 @@ -/* $OpenBSD: remote.c,v 1.10 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: remote.c,v 1.5 1997/04/20 00:02:45 mellon Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1992, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: remote.c,v 1.10 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include <stdio.h> -#include <stdlib.h> - -#include "pathnames.h" -#include "tip.h" - -/* - * Attributes to be gleened from remote host description - * data base. - */ -static char **caps[] = { - &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI, - &ES, &EX, &FO, &RC, &RE, &PA -}; - -static char *capstrings[] = { - "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr", - "di", "es", "ex", "fo", "rc", "re", "pa", 0 -}; - -static char *db_array[3] = { _PATH_REMOTE, 0, 0 }; - -#define cgetflag(f) (cgetcap(bp, f, ':') != NULL) - -static void -getremcap(host) - char *host; -{ - char **p, ***q; - char *bp; - char *rempath; - int stat; - - rempath = getenv("REMOTE"); - if (rempath != NULL) { - if (*rempath != '/') - /* we have an entry */ - cgetset(rempath); - else { /* we have a path */ - db_array[1] = rempath; - db_array[2] = _PATH_REMOTE; - } - } - - if ((stat = cgetent(&bp, db_array, host)) < 0) { - if (DV || - host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) { - CU = DV; - HO = host; - HW = 1; - DU = 0; - if (!BR) - BR = DEFBR; - FS = DEFFS; - return; - } - switch(stat) { - case -1: - fprintf(stderr, "%s: unknown host %s\n", __progname, - host); - break; - case -2: - fprintf(stderr, - "%s: can't open host description file\n", - __progname); - break; - case -3: - fprintf(stderr, - "%s: possible reference loop in host description file\n", __progname); - break; - } - exit(3); - } - - for (p = capstrings, q = caps; *p != NULL; p++, q++) - if (**q == NULL) - cgetstr(bp, *p, *q); - if (!BR && (cgetnum(bp, "br", &BR) == -1)) - BR = DEFBR; - if (cgetnum(bp, "fs", &FS) == -1) - FS = DEFFS; - if (DU < 0) - DU = 0; - else - DU = cgetflag("du"); - if (DV == NOSTR) { - fprintf(stderr, "%s: missing device spec\n", host); - exit(3); - } - if (DU && CU == NOSTR) - CU = DV; - if (DU && PN == NOSTR) { - fprintf(stderr, "%s: missing phone number\n", host); - exit(3); - } - if (DU && AT == NOSTR) { - fprintf(stderr, "%s: missing acu type\n", host); - exit(3); - } - - HD = cgetflag("hd"); - - /* - * This effectively eliminates the "hw" attribute - * from the description file - */ - if (!HW) - HW = (CU == NOSTR) || (DU && equal(DV, CU)); - HO = host; - /* - * see if uppercase mode should be turned on initially - */ - if (cgetflag("ra")) - setboolean(value(RAISE), 1); - if (cgetflag("ec")) - setboolean(value(ECHOCHECK), 1); - if (cgetflag("be")) - setboolean(value(BEAUTIFY), 1); - if (cgetflag("nb")) - setboolean(value(BEAUTIFY), 0); - if (cgetflag("sc")) - setboolean(value(SCRIPT), 1); - if (cgetflag("tb")) - setboolean(value(TABEXPAND), 1); - if (cgetflag("vb")) - setboolean(value(VERBOSE), 1); - if (cgetflag("nv")) - setboolean(value(VERBOSE), 0); - if (cgetflag("ta")) - setboolean(value(TAND), 1); - if (cgetflag("nt")) - setboolean(value(TAND), 0); - if (cgetflag("rw")) - setboolean(value(RAWFTP), 1); - if (cgetflag("hd")) - setboolean(value(HALFDUPLEX), 1); - if (cgetflag("dc")) - setboolean(value(DC), 1); - if (RE == NOSTR) - RE = (char *)"tip.record"; - if (EX == NOSTR) - EX = (char *)"\t\n\b\f"; - if (ES != NOSTR) - vstring("es", ES); - if (FO != NOSTR) - vstring("fo", FO); - if (PR != NOSTR) - vstring("pr", PR); - if (RC != NOSTR) - vstring("rc", RC); - if (cgetnum(bp, "dl", &DL) == -1) - DL = 0; - if (cgetnum(bp, "cl", &CL) == -1) - CL = 0; - if (cgetnum(bp, "et", &ET) == -1) - ET = 10; -} - -char * -getremote(host) - char *host; -{ - char *cp; - static char *next; - static int lookedup = 0; - - if (!lookedup) { - if (host == NOSTR && (host = getenv("HOST")) == NOSTR) { - fprintf(stderr, "%s: no host specified\n", __progname); - exit(3); - } - getremcap(host); - next = DV; - lookedup++; - } - /* - * We return a new device each time we're called (to allow - * a rotary action to be simulated) - */ - if (next == NOSTR) - return (NOSTR); - if ((cp = strchr(next, ',')) == NULL) { - DV = next; - next = NOSTR; - } else { - *cp++ = '\0'; - DV = next; - next = cp; - } - return (DV); -} diff --git a/usr.bin/tip/tip/tip.1 b/usr.bin/tip/tip/tip.1 deleted file mode 100644 index 805d77c4151c..000000000000 --- a/usr.bin/tip/tip/tip.1 +++ /dev/null @@ -1,580 +0,0 @@ -.\" $OpenBSD: tip.1,v 1.19 2001/09/23 06:15:30 pvalchev Exp $ -.\" $NetBSD: tip.1,v 1.7 1994/12/08 09:31:05 jtc Exp $ -.\" -.\" Copyright (c) 1980, 1990, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)tip.1 8.4 (Berkeley) 4/18/94 -.\" -.Dd September 9, 2001 -.Dt TIP 1 -.Os -.Sh NAME -.Nm tip , -.Nm cu -.Nd connect to a remote system -.Sh SYNOPSIS -.Nm tip -.Op Fl nv -.Op Fl Ar speed -.Op Ar system\-name -.Nm cu -.Op Fl ehot -.Op Fl a Ar acu -.Op Fl l Ar line -.Op Fl s Ar speed -.Op Fl # -.Op Ar phone\-number -.Sh DESCRIPTION -.Nm -and -.Nm cu -establish a full-duplex connection to another machine, giving the -appearance of being logged in directly on the remote CPU. -It goes without saying that you must have a login on the machine (or -equivalent) to which you wish to connect. -The preferred interface is -.Nm tip . -The -.Nm cu -interface is included for those people attached to the -``call -.Ux Ns '' -command of -.At v7 . -This manual page -describes only -.Nm tip . -.Pp -The options are as follows: -.Bl -tag -width 4n -.It Fl a Ar acu -Set the acu. -.It Fl l Ar line -For -.Nm cu , -specify the line to use. Either of the forms like -.Pa tty00 -or -.Pa /dev/tty00 -are permitted. -.It Fl n -No escape (disable tilde). -.It Fl s Ar speed -For -.Nm cu , -set the speed of the connection. Defaults to 9600. -.It Fl v -Set verbose mode. -.El -.Pp -If -.Ar speed -is specified it will override any baudrate specified in the system -description being used. -.Pp -If neither -.Ar speed -nor -.Ar system-name -are specified, -.Ar system-name -will be set to the value of the -.Ev HOST -environment variable. -.Pp -If -.Ar speed -is specified but -.Ar system-name -is not, -.Ar system-name -will be set to a value of 'tip' with -.Ar speed -appended. -e.g. -.Ic tip -1200 -will set -.Ar system-name -to 'tip1200'. -.Pp -Typed characters are normally transmitted directly to the remote -machine (which does the echoing as well). -A tilde -.Pq Ql ~ -appearing as the first character of a line is an escape signal; the -following are recognized: -.Bl -tag -offset indent -width Fl -.It Ic \&~^D No or Ic \&~ . -Drop the connection and exit (you may still be logged in on the remote -machine). -.It Ic \&~c Op Ar name -Change directory to -.Ar name -(no argument implies change to your home directory). -.It Ic \&~! -Escape to a shell (exiting the shell will return you to -.Nm tip Ns ). -.It Ic \&~> -Copy file from local to remote. -.Nm -prompts for the name of a local file to transmit. -.It Ic \&~< -Copy file from remote to local. -.Nm -prompts first for the name of the file to be sent, then for a command -to be executed on the remote machine. -.It Ic \&~p Ar from Op Ar to -Send a file to a remote -.Ux -host. -The put command causes the remote -.Ux -system to run the command string -.Dq cat > 'to' , -while -.Nm -sends it the -.Dq from -file. -If the -.Dq to -file isn't specified the -.Dq from -file name is used. -this command is actually a -.Ux -specific version of the -.Ic ~> -command. -.It Ic \&~t Ar from Op Ar to -Take a file from a remote -.Ux -host. -As in the put command the -.Dq to -file defaults to the -.Dq from -file name if it isn't specified. -The remote host executes the command string -.Dq cat 'from';echo ^A -to send the file to -.Nm tip . -.It Ic \&~| -Pipe the output from a remote command to a local -.Ux -process. -The command string sent to the local -.Ux -system is processed by the shell. -.It Ic \&~$ -Pipe the output from a local -.Ux -process to the remote host. -The command string sent to the local -.Ux -system is processed by the shell. -.It Ic \&~C -Fork a child process on the local system to perform special protocols -such as \s-1XMODEM\s+1. -The child program will be run with the following somewhat unusual -arrangement of file descriptors: -.Bd -literal -offset indent -0 <-> local tty in -1 <-> local tty out -2 <-> local tty out -3 <-> remote tty in -4 <-> remote tty out -.Ed -.It Ic \&~# -Send a -.Dv BREAK -to the remote system. -For systems which don't support the necessary -.Fn ioctl -call the break is simulated by a sequence of line speed changes and -DEL characters. -.It Ic \&~s -Set a variable (see the discussion below). -.It Ic \&~v -List all variables and their values (if set). -.It Ic \&~^Z -Stop -.Nm -(only available with job control). -.It Ic \&~^Y -Stop only the -.Dq local side -of -.Nm -(only available with job control); the -.Dq remote side -of -.Nm tip , -the side that displays output from the remote host, is left running. -.It Ic \&~? -Get a summary of the tilde escapes. -.El -.Pp -To find the system description and thus the operating characteristics -of -.Ar system-name , -.Nm -searches for a system description with a name identical to -.Ar system-name . -The search order is -.Bl -enum -offset indent -.It -If the environment variable -.Ev REMOTE -does not start with a -.Ql \&/ -it is assumed to be a system description, and is considered first. -.It -If the environment variable -.Ev REMOTE -begins with a -.Ql \&/ -it is assumed to be a path to a -.Xr remote 5 -database, and the specified database is searched. -.It -The default -.Xr remote 5 -database, -.Pa /etc/remote , -is searched. -.El -.Pp -See -.Xr remote 5 -for full documentation on system descriptions. -.Pp -The -.Ar ba -capability is used in system descriptions to specify the baud rate -with which to establish a connection. -If the value specified is not suitable, the baud rate to be used may -be given on the command line, e.g., -.Ql "tip -300 mds" . -.Pp -When -.Nm -establishes a connection it sends out the connection message -specified in the -.Ar cm -capability of the system description being used. -.Pp -When -.Nm -prompts for an argument (e.g., during setup of a file transfer) the -line typed may be edited with the standard erase and kill characters. -A null line in response to a prompt, or an interrupt, will abort the -dialogue and return you to the remote machine. -.Pp -.Nm -guards against multiple users connecting to a remote system by opening -modems and terminal lines with exclusive access, and by honoring the -locking protocol used by -.Xr uucico 8 . -.Pp -During file transfers -.Nm -provides a running count of the number of lines transferred. -When using the -.Ic ~> -and -.Ic ~< -commands, the -.Dq eofread -and -.Dq eofwrite -variables are used to recognize end-of-file when reading, and specify -end-of-file when writing (see below). -File transfers normally depend on tandem mode for flow control. -If the remote system does not support tandem mode, -.Dq echocheck -may be set to indicate -.Nm -should synchronize with the remote system on the echo of each -transmitted character. -.Pp -When -.Nm -must dial a phone number to connect to a system it will print various -messages indicating its actions. -.Nm -supports a variety of auto-call units and modems with the -.Ar at -capability in system descriptions. -.Pp -Support for Ventel 212+ (ventel), Hayes AT-style (hayes), -USRobotics Courier (courier), Telebit T3000 (t3000) and -Racal-Vadic 831 (vadic) units is enabled by default. -.Pp -Support for Bizcomp 1031[fw] (biz31[fw]), Bizcomp 1022[fw] -(biz22[fw]), DEC DF0[23]-AC (df0[23]), DEC DN-11 (dn11) and -Racal-Vadic 3451 (v3451) units can be added by recompiling -.Xr tip 1 -with the appropriate defines. -.Pp -Note that if support for both the Racal-Vadic 831 and 3451 is enabled -they are referred to as the v831 and v3451 respectively. -If only one of the two is supported, it is referred to as vadic. -.Ss VARIABLES -.Nm -maintains a set of variables which control its operation. -Some of these variables are read-only to normal users (root is allowed -to change anything of interest). -Variables may be displayed and set through the -.Sq s -escape. -The syntax for variables is patterned after -.Xr vi 1 -and -.Xr Mail 1 . -Supplying -.Dq all -as an argument to the set command displays all variables readable by -the user. -Alternatively, the user may request display of a particular variable -by attaching a -.Ql ? -to the end. -For example, -.Dq escape? -displays the current escape character. -.Pp -Variables are numeric, string, character, or boolean values. -Boolean variables are set merely by specifying their name; they may be -reset by prepending a -.Ql ! -to the name. -Other variable types are set by concatenating an -.Ql = -and the value. -The entire assignment must not have any blanks in it. -A single set command may be used to interrogate as well as set a -number of variables. -Variables may be initialized at run time by placing set commands -(without the -.Ql ~s -prefix in a file -.Pa .tiprc -in one's home directory). -The -.Fl v -option causes -.Nm -to display the sets as they are made. -Certain common variables have abbreviations. -The following is a list of common variables, their abbreviations, and -their default values: -.Bl -tag -width Ar -.It Ar beautify -(bool) Discard unprintable characters when a session is being -scripted; abbreviated -.Ar be . -.It Ar baudrate -(num) The baud rate at which the connection was established; -abbreviated -.Ar ba . -.It Ar dialtimeout -(num) When dialing a phone number, the time (in seconds) to wait for a -connection to be established; abbreviated -.Ar dial . -.It Ar echocheck -(bool) Synchronize with the remote host during file transfer by -waiting for the echo of the last character transmitted; default is -.Ar off . -.It Ar eofread -(str) The set of characters which signify an end-of-transmission -during a -.Ic ~< -file transfer command; abbreviated -.Ar eofr . -.It Ar eofwrite -(str) The string sent to indicate end-of-transmission during a -.Ic ~> -file transfer command; abbreviated -.Ar eofw . -.It Ar eol -(str) The set of characters which indicate an end-of-line. -.Nm -will recognize escape characters only after an end-of-line. -.It Ar escape -(char) The command prefix (escape) character; abbreviated -.Ar es ; -default value is -.Ql ~ . -.It Ar exceptions -(str) The set of characters which should not be discarded due to the -beautification switch; abbreviated -.Ar ex ; -default value is -.Dq \et\en\ef\eb . -.It Ar force -(char) The character used to force literal data transmission; -abbreviated -.Ar fo ; -default value is -.Ql ^P . -.It Ar framesize -(num) The amount of data (in bytes) to buffer between filesystem -writes when receiving files; abbreviated -.Ar fr . -.It Ar host -(str) The name of the host to which you are connected; abbreviated -.Ar ho . -.It Ar prompt -(char) The character which indicates an end-of-line on the remote -host; abbreviated -.Ar pr ; -default value is -.Ql \en . -This value is used to synchronize during data transfers. -The count of lines transferred during a file transfer command is based -on receipt of this character. -.It Ar raise -(bool) Upper case mapping mode; abbreviated -.Ar ra ; -default value is -.Ar off . -When this mode is enabled, all lowercase letters will be mapped to -uppercase by -.Nm -for transmission to the remote machine. -.It Ar raisechar -(char) The input character used to toggle uppercase mapping mode; -abbreviated -.Ar rc ; -default value is -.Ql ^A . -.It Ar record -(str) The name of the file in which a session script is recorded; -abbreviated -.Ar rec ; -default value is -.Dq tip.record . -.It Ar script -(bool) Session scripting mode; abbreviated -.Ar sc ; -default is -.Ar off . -When -.Ar script -is -.Li true , -.Nm -will record everything transmitted by the remote machine in the script -record file specified in -.Ar record . -If the -.Ar beautify -switch is on, only printable -.Tn ASCII -characters will be included in the script file (those characters -between 040 and 0177). -The variable -.Ar exceptions -is used to indicate characters which are an exception to the normal -beautification rules. -.It Ar tabexpand -(bool) Expand tabs to spaces during file transfers; abbreviated -.Ar tab ; -default value is -.Ar false . -Each tab is expanded to 8 spaces. -.It Ar verbose -(bool) Verbose mode; abbreviated -.Ar verb ; -default is -.Ar true . -When verbose mode is enabled, -.Nm -prints messages while dialing, shows the current number of lines -transferred during a file transfer operations, and more. -.El -.Sh ENVIRONMENT -.Bl -tag -width Fl -.It Ev SHELL -The name of the shell to use for the -.Ic ~! -command; default value is -.Dq /bin/sh . -.It Ev HOME -The home directory to use for the -.Ic ~c -command. -.It Ev HOST -The default value for -.Ar system-name -if none is specified via the command line. -.It Ev REMOTE -A system description, or an absolute path to a -.Xr remote 5 -system description database. -.It Ev PHONES -A path to a -.Xr phones 5 -database. -.El -.Sh FILES -.Bl -tag -width "/var/spool/lock/LCK..*" -compact -.It Pa /etc/remote -global -.Xr remote 5 -database -.It Pa /etc/phones -default -.Xr phones 5 -file -.It Pa ~/.tiprc -initialization file -.It Pa tip.record -record file -.It Pa /var/log/aculog -line access log -.It Pa /var/spool/lock/LCK..* -lock file to avoid conflicts with -.Xr uucp -.El -.Sh SEE ALSO -.Xr phones 5 , -.Xr remote 5 -.Sh HISTORY -The -.Nm -appeared command in -.Bx 4.2 . -.Sh BUGS -The full set of variables is undocumented and should, probably, be -pared down. diff --git a/usr.bin/tip/tip/tip.c b/usr.bin/tip/tip/tip.c deleted file mode 100644 index 64cd76021531..000000000000 --- a/usr.bin/tip/tip/tip.c +++ /dev/null @@ -1,629 +0,0 @@ -/* $OpenBSD: tip.c,v 1.15 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: tip.c,v 1.13 1997/04/20 00:03:05 mellon Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1983, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: tip.c,v 1.15 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * tip - UNIX link to other systems - * tip [-v] [-speed] system-name - * or - * cu phone-number [-s speed] [-l line] [-a acu] - */ -#include "tip.h" -#include "pathnames.h" - -/* - * Baud rate mapping table - */ -int rates[] = { - 0, 50, 75, 110, 134, 150, 200, 300, 600, - 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, -1 -}; - -int disc = TTYDISC; /* tip normally runs this way */ -void intprompt(); -void timeout(); -void cleanup(); -char PNbuf[256]; /* This limits the size of a number */ - -int -main(argc, argv) - int argc; - char *argv[]; -{ - char *system = NOSTR; - int i; - char *p; - char sbuf[12]; - - gid = getgid(); - egid = getegid(); - uid = getuid(); - euid = geteuid(); - if (equal(__progname, "cu")) { - cumode = 1; - cumain(argc, argv); - goto cucommon; - } - - if (argc > 4) { - fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n"); - exit(1); - } - if (!isatty(0)) { - fprintf(stderr, "%s: must be interactive\n", __progname); - exit(1); - } - - for (; argc > 1; argv++, argc--) { - if (argv[1][0] != '-') - system = argv[1]; - else switch (argv[1][1]) { - - case 'v': - vflag++; - break; - - case 'n': - noesc++; - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - BR = atoi(&argv[1][1]); - break; - - default: - fprintf(stderr, "%s: %s, unknown option\n", __progname, - argv[1]); - break; - } - } - - if (system == NOSTR) - goto notnumber; - if (isalpha(*system)) - goto notnumber; - /* - * System name is really a phone number... - * Copy the number then stomp on the original (in case the number - * is private, we don't want 'ps' or 'w' to find it). - */ - if (strlen(system) > sizeof PNbuf - 1) { - fprintf(stderr, "%s: phone number too long (max = %d bytes)\n", - __progname, (int)sizeof(PNbuf) - 1); - exit(1); - } - strncpy( PNbuf, system, sizeof PNbuf - 1 ); - for (p = system; *p; p++) - *p = '\0'; - PN = PNbuf; - (void)snprintf(sbuf, sizeof(sbuf), "tip%ld", BR); - system = sbuf; - -notnumber: - (void)signal(SIGINT, cleanup); - (void)signal(SIGQUIT, cleanup); - (void)signal(SIGHUP, cleanup); - (void)signal(SIGTERM, cleanup); - - if ((i = hunt(system)) == 0) { - printf("all ports busy\n"); - exit(3); - } - if (i == -1) { - printf("link down\n"); - (void)uu_unlock(uucplock); - exit(3); - } - setbuf(stdout, NULL); - loginit(); - - /* - * Now that we have the logfile and the ACU open - * return to the real uid and gid. These things will - * be closed on exit. Swap real and effective uid's - * so we can get the original permissions back - * for removing the uucp lock. - */ - user_uid(); - - /* - * Kludge, their's no easy way to get the initialization - * in the right order, so force it here - */ - if ((PH = getenv("PHONES")) == NOSTR) - PH = _PATH_PHONES; - vinit(); /* init variables */ - setparity("none"); /* set the parity table */ - if ((i = speed(number(value(BAUDRATE)))) == 0) { - printf("%s: bad baud rate %ld\n", __progname, - number(value(BAUDRATE))); - daemon_uid(); - (void)uu_unlock(uucplock); - exit(3); - } - - /* - * Hardwired connections require the - * line speed set before they make any transmissions - * (this is particularly true of things like a DF03-AC) - */ - if (HW) - ttysetup(i); - if ((p = connect())) { - printf("\07%s\n[EOT]\n", p); - daemon_uid(); - (void)uu_unlock(uucplock); - exit(1); - } - if (!HW) - ttysetup(i); -cucommon: - /* - * From here down the code is shared with - * the "cu" version of tip. - */ - - i = fcntl(FD, F_GETFL); - if (i == -1) { - perror("fcntl"); - cleanup(); - } - i = fcntl(FD, F_SETFL, i & ~O_NONBLOCK); - if (i == -1) { - perror("fcntl"); - cleanup(); - } - - tcgetattr(0, &defterm); - term = defterm; - term.c_lflag &= ~(ICANON|IEXTEN|ECHO); - term.c_iflag &= ~(INPCK|ICRNL); - term.c_oflag &= ~OPOST; - term.c_cc[VMIN] = 1; - term.c_cc[VTIME] = 0; - defchars = term; - term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] = - term.c_cc[VDSUSP] = term.c_cc[VDISCARD] = - term.c_cc[VLNEXT] = _POSIX_VDISABLE; - raw(); - - pipe(fildes); pipe(repdes); - (void)signal(SIGALRM, timeout); - - /* - * Everything's set up now: - * connection established (hardwired or dialup) - * line conditioned (baud rate, mode, etc.) - * internal data structures (variables) - * so, fork one process for local side and one for remote. - */ - printf(cumode ? "Connected\r\n" : "\07connected\r\n"); - if ((pid = fork())) - tipin(); - else - tipout(); - /*NOTREACHED*/ - exit(0); -} - -void -cleanup() -{ - - daemon_uid(); - (void)uu_unlock(uucplock); - if (odisc) - ioctl(0, TIOCSETD, (char *)&odisc); - exit(0); -} - -/* - * Muck with user ID's. We are setuid to the owner of the lock - * directory when we start. user_uid() reverses real and effective - * ID's after startup, to run with the user's permissions. - * daemon_uid() switches back to the privileged uid for unlocking. - * Finally, to avoid running a shell with the wrong real uid, - * shell_uid() sets real and effective uid's to the user's real ID. - */ -static int uidswapped; - -void -user_uid() -{ - if (uidswapped == 0) { - seteuid(uid); - uidswapped = 1; - } -} - -void -daemon_uid() -{ - - if (uidswapped) { - seteuid(euid); - uidswapped = 0; - } -} - -void -shell_uid() -{ - setegid(gid); - seteuid(uid); -} - -/* - * put the controlling keyboard into raw mode - */ -void -raw() -{ - tcsetattr(0, TCSADRAIN, &term); -} - - -/* - * return keyboard to normal mode - */ -void -unraw() -{ - tcsetattr(0, TCSADRAIN, &defterm); -} - -static jmp_buf promptbuf; - -/* - * Print string ``s'', then read a string - * in from the terminal. Handles signals & allows use of - * normal erase and kill characters. - */ -int -prompt(s, p, sz) - char *s; - char *p; - size_t sz; -{ - int c; - char *b = p; - sig_t oint, oquit; - - stoprompt = 0; - oint = signal(SIGINT, intprompt); - oquit = signal(SIGQUIT, SIG_IGN); - unraw(); - printf("%s", s); - if (setjmp(promptbuf) == 0) - while ((c = getchar()) != EOF && (*p = c) != '\n' && --sz > 0) - p++; - *p = '\0'; - - raw(); - (void)signal(SIGINT, oint); - (void)signal(SIGQUIT, oquit); - return (stoprompt || p == b); -} - -/* - * Interrupt service routine during prompting - */ -void -intprompt() -{ - - (void)signal(SIGINT, SIG_IGN); - stoprompt = 1; - printf("\r\n"); - longjmp(promptbuf, 1); -} - -/* - * ****TIPIN TIPIN**** - */ -void -tipin() -{ - char gch, bol = 1; - - /* - * Kinda klugey here... - * check for scripting being turned on from the .tiprc file, - * but be careful about just using setscript(), as we may - * send a SIGEMT before tipout has a chance to set up catching - * it; so wait a second, then setscript() - */ - if (boolean(value(SCRIPT))) { - sleep(1); - setscript(); - } - - while (1) { - gch = getchar()&STRIP_PAR; - if ((gch == character(value(ESCAPE))) && bol) { - if (!noesc) { - if (!(gch = escape())) - continue; - } - } else if (!cumode && gch == character(value(RAISECHAR))) { - setboolean(value(RAISE), !boolean(value(RAISE))); - continue; - } else if (gch == '\r') { - bol = 1; - parwrite(FD, &gch, 1); - if (boolean(value(HALFDUPLEX))) - printf("\r\n"); - continue; - } else if (!cumode && gch == character(value(FORCE))) - gch = getchar()&STRIP_PAR; - bol = any(gch, value(EOL)); - if (boolean(value(RAISE)) && islower(gch)) - gch = toupper(gch); - parwrite(FD, &gch, 1); - if (boolean(value(HALFDUPLEX))) - printf("%c", gch); - } -} - -extern esctable_t etable[]; - -/* - * Escape handler -- - * called on recognition of ``escapec'' at the beginning of a line - */ -int -escape() -{ - char gch; - esctable_t *p; - char c = character(value(ESCAPE)); - - gch = (getchar()&STRIP_PAR); - for (p = etable; p->e_char; p++) - if (p->e_char == gch) { - if ((p->e_flags&PRIV) && uid) - continue; - printf("%s", ctrl(c)); - (*p->e_func)(gch); - return (0); - } - /* ESCAPE ESCAPE forces ESCAPE */ - if (c != gch) - parwrite(FD, &c, 1); - return (gch); -} - -int -speed(n) - int n; -{ - int *p; - - for (p = rates; *p != -1; p++) - if (*p == n) - return n; - return 0; -} - -int -any(cc, p) - int cc; - char *p; -{ - char c = cc; - while (p && *p) - if (*p++ == c) - return (1); - return (0); -} - -int -size(s) - char *s; -{ - int i = 0; - - while (s && *s++) - i++; - return (i); -} - -char * -interp(s) - char *s; -{ - static char buf[256]; - char *p = buf, c, *q; - - while ((c = *s++)) { - for (q = "\nn\rr\tt\ff\033E\bb"; *q; q++) - if (*q++ == c) { - *p++ = '\\'; *p++ = *q; - goto next; - } - if (c < 040) { - *p++ = '^'; *p++ = c + 'A'-1; - } else if (c == 0177) { - *p++ = '^'; *p++ = '?'; - } else - *p++ = c; - next: - ; - } - *p = '\0'; - return (buf); -} - -char * -ctrl(c) - char c; -{ - static char s[3]; - - if (c < 040 || c == 0177) { - s[0] = '^'; - s[1] = c == 0177 ? '?' : c+'A'-1; - s[2] = '\0'; - } else { - s[0] = c; - s[1] = '\0'; - } - return (s); -} - -/* - * Help command - */ -void -help(c) - char c; -{ - esctable_t *p; - - printf("%c\r\n", c); - for (p = etable; p->e_char; p++) { - if ((p->e_flags&PRIV) && uid) - continue; - printf("%2s", ctrl(character(value(ESCAPE)))); - printf("%-2s %c %s\r\n", ctrl(p->e_char), - p->e_flags&EXP ? '*': ' ', p->e_help); - } -} - -/* - * Set up the "remote" tty's state - */ -void -ttysetup(speed) - int speed; -{ - struct termios cntrl; - - tcgetattr(FD, &cntrl); - cfsetospeed(&cntrl, speed); - cfsetispeed(&cntrl, speed); - cntrl.c_cflag &= ~(CSIZE|PARENB); - cntrl.c_cflag |= CS8; - if (boolean(value(DC))) - cntrl.c_cflag |= CLOCAL; - cntrl.c_iflag &= ~(ISTRIP|ICRNL); - cntrl.c_oflag &= ~OPOST; - cntrl.c_lflag &= ~(ICANON|ISIG|IEXTEN|ECHO); - cntrl.c_cc[VMIN] = 1; - cntrl.c_cc[VTIME] = 0; - if (boolean(value(TAND))) - cntrl.c_iflag |= IXOFF; - tcsetattr(FD, TCSAFLUSH, &cntrl); -} - -static char partab[0200]; - -/* - * Do a write to the remote machine with the correct parity. - * We are doing 8 bit wide output, so we just generate a character - * with the right parity and output it. - */ -void -parwrite(fd, buf, n) - int fd; - char *buf; - int n; -{ - int i; - char *bp; - - bp = buf; - if (bits8 == 0) - for (i = 0; i < n; i++) { - *bp = partab[(*bp) & 0177]; - bp++; - } - if (write(fd, buf, n) < 0) { - if (errno == EIO) - tipabort("Lost carrier."); - /* this is questionable */ - perror("write"); - } -} - -/* - * Build a parity table with appropriate high-order bit. - */ -void -setparity(defparity) - char *defparity; -{ - int i, flip, clr, set; - char *parity; - extern const unsigned char evenpartab[]; - - if (value(PARITY) == NOSTR) - value(PARITY) = defparity; - parity = value(PARITY); - if (equal(parity, "none")) { - bits8 = 1; - return; - } - bits8 = 0; - flip = 0; - clr = 0377; - set = 0; - if (equal(parity, "odd")) - flip = 0200; /* reverse bit 7 */ - else if (equal(parity, "zero")) - clr = 0177; /* turn off bit 7 */ - else if (equal(parity, "one")) - set = 0200; /* turn on bit 7 */ - else if (!equal(parity, "even")) { - (void) fprintf(stderr, "%s: unknown parity value\r\n", parity); - (void) fflush(stderr); - } - for (i = 0; i < 0200; i++) - partab[i] = (evenpartab[i] ^ flip | set) & clr; -} diff --git a/usr.bin/tip/tip/tip.h b/usr.bin/tip/tip/tip.h deleted file mode 100644 index 4c5ab2064eec..000000000000 --- a/usr.bin/tip/tip/tip.h +++ /dev/null @@ -1,312 +0,0 @@ -/* $OpenBSD: tip.h,v 1.11 2001/09/09 19:30:49 millert Exp $ */ -/* $NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tip.h 8.1 (Berkeley) 6/6/93 - */ - -/* - * tip - terminal interface program - */ - -#include <sys/types.h> -#include <sys/file.h> -#include <sys/time.h> -#include <sys/wait.h> -#include <sys/ioctl.h> - -#include <termios.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <pwd.h> -#include <ctype.h> -#include <setjmp.h> -#include <unistd.h> -#include <errno.h> -#include <limits.h> - -/* - * Remote host attributes - */ -char *DV; /* UNIX device(s) to open */ -char *EL; /* chars marking an EOL */ -char *CM; /* initial connection message */ -char *IE; /* EOT to expect on input */ -char *OE; /* EOT to send to complete FT */ -char *CU; /* call unit if making a phone call */ -char *AT; /* acu type */ -char *PN; /* phone number(s) */ -char *DI; /* disconnect string */ -char *PA; /* parity to be generated */ - -char *PH; /* phone number file */ -char *RM; /* remote file name */ -char *HO; /* host name */ - -long BR; /* line speed for conversation */ -long FS; /* frame size for transfers */ - -short DU; /* this host is dialed up */ -short HW; /* this device is hardwired, see hunt.c */ -char *ES; /* escape character */ -char *EX; /* exceptions */ -char *FO; /* force (literal next) char*/ -char *RC; /* raise character */ -char *RE; /* script record file */ -char *PR; /* remote prompt */ -long DL; /* line delay for file transfers to remote */ -long CL; /* char delay for file transfers to remote */ -long ET; /* echocheck timeout */ -short HD; /* this host is half duplex - do local echo */ -short DC; /* this host is directly connected. */ - -/* - * String value table - */ -typedef - struct { - char *v_name; /* whose name is it */ - char v_type; /* for interpreting set's */ - char v_access; /* protection of touchy ones */ - char *v_abrev; /* possible abreviation */ - char *v_value; /* casted to a union later */ - } - value_t; - -#define STRING 01 /* string valued */ -#define BOOL 02 /* true-false value */ -#define NUMBER 04 /* numeric value */ -#define CHAR 010 /* character value */ - -#define WRITE 01 /* write access to variable */ -#define READ 02 /* read access */ - -#define CHANGED 01 /* low bit is used to show modification */ -#define PUBLIC 1 /* public access rights */ -#define PRIVATE 03 /* private to definer */ -#define ROOT 05 /* root defined */ - -#define TRUE 1 -#define FALSE 0 - -#define ENVIRON 020 /* initialize out of the environment */ -#define IREMOTE 040 /* initialize out of remote structure */ -#define INIT 0100 /* static data space used for initialization */ -#define TMASK 017 - -/* - * Definition of ACU line description - */ -typedef - struct { - char *acu_name; - int (*acu_dialer)(); - int (*acu_disconnect)(); - int (*acu_abort)(); - } - acu_t; - -#define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */ - -/* - * variable manipulation stuff -- - * if we defined the value entry in value_t, then we couldn't - * initialize it in vars.c, so we cast it as needed to keep lint - * happy. - */ - -#define value(v) vtable[v].v_value - -#define number(v) ((long)(v)) -#define boolean(v) ((short)(long)(v)) -#define character(v) ((char)(long)(v)) -#define address(v) ((long *)(v)) - -#define setnumber(v,n) do { (v) = (char *)(long)(n); } while (0) -#define setboolean(v,n) do { (v) = (char *)(long)(n); } while (0) -#define setcharacter(v,n) do { (v) = (char *)(long)(n); } while (0) -#define setaddress(v,n) do { (v) = (char *)(n); } while (0) - -/* - * Escape command table definitions -- - * lookup in this table is performed when ``escapec'' is recognized - * at the begining of a line (as defined by the eolmarks variable). -*/ - -typedef - struct { - char e_char; /* char to match on */ - char e_flags; /* experimental, priviledged */ - char *e_help; /* help string */ - int (*e_func)(); /* command */ - } - esctable_t; - -#define NORM 00 /* normal protection, execute anyone */ -#define EXP 01 /* experimental, mark it with a `*' on help */ -#define PRIV 02 /* priviledged, root execute only */ - -extern int vflag; /* verbose during reading of .tiprc file */ -extern int noesc; /* no escape `~' char */ -extern value_t vtable[]; /* variable table */ - -#ifndef ACULOG -#define logent(a, b, c, d) -#define loginit() -#endif - -/* - * Definition of indices into variable table so - * value(DEFINE) turns into a static address. - */ - -#define BEAUTIFY 0 -#define BAUDRATE 1 -#define DIALTIMEOUT 2 -#define EOFREAD 3 -#define EOFWRITE 4 -#define EOL 5 -#define ESCAPE 6 -#define EXCEPTIONS 7 -#define FORCE 8 -#define FRAMESIZE 9 -#define HOST 10 -#define LOG 11 -#define PHONES 12 -#define PROMPT 13 -#define RAISE 14 -#define RAISECHAR 15 -#define RECORD 16 -#define REMOTE 17 -#define SCRIPT 18 -#define TABEXPAND 19 -#define VERBOSE 20 -#define SHELL 21 -#define HOME 22 -#define ECHOCHECK 23 -#define DISCONNECT 24 -#define TAND 25 -#define LDELAY 26 -#define CDELAY 27 -#define ETIMEOUT 28 -#define RAWFTP 29 -#define HALFDUPLEX 30 -#define LECHO 31 -#define PARITY 32 - -#define NOVAL ((value_t *)NULL) -#define NOACU ((acu_t *)NULL) -#define NOSTR ((char *)NULL) -#define NOFILE ((FILE *)NULL) -#define NOPWD ((struct passwd *)0) - -struct termios term; /* current mode of terminal */ -struct termios defterm; /* initial mode of terminal */ -struct termios defchars; /* current mode with initial chars */ - -FILE *fscript; /* FILE for scripting */ - -int fildes[2]; /* file transfer synchronization channel */ -int repdes[2]; /* read process sychronization channel */ -int FD; /* open file descriptor to remote host */ -int AC; /* open file descriptor to dialer (v831 only) */ -int vflag; /* print .tiprc initialization sequence */ -int noesc; /* no `~' escape char */ -int sfd; /* for ~< operation */ -int pid; /* pid of tipout */ -uid_t uid, euid; /* real and effective user id's */ -gid_t gid, egid; /* real and effective group id's */ -int stop; /* stop transfer session flag */ -int quit; /* same; but on other end */ -int intflag; /* recognized interrupt */ -int stoprompt; /* for interrupting a prompt session */ -int timedout; /* ~> transfer timedout */ -int cumode; /* simulating the "cu" program */ -int bits8; /* terminal is is 8-bit mode */ -#define STRIP_PAR (bits8 ? 0377 : 0177) - -char fname[PATH_MAX]; /* file name buffer for ~< */ -char copyname[PATH_MAX]; /* file name buffer for ~> */ -char ccc; /* synchronization character */ -char ch; /* for tipout */ -char *uucplock; /* name of lock file for uucp's */ - -int odisc; /* initial tty line discipline */ -extern int disc; /* current tty discpline */ - -extern char *__progname; /* program name */ - -extern char *ctrl(); -extern char *vinterp(); -extern char *connect(); - -char *sname __P((char *s)); -int any __P((int cc, char *p)); -int anyof __P((char *s1, char *s2)); -int args __P((char *buf, char *a[], int num)); -int escape __P((void)); -int prompt __P((char *s, char *p, size_t sz)); -int size __P((char *s)); -int speed __P((int n)); -int uu_lock __P((char *ttyname)); -int uu_unlock __P((char *ttyname)); -int vstring __P((char *s, char *v)); -long hunt __P((char *name)); -void cumain __P((int argc, char *argv[])); -void daemon_uid __P((void)); -void disconnect __P((char *reason)); -void execute __P((char *s)); -void logent __P((char *group, char *num, char *acu, char *message)); -void loginit __P((void)); -void prtime __P((char *s, time_t a)); -void parwrite __P((int fd, char *buf, int n)); -void raw __P((void)); -void send __P((int c)); -void setparity __P((char *defparity)); -void setscript __P((void)); -void shell_uid __P((void)); -void tandem __P((char *option)); -void tipabort __P((char *msg)); -void tipin __P((void)); -void tipout __P((void)); -void transfer __P((char *buf, int fd, char *eofchars)); -void transmit __P((FILE *fd, char *eofchars, char *command)); -void ttysetup __P((int speed)); -void unraw __P((void)); -void user_uid __P((void)); -void vinit __P((void)); -void vlex __P((char *s)); diff --git a/usr.bin/tip/tip/tipout.c b/usr.bin/tip/tip/tipout.c deleted file mode 100644 index d1ff53cdc0bb..000000000000 --- a/usr.bin/tip/tip/tipout.c +++ /dev/null @@ -1,172 +0,0 @@ -/* $OpenBSD: tipout.c,v 1.8 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: tipout.c,v 1.5 1996/12/29 10:34:12 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)tipout.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: tipout.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" -/* - * tip - * - * lower fork of tip -- handles passive side - * reading from the remote host - */ - -static jmp_buf sigbuf; - -/* - * TIPOUT wait state routine -- - * sent by TIPIN when it wants to posses the remote host - */ -void -intIOT() -{ - - write(repdes[1],&ccc,1); - read(fildes[0], &ccc,1); - longjmp(sigbuf, 1); -} - -/* - * Scripting command interpreter -- - * accepts script file name over the pipe and acts accordingly - */ -void -intEMT() -{ - char c, line[256]; - char *pline = line; - char reply; - - read(fildes[0], &c, 1); - while (c != '\n' && pline - line < sizeof(line)) { - *pline++ = c; - read(fildes[0], &c, 1); - } - *pline = '\0'; - if (boolean(value(SCRIPT)) && fscript != NULL) - fclose(fscript); - if (pline == line) { - setboolean(value(SCRIPT), FALSE); - reply = 'y'; - } else { - if ((fscript = fopen(line, "a")) == NULL) - reply = 'n'; - else { - reply = 'y'; - setboolean(value(SCRIPT), TRUE); - } - } - write(repdes[1], &reply, 1); - longjmp(sigbuf, 1); -} - -void -intTERM() -{ - - if (boolean(value(SCRIPT)) && fscript != NULL) - fclose(fscript); - exit(0); -} - -void -intSYS() -{ - - setboolean(value(BEAUTIFY), !boolean(value(BEAUTIFY))); - longjmp(sigbuf, 1); -} - -/* - * ****TIPOUT TIPOUT**** - */ -void -tipout() -{ - char buf[BUFSIZ]; - char *cp; - int cnt; - sigset_t mask, omask; - - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - signal(SIGEMT, intEMT); /* attention from TIPIN */ - signal(SIGTERM, intTERM); /* time to go signal */ - signal(SIGIOT, intIOT); /* scripting going on signal */ - signal(SIGHUP, intTERM); /* for dial-ups */ - signal(SIGSYS, intSYS); /* beautify toggle */ - (void) setjmp(sigbuf); - sigprocmask(SIG_BLOCK, NULL, &omask); - for (;;) { - sigprocmask(SIG_SETMASK, &omask, NULL); - cnt = read(FD, buf, BUFSIZ); - if (cnt <= 0) { - /* lost carrier */ - if (cnt < 0 && errno == EIO) { - sigemptyset(&mask); - sigaddset(&mask, SIGTERM); - sigprocmask(SIG_BLOCK, &mask, NULL); - intTERM(); - /*NOTREACHED*/ - } - continue; - } - sigemptyset(&mask); - sigaddset(&mask, SIGEMT); - sigaddset(&mask, SIGTERM); - sigaddset(&mask, SIGIOT); - sigaddset(&mask, SIGSYS); - sigprocmask(SIG_BLOCK, &mask, NULL); - for (cp = buf; cp < buf + cnt; cp++) - *cp &= STRIP_PAR; - write(1, buf, cnt); - if (boolean(value(SCRIPT)) && fscript != NULL) { - if (!boolean(value(BEAUTIFY))) { - fwrite(buf, 1, cnt, fscript); - continue; - } - for (cp = buf; cp < buf + cnt; cp++) - if ((*cp >= ' ' && *cp <= '~') || - any(*cp, value(EXCEPTIONS))) - putc(*cp, fscript); - } - } -} diff --git a/usr.bin/tip/tip/uucplock.c b/usr.bin/tip/tip/uucplock.c deleted file mode 100644 index a2a703b9edbe..000000000000 --- a/usr.bin/tip/tip/uucplock.c +++ /dev/null @@ -1,132 +0,0 @@ -/* $OpenBSD: uucplock.c,v 1.6 1998/07/13 02:11:44 millert Exp $ */ -/* $NetBSD: uucplock.c,v 1.7 1997/02/11 09:24:08 mrg Exp $ */ - -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: uucplock.c,v 1.6 1998/07/13 02:11:44 millert Exp $"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/file.h> -#include <sys/dir.h> -#include <stdio.h> -#include <string.h> -#include <signal.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#include "pathnames.h" - -/* - * uucp style locking routines - * return: 0 - success - * -1 - failure - */ - -int -uu_lock(ttyname) - char *ttyname; -{ - int fd, pid; - char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN]; - char text_pid[81]; - int len; - - (void)snprintf(tbuf, sizeof tbuf, _PATH_LOCKDIRNAME, ttyname); - fd = open(tbuf, O_RDWR|O_CREAT|O_EXCL, 0660); - if (fd < 0) { - /* - * file is already locked - * check to see if the process holding the lock still exists - */ - fd = open(tbuf, O_RDWR, 0); - if (fd < 0) { - perror(tbuf); - fprintf(stderr, "Can't open lock file.\n"); - return(-1); - } - len = read(fd, text_pid, sizeof(text_pid)-1); - if(len<=0) { - perror(tbuf); - (void)close(fd); - fprintf(stderr, "Can't read lock file.\n"); - return(-1); - } - text_pid[len] = 0; - pid = atol(text_pid); - - if (kill(pid, 0) == 0 || errno != ESRCH) { - (void)close(fd); /* process is still running */ - return(-1); - } - /* - * The process that locked the file isn't running, so - * we'll lock it ourselves - */ - fprintf(stderr, "Stale lock on %s PID=%d... overriding.\n", - ttyname, pid); - if (lseek(fd, (off_t)0, SEEK_SET) < 0) { - perror(tbuf); - (void)close(fd); - fprintf(stderr, "Can't seek lock file.\n"); - return(-1); - } - /* fall out and finish the locking process */ - } - pid = getpid(); - (void)sprintf(text_pid, "%10d\n", pid); - len = strlen(text_pid); - if (write(fd, text_pid, len) != len) { - (void)close(fd); - (void)unlink(tbuf); - perror("lock write"); - return(-1); - } - (void)close(fd); - return(0); -} - -int -uu_unlock(ttyname) - char *ttyname; -{ - char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN]; - - (void)snprintf(tbuf, sizeof tbuf, _PATH_LOCKDIRNAME, ttyname); - return(unlink(tbuf)); -} diff --git a/usr.bin/tip/tip/value.c b/usr.bin/tip/tip/value.c deleted file mode 100644 index 20817e9cdffc..000000000000 --- a/usr.bin/tip/tip/value.c +++ /dev/null @@ -1,365 +0,0 @@ -/* $OpenBSD: value.c,v 1.7 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: value.c,v 1.6 1997/02/11 09:24:09 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)value.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: value.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -#define MIDDLE 35 - -static value_t *vlookup(); -static int col = 0; - -/* - * Variable manipulation - */ -void -vinit() -{ - value_t *p; - char *cp; - FILE *f; - char file[FILENAME_MAX]; - - for (p = vtable; p->v_name != NULL; p++) { - if (p->v_type&ENVIRON) - if ((cp = getenv(p->v_name))) - p->v_value = cp; - if (p->v_type&IREMOTE) - setnumber(p->v_value, *address(p->v_value)); - } - /* - * Read the .tiprc file in the HOME directory - * for sets - */ - if (strlen(value(HOME)) + sizeof("/.tiprc") > sizeof(file)) { - (void)fprintf(stderr, "Home directory path too long: %s\n", - value(HOME)); - } else { - snprintf(file, sizeof file, "%s/.tiprc", value(HOME)); - if ((f = fopen(file, "r")) != NULL) { - char *tp; - - while (fgets(file, sizeof(file)-1, f) != NULL) { - if (vflag) - printf("set %s", file); - if ((tp = strrchr(file, '\n'))) - *tp = '\0'; - vlex(file); - } - fclose(f); - } - } - /* - * To allow definition of exception prior to fork - */ - vtable[EXCEPTIONS].v_access &= ~(WRITE<<PUBLIC); -} - -static int vaccess(); - -/*VARARGS1*/ -void -vassign(p, v) - value_t *p; - char *v; -{ - - if (!vaccess(p->v_access, WRITE)) { - printf("access denied\r\n"); - return; - } - switch (p->v_type&TMASK) { - - case STRING: - if (p->v_value && equal(p->v_value, v)) - return; - if (!(p->v_type&(ENVIRON|INIT))) - free(p->v_value); - if ((p->v_value = strdup(v)) == NOSTR) { - printf("out of core\r\n"); - return; - } - p->v_type &= ~(ENVIRON|INIT); - break; - - case NUMBER: - if (number(p->v_value) == number(v)) - return; - setnumber(p->v_value, number(v)); - break; - - case BOOL: - if (boolean(p->v_value) == (*v != '!')) - return; - setboolean(p->v_value, (*v != '!')); - break; - - case CHAR: - if (character(p->v_value) == *v) - return; - setcharacter(p->v_value, *v); - } - p->v_access |= CHANGED; -} - -static void vprint(); -static void vtoken(); - -void -vlex(s) - char *s; -{ - value_t *p; - - if (equal(s, "all")) { - for (p = vtable; p->v_name; p++) - if (vaccess(p->v_access, READ)) - vprint(p); - } else { - char *cp; - - do { - if ((cp = vinterp(s, ' '))) - cp++; - vtoken(s); - s = cp; - } while (s); - } - if (col > 0) { - printf("\r\n"); - col = 0; - } -} - -static void -vtoken(s) - char *s; -{ - value_t *p; - char *cp; - char *expand(); - - if ((cp = strchr(s, '='))) { - *cp = '\0'; - if ((p = vlookup(s))) { - cp++; - if (p->v_type&NUMBER) - vassign(p, atoi(cp)); - else { - if (strcmp(s, "record") == 0) - cp = expand(cp); - vassign(p, cp); - } - return; - } - } else if ((cp = strchr(s, '?'))) { - *cp = '\0'; - if ((p = vlookup(s)) && vaccess(p->v_access, READ)) { - vprint(p); - return; - } - } else { - if (*s != '!') - p = vlookup(s); - else - p = vlookup(s+1); - if (p != NOVAL) { - vassign(p, s); - return; - } - } - printf("%s: unknown variable\r\n", s); -} - -static void -vprint(p) - value_t *p; -{ - char *cp; - extern char *interp(), *ctrl(); - - if (col > 0 && col < MIDDLE) - while (col++ < MIDDLE) - putchar(' '); - col += size(p->v_name); - switch (p->v_type&TMASK) { - - case BOOL: - if (boolean(p->v_value) == FALSE) { - col++; - putchar('!'); - } - printf("%s", p->v_name); - break; - - case STRING: - printf("%s=", p->v_name); - col++; - if (p->v_value) { - cp = interp(p->v_value, NULL); - col += size(cp); - printf("%s", cp); - } - break; - - case NUMBER: - col += 6; - printf("%s=%-5ld", p->v_name, number(p->v_value)); - break; - - case CHAR: - printf("%s=", p->v_name); - col++; - if (p->v_value) { - cp = ctrl(character(p->v_value)); - col += size(cp); - printf("%s", cp); - } - break; - } - if (col >= MIDDLE) { - col = 0; - printf("\r\n"); - return; - } -} - - -static int -vaccess(mode, rw) - unsigned mode, rw; -{ - if (mode & (rw<<PUBLIC)) - return (1); - if (mode & (rw<<PRIVATE)) - return (1); - return ((mode & (rw<<ROOT)) && getuid() == 0); -} - -static value_t * -vlookup(s) - char *s; -{ - value_t *p; - - for (p = vtable; p->v_name; p++) - if (equal(p->v_name, s) || (p->v_abrev && equal(p->v_abrev, s))) - return (p); - return (NULL); -} - -char * -vinterp(s, stop) - char *s; - char stop; -{ - char *p = s, c; - int num; - - while ((c = *s++) && c != stop) - switch (c) { - - case '^': - if (*s) - *p++ = *s++ - 0100; - else - *p++ = c; - break; - - case '\\': - num = 0; - c = *s++; - if (c >= '0' && c <= '7') - num = (num<<3)+(c-'0'); - else { - char *q = "n\nr\rt\tb\bf\f"; - - for (; *q; q++) - if (c == *q++) { - *p++ = *q; - goto cont; - } - *p++ = c; - cont: - break; - } - if ((c = *s++) >= '0' && c <= '7') { - num = (num<<3)+(c-'0'); - if ((c = *s++) >= '0' && c <= '7') - num = (num<<3)+(c-'0'); - else - s--; - } else - s--; - *p++ = num; - break; - - default: - *p++ = c; - } - *p = '\0'; - return (c == stop ? s-1 : NULL); -} - -/* - * assign variable s with value v (for NUMBER or STRING or CHAR types) - */ -int -vstring(s,v) - char *s; - char *v; -{ - value_t *p; - char *expand(); - - p = vlookup(s); - if (p == 0) - return (1); - if (p->v_type&NUMBER) - vassign(p, atoi(v)); - else { - if (strcmp(s, "record") == 0) - v = expand(v); - vassign(p, v); - } - return (0); -} diff --git a/usr.bin/tip/tip/vars.c b/usr.bin/tip/tip/vars.c deleted file mode 100644 index 6131dd29f97d..000000000000 --- a/usr.bin/tip/tip/vars.c +++ /dev/null @@ -1,118 +0,0 @@ -/* $OpenBSD: vars.c,v 1.2 1996/06/26 05:40:50 deraadt Exp $ */ -/* $NetBSD: vars.c,v 1.3 1994/12/08 09:31:19 jtc Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)vars.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: vars.c,v 1.2 1996/06/26 05:40:50 deraadt Exp $"; -#endif /* not lint */ - -#include "tip.h" -#include "pathnames.h" - -/* - * Definition of variables - */ -value_t vtable[] = { - { "beautify", BOOL, (READ|WRITE)<<PUBLIC, - "be", (char *)TRUE }, - { "baudrate", NUMBER|IREMOTE|INIT, (READ<<PUBLIC)|(WRITE<<ROOT), - "ba", (char *)&BR }, - { "dialtimeout",NUMBER, (READ<<PUBLIC)|(WRITE<<ROOT), - "dial", (char *)60 }, - { "eofread", STRING|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "eofr", (char *)&IE }, - { "eofwrite", STRING|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "eofw", (char *)&OE }, - { "eol", STRING|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - NOSTR, (char *)&EL }, - { "escape", CHAR, (READ|WRITE)<<PUBLIC, - "es", (char *)'~' }, - { "exceptions", STRING|INIT|IREMOTE, (READ|WRITE)<<PUBLIC, - "ex", (char *)&EX }, - { "force", CHAR, (READ|WRITE)<<PUBLIC, - "fo", (char *)CTRL('p') }, - { "framesize", NUMBER|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "fr", (char *)&FS }, - { "host", STRING|IREMOTE|INIT, READ<<PUBLIC, - "ho", (char *)&HO }, - { "log", STRING|INIT, (READ|WRITE)<<ROOT, - NOSTR, _PATH_ACULOG }, - { "phones", STRING|INIT|IREMOTE, READ<<PUBLIC, - NOSTR, (char *)&PH }, - { "prompt", CHAR, (READ|WRITE)<<PUBLIC, - "pr", (char *)'\n' }, - { "raise", BOOL, (READ|WRITE)<<PUBLIC, - "ra", (char *)FALSE }, - { "raisechar", CHAR, (READ|WRITE)<<PUBLIC, - "rc", (char *)CTRL('a') }, - { "record", STRING|INIT|IREMOTE, (READ|WRITE)<<PUBLIC, - "rec", (char *)&RE }, - { "remote", STRING|INIT|IREMOTE, READ<<PUBLIC, - NOSTR, (char *)&RM }, - { "script", BOOL, (READ|WRITE)<<PUBLIC, - "sc", (char *)FALSE }, - { "tabexpand", BOOL, (READ|WRITE)<<PUBLIC, - "tab", (char *)FALSE }, - { "verbose", BOOL, (READ|WRITE)<<PUBLIC, - "verb", (char *)TRUE }, - { "SHELL", STRING|ENVIRON|INIT, (READ|WRITE)<<PUBLIC, - NULL, _PATH_BSHELL }, - { "HOME", STRING|ENVIRON, (READ|WRITE)<<PUBLIC, - NOSTR, NOSTR }, - { "echocheck", BOOL, (READ|WRITE)<<PUBLIC, - "ec", (char *)FALSE }, - { "disconnect", STRING|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "di", (char *)&DI }, - { "tandem", BOOL, (READ|WRITE)<<PUBLIC, - "ta", (char *)TRUE }, - { "linedelay", NUMBER|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "ldelay", (char *)&DL }, - { "chardelay", NUMBER|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "cdelay", (char *)&CL }, - { "etimeout", NUMBER|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "et", (char *)&ET }, - { "rawftp", BOOL, (READ|WRITE)<<PUBLIC, - "raw", (char *)FALSE }, - { "halfduplex", BOOL, (READ|WRITE)<<PUBLIC, - "hdx", (char *)FALSE }, - { "localecho", BOOL, (READ|WRITE)<<PUBLIC, - "le", (char *)FALSE }, - { "parity", STRING|INIT|IREMOTE, (READ|WRITE)<<PUBLIC, - "par", (char *)&PA }, - { NOSTR, NULL, NULL, NOSTR, NOSTR } -}; |