snmptrapfmt-1.17/0000755000000000000000000000000013717531701010710 5ustar snmptrapfmt-1.17/.gitignore0000644000000000000000000000042211167410632012672 0ustar .gitignore *.o debian/files debian/snmptrapfmt.debhelper.log debian/snmptrapfmt.postinst.debhelper debian/snmptrapfmt.postrm.debhelper debian/snmptrapfmt.prerm.debhelper debian/snmptrapfmt.substvars debian/snmptrapfmt debian/stamp-makefile-build snmptrapfmt snmptrapfmthdlr snmptrapfmt-1.17/COPYING0000644000000000000000000010437411167410632011750 0ustar GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 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. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . snmptrapfmt-1.17/Makefile0000755000000000000000000000157213717531701012360 0ustar # Makefile for snmptrapfmt # TARGETS= snmptrapfmthdlr snmptrapfmt MANPAGES= snmptrapfmthdlr.8 snmptrapfmt.8 CONFFILES= snmptrapfmt.conf DEFS= -I /usr/include/ucd-snmp -DSTDC_HEADERS -DDEBUG # Compilation parameters: CFLAGS= -O2 -g -Wall $(DEFS) `dpkg-buildflags --get CFLAGS` `dpkg-buildflags --get CPPFLAGS` LIBS= `dpkg-buildflags --get LDFLAGS` -lsnmp # You should not need to change anything below this line. all: $(TARGETS) package: clean dpkg-buildpackage -us -uc deb: clean debuild binary snmptrapfmt: snmptrapfmt.o log.o ${CC} -g -o $@ snmptrapfmt.o log.o ${LIBS} snmptrapfmthdlr: snmptrapfmthdlr.o log.o ${CC} -g -o $@ snmptrapfmthdlr.o log.o ${LIBS} clean: rm -f core *.o *.bak ${TARGETS} clobber: clean rm -f $(TARGETS) install: make cp ${TARGETS} ${DESTDIR}/usr/sbin cp ${MANPAGES} ${DESTDIR}/usr/share/man/man8 cp $(CONFFILES) $(DESTDIR)/etc/snmp snmptrapfmt-1.17/debian/0000755000000000000000000000000013717531701012132 5ustar snmptrapfmt-1.17/debian/README.debian0000755000000000000000000000115611167410632014235 0ustar snmptrapfmt for DEBIAN ---------------------- Snmptrapfmt offers formatting functionality to snmptrapd. To achieve this snmptrapd is configured to call snmptrapfmthdlr. This small program is called for each trap by default. You could configure it to be called only for selected traps. The trap data is then forwarded to a local pipe from which snmptrapfmt picks it up and does further processing. An example configuration for snmptrapd is provided in /usr/share/doc/snmptrapfmt/examples/snmptrapd.conf. See also: SNMPTRAPFMTHDLR(8) SNMPTRAPFMT(8) Jochen Friedrich Thu, 9 Apr 2009 16.12:39 +0200 snmptrapfmt-1.17/debian/changelog0000644000000000000000000001043213717531701014004 0ustar snmptrapfmt (1.17) unstable; urgency=medium * QA upload. * Makefile: do not link with -lnsl as no symbols from that library are used. -- Aurelien Jarno Thu, 20 Aug 2020 19:32:49 +0200 snmptrapfmt (1.16) unstable; urgency=medium * QA upload. * debian/rules: do not link with now obsolete libieee.a. -- Aurelien Jarno Mon, 12 Feb 2018 18:16:00 +0000 snmptrapfmt (1.15) unstable; urgency=medium * QA upload. * Set maintainer to Debian QA Group. (see #878721) * Remove Conflicts/Replaces with "none". (Closes: #747753) * Actually link against the snmp library. -- Adrian Bunk Sat, 21 Oct 2017 21:26:43 +0300 snmptrapfmt (1.14+nmu1) unstable; urgency=low * Non-maintainer upload. * Enable hardened build flags (Closes: #656783) -- Moritz Muehlenhoff Fri, 01 Jun 2012 16:39:26 +0200 snmptrapfmt (1.14) unstable; urgency=low * Update Policy to 3.8.1 (no changes) * Update debhelper to version 7 (replacing cdbs) * Add short description to LSB header * Add Vcs and Homepage to control file * Remove unnecessary install scripts (Closes: #522915) * Replace autoupdate of snmptrapd config by example config (Closes: #552917) * Add GPL-3 boilerplate to source files * Add misc:Depends for debhelpers to package dependencies -- Jochen Friedrich Thu, 09 Apr 2009 17:07:13 +0200 snmptrapfmt (1.13) unstable; urgency=low * Update Policy to 3.7.3 * Add patch from Len Sorensen to fix a segfault on traps without enterprise value (Closes: #442162) * Add LSB header to init script (Closes: #457752) -- Jochen Friedrich Tue, 29 Jan 2008 16:25:28 +0100 snmptrapfmt (1.12) unstable; urgency=low * Fix dependecies (Closes: #431924) * Update Policy to 3.7.2 (no changes) * Update debhelper compat level to 5 -- Jochen Friedrich Wed, 11 Jul 2007 10:50:10 +0200 snmptrapfmt (1.11) unstable; urgency=low * Convert build system to cdbs. -- Jochen Friedrich Wed, 22 Mar 2006 21:14:58 +0100 snmptrapfmt (1.10) unstable; urgency=high * Fixed insecure temporary log file [log.c, CVE-2006-0050] Thanks to Will Aoki for finding this bug. -- Jochen Friedrich Wed, 15 Mar 2006 19:39:00 +0100 snmptrapfmt (1.09) unstable; urgency=low * Update for libsnmp transition. -- Jochen Friedrich Thu, 15 Sep 2005 20:51:06 +0200 snmptrapfmt (1.08) unstable; urgency=low * New Maintainer (Closes: #266820) * Updated to use net-snmp instead of UCD snmp. (Closes: #237760) -- Jochen Friedrich Fri, 7 Jan 2005 22:51:17 +0100 snmptrapfmt (1.07) unstable; urgency=low * New Version for upload. No changes. Closes #174401. -- Bernd Schumacher Fri, 3 Oct 2003 16:32:58 +0200 snmptrapfmt (1.06) unstable; urgency=low * fixed SIGSEV. Closes #174401. -- Uwe Maier Mon, 29 Sep 2003 12:56:30 +0200 snmptrapfmt (1.05) unstable; urgency=low * New version, just to get the source signed with my gpg key. * See (1.04). Closes #131737. -- Bernd Schumacher Tue, 25 Feb 2003 22:12:24 +0100 snmptrapfmt (1.04) unstable; urgency=low * Uses proper daemonization mechanism. Closes #131737. * Startup parameters without fixed sequence. -- Uwe Maier Thu, 12 Feb 2003 17:24:51 +0100 snmptrapfmt (1.03) unstable; urgency=low * Now depends on libsnmp4.2/libsnmp4.2-dev. Closes #97230. -- Bernd Schumacher Sat, 12 May 2001 14:07:04 +0200 snmptrapfmt (1.02) unstable; urgency=low * New version number indicates that this is a debian-only package. * Changed copyright to gnu. * Changed autor of version 1.0-1 to real autor in changelog. * Wrote file Readme.debian. * Extended description of OID format in snmptrapfmt.conf * Corrected lintian errors in conffiles, control and prerm * Enabled -Wall in Makefile. Corrected Warnings in sources. -- Bernd Schumacher Fri, 4 May 2001 21:09:39 +0200 snmptrapfmt (1.0-1) unstable; urgency=low * Initial Release. -- Siegfried Rupietta Tue, 01 May 2001 09:33:57 +0200 Local variables: mode: debian-changelog End: snmptrapfmt-1.17/debian/compat0000644000000000000000000000000211167410632013324 0ustar 7 snmptrapfmt-1.17/debian/control0000644000000000000000000000163013172710543013533 0ustar Source: snmptrapfmt Section: net Priority: optional Maintainer: Debian QA Group Standards-Version: 3.8.1 Build-Depends: debhelper (>=7), libsnmp-dev Homepage: https://alioth.debian.org/projects/snmptrapfmt/ Vcs-Git: git://git.debian.org/git/collab-maint/snmptrapfmt.git Vcs-Browser: http://git.debian.org/?p=collab-maint/snmptrapfmt.git Package: snmptrapfmt Architecture: any Depends: snmpd, ${shlibs:Depends}, ${misc:Depends} Description: configurable snmp trap handler daemon for snmpd This package contains a configurable snmp trap handler daemon for snmpd. The output of this trap handler daemon may be specified via a configuration file and written to a logfile or to the syslog daemon. During installation of this package, the configuration file for the snmptrapd daemon is changed (old version is saved) to activate the trap handler. The snmpd and snmptrapd daemons are restarted. snmptrapfmt-1.17/debian/copyright0000644000000000000000000000214211167410632014060 0ustar Copyright (C) 2001 Uwe Maier Copyright (C) 2001 - 2005 Bernd Schumacher Hewlett Packard Consulting Copyright (C) 2005 - 2009 Jochen Friedrich This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 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. See the GNU General Public License in the COPYING file at the root directory of this project for more details. On Debian GNU/Linux systems, the complete text of the GNU General Public License can be found in `/usr/share/common-licenses/GPL-3'. This package was built by Uwe Maier and is maintained by Jochen Friedrich . Bernd Schumacher Hewlett Packard Consulting previously maintained this package. snmptrapfmt-1.17/debian/dirs0000644000000000000000000000006011167410632013006 0ustar usr/sbin usr/share/man/man8 etc/init.d etc/snmp snmptrapfmt-1.17/debian/examples/0000755000000000000000000000000011167410632013744 5ustar snmptrapfmt-1.17/debian/examples/snmptrapd.conf0000644000000000000000000000051411167410632016623 0ustar ############################################################################### # # An example configuration file for configuring the Net-SNMP # snmptrapd agent to forward traps to snmptrapfmthdlr. # ############################################################################### # traphandle default /usr/sbin/snmptrapfmthdlr snmptrapfmt-1.17/debian/init.d0000755000000000000000000000253611167410632013247 0ustar #! /bin/sh # ### BEGIN INIT INFO # Provides: snmptrapfmt # Required-Start: $remote_fs # Required-Stop: $remote_fs # Should-Start: $network snmpd # Should-Stop: $network snmpd # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: SNMP Trap Formatting Agent ### END INIT INFO # # Written by Miquel van Smoorenburg . # Modified for Debian GNU/Linux by Ian Murdock . # Modified for Debian by Christoph Lameter PATH=/bin:/usr/bin:/sbin:/usr/sbin DAEMON=/usr/sbin/snmptrapfmt # The following value is extracted by debstd to figure out how to generate # the postinst script. Edit the field to change the way the script is # registered through update-rc.d (see the manpage for update-rc.d!) FLAGS="defaults 50" test -f $DAEMON || exit 0 case "$1" in start) start-stop-daemon --start --verbose --exec $DAEMON -- -D -f /etc/snmp/snmptrapfmt.conf ;; stop) start-stop-daemon --stop --verbose --exec $DAEMON -p /var/run/snmptrapfmt.pid ;; restart|reload|force-reload) start-stop-daemon --stop --verbose --exec $DAEMON -p /var/run/snmptrapfmt.pid start-stop-daemon --start --verbose --exec $DAEMON -- -D -f /etc/snmp/snmptrapfmt.conf ;; *) echo "Usage: /etc/init.d/snmptrapfmt {start|stop}" exit 1 ;; esac exit 0 snmptrapfmt-1.17/debian/postrm0000755000000000000000000000040511167410632013377 0ustar #!/bin/sh set -e # remove pid and pipe file only when being removed case "$1" in "remove"| "purge"| "abort-install") # make sure pipe and pid file are removed rm -f /var/run/snmptrapfmt.p /var/run/snmptrapfmt.pid ;; *) ;; esac #DEBHELPER# snmptrapfmt-1.17/debian/rules0000755000000000000000000000044111167410632013205 0ustar #!/usr/bin/make -f build: build-stamp build-stamp: dh build touch build-stamp clean: dh clean install: build install-stamp install-stamp: dh install touch install-stamp binary-arch: install dh binary-arch binary-indep: install dh binary-indep binary: binary-arch binary-indep snmptrapfmt-1.17/debian/snmptrapfmt.examples0000644000000000000000000000003711167410632016241 0ustar debian/examples/snmptrapd.conf snmptrapfmt-1.17/log.c0000755000000000000000000000512311167410632011635 0ustar /* * log.c * * Generic log module. * * Usage: loginit(ProcessName, NameOfLogFile, LogLevel, appendMode); * logging(level, msg, ...); * * Copyright (C) 2001 Uwe Maier * Copyright (C) 2001 - 2005 Bernd Schumacher Hewlett Packard Consulting * * Copyright (C) 2005 - 2009 Jochen Friedrich * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * 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. * * See the GNU General Public License in the COPYING file at the * root directory of this project for more details. * */ /* --- include section --- */ #include "log.h" #include #include #include #include #include #include #include #include #include #include /* --- private variables --- */ static char *fp_pname; static char *fp_fname; static int fp_level; static int fp_appmode; static FILE *fp_log = NULL; /* --- public functions --- */ void loginit (char *pname, char *fname, int loglevel, int appendMode) { fp_pname = pname; fp_fname = fname; fp_level = loglevel; fp_appmode = appendMode; } void logging (int level, char *fmt, ...) { va_list ap; char tbuf[24]; time_t curtime; int fp_fd; /* level of current message too high ? */ if (level > fp_level) { return; } /* open the log file, if necessary */ if (!fp_log) { fp_fd = open (fp_fname, O_CREAT|O_EXCL|O_WRONLY, S_IREAD|S_IWRITE); if (fp_fd < 0) { fprintf (stderr, "Cannot open log file '%s' [%s]\n", fp_fname, strerror (errno)); exit (1); } fp_log = fdopen (fp_fd, "w"); if (fp_log == NULL) { fprintf (stderr, "Cannot open log file '%s' [%s]\n", fp_fname, strerror (errno)); exit (1); } } /* construct the log entry */ time (&curtime); strftime (tbuf, sizeof (tbuf), "%Y%m%d.%H%M%S", localtime (&curtime)); fprintf (fp_log, "%s (%s-%d): ", tbuf, fp_pname, getpid ()); va_start (ap, fmt); vfprintf (fp_log, fmt, ap); va_end (ap); fprintf (fp_log, "\n"); fflush (fp_log); } snmptrapfmt-1.17/log.h0000755000000000000000000000214711167410632011645 0ustar /* * log.c * * Generic log module. * * Usage: loginit(ProcessName, NameOfLogFile, LogLevel, appendMode); * logging(level, msg, ...); * * Copyright (C) 2001 Uwe Maier * Copyright (C) 2001 - 2005 Bernd Schumacher Hewlett Packard Consulting * * Copyright (C) 2005 - 2009 Jochen Friedrich * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * 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. * * See the GNU General Public License in the COPYING file at the * root directory of this project for more details. * */ /* --- public functions --- */ void loginit (char* pname, char* fname, int loglevel, int appendMode); void logging (int level, char* fmt, ...); snmptrapfmt-1.17/snmptrapfmt.80000755000000000000000000000443011167410632013354 0ustar .\"/*********************************************************** .\" Copyright 2001 by Hewlett-Packard GmbH .\" .\" All Rights Reserved .\" .\" ******************************************************************/ .TH SNMPTRAPFMT 8 "19 DECEMBER 2002" .UC 4 .SH NAME snmptrapfmt - Receive and log SNMP trap messages from a trap handler. .SH SYNOPSIS snmptrapfmt [-d num] [-D] [-f cfgfile] .SH DESCRIPTION Snmptrapfmt receives SNMP trap data through a local pipe. The trap data is written to this pipe by a SNMP trap handler which is called by .B "snmptrapd" (configuration is done in /etc/snmp/snmptrapd.conf) during the installation if this package. Snmptrapfmt formats the received trap data according to the specifications in the configuration file /etc/snmp/snmptrapfmt.conf (see this file for the syntax). The output of the snmptrapfmt application may be written to a log file or forwarded to the syslog daemon. .PP The option .B "-d 1" should be specified to enable tracing. Trace information is then written to the file /var/tmp/snmptrapfmt.trc. .PP If the option .B "-f cfgfile" is given, the output of the daemon is configured via the mentioned configuration file. If this option is not specified, a default output format is used. .PP If the option .B "-D" is given, the the program will daemonize into the background. .PP The syntax of the configuration file is explained in .B "/etc/snmp/snmptrapfmt.conf" ! .PP .SH "FILES" .B "/etc/init.d/snmptrapfmt" is the start/stop script. .PP .B "/etc/snmp/snmptrapfmt.conf" is the configuration file. .PP .B "/var/run/snmptrapfmt.pid" is the PID file. .PP .B "/etc/snmp/snmptrapd.conf" is the configuration file of the snmptrapd daemon, which calls the trap handler snmptrapfmthdlr. .PP .B "/usr/sbin/snmptrapfmt" is the executable of the application. .PP .B "/usr/sbin/snmptrapfmthdlr" is the executable of the trap handler. .PP .B "/var/run/snmptrapfmt.p" is the communication pipe between the trap handler snmptrapfmthdlr and the formatter snmptrapfmt. .PP .B "/var/tmp/snmptrapfmt.trc" is the trace file if the option -d is specified. .PP .B "/var/log/snmptrapfmt.log" is the log file as specified in the configuration file. .PP .SH "SEE ALSO" snmptrapfmthdlr(8), syslog(8), variables(5), RFC 1155, RFC 1156, RFC 1157, SNMP Security Internet Drafts snmptrapfmt-1.17/snmptrapfmt.c0000755000000000000000000012115711167410632013435 0ustar /* --------------------------------------------------------------------------- * * snmptrapfmt.c - receive snmp trapd from a trap handler and log them * * formatted with `indent -gnu -di16 -nut -bls -bli0 -cli2 -cdb -sc -ts2 -ncdb -c33 -cs -npcs` * --------------------------------------------------------------------------- * Copyright (C) 2001 Uwe Maier * Copyright (C) 2001 - 2005 Bernd Schumacher Hewlett Packard Consulting * * Copyright (C) 2005 - 2009 Jochen Friedrich * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * 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. * * See the GNU General Public License in the COPYING file at the * root directory of this project for more details. * */ /* --- imprt section --- */ #include "snmptrapfmt.h" #include "log.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* --- local defines and type --- */ #define FREEMEM(x) if(x){free(x);} #define PNAME "snmptrapfmt" #define LOGFILE "/var/tmp/snmptrapfmt.trc" #define USAGE "Usage: snmptrapfmt [-f cfgfile] [-D] [-d level]\n" #define CFGNAME "/etc/snmp/snmptrapfmt.conf" #define PIDFILE "/var/run/snmptrapfmt.pid" /* definitions of standard OIDs */ #define OID_SYM_SNMPTRAPADDRESS ".iso.org.dod.internet.snmpV2.snmpModules.snmpCommunityMIB.snmpCommunityMIBObjects.snmpTrapAddress.0" #define OID_NUM_SNMPTRAPADDRESS ".1.3.6.1.6.3.18.1.3.0" #define OID_SYM_SNMPTRAPCOMMUNITY ".iso.org.dod.internet.snmpV2.snmpModules.snmpCommunityMIB.snmpCommunityMIBObjects.snmpTrapCommunity.0" #define OID_NUM_SNMPTRAPCOMMUNITY ".1.3.6.1.6.3.18.1.4.0" #define OID_SYM_SNMPTRAPENTERPRISE ".iso.org.dod.internet.snmpV2.snmpModules.snmpMIB.snmpMIBObjects.snmpTrap.snmpTrapEnterprise.0" #define OID_NUM_SNMPTRAPENTERPRISE ".1.3.6.1.6.3.1.1.4.3.0" typedef struct { /* --- a trap variable --- */ char *v_oid; /* the oid */ char *v_val; /* the value */ } t_var; typedef struct { /* --- a received trap --- */ char *s_agentname; /* hostname of agent (in PDU) */ char *s_agentaddr; /* IP of agent (in PDU) */ char *s_senderaddr; /* IP of trap sender (real) */ char *s_uptime; /* uptime of agent */ char *s_trapoid; /* trap OID (snmpV2 notation) */ char *s_community; /* trap community */ char *s_enterprise; /* trap enterprise */ int n_var; /* number of trap variables in the array */ t_var *a_var; /* array of trap variables */ } t_trap; /* --- local variables --- */ int o_loglev = 0; /* log level */ char *o_cfgname = CFGNAME; /* configuration file name */ FILE *o_logfile = NULL; /* log file handle */ long pid; /* value of already running process */ /* --- logfile configuration section --- */ /* logfile configuration constants */ #define OIDFMT_OID 0 /* print OIDs numerical */ #define OIDFMT_TEXT 1 /* print OIDs symbolically */ #define NODEFMT_IP 0 /* print nodenames as IP address */ #define NODEFMT_FQDN 1 /* print nodenames as FQDN */ #define NODEFMT_NAME 2 /* print short nodenames */ /* logfile configuration tokens */ #define TOK_SUBST "SUBST" #define TOK_OIDFMT "OIDFMT" #define TOK_NODEFMT "NODEFMT" #define TOK_VARFMT "VARFMT" #define TOK_LOGFMT "LOGFMT" #define TOK_LOGFILE "LOGFILE" #define TOK_CMUSNMP "CMUSNMP" /* logfile configuration variables */ char cfg_subst1 = ';'; /* subst this char in var values */ char cfg_subst2 = ' '; /* by this char */ int cfg_oidfmt = OIDFMT_OID; /* format for OID's */ int cfg_nodefmt = NODEFMT_FQDN; /* format for nodenames */ char *cfg_varfmt = ";[%s] %n (%t) : %v"; /* format string for vars in '$*' */ char *cfg_logfmt = "$x;$A;$e;$G;$S$*"; /* format for the logfile entry */ char *cfg_logname = NULL; /* --- local functions --- */ static void lg_print_config(); static FILE *lg_parse_config(); static char *lg_format_buffer(); static void lg_sprint_node(); static void lg_sprint_oid(); static void lg_sprint_int(); static void lg_sprint_ulong(); static void lg_sprint_ASNtype(); static void lg_sprint_var(); static void lg_sprint_string(); static void free_trap(t_trap * p_trap); static void process_trapdata(FILE * f); static int read_trapdata(FILE * f, t_trap * p_trap); static char *copy_string(char *buf); static int read_oidval(FILE * f, char **pp_oid, char **pp_val, char *msg); static char *get_generic_id(char *trapoid); static char *get_specific_id(char *trapoid); static u_long uptime_ticks(char *uptime); static long create_pidfile(void); /* ------------------------------------------------------------------------- */ char * trap_description(trap) int trap; { switch (trap) { case 0: return "Cold Start"; case 1: return "Warm Start"; case 2: return "Link Down"; case 3: return "Link Up"; case 4: return "Authentication Failure"; case 5: return "EGP Neighbor Loss"; case 6: return "Enterprise Specific"; default: return "Unknown Type"; } } /* ------------------------------------------------------------------------- */ static u_long uptime_ticks(char *uptime) { int days; int hours; int mins; int secs; int csecs; u_long ticks = 0; if (sscanf(uptime, "%d:%d:%d:%d.%d", &days, &hours, &mins, &secs, &csecs) == 5) { ticks = (60 * 60 * 24 * days + 60 * 60 * hours + 60 * mins + secs) * 100 + csecs; } return ticks; } /* ------------------------------------------------------------------------- */ static long create_pidfile(void) { long retval = -1; int pidfile; /* create new pidfile - or open existing one without destroying it */ if ((pidfile = open(PIDFILE, O_WRONLY | O_CREAT, 0644)) != -1) { /* File created or opened, now try to lock */ if (flock(pidfile, LOCK_EX | LOCK_NB) == 0) { char pid[11]; /* we have been too nice when opening file - now start at beginning */ ftruncate(pidfile, 0); lseek(pidfile, 0, SEEK_SET); sprintf(pid, "%d", getpid()); write(pidfile, pid, strlen(pid)); /* we don't close the file - so try to get output to file */ fsync(pidfile); retval = 0; } else { /* file is locked by other process */ } } else { retval = errno; } return retval; } /* ------------------------------------------------------------------------- */ int main(argc, argv) int argc; char *argv[]; { int fd_pipe; FILE *f_pipe; fd_set fdset; struct timeval timeout; int numfds; char is_daemon = FALSE; int c; /* Check the arguments */ while (1) { int option_index = 0; static struct option long_options[] = { {"D", 0, 0, 0}, {"d", 1, 0, 0}, {"f", 1, 0, 0}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "Dd:f:", long_options, &option_index); if (c == -1) break; switch (c) { case 'd': o_loglev = atoi(optarg); break; case 'D': is_daemon = TRUE; break; case 'f': o_cfgname = optarg; break; default: printf("Unknown argument %c", c); } } /* now go into daemon mode if commandline parameter is set */ if (is_daemon) { if (daemon(0, 1) != 0) { /* error occured while going into daemon mode */ fprintf(stderr, "Error while daemonizing (%s)\n", strerror(errno)); fprintf(stderr, "Aborting ...\n"); exit(1); } } /* check for existing process - allocate PID file */ if (create_pidfile() != 0) { fprintf(stderr, "Error occured while creating pid file\n"); fprintf(stderr, " not running as root or other snmptrapfmt running?\n"); fprintf(stderr, "Aborting ...\n"); /* that's it - drop off now */ exit(1); } /* In daemon mode, now redirect std* to /dev/null */ if (is_daemon) { freopen("/dev/null", "r", stdin); freopen("/dev/null", "w", stdout); freopen("/dev/null", "w", stderr); } /* Init the logfile, non append mode, i.e. create a new one */ loginit(PNAME, LOGFILE, o_loglev, 0); logging(1, "Starting ..."); /* Parse the configuration file */ o_logfile = lg_parse_config(o_cfgname); /* Print the logfile output specification */ if (o_loglev > 0) { lg_print_config(); } /* Create and open the pipe */ logging(1, "Create the pipe '%s' ...", PIPENAME); if ((mkfifo(PIPENAME, S_IWUSR | S_IRUSR) == -1) && (errno != EEXIST)) { logging(0, "Cannot create the pipe '%s' [%s]", PIPENAME, strerror(errno)); exit(1); } fd_pipe = open(PIPENAME, O_RDWR, S_IWUSR | S_IRUSR); if (fd_pipe < 0) { logging(0, "Cannot open the pipe '%s' [%s]", PIPENAME, strerror(errno)); exit(1); } f_pipe = fdopen(fd_pipe, "w+"); if (f_pipe == NULL) { logging(0, "Cannot associate stream with file handle for pipe '%s' [%s]", PIPENAME, strerror(errno)); exit(1); } logging(1, "Pipe opened for reading"); /* Main loop: sit and wait until data arrives on the pipe */ while (1) { FD_ZERO(&fdset); /* wait for data on the pipe handle */ FD_SET(fd_pipe, &fdset); timeout.tv_sec = 5; /* wait 5 seconds for data */ timeout.tv_usec = 0; numfds = select(fd_pipe + 1, &fdset, 0, 0, &timeout); switch (numfds) { case 0: logging(1, "Timeout occurred ..."); break; case -1: if (errno == EINTR) { logging(1, "Interrupted select() - continue"); continue; } else { logging(0, "Error from select() [%s]", strerror(errno)); exit(1); } break; default: logging(1, "Data available ..."); process_trapdata(f_pipe); break; } } /* not reached */ } /* ------------------------------------------------------------------------- */ /* Parse the configuration file: * - check for the tokens and set the config variables * - open the logfile and return the file pointer (or NULL if no logfile) * - syntax of configuration file (fixed text in '') * comment lines begin with '#' * file ::= line | file line * line ::= 'SUBST' '=' '\'char'\'char'\' * | 'OIDFMT' '=' ( 'text' | 'oid' ) * | 'NODEFMT' '=' ( 'ip' | 'fqdn' | 'name' ) * | 'VARFMT' '=' stringV * | 'LOGFMT' '=' stringL * | 'LOGFILE' '=' string * | 'CMUSNMP' '=' string >>>OBSOLETE<<< * string ::= '"' { char | '\"' } '"' * stringV ::= '"' { char | '%s' | '%n' | '%t' | '%v' | '%%' } '"' * stringL ::= '"' { char | '$#' | '$*' | '$x' | '$r' | '$R' * | '$e' | '$A' | '$G' | '$S' | '$T' * | '$$' * | '\n' | '\r' | '\t' | '\\' } '"' * * - Tokens and associated config variables are: * SUBST ... cfg_subst1, cfg_subst2 (both char) * OIDFMT ... cfg_oidfmt (OIDFMT_TEXT,_OID) * NODEFMT ... cfg_nodefmt (NODEFMT_IP, _FQDN, _NAME) * VARFMT ... cfg_varfmt (char*) * LOGFMT ... cfg_logfmt (char*) * LOGFILE ... cfg_logname (char*) * CMUSNMP ... cfg_cmusnmp (char*) >>>OBSOLETE<<< * */ static FILE * lg_parse_config(cfgname) char *cfgname; { FILE *cfg; FILE *f_log = NULL; char lbuf[1024]; int lno = 0; logging(1, "Parsing config file '%s'", cfgname); if (!(cfg = fopen(cfgname, "r"))) { logging(0, "Cannot open config file '%s' - %s\n", cfgname, strerror(errno)); return NULL; } while (fgets(lbuf, sizeof(lbuf), cfg)) { char *p; logging(1, "Read line '%s'", lbuf); p = strtok(lbuf, "=\n"); /* check for comment or empty lines */ lno++; if (!p || (*p == '#')) { continue; } /* check for tokens */ if (strcasecmp(TOK_SUBST, p) == 0) { char *p1 = strtok(NULL, "\n"); /* the substitution */ int ok = 1; if (!p1 || !*p1 || (*p1 != '\\')) { ok = 0; } else { p1++; cfg_subst1 = *p1++; if (*p1++ == '\\' && *p1) { cfg_subst2 = *p1; } else { ok = 0; } } if (!ok) { logging(0, "Expected: %s=\\\\\\ in file '%s',%d", TOK_SUBST, cfgname, lno); } } else if (strcasecmp(TOK_OIDFMT, p) == 0) { char *p1 = strtok(NULL, " \n"); int ok = 1; if (!p1 || !*p1) { ok = 0; } else if (strcasecmp("text", p1) == 0) { #if 0 cfg_oidfmt = OIDFMT_TEXT; #else logging(0, "Error: Format for OID must be set in /etc/snmp/snmp.conf"); cfg_oidfmt = OIDFMT_OID; #endif } else if (strcasecmp("oid", p1) == 0) { cfg_oidfmt = OIDFMT_OID; } else { ok = 0; } if (!ok) { logging(0, "Expected: %s='text' | 'oid' in file '%s',%d", TOK_OIDFMT, cfgname, lno); } } else if (strcasecmp(TOK_NODEFMT, p) == 0) { char *p1 = strtok(NULL, " \n"); int ok = 1; if (!p1) { ok = 0; } else if (strcasecmp("ip", p1) == 0) { cfg_nodefmt = NODEFMT_IP; } else if (strcasecmp("fqdn", p1) == 0) { cfg_nodefmt = NODEFMT_FQDN; } else if (strcasecmp("name", p1) == 0) { cfg_nodefmt = NODEFMT_NAME; } else { ok = 0; } if (!ok) { logging(0, "Expected: %s='ip' | 'fqdn' | 'name' in file '%s',%d", TOK_NODEFMT, cfgname, lno); } } else if ((strcasecmp(TOK_VARFMT, p) == 0) || (strcasecmp(TOK_LOGFMT, p) == 0) || (strcasecmp(TOK_LOGFILE, p) == 0) || (strcasecmp(TOK_CMUSNMP, p) == 0)) { char *p1 = strtok(NULL, "\n"); int ok = 1; if (!p1) { ok = 0; } else if (*p1 == '\"') { char *p2 = strrchr(++p1, '\"'); if (p2) { char *pval; *p2 = '\0'; pval = strdup(p1); if (strcasecmp(TOK_VARFMT, p) == 0) { cfg_varfmt = pval; } else if (strcasecmp(TOK_LOGFMT, p) == 0) { cfg_logfmt = pval; } else if (strcasecmp(TOK_LOGFILE, p) == 0) { cfg_logname = pval; } else if (strcasecmp(TOK_CMUSNMP, p) == 0) { logging(0, "The option 'CMUSNMP' is obsolete"); } } else { ok = 0; } } else { ok = 0; } if (!ok) { logging(0, "Expected: %s=\"\" in file '%s',%d", p, cfgname, lno); } } else { logging(0, "Missing token in file '%s',%d", cfgname, lno); } } fclose(cfg); /* now open the log file (if any) */ if (cfg_logname && *cfg_logname) { f_log = fopen(cfg_logname, "a"); if (!f_log) { logging(0, "Cannot append to logfile '%s' [%s]", cfg_logname, strerror(errno)); } } return f_log; } /* ------------------------------------------------------------------------- */ /* print the logfile configuration values */ static void lg_print_config() { char *oidfmt[2]; char *nodefmt[3]; oidfmt[OIDFMT_OID] = "oid"; oidfmt[OIDFMT_TEXT] = "text"; nodefmt[NODEFMT_IP] = "ip"; nodefmt[NODEFMT_FQDN] = "fqdn"; nodefmt[NODEFMT_NAME] = "name"; logging(1, "Configuration variables:"); logging(1, " cfg_subst1 = '%c'", cfg_subst1); logging(1, " cfg_subst2 = '%c'", cfg_subst2); logging(1, " cfg_oidfmt = %s", oidfmt[cfg_oidfmt]); logging(1, " cfg_nodefmt = %s", nodefmt[cfg_nodefmt]); logging(1, " cfg_varfmt = \"%s\"", cfg_varfmt); logging(1, " cfg_logfmt = \"%s\"", cfg_logfmt); logging(1, " cfg_logname = \"%s\"", (cfg_logname && *cfg_logname ? cfg_logname : "")); } /* ------------------------------------------------------------------------- */ /* Allocate and format the output buffer. * Return the pointer to the allocated area or NULL if an error occurred. */ static char * lg_format_buffer(t_trap * p_trap, time_t trap_time) { static char buf[4000]; /* the output buffer */ char *cPtr; /* points to next character in output buf */ int bRem; /* number of remaining chars in output buf */ /* (starting with cPtr) */ char *lPtr; /* points to next char in log format */ int seqno; /* sequence number of variable */ logging(1, "Formatting the trap data with '%s' ...", cfg_logfmt); /* init */ bRem = sizeof(buf) - 1; /* leave space for EOS */ cPtr = buf; /* process the log format string */ for (lPtr = cfg_logfmt; *lPtr; lPtr++) { int l; /* local */ /* Assertion: bRem > 0 */ switch (*lPtr) { case '\\': switch (*++lPtr) { case 'n': *cPtr++ = '\n'; break; case 'r': *cPtr++ = '\r'; break; case 't': *cPtr++ = '\t'; break; default: *cPtr++ = *lPtr; break; } bRem--; break; case '$': switch (*++lPtr) { case 'x': /* time trap was received */ l = strftime(cPtr, bRem, "%Y%m%d.%H%M%S", localtime(&trap_time)); cPtr += l; bRem -= l; break; case 'A': /* agents address */ if (p_trap->s_agentaddr == NULL) lg_sprint_node(p_trap->s_agentname, cfg_nodefmt, &cPtr, &bRem); else lg_sprint_node(p_trap->s_agentaddr, cfg_nodefmt, &cPtr, &bRem); break; case 'r': /* implied source (agent address) */ lg_sprint_node(p_trap->s_agentname, cfg_nodefmt, &cPtr, &bRem); break; case 'R': /* true source (peer address) */ lg_sprint_node(p_trap->s_senderaddr, cfg_nodefmt, &cPtr, &bRem); break; case 'e': /* enterprise */ lg_sprint_oid(p_trap->s_enterprise, cfg_oidfmt, &cPtr, &bRem); break; case 'G': /* generic trap number */ lg_sprint_string(get_generic_id(p_trap->s_trapoid), &cPtr, &bRem); break; case 'S': /* specific trap number */ lg_sprint_string(get_specific_id(p_trap->s_trapoid), &cPtr, &bRem); break; case 'T': /* agent's sysUpTime in 1/100 seconds */ lg_sprint_ulong(uptime_ticks(p_trap->s_uptime), "%lu", &cPtr, &bRem); break; case '#': /* number of variables in trap */ lg_sprint_int(p_trap->n_var, "%d", &cPtr, &bRem); break; case '*': /* all variables in trap */ for (seqno = 1; seqno <= p_trap->n_var; seqno++) { lg_sprint_var(&p_trap->a_var[seqno - 1], cfg_varfmt, seqno, &cPtr, &bRem); } break; case '$': /* insert '$' */ *cPtr++ = '$'; bRem--; break; default: /* insert the characters verbatim */ *cPtr++ = '$'; *cPtr++ = *lPtr; bRem -= 2; } break; default: *cPtr++ = *lPtr; bRem--; break; } /* leave if no more space is left */ if (bRem == 0) { logging(0, "No more internal space left for remaining format '%s'", lPtr); break; } } *cPtr = '\0'; /* Debug output */ logging(1, "Output buffer: '%s'", buf); /* this is the result */ return buf; } /* ------------------------------------------------------------------------- */ /* print a nodes ip-address, fully qualified domain name or * short hostname according to the specified format into the * output buffer */ static void lg_sprint_node(name, nodeFmt, cPPtr, bRemP) char *name; /* node name (or ip) */ int nodeFmt; /* NODEFMT_IP/_FQDN/_NAME */ char **cPPtr; /* address of pointer to current outchar */ int *bRemP; /* address of counter of remaining chars */ { char lbuf[80]; /* local buffer for result */ int l; struct hostent *hent = gethostbyname(name); logging(1, "lg_sprint_node(%s, ...)", name); switch (nodeFmt) { case NODEFMT_FQDN: /* use FQDN (resolver) */ case NODEFMT_NAME: /* use the short name (hostname) */ if (hent) { sprintf(lbuf, "%s", hent->h_name); } else { /* no result, use the passed name instead */ sprintf(lbuf, "%s", name); } if (nodeFmt == NODEFMT_NAME) { /* strip the domain part */ char *p = strchr(lbuf, '.'); if (p) { *p = '\0'; } } break; case NODEFMT_IP: /* use ip address */ default: /* shouldn't happen */ if (hent) { struct in_addr in; memcpy(&in.s_addr, hent->h_addr, sizeof(in.s_addr)); sprintf(lbuf, "%s", inet_ntoa(in)); } else { sprintf(lbuf, "%s", name); } break; } /* insert the local buffer into the output buffer */ l = strlen(lbuf); if (l <= *bRemP) { strncpy(*cPPtr, lbuf, l); (*cPPtr) += l; (*bRemP) -= l; } else { logging(0, "No more internal space left for '%s'", lbuf); } } /* ------------------------------------------------------------------------- */ /* print an oid according to the specified format into the output buffer */ static void lg_sprint_oid(oidP, oidFmt, cPPtr, bRemP) char *oidP; /* the OID */ int oidFmt; /* OIDFMT_TEXT/_OID */ char **cPPtr; /* address of pointer to current outchar */ int *bRemP; /* address of counter of remaining chars */ { char lbuf[1024]; /* local buffer */ int l; logging(1, "lg_sprint_oid(%s, ...)", oidP); switch (oidFmt) { case OIDFMT_TEXT: /* use textual format for the oid */ sprintf(lbuf, "%s", oidP ? oidP : "(null)"); break; case OIDFMT_OID: /* usenumerical format for the oid */ default: /* shouldn't happen */ sprintf(lbuf, "%s", oidP ? oidP : "(null)"); break; } /* insert the local buffer into the output buffer */ l = strlen(lbuf); if (l <= *bRemP) { strncpy(*cPPtr, lbuf, l); (*cPPtr) += l; (*bRemP) -= l; } else { logging(0, "No more internal space left for '%s'", lbuf); } } /* ------------------------------------------------------------------------- */ /* print a string according to the specified format into the output buffer */ static void lg_sprint_string(stringP, cPPtr, bRemP) char *stringP; /* the string */ char **cPPtr; /* address of pointer to current outchar */ int *bRemP; /* address of counter of remaining chars */ { int l; logging(1, "lg_sprint_string(%s, ...)", stringP); /* insert the string into the output buffer */ l = strlen(stringP); if (l <= *bRemP) { strncpy(*cPPtr, stringP, l); (*cPPtr) += l; (*bRemP) -= l; } else { logging(0, "No more internal space left for '%s'", stringP); } } /* ------------------------------------------------------------------------- */ /* print an integer according to the specified format into the output buffer */ static void lg_sprint_int(ival, iFmt, cPPtr, bRemP) int ival; /* the integer value */ char *iFmt; /* the format string */ char **cPPtr; /* address of pointer to current outchar */ int *bRemP; /* address of counter of remaining chars */ { char lbuf[20]; /* local buffer */ int l; logging(1, "lg_spring_int(%d, ...)", ival); /* fill the local buffer */ sprintf(lbuf, iFmt, ival); /* insert the local buffer into the output buffer */ l = strlen(lbuf); if (l <= *bRemP) { strncpy(*cPPtr, lbuf, l); (*cPPtr) += l; (*bRemP) -= l; } else { logging(0, "No more internal space left for '%s'", lbuf); } } /* ------------------------------------------------------------------------- */ /* print an u_long according to the specified format into the output buffer */ static void lg_sprint_ulong(uval, uFmt, cPPtr, bRemP) unsigned long uval; /* the integer value */ char *uFmt; /* the format string */ char **cPPtr; /* address of pointer to current outchar */ int *bRemP; /* address of counter of remaining chars */ { char lbuf[20]; /* local buffer */ int l; logging(1, "lg_sprint_ulong(%lu, ...)", uval); /* fill the local buffer */ sprintf(lbuf, uFmt, uval); /* insert the local buffer into the output buffer */ l = strlen(lbuf); if (l <= *bRemP) { strncpy(*cPPtr, lbuf, l); (*cPPtr) += l; (*bRemP) -= l; } else { logging(0, "No more internal space left for '%s'", lbuf); } } /* ------------------------------------------------------------------------- */ /* print an ASN.1 type ito the output buffer */ static void lg_sprint_ASNtype(asntype, cPPtr, bRemP) u_char asntype; /* ASN.1 type */ char **cPPtr; /* address of pointer to current outchar */ int *bRemP; /* address of counter of remaining chars */ { char *p; int l; logging(1, "lg_sprint_ASNtype(%c, ...)", asntype); switch (asntype) { case ASN_BOOLEAN: p = "Boolean"; break; case ASN_INTEGER: p = "Integer"; break; case ASN_BIT_STR: p = "BitString"; break; case ASN_OCTET_STR: p = "OctetString"; break; case ASN_NULL: p = "Null"; break; case ASN_OBJECT_ID: p = "ObjectIdentifier"; break; case ASN_OPAQUE: p = "Opaque"; break; case ASN_TIMETICKS: p = "Timeticks"; break; case ASN_GAUGE: p = "Gauge"; break; case ASN_COUNTER: p = "Counter"; break; case ASN_IPADDRESS: p = "IpAddress"; break; case ASN_UINTEGER: p = "UnsignedInteger32"; break; default: p = "BadType"; break; } /* insert the local buffer into the output buffer */ l = strlen(p); if (l <= *bRemP) { strncpy(*cPPtr, p, l); (*cPPtr) += l; (*bRemP) -= l; } else { logging(0, "No more internal space left for '%s'", p); } /* temporary close the string */ **cPPtr = '\0'; } /* ------------------------------------------------------------------------- */ /* print a snmp variable according to the specified format into the * output buffer */ static void lg_sprint_var(var, vFmt, seqno, cPPtr, bRemP) t_var *var; /* the snmp variable */ char *vFmt; /* the output format string */ int seqno; /* current sequence number */ char **cPPtr; /* address of pointer to current outchar */ int *bRemP; /* address of counter of remaining chars */ { char *vPtr; /* current varfmt character */ logging(1, "lg_sprint_var(%s/%s, %s, %d, ...)", var->v_oid, var->v_val, vFmt, seqno); /* process the variable format */ for (vPtr = vFmt; *vPtr; vPtr++) { switch (*vPtr) { case '\\': if (*bRemP > 0) { switch (*++vPtr) { case 'n': *(*cPPtr)++ = '\n'; (*bRemP)--; break; case 'r': *(*cPPtr)++ = '\r'; (*bRemP)--; break; case 't': *(*cPPtr)++ = '\t'; (*bRemP)--; break; default: *(*cPPtr)++ = *vPtr; (*bRemP)--; } } break; case '%': /* special char follows */ switch (*++vPtr) { case 's': /* the sequence number */ lg_sprint_int(seqno, "%d", cPPtr, bRemP); break; case 'n': /* the name */ lg_sprint_oid(var->v_oid, cfg_oidfmt, cPPtr, bRemP); break; case 't': /* the type */ logging(1, "Type info not available - using ASN_OCTET_STR"); lg_sprint_ASNtype(ASN_OCTET_STR, cPPtr, bRemP); break; case 'v': /* the value */ /* special handling for some (distinguishable) types */ if (var->v_val[0] == '"') { /* we got a string: strip delims and substitute characters */ int l = strlen(var->v_val); char *p; if ((l > 0) && (var->v_val[l - 1] == '"')) { var->v_val[l - 1] = '\0'; l--; } if (l > 0) { for (p = var->v_val + 1; *p; p++) { if (*p == cfg_subst1) { *p = cfg_subst2; } } } lg_sprint_string(var->v_val + 1, cPPtr, bRemP); } else { /* Standard */ lg_sprint_string(var->v_val, cPPtr, bRemP); } break; case '%': /* insert '%' */ if (*bRemP > 0) { *(*cPPtr)++ = '%'; (*bRemP)--; } break; default: /* insert the two chars verbatim */ if (*bRemP > 1) { *(*cPPtr)++ = '%'; *(*cPPtr)++ = *vPtr; (*bRemP) -= 2; } else { *bRemP = 0; } break; } break; default: /* insert char verbatim */ if (*bRemP > 0) { *(*cPPtr)++ = *vPtr; (*bRemP)--; } } if (*bRemP <= 0) { logging(0, "No more internal space left for variable %d", seqno); *bRemP = 0; break; } } } /* ------------------------------------------------------------------------- */ /* Read the trap data from the pipe and store the data * - Returns 0 if ok, -1 if error */ static int read_trapdata(FILE * f, t_trap * p_trap) { char *oid; char *val; /* Read the constant header */ if (read_oidval(f, &p_trap->s_agentname, NULL, "Missing AGENTNAME from handler") == -1) { return -1; } logging(1, "Store: AGENTNAME := '%s'", p_trap->s_agentname); if (read_oidval(f, &p_trap->s_senderaddr, NULL, "Missing SENDERIP from handler") == -1) { return -1; } logging(1, "Store: SENDERADDR := '%s'", p_trap->s_senderaddr); if (read_oidval(f, NULL, &p_trap->s_uptime, "Missing UPTIME from handler") == -1) { return -1; } logging(1, "Store: UPTIME := '%s'", p_trap->s_uptime); if (read_oidval(f, NULL, &p_trap->s_trapoid, "Missing TRAPOID from handler") == -1) { return -1; } logging(1, "Store: TRAPOID := '%s'", p_trap->s_trapoid); /* Now read all remaining OID/VAL pairs */ while (read_oidval(f, &oid, &val, NULL) == 0) { if (oid[0] == '\0') { /* End of data from handler */ logging(1, "End of handler data reached"); free(oid); free(val); break; } else if ((strcmp(oid, OID_SYM_SNMPTRAPADDRESS) == 0) || (strcmp(oid, OID_NUM_SNMPTRAPADDRESS) == 0)) { free(oid); p_trap->s_agentaddr = val; logging(1, "Store: SNMPTRAPADDRESS := '%s'", p_trap->s_agentaddr); } else if ((strcmp(oid, OID_SYM_SNMPTRAPCOMMUNITY) == 0) || (strcmp(oid, OID_NUM_SNMPTRAPCOMMUNITY) == 0)) { free(oid); p_trap->s_community = val; logging(1, "Store: SNMPTRAPCOMMUNITY := '%s'", p_trap->s_community); } else if ((strcmp(oid, OID_SYM_SNMPTRAPENTERPRISE) == 0) || (strcmp(oid, OID_NUM_SNMPTRAPENTERPRISE) == 0)) { free(oid); p_trap->s_enterprise = val; logging(1, "Store: SNMPTRAPENTERPRISE := '%s'", p_trap->s_enterprise); } else { /* store as a variable */ void *p; p_trap->n_var++; p = realloc(p_trap->a_var, p_trap->n_var * sizeof(t_var)); if (p == NULL) { logging(0, "Out of memory - aborting"); exit(1); } p_trap->a_var = p; p_trap->a_var[p_trap->n_var - 1].v_oid = oid; p_trap->a_var[p_trap->n_var - 1].v_val = val; logging(1, "Store var %d: '%s' := '%s'", p_trap->n_var, oid, val); } } return 0; } /* ------------------------------------------------------------------------- */ /* Read the trap data from the handlers pipe and format the output buffer */ void process_trapdata(FILE * f) { char *buf; t_trap trapdata; /* Fetch the trap data */ memset(&trapdata, '\0', sizeof(trapdata)); if (read_trapdata(f, &trapdata) == -1) { logging(0, "Error reading trap data - skip formatting"); free_trap(&trapdata); return; } /* Format the trap data */ buf = lg_format_buffer(&trapdata, time(NULL)); /* And now log the data according to the configuration */ if (!buf) { logging(0, "Error: Cannot allocate/format output buffer"); } else if (o_logfile) { logging(1, "Logging to file '%s'", buf); fprintf(o_logfile, "%s\n", buf); fflush(o_logfile); } else { logging(1, "Logging to syslog 'LOG_WARNING:%s'", buf); syslog(LOG_WARNING, "%s\n", buf); } free_trap(&trapdata); } /* ------------------------------------------------------------------------- */ /* Read a OID/VAL pair from the pipe, allocate memory and store the pointers * (if specified). If an error occurs, emit msg (if any) and return -1, else * return 0. */ static int read_oidval(FILE * f, char **pp_oid, char **pp_val, char *msg) { char rbuf[1024]; if (fgets(rbuf, sizeof(rbuf), f) == NULL) { if (msg) { logging(0, msg); } return -1; } else { /* look for a delimiting blank */ char *p_del; int l; /* strip the trailing EOL */ l = strlen(rbuf); if ((l > 0) && (rbuf[l - 1] == '\n')) { rbuf[l - 1] = '\0'; } logging(1, "Read from handler: '%s'", rbuf); /* split the line (if two components are on the line) */ p_del = strchr(rbuf, ' '); if (p_del) { *p_del = '\0'; } /* fetch and store the oid */ if (pp_oid) { *pp_oid = copy_string(rbuf); } /* fetch and store the value */ if (pp_val) { *pp_val = copy_string(p_del ? p_del + 1 : rbuf); } logging(1, " Split: OID = '%s', VAL = '%s'", rbuf, (p_del ? p_del + 1 : rbuf)); } return 0; } /* ------------------------------------------------------------------------- */ /* Copy a string into allocated memory (but do not copy the trailing EOL) */ static char * copy_string(char *buf) { char *s; int l = strlen(buf); if ((l > 0) && (buf[l - 1] == '\n')) { buf[--l] = '\0'; } s = strdup(buf); if (s == NULL) { logging(0, "Out of memory - aborting"); exit(1); } return s; } /* ------------------------------------------------------------------------- */ /* Free a trap data structure */ static void free_trap(t_trap * p_trap) { if (p_trap) { int i; FREEMEM(p_trap->s_agentname); FREEMEM(p_trap->s_agentaddr); FREEMEM(p_trap->s_senderaddr); FREEMEM(p_trap->s_uptime); FREEMEM(p_trap->s_trapoid); FREEMEM(p_trap->s_community); FREEMEM(p_trap->s_enterprise); for (i = 0; i < p_trap->n_var; i++) { FREEMEM(p_trap->a_var[i].v_oid); FREEMEM(p_trap->a_var[i].v_val); } if (p_trap->n_var > 0) { FREEMEM(p_trap->a_var); } } } /* ------------------------------------------------------------------------- */ /* extract the Generid ID from the Trap OID by checking the second to last * component of the Trap OID */ static char * get_generic_id(char *trapoidP) { char *p_delim; char trapoid[2048]; static char buf[80]; /* Save the trap OID */ strcpy(trapoid, trapoidP); /* look for the last period */ p_delim = strrchr(trapoid, '.'); if (p_delim) { char *p_delim0; *p_delim = '\0'; /* now look for the previous delim */ p_delim0 = strrchr(trapoid, '.'); if (p_delim0) { /* inspect the second to last component */ if (strcmp(p_delim0 + 1, "0") == 0) { /* this is a specific trap, thus the GID is 6 */ sprintf(buf, "%d", SNMP_TRAP_ENTERPRISESPECIFIC); } else { /* this is a generic trap, return the last component * (but decrement if numeric) */ if (isdigit(p_delim[1])) { int gid; sscanf(p_delim + 1, "%d", &gid); sprintf(buf, "%d", gid - 1); } else { strcpy(buf, p_delim + 1); } } } else { /* only one delimiter in this trap OID, must be generic */ if (isdigit(p_delim[1])) { int gid; sscanf(p_delim + 1, "%d", &gid); sprintf(buf, "%d", gid - 1); } else { strcpy(buf, p_delim + 1); } } } else { /* no delimiter in this trap, must be generic */ if (isdigit(trapoid[0])) { int gid; sscanf(trapoid, "%d", &gid); sprintf(buf, "%d", gid - 1); } else { strcpy(buf, trapoid); } } return buf; } /* ------------------------------------------------------------------------- */ /* extract the Specific ID from the Trap OID */ static char * get_specific_id(char *trapoidP) { char *p_delim; char trapoid[2048]; static char buf[80]; /* Save the trap OID */ strcpy(trapoid, trapoidP); /* look for the last period */ p_delim = strrchr(trapoid, '.'); if (p_delim) { char *p_delim0; *p_delim = '\0'; /* now look for the previous delim */ p_delim0 = strrchr(trapoid, '.'); if (p_delim0) { /* inspect the second to last component */ if (strcmp(p_delim0 + 1, "0") == 0) { /* this is a specific trap */ strcpy(buf, p_delim + 1); } else { /* this is a generic trap */ strcpy(buf, "0"); } } else { /* only one delimiter in this trap OID, must be generic */ strcpy(buf, "0"); } } else { /* no delimiter in this trap, must be generic */ strcpy(buf, "0"); } return buf; } /* ------------------------------------------------------------------------- */ snmptrapfmt-1.17/snmptrapfmt.conf0000644000000000000000000000504311167410632014130 0ustar # ----------------------------------------------------------------------------- # Configuration file for snmptrapfmt-1.0 # # Comment lines start with the character '#' # Blank lines are ignored # # In order to configure the log output, use the following keywords. # ----------------------------------------------------------------------------- # - SUBST=\a\b\ # substitute char 'a' with 'b' in variable values # Default: \;\ \ SUBST=\#\ \ # NOTE: The OID Format has to be set in the /etc/snmp/snmp.conf. # See SNMP.CONF(5). It is valid for all snmp programs of package SNMPD. # You can specify it with: printNumericOids (1|yes|true|0|no|false) # # snmptrapfmt uses it in formats $e $* # NODEFMT=ip | fqdn | name # print nodenames as IP address (ip), as fully qualified domain name (fqdn) # or in the short form (name); # used in formats $A $R $r $* # Default: fqdn NODEFMT=ip # VARFMT="format string for variables" # specify the output of variables when using the '$*' format specifier # in the logfile format; # special chars recognized: # %s ... sequence number of the variable # %n ... the name of the variable (see OIDFMT) # %t ... the type of the variable # %v ... the value of the variable # used in format $* # Default: ";[%s] %n (%t) : %v" #VARFMT="\n\t[%s] %n (%t) : %v" VARFMT="#[%s] %n (%t) : %v" # LOGFMT="format string for logfile entry" # specify the output of the logfile entry; # special char recognized: # \n ... newline # \r ... carriage return # \t ... horizontal tab # \\ ... backslash # $# ... number of variables in the trap # $* ... print all variables of the trap as specified in VARFMT # $x ... date the trap was received (YYYYMMDD.HHMMSS) # $r ... the implied source of the trap (agent address) (see NODEFMT) # $R ... the true source of the trap (via transport layer) (see NODEFMT) # $$ ... the character '$' # $e ... the enterprise of the trap as specified in OIDFMT # $A ... the trap agent address as specified in NODEFMT # $G ... the trap generic number # $S ... the trap specific number # $T ... the trap's sysUpTime timestamp (in seconds) # ordinary characters represent themselfes # Default: "$x;$A;$e;$G;$S$*" #LOGFMT="\n$$x=$x\n$$r=$r\n$$R=$R\n$$e=$e\n$$A=$A\n$$G=$G\n$$S=$S\n$$T=$T\n$$#=$#$*" LOGFMT="$x#$A#$e#$G#$S#$T$*" # LOGFILE="path to logfile" # specify the pathname of the logfile; if none or the empty string "" is # given, use the syslog() mechanism to log the traps # Default: "" LOGFILE="/var/log/snmptrapfmt.log" snmptrapfmt-1.17/snmptrapfmt.h0000644000000000000000000000200511167410632013425 0ustar /* * snmptrapfmt.h * * Definitions for the snmptrapfmthdlr/snmptrapfmt pair. * * Copyright (C) 2001 Uwe Maier * Copyright (C) 2001 - 2005 Bernd Schumacher Hewlett Packard Consulting * * Copyright (C) 2005 - 2009 Jochen Friedrich * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * 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. * * See the GNU General Public License in the COPYING file at the * root directory of this project for more details. * */ /* * The name of the communication fifo between the two processes. */ #define PIPENAME "/var/run/snmptrapfmt.p" snmptrapfmt-1.17/snmptrapfmthdlr.80000755000000000000000000000224211167410632014225 0ustar .\"/*********************************************************** .\" Copyright 2001 by Hewlett-Packard GmbH .\" .\" All Rights Reserved .\" .\" ******************************************************************/ .TH SNMPTRAPFMTHDLR 8 "30 APRIL 2001" .UC 4 .SH NAME snmptrapfmthdlr - Trap handler for receiving SNMP Traps .SH SYNOPSIS snmptrapfmthdlr .SH DESCRIPTION Snmptrapfmthdlr is an application that receives SNMP traps from snmptrapd as a trap handler. The trap data is then forwarded to a local pipe from which a formatting application picks it up and does further processing. The formatting application is snmptrapfmt. .PP .SH "FILES" .B "/etc/snmp/snmptrapd.conf" is the configuration file of the snmptrapd daemon, which calls the trap handler snmptrapfmthdlr. .PP .B "/usr/sbin/snmptrapfmt" is the executable of the formatting application. .PP .B "/usr/sbin/snmptrapfmthdlr" is the executable of the trap handler. .PP .B "/var/run/snmptrapfmt.p" is the communication pipe between the trap handler snmptrapfmthdlr and the formatter snmptrapfmt. .PP .B "/var/tmp/snmptrapfmt.trc" is the error file of the application. .PP .SH "SEE ALSO" snmptrapfmt(8) snmptrapfmt-1.17/snmptrapfmthdlr.c0000644000000000000000000000617311167410632014304 0ustar /* * snmptrapfmthdlr.c * * This is the trap handler which is called by 'snmptrapd' * * Usage: snmptrapfmthdlr [-d loglev] * * Copyright (C) 2001 Uwe Maier * Copyright (C) 2001 - 2005 Bernd Schumacher Hewlett Packard Consulting * * Copyright (C) 2005 - 2009 Jochen Friedrich * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * 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. * * See the GNU General Public License in the COPYING file at the * root directory of this project for more details. * */ /* --- import section --- */ #include "snmptrapfmt.h" #include "log.h" #include #include #include #include #include #include #include /* --- local defines --- */ #define PNAME "snmptrapfmthdlr" #define LOGFILE "/var/tmp/snmptrapfmt.trc" /* --- local types --- */ /* --- local variables --- */ int o_loglev = 0; /* the log level */ /* --- local functions --- */ /* -------------------------------------------------------------------------- */ int main (int argc, char **argv) { int fd; /* the handle for the pipe */ char inbuf[8192]; /* the read buffer */ ssize_t rcnt; /* number of chars read from stdin */ /* * Check the arguments */ if ((argc > 2) && (strcmp (argv[1], "-d") == 0)) { o_loglev = atoi (argv[2]); } /* Init log file handling, append mode is on */ loginit (PNAME, LOGFILE, o_loglev, 1); logging (1, "Traphandler started ..."); /* * Check if the named pipe exists and a reader has opened. * If not, the snmptrapfmt daemon does not run and this trap handlers * existence is obsolete ... */ fd = open (PIPENAME, O_WRONLY | O_NONBLOCK); if (fd == -1) { logging (0, "Error opening pipe '%s' [%s]", PIPENAME, strerror (errno)); exit (1); } logging (1, "Opened pipe '%s'", PIPENAME); /* * Read all data from stdin and forward to the pipe */ while ((rcnt = read (0, inbuf, sizeof (inbuf))) > 0) { logging (1, "Read line from stdin: '%s'", inbuf); if (rcnt != write (fd, inbuf, rcnt)) { logging (0, "Error writing to pipe '%s' [%s]", PIPENAME, strerror (errno)); close (fd); exit (1); } } if (write (fd, "\n", 1) != 1) { logging (0, "Error writing EOD to pipe '%s' [%s]", PIPENAME, strerror (errno)); close (fd); exit (1); } logging (1, "Wrote EOD to pipe"); if (rcnt < 0) { logging (0, "Error reading from stdin [%s]", strerror (errno)); } close (fd); logging (1, "Traphandler terminated."); return (rcnt == 0 ? 0 : 1); } /* -------------------------------------------------------------------------- */ snmptrapfmt-1.17/test/0000755000000000000000000000000011167410632011663 5ustar snmptrapfmt-1.17/test/snmptrapfmt.conf0000755000000000000000000000506411167410632015115 0ustar # ----------------------------------------------------------------------------- # Configuration file for snmptrapfmt-1.0 # # Comment lines start with the character '#' # Blank lines are ignored # # In order to configure the log output, use the following keywords. # ----------------------------------------------------------------------------- # - SUBST=\a\b\ # substitute char 'a' with 'b' in variable values # Default: \;\ \ SUBST=\#\ \ # NOTE: The OIDFMT has to be set in the /etc/snmp/snmp.conf file and is # valid for all snmp programs of package SNMPD. It is ignored here. # - OIDFMT=text | oid # print OIDs symbolically (text) or numerical (oid); # used in formats $e $* # Default: oid #OIDFMT=text # NODEFMT=ip | fqdn | name # print nodenames as IP address (ip), as fully qualified domain name (fqdn) # or in the short form (name); # used in formats $A $R $r $* # Default: fqdn NODEFMT=ip # VARFMT="format string for variables" # specify the output of variables when using the '$*' format specifier # in the logfile format; # special chars recognized: # %s ... sequence number of the variable # %n ... the name of the variable (see OIDFMT) # %t ... the type of the variable # %v ... the value of the variable # used in format $* # Default: ";[%s] %n (%t) : %v" #VARFMT="\n\t[%s] %n (%t) : %v" VARFMT="#[%s] %n (%t) : %v" # LOGFMT="format string for logfile entry" # specify the output of the logfile entry; # special char recognized: # \n ... newline # \r ... carriage return # \t ... horizontal tab # \\ ... backslash # $# ... number of variables in the trap # $* ... print all variables of the trap as specified in VARFMT # $x ... date the trap was received (YYYYMMDD.HHMMSS) # $r ... the implied source of the trap (agent address) (see NODEFMT) # $R ... the true source of the trap (via transport layer) (see NODEFMT) # $$ ... the character '$' # $e ... the enterprise of the trap as specified in OIDFMT # $A ... the trap agent address as specified in NODEFMT # $G ... the trap generic number # $S ... the trap specific number # $T ... the trap's sysUpTime timestamp (in seconds) # ordinary characters represent themselfes # Default: "$x;$A;$e;$G;$S$*" #LOGFMT="\n$$x=$x\n$$r=$r\n$$R=$R\n$$e=$e\n$$A=$A\n$$G=$G\n$$S=$S\n$$T=$T\n$$#=$#$*" LOGFMT="$x#$A#$e#$G#$S#$T$*" # LOGFILE="path to logfile" # specify the pathname of the logfile; if none or the empty string "" is # given, use the syslog() mechanism to log the traps # Default: "" LOGFILE="/var/log/snmptrapfmt.log" snmptrapfmt-1.17/test/testtraps.sh0000755000000000000000000000242511167410632014256 0ustar #!/bin/sh # # Send some test traps if [ $# -eq 0 ]; then echo "usage: $(basename $0) target-host" exit 1 fi # V1 Traps echo "Send V1 Trap ..." snmptrap -v 1 -c trap-comm $1 \ .1.3.6.1.4.1.11.2.17.1 \ 192.168.0.1 \ 6 123456 18012202 \ .1.3.6.1.4.1.11.2.17.2.1 s "First \"Arg\" (with quotes)" \ .1.3.6.1.4.1.11.2.17.2.2 i 504 \ .1.3.6.1.4.1.11.2.17.2.3 a 192.168.0.78 \ .1.3.6.1.4.1.11.2.17.2.4 s "String with hash (#)" snmptrap -v 1 -c trap-comm $1 \ .1.3.6.1.4.1.11.2.17.1 \ 192.168.0.1 \ 1 0 18012203 echo "Send V2 Trap ..." snmptrap -v2c -c geheim $1 \ 18012204 \ .1.3.6.1.4.1.11.2.17.1.0.123457 \ .1.3.6.1.6.3.18.1.3.0 a 192.168.0.1 \ .1.3.6.1.6.3.18.1.4.0 s geheim \ .1.3.6.1.6.3.1.1.4.3.0 o .1.3.6.1.4.1.11.2.17.1 \ .1.3.6.1.4.1.11.2.17.2.1 s "First \"Arg\" (with quotes)" \ .1.3.6.1.4.1.11.2.17.2.2 i 504 \ .1.3.6.1.4.1.11.2.17.2.3 a 192.168.0.78 \ .1.3.6.1.4.1.11.2.17.2.4 s "String with hash (#)" snmptrap -v2c -c geheim $1 \ 18012205 \ .1.3.6.1.6.3.1.1.5.2 \ .1.3.6.1.6.3.18.1.3.0 a 192.168.0.1 \ .1.3.6.1.6.3.18.1.4.0 s geheim \ .1.3.6.1.6.3.1.1.4.3.0 o .1.3.6.1.4.1.11.2.17.1