Project import generated by Copybara. NOKEYCHECK=True GitOrigin-RevId: ad32a631b4ba687fcbbb0d68f7d0db16091d96dd
diff --git a/.mailmap b/.mailmap new file mode 100644 index 0000000..4f386b9 --- /dev/null +++ b/.mailmap
@@ -0,0 +1,10 @@ +Benjamin Reed <rangerrick@befunk.com> Benjamin Reed <ranger@befunk.com> +Benjamin Reed <rangerrick@befunk.com> Benjamin Reed <ranger@Sin.local> +Christian Dywan <christian.dywan@lanedo.com> Christian Dywan <christian@lanedo.com> +Colin Walters <walters@verbum.org> Colin Walters <walters@lightbox.localdomain> +Colin Walters <walters@verbum.org> Colin Walters <walters@space-ghost.verbum.private> +Havoc Pennington <hp@pobox.com> Havoc Pennington <hp@localhost.localdomain> +Ralf Habacker <ralf.habacker@freenet.de> Ralf Habacker <Ralf.Habacker@freenet.de> +Ralf Habacker <ralf.habacker@freenet.de> Ralf Habacker <ralf@s15291359.onlinehome-server.info> +Ralf Habacker <ralf.habacker@freenet.de> unknown <Administrator@.(none)> +Ralf Habacker <ralf.habacker@freenet.de> unknown <Habacker@.(none)>
diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..ed8afdf --- /dev/null +++ b/AUTHORS
@@ -0,0 +1,122 @@ +Alban Crequy <alban.crequy@collabora.co.uk> +Alexander Larsson <alexl@redhat.com> +Anders Carlsson <andersca@codefactory.se> +Andre Heinecke <aheinecke@intevation.de> +Artem Bityutskiy <Artem.Bityutskiy@nokia.com> +Aurelien Jarno <aurel32@debian.org> +Benjamin Reed <rangerrick@befunk.com> +Brian Cameron <brian.cameron@oracle.com> +Brian Cameron <brian.cameron@sun.com> +Chris Mayo <aklhfex gmail com> +Christian Dywan <christian.dywan@lanedo.com> +Christian Ehrlicher <Ch.Ehrlicher@gmx.de> +Christian Persch (GNOME) <chpe@gnome.org> +Colin Walters <walters@verbum.org> +Colin Watson <cjwatson@ubuntu.com> +Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> +Cristian Rodríguez <cristian.rodriguez@opensuse.org> +Cyril Brulebois <kibi@debian.org> +Daniel P. Berrange <dan@berrange.com> +Daniel Reed <djr@redhat.com> +David Zeuthen <davidz@redhat.com> +Dennis Kaarsemaker <dennis@kaarsemaker.net> +Diego E. 'Flameeyes' Pettenò <flameeyes@gmail.com> +Eamon Walsh <ewalsh@tycho.nsa.gov> +Federico Mena Quintero <federico@novell.com> +Frank Osterfeld <frank@kdab.net> +Frederic Crozat <fcrozat@mandriva.com> +Fridrich Štrba <fridrich.strba@bluewin.ch> +Grzegorz Dąbrowski <gdx@poczta.fm> +Harald Fernengel <harry@kdevelop.org> +Harri Porten <porten@kde.org> +Hasso Tepper <hasso@estpak.ee> +Havoc Pennington <hp@pobox.com> +Havoc Pennington <hp@redhat.com> +Hendrik Buschmeier <hbuschme@TechFak.Uni-Bielefeld.DE> +James Carter <jwcart2@tycho.nsa.gov> +James Westby <jw+debian@jameswestby.net> +James Willcox <jwillcox@gnome.org> +Jens Granseuer <jensgr@gmx.net> +Jérémie Dimino <jeremie@dimino.org> +Jiří Klimeš <jklimes@redhat.com> +Joe Marcus Clarke <marcus@freedesktop.org> +Joe Shaw <joeshaw@novell.com> +Johan Gyllenspetz <johangy@axis.com> +Johannes Carlsson <johannes.carlsson.x@sonyericsson.com> +John (J5) Palmieri <johnp@redhat.com> +Jon Gosting <yukarionsen@gmail.com> +Jon Trowbridge <trow@ximian.com> +Kay Sievers <kay.sievers@vrfy.org> +Kimmo Hämäläinen <kimmo.hamalainen@nokia.com> +Kjartan Maraas <kmaraas@gnome.org> +Kristian Høgsberg <krh@redhat.com> +Kristian Rietveld <kris@gtk.org> +Kurt Miller <kurt@intricatesoftware.com> +Lawrence R. Steeger <lsteeger@gmail.com> +Lennart Poettering <lennart@poettering.net> +Lennart Poettering <mzqohf@0pointer.de> +Lionel Landwerlin <lionel.landwerlin@openwide.fr> +Luiz Augusto Von Dentz <luiz.dentz-von@nokia.com> +Marc Brockschmidt <he@debian.org> +Marc Mutz <marc@kdab.net> +Marcus Brinkmann <marcus.brinkmann@ruhr-uni-bochum.de> +Mark Brand <mabrand@mabrand.nl> +Mark McLoughlin <mark@skynet.ie> +Matthias Clasen <mclasen@redhat.com> +Matt McCutchen <matt@mattmccutchen.net> +Michael Meeks <michael.meeks@novell.com> +Michael Meeks <michael@ximian.com> +Mikael Hallendal <micke@codefactory.se> +Mikael Hallendal <micke@imendio.com> +Mike McQuaid <mike@mikemcquaid.com> +Miloslav Trmac <mitr@volny.cz> +Murray Cumming <murrayc@murrayc.com> +Nguyễn Thái Ngọc Duy <pclouds@gmail.com> +Ole André Vadla Ravnås <ole.andre.ravnas@tandberg.com> +Olivier Andrieu <oliv__a@users.sourceforge.net> +Oswald Buddenhagen <ossi@kde.org> +Owen Fraser-Green <owen@discobabe.net> +Patrick von Reth <patrick.vonreth@gmail.com> +Pau Garcia i Quiles <pgquiles@elpauer.org> +Paul Bolle <pebolle@tiscali.nl> +Peter Breitenlohner <peb@mppmu.mpg.de> +Peter Kümmel <syntheticpp@gmx.net> +Peter McCurdy <pmccurdy@skeptopotamus> +Philip Blundell <philb@gnu.org> +Plácido Revilla <unknown@unknown.domain> +Ralf Habacker <ralf.habacker@freenet.de> +Ray Strode <rstrode@redhat.com> +Richard A. Hankins <richard.a.hankins@gmail.com> +Richard Hughes <richard@hughsie.com> +Richard Hult <rhult@codefactory.se> +Richard Hult <richard@imendio.com> +Robert McQueen <robot101@debian.org> +Roberto Guido <bob4job@gmail.com> +Romain Pokrzywka <romain@kdab.com> +Ross Burton <ross@openedhand.com> +Ryan Lortie <desrt@desrt.ca> +Sascha Silbe <sascha-pgp@silbe.org> +Sascha Silbe <sascha-web-bugs.freedesktop.org@silbe.org> +Scott James Remnant <scott@netsplit.com> +Scott James Remnant <scott@ubuntu.com> +Sebastian Sauer <sebsauer@kdab.net> +Seth Nickell <seth@gnome.org> +Simon McVittie <simon.mcvittie@collabora.co.uk> +Sjoerd Simons <sjoerd@luon.net> +Sledz <sledz@MOBIL-400-586.intern.dresearch.de> +Steve Grubb <sgrubb@redhat.com> +Sven Herzberg <sven@imendio.com> +Thiago Macieira <thiago@kde.org> +Tim Dijkstra <tim@famdijkstra.org> +Tobias Mueller <fdo-bugs@cryptobitch.de> +Tomas Hoger <thoger@redhat.com> +Tomas Pelka <tpelka@redhat.com> +Tom Hughes <tom.hughes@palm.com> +Tor Lillqvist <tml@iki.fi> +Waldo Bastian <bastian@kde.org> +William Lachance <wrlach@gmail.com> +Will Thompson <will.thompson@collabora.co.uk> +Wulf C. Krueger <philantrop@exherbo.org> +Xan Lopez <xan@gnome.org> +Yaakov Selkowitz <yselkowitz@users.sourceforge.net> +Zack Rusin <zack@kde.org>
diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000..5053e7d --- /dev/null +++ b/Android.mk
@@ -0,0 +1 @@ +include $(call all-subdir-makefiles)
diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..8260b10 --- /dev/null +++ b/COPYING
@@ -0,0 +1,552 @@ +D-Bus is licensed to you under your choice of the Academic Free +License version 2.1, or the GNU General Public License version 2 +(or, at your option any later version). + +Both licenses are included here. Some of the standalone binaries are +under the GPL only; in particular, but not limited to, +tools/dbus-cleanup-sockets.c and test/decode-gcov.c. Each source code +file is marked with the proper copyright information - if you find a +file that isn't marked please bring it to our attention. + +The Academic Free License +v. 2.1 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following notice immediately following the copyright notice for the Original Work: + +Licensed under the Academic Free License version 2.1 + +1) Grant of Copyright License. Licensor hereby grants You a +world-wide, royalty-free, non-exclusive, perpetual, sublicenseable +license to do the following: + +a) to reproduce the Original Work in copies; + +b) to prepare derivative works ("Derivative Works") based upon the Original Work; + +c) to distribute copies of the Original Work and Derivative Works to the public; + +d) to perform the Original Work publicly; and + +e) to display the Original Work publicly. + +2) Grant of Patent License. Licensor hereby grants You a world-wide, +royalty-free, non-exclusive, perpetual, sublicenseable license, under +patent claims owned or controlled by the Licensor that are embodied in +the Original Work as furnished by the Licensor, to make, use, sell and +offer for sale the Original Work and Derivative Works. + +3) Grant of Source Code License. The term "Source Code" means the +preferred form of the Original Work for making modifications to it and +all available documentation describing how to modify the Original +Work. Licensor hereby agrees to provide a machine-readable copy of the +Source Code of the Original Work along with each copy of the Original +Work that Licensor distributes. Licensor reserves the right to satisfy +this obligation by placing a machine-readable copy of the Source Code +in an information repository reasonably calculated to permit +inexpensive and convenient access by You for as long as Licensor +continues to distribute the Original Work, and by publishing the +address of that information repository in a notice immediately +following the copyright notice that applies to the Original Work. + +4) Exclusions From License Grant. Neither the names of Licensor, nor +the names of any contributors to the Original Work, nor any of their +trademarks or service marks, may be used to endorse or promote +products derived from this Original Work without express prior written +permission of the Licensor. Nothing in this License shall be deemed to +grant any rights to trademarks, copyrights, patents, trade secrets or +any other intellectual property of Licensor except as expressly stated +herein. No patent license is granted to make, use, sell or offer to +sell embodiments of any patent claims other than the licensed claims +defined in Section 2. No right is granted to the trademarks of +Licensor even if such marks are included in the Original Work. Nothing +in this License shall be interpreted to prohibit Licensor from +licensing under different terms from this License any Original Work +that Licensor otherwise would have a right to license. + +5) This section intentionally omitted. + +6) Attribution Rights. You must retain, in the Source Code of any +Derivative Works that You create, all copyright, patent or trademark +notices from the Source Code of the Original Work, as well as any +notices of licensing and any descriptive text identified therein as an +"Attribution Notice." You must cause the Source Code for any +Derivative Works that You create to carry a prominent Attribution +Notice reasonably calculated to inform recipients that You have +modified the Original Work. + +7) Warranty of Provenance and Disclaimer of Warranty. Licensor +warrants that the copyright in and to the Original Work and the patent +rights granted herein by Licensor are owned by the Licensor or are +sublicensed to You under the terms of this License with the permission +of the contributor(s) of those copyrights and patent rights. Except as +expressly stated in the immediately proceeding sentence, the Original +Work is provided under this License on an "AS IS" BASIS and WITHOUT +WARRANTY, either express or implied, including, without limitation, +the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL +WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential +part of this License. No license to Original Work is granted hereunder +except under this disclaimer. + +8) Limitation of Liability. Under no circumstances and under no legal +theory, whether in tort (including negligence), contract, or +otherwise, shall the Licensor be liable to any person for any direct, +indirect, special, incidental, or consequential damages of any +character arising as a result of this License or the use of the +Original Work including, without limitation, damages for loss of +goodwill, work stoppage, computer failure or malfunction, or any and +all other commercial damages or losses. This limitation of liability +shall not apply to liability for death or personal injury resulting +from Licensor's negligence to the extent applicable law prohibits such +limitation. Some jurisdictions do not allow the exclusion or +limitation of incidental or consequential damages, so this exclusion +and limitation may not apply to You. + +9) Acceptance and Termination. If You distribute copies of the +Original Work or a Derivative Work, You must make a reasonable effort +under the circumstances to obtain the express assent of recipients to +the terms of this License. Nothing else but this License (or another +written agreement between Licensor and You) grants You permission to +create Derivative Works based upon the Original Work or to exercise +any of the rights granted in Section 1 herein, and any attempt to do +so except under the terms of this License (or another written +agreement between Licensor and You) is expressly prohibited by +U.S. copyright law, the equivalent laws of other countries, and by +international treaty. Therefore, by exercising any of the rights +granted to You in Section 1 herein, You indicate Your acceptance of +this License and all of its terms and conditions. + +10) Termination for Patent Action. This License shall terminate +automatically and You may no longer exercise any of the rights granted +to You by this License as of the date You commence an action, +including a cross-claim or counterclaim, against Licensor or any +licensee alleging that the Original Work infringes a patent. This +termination provision shall not apply for an action alleging patent +infringement by combinations of the Original Work with other software +or hardware. + +11) Jurisdiction, Venue and Governing Law. Any action or suit relating +to this License may be brought only in the courts of a jurisdiction +wherein the Licensor resides or in which Licensor conducts its primary +business, and under the laws of that jurisdiction excluding its +conflict-of-law provisions. The application of the United Nations +Convention on Contracts for the International Sale of Goods is +expressly excluded. Any use of the Original Work outside the scope of +this License or after its termination shall be subject to the +requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 +et seq., the equivalent laws of other countries, and international +treaty. This section shall survive the termination of this License. + +12) Attorneys Fees. In any action to enforce the terms of this License +or seeking damages relating thereto, the prevailing party shall be +entitled to recover its costs and expenses, including, without +limitation, reasonable attorneys' fees and costs incurred in +connection with such action, including any appeal of such action. This +section shall survive the termination of this License. + +13) Miscellaneous. This License represents the complete agreement +concerning the subject matter hereof. If any provision of this License +is held to be unenforceable, such provision shall be reformed only to +the extent necessary to make it enforceable. + +14) Definition of "You" in This License. "You" throughout this +License, whether in upper or lower case, means an individual or a +legal entity exercising rights under, and complying with all of the +terms of, this License. For legal entities, "You" includes any entity +that controls, is controlled by, or is under common control with +you. For purposes of this definition, "control" means (i) the power, +direct or indirect, to cause the direction or management of such +entity, whether by contract or otherwise, or (ii) ownership of fifty +percent (50%) or more of the outstanding shares, or (iii) beneficial +ownership of such entity. + +15) Right to Use. You may use the Original Work in all ways not +otherwise restricted or conditioned by this License or by law, and +Licensor promises not to interfere with or be responsible for such +uses by You. + +This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights +reserved. Permission is hereby granted to copy and distribute this +license without modification. This license may not be modified without +the express written permission of its copyright owner. + + +-- +END OF ACADEMIC FREE LICENSE. The following is intended to describe the essential +differences between the Academic Free License (AFL) version 1.0 and other +open source licenses: + +The Academic Free License is similar to the BSD, MIT, UoI/NCSA and Apache +licenses in many respects but it is intended to solve a few problems with +those licenses. + +* The AFL is written so as to make it clear what software is being +licensed (by the inclusion of a statement following the copyright notice +in the software). This way, the license functions better than a template +license. The BSD, MIT and UoI/NCSA licenses apply to unidentified software. + +* The AFL contains a complete copyright grant to the software. The BSD +and Apache licenses are vague and incomplete in that respect. + +* The AFL contains a complete patent grant to the software. The BSD, MIT, +UoI/NCSA and Apache licenses rely on an implied patent license and contain +no explicit patent grant. + +* The AFL makes it clear that no trademark rights are granted to the +licensor's trademarks. The Apache license contains such a provision, but the +BSD, MIT and UoI/NCSA licenses do not. + +* The AFL includes the warranty by the licensor that it either owns the +copyright or that it is distributing the software under a license. None of +the other licenses contain that warranty. All other warranties are disclaimed, +as is the case for the other licenses. + +* The AFL is itself copyrighted (with the right granted to copy and distribute +without modification). This ensures that the owner of the copyright to the +license will control changes. The Apache license contains a copyright notice, +but the BSD, MIT and UoI/NCSA licenses do not. +-- +START OF GNU GENERAL PUBLIC LICENSE +-- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE 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. + + 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 +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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 2 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This 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 Library General +Public License instead of this License.
diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..0bc33d4 --- /dev/null +++ b/ChangeLog
@@ -0,0 +1,5 @@ +2008-04-16 John (J5) Palmieri <johnp@redhat.com> + + * tools/dbus-monitor.c: take out the trailing comma in the + ProfileAttributeFlags enum as it isn't in our style guides + and causes some compilers to error out
diff --git a/ChangeLog.pre-1-0 b/ChangeLog.pre-1-0 new file mode 100644 index 0000000..eab5982 --- /dev/null +++ b/ChangeLog.pre-1-0
@@ -0,0 +1,15146 @@ +2006-11-09 John (J5) Palmieri <johnp@redhat.com> + + * Released 1.0.0 + +2006-11-09 John (J5) Palmieri <johnp@redhat.com> + + * AUTHORS: added Peter and Tor of windows porting fame + +2006-11-08 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.xml: add a note about protocol stability + + * doc/TODO: Remove "important for 1.0" section, replace with + "important for 1.2" section + +2006-11-08 John (J5) Palmieri <johnp@redhat.com> + + * README: remove some of the out of date flags + + * doc/TODO: Remove todo items which are done + +2006-11-08 John (J5) Palmieri <johnp@redhat.com> + + * tools/dbus-monitor.c: Handle sigint so we flush stdout + (Patch from Olli Salli <olli dot salli at collabora dot co dot uk>) + +2006-11-08 John (J5) Palmieri <johnp@redhat.com> + + * tools/dbus-monitor.1: update the manpage for dbus-monitor + (Patch from Olli Salli <olli dot salli at collabora dot co dot uk>) + +2006-11-08 John (J5) Palmieri <johnp@redhat.com> + + * AUTHORS: Update with all people listed in the ChangeLog + +2006-11-08 John (J5) Palmieri <johnp@redhat.com> + + * tools/dbus-monitor.c: add profiling tools to dbus-monitor + (Patch from Olli Salli <olli dot salli at collabora dot co dot uk>) + +2006-11-07 Havoc Pennington <hp@redhat.com> + + * HACKING: Update release instructions to include stuff about + stable releases, branching, etc. May not be totally correct, + please fix if needed, but keep instructions up-to-date so we do + each stable release consistently in the future. + +2006-11-07 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.xml, doc/dbus-faq.xml, README: various + documentation updates. Bump faq/spec versions (not to 1.0; I don't + think the spec will be "finished"/1.0 when we ship the 1.0 library). + +2006-11-06 John (J5) Palmieri <johnp@redhat.com> + + * bus/bus.c: Missed patch - pass in the context to the directory watch + +2006-11-02 John (J5) Palmieri <johnp@redhat.com> + + * Released D-Bus 1.0 RC 3(0.95) + +2006-11-02 John (J5) Palmieri <johnp@redhat.com> + + * bus/activation.c (bus_activation_new): don't fail if we can not read + the directory as it may not exist + +2006-11-02 John (J5) Palmieri <johnp@redhat.com> + + * bus/config-parser.c (service_dirs_find_dir): use + _dbus_list_get_next_link so we don't get stuck in an infinite loop + (start_busconfig_child): move processing of standard_session_servicedirs + tags here because they have no content + (bus_config_parser_content): check we don't have content in + standard_session_servicedirs tag + +2006-11-02 John (J5) Palmieri <johnp@redhat.com> + + * tools/Makefile.am: Make sure the /var/lib/dbus directory is created + Packagers need to own this directory + +2006-11-02 John (J5) Palmieri <johnp@redhat.com> + + * tools/run-with-tmp-session-bus.sh: fixed script to replace the + <standard_session_servicedirs> tag with a <sevicedir> tag that + points to the test service directory + +2006-11-02 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: Add a check for DIR *dirp->dd_fd + + * dbus/dbus-sysdeps-util-unix: if HAVE_DDFD is defined use + DIR *dirp->dd_fd else use DIR *dirp->__dd_fd. This takes care + of both Solaris and Irix + +2006-11-01 Havoc Pennington <hp@redhat.com> + + * bus/dbus-daemon.1.in: document standard_session_servicedirs + +2006-11-01 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: expose DBUS_DATADIR + + * bus/config-parser.c: add the standard_session_servicedirs element + to the parser + (bus_config_parser_content): process the standard_session_servicedirs + element by getting the standard directories from sysdeps and merging + them into the service directory list + (test_default_session_servicedirs): make sure we get what we expect + + * bus/session.conf.in: replace the servicedir tag with the + standard_session_servicedirs tag + + * dbus/dbus-list.h: remove the typedef of DBusList and place it in + dbus-sysdeps.h to avoid circular header dependencies + + * dbus/dbus-sysdeps.h: add the typedef of DBusList + + * dbus/dbus-sysdeps-unix.c (split_paths_and_append): utility function + which takes a string of directories delimited by colons, parses them + out, appends a suffix and puts them in a list ignoring empty elements + (_dbus_get_standard_session_servicedirs): returns the standard + directories for a session bus to look for service activation files + on Unix which includes the XDG_DATA_HOME, XDG_DATA_DIRS and + DBUS_DATADIR directories + + * test/data/valid-config-files/many-rules.conf: add the + standard_session_servicedirs tag to the valid config file tests + +2006-10-30 Havoc Pennington <hp@redhat.com> + + * tools/dbus-launch.1, doc/TODO: capture intent to change the + command line options of dbus-launch a bit post 1.0 + +2006-10-27 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c (dbus_connection_open_private): document + how to choose shared vs. private connections + +2006-10-27 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-test.c: enclose more of the file in the + DBUS_BUILD_TESTS check. + + * dbus/dbus-sysdeps-pthread.c (PTHREAD_CHECK): fix for + DBUS_DISABLE_ASSERT case. + + * dbus/dbus-connection.c (dbus_connection_get_unix_user): document + that it only works on the server side + + * dbus/dbus-bus.c: add a global lock covering the BusData we + attach to each connection + (internal_bus_get): lock our access to the BusData + (dbus_bus_register): lock the entire registration process + with _DBUS_LOCK(bus_datas). If we get the lock and + registration is already complete, silently return (vs. previous + behavior of aborting). + (dbus_bus_set_unique_name): lock the BusData + (dbus_bus_get_unique_name): lock the BusData + +2006-10-27 John (J5) Palmieri <johnp@redhat.com> + + * bus/config-parser.c (service_dirs_find_dir, + service_dirs_append_unique_or_free, + service_dirs_append_link_unique_or_free): New static methods + for only appending unique service directory names into + the service directory list + (merge_included, bus_config_parser_content): Only add unique + service directory names into the list + +2006-10-27 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps-pthread.c: make the "count" and "holder" + variables volatile, suggested by Thiago. Document struct fields. + (PTHREAD_CHECK): remove pthread error checking if assertions are + disabled, should reduce the no-assertions case to the bare + minimum code. + +2006-10-26 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps-pthread.c (_dbus_pthread_mutex_lock): change + to be recursive + (_dbus_pthread_mutex_unlock): make it recursive + (_dbus_pthread_condvar_wait): save/restore the recursion count + (_dbus_pthread_condvar_wait_timeout): save/restore the recursion count + +2006-10-26 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.xml: clarify the UUID text slightly + + * dbus/dbus-sysdeps-pthread.c: check for and mostly abort on + pthread errors. Add DBusMutexPThread and DBusCondVarPThread + in preparation for being able to extend them for e.g. recursive + mutexes. + +2006-10-26 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-threads.[hc]: Documentation improvements. Clarify how + condition variables relate to recursive mutexes. + + * dbus/dbus-sysdeps-pthread.c, dbus/dbus-sysdeps-win-thread.c, + dbus/dbus-threads.c: Split the platforms-specific thread + implementations into their own files. + + * dbus/dbus-sysdeps-pthread.c + (_dbus_pthread_condvar_wait_timeout): invert the return value, it + was backward. Not that anything uses it. + +2006-10-26 John (J5) Palmieri <johnp@redhat.com> + + * dbus-sysdeps-unix.c (_dbus_set_local_creds): Clean up the + LOCAL_CREDS vs CMSGCRED stuff a bit. Prefer CMSGCRED. This + needs to be cleaned up more. + + * doc/TODO: Add a todo that *BSD hackers should look at cleaning + up the CREDS issue. + +2006-10-26 John (J5) Palmieri <johnp@redhat.com> + + * configure.in, dbus-1.pc.in: Check to see if thread methods + are in glibc or libpthread and add -lpthread to the link stage + if it is the latter + +2006-10-26 Thiago Macieira <thiago@kde.org> + + * dbus/dbus-connection.c (_dbus_connection_open_internal): Fix + bug 8780: the connection lock is only required while recording + the shared connection, so protect only that code + section. Don't require connection_lookup_shared to return a + locked connection. + +2006-10-26 Thiago Macieira <thiago@kde.org> + + * tools/dbus-launch-x11.c (get_session_file, init_x_atoms): + check if get_machine_uuid() returns NULL before proceeding any + further: we can't init the X atoms or create a session file + name if there is no machine ID. + This solves a crash reported by some users if + --exit-with-session was used without --autolaunch=<machine-id> + +2006-10-26 John (J5) Palmieri <johnp@redhat.com> + + * tools/dbus-launch.c (main): run the dbus-daemon in the builddir + if tests are enabled and the DBUS_USE_TEST_BINARY env variable is set + + * tools/run-with-tmp-session-bus.sh: set DBUS_USE_TEST_BINARY + before we run dbus-launch + + * configure.in: define TEST_BUS_BINARY to be the full path to + dbus-daemon in the build root + +2006-10-25 Sjoerd Simons <sjoerd@luon.net> + + * dbus/Makefile.am: + * tools/Makefile.am: + * toos/dbus-uuidgen.1: + Move the machine-id file to /var/lib/dbus + +2006-10-24 David Zeuthen <davidz@redhat.com> + + * dbus/dbus-threads.c (init_uninitialized_locks): Fix typo so it's + _dbus_assert (thread_init_generation != _dbus_current_generation) + not _dbus_assert (thread_init_generation == _dbus_current_generation) + +2006-10-24 Thiago Macieira <thiago@kde.org> + + * dbus/dbus-sysdeps.h: + * dbus/dbus-sysdeps-unix.c: Add function + _dbus_make_file_world_readable that chmods a file to 0644. + + * dbus/dbus-sysdeps-unix.c (_dbus_get_autolaunch_address): + Avoid writing to the static "argv" array, thereby avoiding a + COW on the child process. + + * dbus/dbus-internals.c (_dbus_create_uuid_file_exclusively): + call _dbus_make_file_world_readable on the created file. + +2006-10-23 David Zeuthen <davidz@redhat.com> + + * dbus/dbus-memory.c: Use atomic variable to protect + n_blocks_outstanding otherwise OOM will be reported using SMP on + some arches + + * bus/dispatch.c: Add missing end of line characters + + * bus/desktop-file.c (parse_section_start, parse_key_value) + (bus_desktop_file_load): Propertly handle OOM + + * dbus/dbus-threads.c (init_uninitialized_locks): Check that + thread_init_generation equals _dbus_current_generation, not 0 + +2006-10-22 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection-internal.h: move prototype of + _dbus_bus_notify_shared_connection_disconnected_unlocked() here so + it isn't in a public header and doesn't end up in the DBusBus + group in Doxygen + +2006-10-21 Havoc Pennington <hp@redhat.com> + + * Makefile.am (EXTRA_DIST): dist cleanup-man-pages.sh so it's in + the tarball if packagers want to run it + + * cleanup-man-pages.sh: Add a script which munges all the internal + API man pages out of the Doxygen output. This reduces the size of + the installed man pages from 7 to 2 megs, and avoids + namespace-polluting pages. Right now (like Doxygen) this script + isn't in the build, it's something packagers can do manually. + +2006-10-21 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.h: don't include the watch/timeout + functions in connection section + +2006-10-21 Havoc Pennington <hp@redhat.com> + + * Documentation! Whee! Doxygen now 100% silent. If you make it + angry again, you will be punished. + +2006-10-21 Havoc Pennington <hp@redhat.com> + + * More documentation - all public API now documented according to + Doxygen + +2006-10-21 Havoc Pennington <hp@redhat.com> + + * Document a bunch of undocumented stuff + +2006-10-21 Havoc Pennington <hp@redhat.com> + + * Clean up Doxygen group markers for public API so Doxygen finds + everything (not comprehensively fixed for private API). + Means all remaining Doxygen warnings are just about missing docs + and thus pretty simple to resolve. + +2006-10-21 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-macros.h: add DBUS_GNUC_DEPRECATED macro + + * dbus/dbus-message.h: mark dbus_message_iter_get_array_len() + as DBUS_GNUC_DEPRECATED + +2006-10-21 Havoc Pennington <hp@redhat.com> + + * Move all private API into the private Doxygen group sections of + the files, so they don't show up in the public API docs + +2006-10-21 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.h: put #ifndef DBUS_DISABLE_DEPRECATED around + dbus_message_iter_get_array_len(). + + * throughout: documentation improvements. + +2006-10-20 Havoc Pennington <hp@redhat.com> + + * doc/TODO: remove the int64 thing from 1.0 since it doesn't + matter, and the message-loader-breaker thing since nobody is going + to do it. Add an item to 1.0 about supporting recursive locks + in dbus_threads_init_default() though, since it should be easy. + + * dbus/dbus-connection.c (_dbus_connection_read_write_dispatch): + Fix this in the !dispatch case to avoid busy-looping after + disconnection + + * More misc docs improvements + +2006-10-19 Havoc Pennington <hp@redhat.com> + + * more Doxygen-related fixes (lots of moving things from the + public to internal section in dbus-connection.c) + +2006-10-19 Havoc Pennington <hp@redhat.com> + + * Fix a pile of Doxygen warnings and missing docs + +2006-10-19 John (J5) Palmieri <johnp@redhat.com> + + * bus/dir-watch-default.c, bus/dir-watch-dnotify.c, + bus/dir-watch-kqueue.c (bus_watch_directory): Pass in a BusContext + instead of a void *. kqueue uses this to get the context's loop + while the other modules ignore the parameter. This allows us to + avoid platform conditionals + + * bus/bus.c (process_config_postinit): Pass in the context to the + watch + +2006-10-19 John (J5) Palmieri <johnp@redhat.com> + + * bus/messagebus.in, bus/rc.messagebus.in: run dbus-uuidgen --ensure + when starting the system bus + +2006-10-18 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: More fixups for cross compile (Patch from + Marco Pracucci <development at pracucci dot com>) + +2006-10-17 Havoc Pennington <hp@redhat.com> + + * tools/dbus-send.c (main): don't close shared connection, fix + from Timo Hoenig + +2006-10-17 Havoc Pennington <hp@redhat.com> + + * configure.in (CPPFLAGS): don't do -DDBUS_API_SUBJECT_TO_CHANGE here + + * dbus/dbus.h: drop the DBUS_API_SUBJECT_TO_CHANGE requirement, + since realistically it doesn't look like we'll be changing it + anymore. + +2006-10-17 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-internals.c (_dbus_warn_check_failed): new function to + be used for return_if_fail type warnings; prefixes the pid, and + fatal by default. + +2006-10-14 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: Released 1.0 RC 2(0.94) + Add check for -fPIC and enable it if available + +2006-10-14 John (J5) Palmieri <johnp@redhat.com> + + * doc/TODO: Remove the check TODO item + +2006-10-13 John (J5) Palmieri <johnp@redhat.com> + + * dbus-transport-socket.c (exchange_credentials): + Print out more detailed errors if reading or sending + credentials fail (Patch from Julio M. Merino Vidal + <jmmv at NetBSD dot org>) + +2006-10-13 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: when checking for posix getpwnam_r assume true + for cross compiles + +2006-10-13 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: Check for gethostbyname first before we check for it + in libnsl. On gnu systems it is implemeneted + +2006-10-13 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c + (dbus_connection_send_with_reply_and_block): fix to handle closed + connections, from Tambet Ingo bug #8631 + +2006-10-11 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: use AC_TRY_COMPILE for dirfd instead of AC_TRY_RUN + +2006-10-11 John (J5) Palmieri <johnp@redhat.com> + + * test/name-test/Makefile.am: don't link against both libdbus and + libdbus-convenience + +2006-10-11 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: check for dirfd even if it is a macro + (Patch from Timothy Redaelli <drizzt at gufi dot org>) + +2006-10-08 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: define _POSIX_PTHREAD_SEMANTICS on solaris + avoid using dirfd on systems that don't have dirfd + (Patch by Brian Cameron <brian dot cameron at sun dot com>) + +2006-10-02 John (J5) Palmieir <johnp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_abort): Remove from + #ifndef DBUS_DISABLE_ASSERTS macro to fix distcheck + + * dbus/dbus-sysdeps-unix.c (_dbus_print_backtrace): Remove from + #if !defined (DBUS_DISABLE_ASSERT) || defined(DBUS_BUILD_TESTS) + macro because _dbus_abort calls it + + * tools/Makefile.am: Add dbus-launch.h to the source list so distcheck + works + +2006-10-02 John (J5) Palmieir <johnp@redhat.com> + + * dbus/dbus-sysdeps-util-unix.c (dirent_buf_size): Add check for + MAXNAMELEN for Mac OSX. (Patch from Jonas B <sanoix at gmail dot com>) + +2006-10-02 Thiago Macieira <thiago@kde.org> + + * tools/dbus-launch.c (main): make it complain and abort + execution in case an unknown option is given. Also, process + the '--' argument as the end of arguments. + +2006-10-01 Havoc Pennington <hp@redhat.com> + + * tools/dbus-launch.c (print_variables): if no syntax is given, + don't print something that's sort-of-half-sh-syntax, just print + a plain key-value pairs thing. + + * tools/dbus-launch-x11.c: use machine ID rather than hostname for + the local machine representation (but still have the hostname in + the display). Remove the hostname from the display if it is + localhost. Change session files to be named + ~/.dbus/session-bus/machine-display. Change X atoms to be + underscore-prefixed so nobody whines about ICCCM compliance. + Otherwise name them the same as the env variables. + Change session file format to include key-value pairs and an + explanatory comment. Keys are the same as the env variables. + (set_address_in_x11): X property format can't depend on + sizeof(pid_t) on a particular machine, fix to always be 32 bits + + * tools/dbus-launch.c: make --autolaunch take a machine id + argument. If --autolaunch is used with a program to run, complain + for now (but add a FIXME). Also, don't look for existing bus if + there's a program to run (but add a FIXME). + + * dbus/dbus-sysdeps-unix.c (_dbus_get_autolaunch_address): pass + machine uuid to dbus-launch (avoids linking dbus-launch to libdbus + just to get this, and avoids duplicating uuid-reading code). + + * tools/dbus-launch.1: clarify various things + +2006-10-01 Havoc Pennington <hp@redhat.com> + + * test/test-service.c (path_message_func): remove broken extra + unref that was hidden by the bugs in dbus-connection.c/dbus-bus.c + + * test/test-shell-service.c (path_message_func): same fix + + * dbus/dbus-connection.c + (_dbus_connection_get_dispatch_status_unlocked): break up the + function a little for clarity and fix the notification of + dbus-bus.c to not require dispatch to be complete + + * dbus/dbus-connection.c (dbus_connection_unref): improve the + warning when you try to finalize an open connection. + +2006-10-01 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-bus.c + (internal_bus_get): only weak ref the connection; this means + _dbus_bus_notify_shared_connection_disconnected_unlocked can be + called safely in any context + (_dbus_bus_notify_shared_connection_disconnected_unlocked): don't + unref + + * dbus/dbus-connection.c + (_dbus_connection_get_dispatch_status_unlocked): move + _dbus_bus_notify_shared_connection_disconnected_unlocked here + when queuing Disconnected instead of when the Disconnected message + arrives, so dbus_bus_get() won't return closed connections. + +2006-10-01 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c (_dbus_connection_close_if_only_one_ref): + Add a hack to make DBusNewConnectionFunction work right. + + * dbus/dbus-server-socket.c (handle_new_client_fd_and_unlock): use + the hack here. Also, fix the todo about refcount leak. + + * dbus/dbus-server-debug-pipe.c (_dbus_transport_debug_pipe_new): + and use the hack here + + * dbus/dbus-connection.c: Kill the "shared" flag vs. the + "shareable" flag; this was completely broken, since it meant + dbus_connection_open() returned a connection of unknown + shared-ness. Now, we always hold a ref on anything opened + as shareable. + + Move the call to notify dbus-bus.c into + connection_forget_shared_unlocked, so libdbus consistently forgets + all its knowledge of a connection at once. This exposed numerous + places where things were totally broken if we dropped a ref inside + get_dispatch_status_unlocked where + connection_forget_shared_unlocked was previously, so move + connection_forget_shared_unlocked into + _dbus_connection_update_dispatch_status_and_unlock. Also move the + exit_on_disconnect here. + + (shared_connections_shutdown): this assumed weak refs to the + shared connections; since we have strong refs now, the assertion + was failing and stuff was left in the hash. Fix it to close + still-open shared connections. + + * bus/dispatch.c: fixup to use dbus_connection_open_private on the + debug pipe connections + + * dbus/dbus-connection.c (dbus_connection_dispatch): only notify + dbus-bus.c if the closed connection is in fact shared + (_dbus_connection_close_possibly_shared): rename from + _dbus_connection_close_internal + (dbus_connection_close, dbus_connection_open, + dbus_connection_open_private): Improve docs to explain the deal + with when you should close or unref or both + + * dbus/dbus-bus.c + (_dbus_bus_notify_shared_connection_disconnected_unlocked): rename + from _dbus_bus_check_connection_and_unref_unlocked and modify to + loop over all connections + + * test/test-utils.c (test_connection_shutdown): don't try to close + shared connections. + + * test/name-test/test-threads-init.c (main): fix warnings in here + + * dbus/dbus-sysdeps.c (_dbus_abort): support DBUS_BLOCK_ON_ABORT + env variable to cause blocking waiting for gdb; drop + DBUS_PRINT_BACKTRACE and just call _dbus_print_backtrace() + unconditionally. + + * configure.in: add -export-dynamic to libtool flags if assertions enabled + so _dbus_print_backtrace works. + + * dbus/dbus-sysdeps-unix.c (_dbus_print_backtrace): use fprintf + instead of _dbus_verbose to print the backtrace, and diagnose lack + of -rdynamic/-export-dynamic + +2006-09-30 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-bus.c (dbus_bus_get_private, dbus_bus_get) + (internal_bus_get): fix screwy code formatting. whoever committed + that was not paying attention! + +2006-09-30 Havoc Pennington <hp@redhat.com> + + * configure.in (LT_CURRENT, LT_AGE): increment current and age to + reflect addition of interfaces. + + * doc/dbus-specification.xml: describe a new + org.freedesktop.DBus.Peer.GetMachineId method + + * dbus/dbus-string.c (_dbus_string_skip_white_reverse): new function + (_dbus_string_skip_white, _dbus_string_skip_blank): use new + DBUS_IS_ASCII_BLANK, DBUS_IS_ASCII_WHITE macros and fix assertion + at end of skip_white + (_dbus_string_chop_white): new function + + * bus/connection.c (bus_connections_setup_connection): call + dbus_connection_set_route_peer_messages. + + * dbus/dbus-connection.c + (_dbus_connection_peer_filter_unlocked_no_update): modify to + support a GetMachineId method. + + Also, support a new flag to let the bus pass peer methods through + to apps on the bus, which can be set with + dbus_connection_set_route_peer_messages. + + Finally, handle and return an error for anything unknown on the + Peer interface, which will allow us to extend the Peer interface + in the future without fear that we're now intercepting something + apps were wanting to see. + + * tools/dbus-uuidgen.c: a thin wrapper around the functions in + dbus/dbus-uuidgen.c + + * dbus/dbus-uuidgen.c: implement the bulk of the dbus-uuidgen + binary here, since most of the code is already in libdbus + + * dbus/dbus-sysdeps.c (_dbus_read_local_machine_uuid): read the + uuid from the system config file + + * dbus/dbus-internals.c (_dbus_generate_uuid, _dbus_uuid_encode) + (_dbus_read_uuid_file_without_creating) + (_dbus_create_uuid_file_exclusively, _dbus_read_uuid_file): new + uuid-related functions, partly factored out from dbus-server.c + + * dbus/dbus-sysdeps.c (_dbus_error_from_errno): convert EEXIST to + DBUS_ERROR_FILE_EXISTS instead of EEXIST + + * dbus/dbus-protocol.h (DBUS_ERROR_FILE_EXISTS): add file exists error + + * tools/dbus-cleanup-sockets.1: explain what the point of this + thing is a bit more + + * autogen.sh (run_configure): add --config-cache to default + configure args + + * dbus/dbus-internals.h (_DBUS_ASSERT_ERROR_IS_SET): disable the + error set/clear assertions when DBUS_DISABLE_CHECKS is defined + + * tools/dbus-launch.c (main): if xdisplay hasn't been opened, + don't try to save address, fixes crash in make check + +2006-09-30 Thiago Macieira <thiago@kde.org> + + * configure.in: add DBUS_BINDIR as a #define to C source code. + + * tools/dbus-launch.c + * tools/dbus-launch.h + * tools/dbus-launch-x11.c: + * tools/dbus-launch.1: Add the --autolaunch option to + dbus-launch, which makes it scan for an existing session + started with --autolaunch. With that option, it also creates + an X11 window and saves the bus address and PID to it. + + * dbus/dbus-sysdeps.h: + * dbus/dbus-sysdeps-unix.c (_dbus_get_autolaunch_address): Add + a function that runs "dbus-launch --autolaunch" to retrieve + the running D-Bus session address (or start one if none was running) + + * dbus/dbus-transport.c: Add the handler for the "autolaunch:" + address protocol, which tries to get the running session from + dbus-launch. + + * dbus/dbus-bus.c: + * dbus/dbus-internals.h: Make "autolaunch:" be the default + D-Bus session bus address. + + * dbus/dbus-connection.c: Fix horrible typo in error message. + +2006-09-18 John (J5) Palmieri <johnp@redhat.com> + + * tools/Makefile.am: use @EXPANDED_DATADIR@ instead of @DATADIRNAME@ + +2006-09-17 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-transport.c (_dbus_transport_get_is_authenticated): + fix so that if unix_user_function is set on windows, we still + do the default check that the auth identity matches the bus identity + +2006-09-16 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-transport.c (_dbus_transport_open): modify to delegate + to _dbus_transport_open_platform_specific, + _dbus_transport_open_socket, + and _dbus_transport_open_debug_pipe + + * dbus/dbus-transport-protected.h: add _dbus_transport_open_platform_specific + +2006-09-16 Havoc Pennington <hp@redhat.com> + + Attempt auditing public API to remove all cases where a Unix + function returns weird emulated goo to Windows. This probably + breaks the bus daemon on Windows, to fix it again we may + need to stop processing unix-specific config options on Windows, + and may need to add Windows-specific public API or config options. + + * configure.in (LT_CURRENT, LT_AGE): increment current and age, + to reflect added interfaces; should not break soname. + + * dbus/dbus-transport.c (_dbus_transport_get_is_authenticated): do + not invoke unix user function on Windows. Kind of a hacky fix, but + we don't want a "unix uid" leaking out on Windows. + + * dbus/dbus-connection.c (dbus_connection_get_socket): add new API + to get the socket fd on Windows or UNIX + (dbus_connection_get_unix_fd): make this always fail on Windows + +2006-09-16 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-server.c (dbus_server_listen): change how this works + to be able to delegate to a set of handlers that can succeed, + fail, or choose not to handle. Allows us to have + dbus_server_listen_platform_specific. + + * dbus/dbus-server-socket.c (_dbus_server_new_for_tcp_socket): + factor out the tcp socket stuff to be used on windows, leaving + unix domain socket only in dbus-socket-unix.c + + * dbus/dbus-transport-socket.c + (_dbus_transport_new_for_tcp_socket): factor out the tcp socket + stuff to be used on windows, leaving unix domain socket only + in dbus-transport-unix.c + + * dbus/dbus-connection.c (dbus_connection_get_unix_user): insert + temporary hack to be sure this fails on windows + (dbus_connection_get_unix_process_id): ditto + +2006-09-16 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps-unix.c (_dbus_open_tcp_socket) + (_dbus_open_unix_socket, _dbus_open_socket): change API for + _dbus_open_socket so the domain/type/protocol from system headers + are not required. This is kind of pointless though unless we move + part of _dbus_connect_tcp_socket into sysdeps.c instead of + sysdeps-unix.c, which would mean adding a wrapper around + bind/listen/etc. + Also, add DBusError to the socket-opening functions so they + don't require use of errno. + +2006-09-16 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps-unix.h: small change to Peter's patch to make + dbus-sysdeps-unix-util.c build, add unix-specific sysdeps header. + + * dbus/dbus-sysdeps.h, dbus-sysdeps-unix.c: patch from Peter + Kümmel bug #8249 to make the sysdeps.h read/write/open/close + functions specifically for sockets only, and move generic + read/write/open/close into unix-specific code. + +2006-09-14 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-transport-unix.c (unix_do_iteration): fix a valgrind + complaint about accessing revents when poll returns 0, from Julian Seward. + +2006-09-14 John (J5) Palmieri <johnp@redhat.com> + + * Released 1.0 RC 1 (0.93) + +2006-09-14 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-sysdeps-util-unix.c (_dbus_write_pid_file): + use _dbus_close instead of close + +2006-09-14 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-sysdeps.c: Add support for LOCAL_CREDS socket + credentials. Fixes "external" authentication under e.g. NetBSD + which does not support any other socket credentials mechanism. + (Patch from Julio M. Merino Vidal <jmmv at NetBSD dot org>) + +2006-09-14 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-threads.c: Allow recursive mutex's to be passed into + dbus_threads_init and be used by the dbus mutex functions to + avoid deadlocks. + + * doc/TODO: Remove recursive mutex dbus_connection_dispatch TODO item + +2006-09-13 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-sysdeps-util-unix.c (_dbus_directory_get_next_file): + use threadsafe readdir_r instead of readdir + +2006-09-13 John (J5) Palmieri <johnp@redhat.com> + + * dbus-threads.c (dbus_threads_init_default): New method for + initializing the internal thread implementation (Patch from + Alexander Larsson <alexl at redhat dot com>) + +2006-09-11 John (J5) Palmieri <johnp@redhat.com> + + * remove a bunch of todo items from the 1.0 list + +2006-09-11 John (J5) Palmieri <johnp@redhat.com> + + * bus/activation.c, bus/desktop-file.c: Distinguish between OOM and + key not found + +2006-09-11 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-internal.c: Add dbus_is_verbose so we can have more + complex debugging code + + * dbus/dbus-marshal-basic.c (_dbus_marshal_read_fixed_multi): Move + between the test suite ifdefs + (_dbus_verbose_bytes): return if verbosity is not enabled + +2006-09-11 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-marshal-recursive-util.c, dbus/dbus-marshal-recursive.c: + remove DBusMark + +2006-09-10 Havoc Pennington <hp@redhat.com> + + patch mostly by Peter Kümmel, bug #8211 + + * dbus/dbus-sysdeps-unix.c: new file, which splits out + unix-specific stuff in dbus-sysdeps.c + + * dbus/dbus-sysdeps.c: don't include any UNIX-only headers, + and move unix-specific stuff to dbus-sysdeps-unix.c + + * configure.in: check HAVE_ERRNO_H + +2006-09-08 John (J5) Palmieri <johnp@redhat.com> + + * bus/test-main.c (main): Initialize threading during tests + + * dbus/dbus-connection.c (_dbus_connection_new_for_transport): + Unlock connection on error + (generate_local_error_message): static method for generating + an error message when we don't have a message to reply to + (_dbus_connection_block_pending_call): Send a disconnect error + instead of just a timeout (NULL) when the bus gets disconnected + while blocking for a reply. + +2006-09-08 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-connection.c (dbus_connection_dispatch): Properly remove + filters (Patch from Kimmo Hämäläinen + <kimmo dot hamalainen at nokia dot com>) + +2006-09-07 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-connection-internal.h: Add prototype for + _dbus_connection_test_get_locks to remove warning + +2006-09-07 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-spawn.c (_dbus_spawn_async_with_babysitter): Make sure we + close child_err_report_pipe[WRITE_END] on exec (Patch from + Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com>) + +2006-09-07 John (J5) Palmieri <johnp@redhat.com> + + * Clean up close calls to use _dbus_close (Patch from + Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com>) + +2006-09-06 John (J5) Palmieri <johnp@redhat.com> + + * doc/TODO: + - Remove pending call locking todo item + - dbus_connection_open now holds hard ref. Remove todo item + - do proper locking on _dbus_bus_check_connection_and_unref + and handle DBUS_BUS_STARTER. Remove todo item + - Warn on closing of a shared connection. Remove todo item + + * bus/bus.c, bus/connection.c, bus/dispatch.c, dbus/dbus-bus.c, + dbus/dbus-connection.c: Use the dbus_connection_close_internal + so we don't get the warning when closing shared connections + + * test/test-service.c, test/test-shell-service.c: Applications + don't close shared connections themselves so we unref instead of + close + + * test/test-utils.c (test_connection_shutdown): Close the connection + + * dbus/dbus-bus.c (_dbus_bus_check_connection_and_unref): Changed to + _dbus_bus_check_connection_and_unref_unlocked since we only call this + method on a locked connection. + Make sure we call _dbus_connection_unref_unlocked instead of + dbus_connection_unref also. + Handle DBUS_BUS_STARTER correctly + + * dbus/dbus-connection.c (connection_record_shared_unlocked): + Mark as shared and hard ref the connection + (connection_forget_shared_unlocked): Remove the hard ref from the + connection + (_dbus_connection_close_internal_and_unlock): New internal function + which takes a locked connection and unlocks it after closing it + (_dbus_connection_close_internal): New internal function which acts + like the origonal dbus_connection_close method by grabbing a connection + lock and calling _dbus_connection_close_internal_and_unlock + (dbus_connection_close): Public close method, warns when the app + trys to close a shared connection + +2006-09-06 John (J5) Palmieri <johnp@redhat.com> + + * bus/driver.c: + (bus_driver_generate_introspect_string): New method for populating + a DBusString with the introspect data + (bus_driver_handle_introspect): Move introspect generation code to + bus_driver_generate_introspect_string + + * bus/main.c: + (introspect): New function which prints out the intropect data and + exits + (main): Add a --introspect switch + +2006-09-06 John (J5) Palmieri <johnp@redhat.com> + + * doc/TODO: Removed dtd publishing item. + It seems the dtd has already been added at + http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd + +2006-09-05 John (J5) Palmieri <johnp@redhat.com> + + * doc/TODO, various source files: Audited todo's and FIXME's and + prepended the ones we should be looking at with 1.0. Those + prepended with 1.0? need clerification or might not be needed + for 1.0 + +2006-09-05 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-pending-call.c: Add some checks so we don't crash on + NULL in the public API (Patch from Kimmo Hämäläinen + <kimmo dot hamalainen at nokia dot com>) + +2006-09-05 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: Fix for OS-X compile time endian issues (patch from + Benjamin Reed <ranger at befunk dot com>) + +2006-09-05 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: Check for no-common compiler flag (OS-X fix from + Benjamin Reed <ranger at befunk dot com>) + +2006-09-01 John (J5) Palmieri <johnp@redhat.com> + + * tools/dbus-launch.c: Add a sigterm handler (patch from Frederic Crozat + <fcrozat at mandriva dot com>) + +2006-08-29 Havoc Pennington <hp@redhat.com> + + * test/test-service.c (path_message_func): fix lack of return value + + * dbus/dbus-sysdeps.c (_dbus_printf_string_upper_bound): fix + formatting, remove #ifdef, and fix docs. #ifdef doesn't make + any more sense than on anything else in this file. + (_dbus_get_tmpdir): add const to return value, and keep the + results of the various getenv around in a static variable. + +2006-08-29 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps-util.c, dbus/dbus-sysdeps-util-unix.c: change + from Ralf Habacker to move UNIX-specific sysdeps into a separate file. + +2006-08-25 John (J5) Palmieri <johnp@redhat.com> + + * test/Makefile.am: change find to use syntax that works with non + gnu versions of find + +2006-08-25 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-transport.c: fix invalid deref when checking if + a vtable method exists (Patch from Christian Ehrlicher + <ch dot ehrlicher at gmx dot de>) + +2006-08-25 John (J5) Palmieri <johnp@redhat.com> + + * configure.in, dbus/Makefile.am, test/name-test/run-test.sh, + test/name-test/Makefile.am: Fixed some issues with getting get dbus + to build with builddir != srcdir (Taken from a patch by Bernard Leak + <bernard at brenda-arkle dot demon dot co dot uk>) + +2006-08-25 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: Fix DBUS_DAEMONDIR to use EXPANDED_BINDIR for the + default case + +2006-08-25 John (J5) Palmieri <johnp@redhat.com> + + * configure.ac, bus/Makefile.am: Generalize kqueue support so that + it works on any system providing this interface, not only FreeBSD. + For example, NetBSD. (Patch by Julio M. Merino Vidal <jmmv at NetBSD dot org>) + +2006-08-20 Havoc Pennington <hp@redhat.com> + + * doc/dbus-faq.xml, doc/dbus-tutorial.xml: some improvements to + the docs + +2006-08-18 John (J5) Palmieri <johnp@redhat.com> + + * Released 0.92 + +2006-08-18 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-threads.c (dbus_threads_init): change the documentation + to reflect the init late change + + * bus/bus.c (bus_context_new): Check user before we fork so we can + print out an error message a user will be able to see + +2006-08-18 John (J5) Palmieri <johnp@redhat.com> + + Patch provided by Ralf Habacker (ralf dot habacker at freenet dot de) + + * dbus/dbus-sysdeps.c, dbus/dbus-threads.c, dbus/dbus-internals.h: + Add two more global locks for use on windows platforms. These are + unused on non-windows platforms but are not ifdefed out to avoid + potential bugs (i.e. the few bytes lost does not warrent the extra + maintanence and complexity that having seperate sets of locks would + cause) + +2006-08-18 John (J5) Palmieri <johnp@redhat.com> + + * bus/services.c (bus_registry_acquire_service): Return an error + when an application tries to register the org.freedesktop.DBus Bus Name + + * bus/services.c (bus_registry_release_service): Return an error + when an application tries to release the org.freedesktop.DBus Bus Name + +2006-08-17 Alp Toker <alp@atoker.com> + + * doc/dbus-specification.xml: Fix some minor typos. + +2006-08-17 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: use $with_init_scripts instead of $operating_system + to determine where to store the pid since the init scripts manipulate + the pid file (patch from Marcelo Ricardo Leitner + <marcelo dot leitner at terra dot com dot br>. + +2006-08-16 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-threads.c: Add static DBusList *uninitialized_mutex_list and + static DBusList *uninitialized_condvar_list to support new late + initialization threading model. In this model threads can be initialized + even after the D-Bus API has been used but still needs to be initialized + before the second thread has been started. Mutexes and condvar addresses + are stored in the two static lists and are replaced with actuall locks + when threads are initalized. + (_dbus_mutex_new_at_location): New method for creating a mutex and placing + the location into the static list + (_dbus_mutex_free_at_location): New method for removing a mutex location + from the static list and freeing the mutex + (_dbus_condvar_new_at_location): New method for creating a conditional + variable and placing the location into the static list + (_dbus_condvar_free_at_location): New method for removing a conditional + variable location from the static list and freeing the conditional variable + (init_uninitialized_locks): Atomic method which goes through the static + lists of mutex and condvar location and updates them with actuall locks + (init_global_locks): changed to init_locks + + * dbus/dbus-connection.c: + (_dbus_connection_test_get_locks): New method for tests to check connections + (_dbus_connection_new_for_transport): Use the new at_location mutex and + condvar API + (dbus_connection_allocate_data_slot): Pass in the global lock address + to _dbus_data_slot_allocator_alloc + + * dbus/dbus-dataslot.c: + (_dbus_data_slot_allocator_alloc): Use the address of the mutex + instead of the mutex itself + + * dbus/dbus-message.c: + (dbus_message_allocate_data_slot): Pass in the global lock address + to _dbus_data_slot_allocator_alloc + + * dbus/dbus-pending-call.c: + (dbus_pending_call_allocate_data_slot): Pass in the global lock address + to _dbus_data_slot_allocator_alloc + + * dbus/dbus-server.c: + (_dbus_server_init_base): Use the new at_location mutex API + (dbus_server_allocate_data_slot): Pass in the global lock address + to _dbus_data_slot_allocator_alloc + + * test/name-test/test-threads-init.c: New test case for late thread + initialization + +2006-08-14 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-dataslot.c (_dbus_data_slot_allocator_alloc): + Change _dbus_abort to _dbus_assert_not_reached because _dbus_abort + causes compile problems when asserts are turned off + Keeping _dbus_warn for printing out the message so even if + asserts are turned off the user gets the messages that something is + wrong + +2006-08-14 John (J5) Palmieri <johnp@redhat.com> + + Patches by Kjartan Maraas <kmaraas at gnome dot org> + + * bus/services.c (bus_service_list_queued_owners): + Add a pointer cast to fix compiler warning + + * dbus/dbus-dataslot.c (_dbus_data_slot_list_get): + return a NULL instead of FALSE since the return type + is not expecting a boolean + + * dbus/dbus-marshal-basic.c (_dbus_marshal_test): + Remove unused variable + + * dbus/dbus-marshal-recursive-util.c (node_new): + return a NULL instead of FALSE since the return type + is not expecting a boolean + + * dbus/dbus-server-debug-pipe.c (_dbus_transport_debug_pipe_new): + Send a NULL into _dbus_transport_new_for_fd instead of a FALSE + because we are expecting a pointer not a boolean + + * dbus/dbus-sysdeps-util.c (_dbus_get_tmpdir): + add void as the parameter so some compilers + don't complain + + * dbus/dbus-transport-unix.c (_dbus_transport_new_for_domain_socket, + _dbus_transport_new_for_tcp_socket): + Send a NULL into _dbus_transport_new_for_fd instead of a FALSE + because we are expecting a pointer not a boolean + + * test/shell-test.c (test_command_line): + cast the second argument to _dbus_list_append to avoid compiler + warnings + + * test/test-names.c (main): remove unused variable + + * test/test-service.c (check_hello_from_self_reply): + Initialize echo_message and echo_reply to NULL + + * test/test-shell-service.c (handle_echo): + Remove unused variable and cast the third parameter passed to + dbus_connection_get_object_path_data to avoid compiler warrnings + + * test/name-test/test-names.c (clear_message_queue): + Remove unused function + + * test/name-test/test-pending-call-dispatch.c: + Fix format string in printf + + +2006-08-14 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-bus.c: + * test/name-test/test-names.c: + Remove test method dbus_bus_connection_get_unique_name because + we already have public method dbus_bus_get_unique_name that + does the exact same thing + +2006-08-10 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-signature.c: + fix typos in Julio's previous patch which cause make check to fail + +2006-08-10 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-address.c (_dbus_address_test): Revert leaking strcmp. + In any case it was wrong since this is a test checking to see if + address parsing is correct. There was no need to get the true + tmp directory. + +2006-08-10 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-macros.h: Revert the addition of stddef.h + as we should not be adding it to library headers + +2006-08-10 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-signature.c: + Fix the unit tests so that they work if assertions are not enabled. + (patch from Julio M. Merino Vidal <jmmv at NetBSD dot org>) + +2006-08-10 John (J5) Palmieri <johnp@redhat.com> + + * tools/run-with-tmp-session-bus.sh: + * test/name-test/run-test.sh: + Remove bashisms (patch from Julio M. Merino Vidal + <jmmv at NetBSD dot org>) + +2006-08-10 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: add a version (>= 2.6.0) check for libxml2 + +2006-08-10 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: make sure the compiler supports -Wfloat-equal + + * bus/dir-watch-dnotify.c: move functional code after + variable declerations (C99 fix) (patches from Jens Granseuer + <jensgr at gmx dot net> + +2006-08-10 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-macros.h: + add #include <stddef.h> so that Sun compilers don't complain about + the defining NULL + +2006-08-10 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-sysdeps.c: + * dbus/dbus-address.c: + * bus/activation.c: + * test/shell-test.c: + don't hardcode tmp directory (patch from Dave Meikle + <dmk at davemeikle dot co dot uk>) + +2006-08-09 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-dataslot.c (_dbus_data_slot_allocator_alloc): + Change an assert to a detailed warning and abort. + When allocator->lock != mutex it indicates that the user has failed + to initalize threads before using the D-Bus library. This warning + helps the user identify the issue and fix their app. + +2006-08-08 John (J5) Palmieri <johnp@redhat.com> + + These are all patches from Kjartan Maraas <kmaraas at gnome dot org> + with cleanups of bugs found from Coverity reports: + + * dbus/dbus-sysdeps-util.c (_dbus_write_pid_file): + close the file on error to avoid a leak + + * bus/expirelist.c (bus_expire_list_test): + Check for NULL on dbus_new0 + + * bus/activation.c (update_directory): + remove dead code + + * bus/config-parser.c (merge_service_context_hash, start_selinux_child): + Fix some leaks + + * bus/bus.c (process_config_every_time): + Fixed a leak + + * bus/desktop-file.c (parse_key_value): + Fixed leak + + * bus/selinux.c (bus_selinux_id_table_insert): + Fixed leak + +2006-08-08 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-object-tree.c (_dbus_object_subtree_new): + remove dead code + +2006-08-08 John (J5) Palmieri <johnp@redhat.com> + + * tools/run-with-tmp-session-bus.sh: use #!/bin/sh instead of + #!/bin/bash + +2006-08-08 John (J5) Palmieri <johnp@redhat.com> + + * Doxyfile.in: fix the INPUT line so we can generate docs + when sourcedir != builddir (patch from Cygwin Ports maintainer + <yselkowitz at users dot sourceforge dot net> + +2006-08-08 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-sysdeps.h: + * dbus/dbus-sysdeps.c: + * dbus/dbus-string.c: + s/_dbus_printf_length/_dbus_printf_string_upper_bound to comform with + GLib's function which does the same thing + + * configure.in: + * bus/Makefile.am: + * bus/dir-watch-default.c: + * bus/dir-watch-dnotify.c: + * bus/dir-watch-kqueue.c: + Add kqueue directory watching for freebsd and split the directory + watching code into seperate files per method/arch + (patches from Timothy Redaelli <drizzt at gufi dotorg>) + +2006-08-08 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: + * tools/Makefile.am: + * tools/dbus-launch.c: + * bus/Makefile.am: + allow --with-dbus-daemondir switch to be used to make the + daemon install to a seperate bindir like /usr/libexec + (patch from Brian Cameron <brian dot cameron at sun dot com) + +2006-08-08 John (J5) Palmieri <johnp@redhat.com> + + * bus/Makefile.am (install-data-hook): removed the slash after + $(DESTDIR) so we don't get the double slash which does not work + in windows (patch from Andras Porjesz + <andras dot porjesz at siemens dot com>) + +2006-08-08 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-sysdeps.h: + * dbus/dbus-sysdeps.c: + add _dbus_printf_length (patch from Peter Kümmel + <syntheticpp at gmx dot net>) + +2006-08-08 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-internals.c: unistd.h is not used + (_dbus_verbose_real): only enable verbose printing + if DBUS_VERBOSE environment var is set to '1' + (patch from Peter Kümmel <syntheticpp at gmx dot net>) + +2006-08-08 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: add a GCC flag check for -Wdeclaration-after-statement + so we still compile on older gcc (patch from Frederic Peters + <fpeters at 0d dot be> + +2006-08-04 Havoc Pennington <hp@redhat.com> + + * configure.in: add -Wdeclaration-after-statement + + * dbus/dbus-connection.c: change all the pending call stuff to + reflect the fact that pending call operations use the connection + lock + + * dbus/dbus-pending-call.c: add locking here + + * dbus/dbus-errors.c (struct DBusRealError): don't make the name + field const consistent with how message field is done + +2006-08-03 John (J5) Palmieri <johnp@redhat.com> + + * s/D-BUS/D-Bus/g + +2006-08-03 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-object-tree.c: Patch by Benjamin Otte + <in7y118 at public.uni-hamburg dot de> - fix invalid + read/write reported by valgrind + +2006-07-24 John (J5) Palmieri <johnp@redhat.com> + + * Released 0.91 + +2006-07-22 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-connection.c: + (_dbus_connection_attach_pending_call_unlocked): + (connection_timeout_and_complete_all_pending_calls_unlocked): + Make sure we set timeout_added on pending calls to FALSE when + we remove the timeout from the connection + +2006-07-21 John (J5) Palmieri <johnp@redhat.com> + + * Removed some extra bindings stuff lingering around (thanks timo) + * dbus-pendingcall.c (_dbus_pending_call_new): + s/dbus_connection_ref/_dbus_connection_ref_unlocked fixes assertion + when we tried to take a lock on an already locked connection + +2006-07-17 John (J5) Palmieri <johnp@redhat.com> + + * Released 0.90 + +2006-07-17 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-marshal-basic.c (_dbus_type_to_string): support 64-bit + ints, reported by Owen Taylor + +2006-07-17 John (J5) Palmieri <johnp@redhat.com> + + * doc/TODO: + * dbus/dbus-bus.c: + * dbus-errors.c: + * dbus/dbus-marshal-validate.c: + Removed TODO items which were fixed or are no longer relevent + +2006-07-17 John (J5) Palmieri <johnp@redhat.com> + + * dbus-qt4-1.pc.in, dbus-sharp.pc.in: + Remove stray files from the stripped bindings + +2006-07-16 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-pending-call.c (_dbus_pending_call_set_timeout_error): + Improve the error message on reply timeout + +2006-07-14 John (J5) Palmieri <johnp@redhat.com> + + * Remove all bindings + +2006-07-13 John (J5) Palmieri <johnp@redhat.com> + + * dbus-connection.c (dbus_connection_send_with_reply): return TRUE + and set pending_reply out arg to NULL is connection is disconnected + (connection_timeout_and_complete_all_pending_calls_unlocked): New + static method for cleaning up pending calls on disconnect + (_dbus_connection_get_dispatch_status_unlocked): If we have pending + calls queued timeouts on disconnect + + * dbus/dbus-pending-call.c (_dbus_pending_call_set_connection): + Remove + +2006-07-13 Carlos Garcia Campos <carlosgc@gnome.org> + + * bus/activation.[ch] (bus_activation_list_services): new function to + get the list of services that can be activated + + * bus/dispatch.c: test coverage for the new bus method + ListActivatableNames + + * bus/driver.c: new bus method ListActivatableNames to get the list of + services that can be activated + + * doc/dbus-specification.xml: ListActivatableNames method documentation + +2006-07-12 John (J5) Palmieri <johnp@redhat.com> + * dbus/Makefile.am: add dbus-pending-call-internal.h to the list of + source files + +2006-07-12 John (J5) Palmieri <johnp@redhat.com> + * dbus/dbus-message-factory.c: + Fix index into an array (patch by Peter Kümmel <syntheticpp at gmx.net>) + +2006-07-12 John (J5) Palmieri <johnp@redhat.com> + * dbus/dbus-connection-internal.h: + * dbus/dbus-connection.c: + * file dbus/dbus-pending-call.c: + * dbus/dbus-pending-call.h: + Make DBusPendingCall an opaque type even to D-Bus internals + +2006-07-07 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-connection.h: remove connection_disconnect and replace with + connection_close + + * dbus/dbus-connection.c: include dbus-bus.h + (_dbus_connection_read_write_dispatch): make static + +2006-07-07 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-connection.c (dbus_connection_close): removed deprecated + function + (dbus_connection_dispatch): On disconnect unref any shared connections + + * dbus/dbus-bus.c (_dbus_bus_check_connection_and_unref): new function + for cleaning up shared connections on disconnect + (internal_bus_get): get a hard refrence to shared connections when + they are created + + * doc/TODO: Remove items which are no longer relevent or have been fixed + Split 1.0 todo items with a 0.90 freeze todo list + +2006-06-14 Ross Burton <ross@openedhand.com> + + * glib/dbus-gobject.c: + Free a leaking GArray (surely not!) in dbus_g_method_return. + +2006-06-14 Ross Burton <ross@openedhand.com> + + * tools/Makefile.am: + * tools/dbus-monitor.c: + Don't use the GLib bindings in dbus-monitor (patch from Ralf + Habacker). + +2006-06-14 Ross Burton <ross@openedhand.com> + + * tools/dbus-print-message.c: + Also print the object path when outputting signals or method calls. + +2006-06-13 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/src/Makefile.am: install the qdbus.h header. + This allows people to actually use the installed code. + +2006-06-12 Ross Burton <ross@openedhand.com> + + * glib/dbus-gproxy.c: + Don't leak a GArray when firing signals (thank Rob Taylor for review). + +2006-06-12 Thiago Macieira <thiago.macieira@trolltech.com> + + * Released 0.62 + +2006-06-12 Thiago Macieira <thiago.macieira@trolltech.com> + + * dbus/dbus-arch-deps.h.in: Remove spurious semi-colons that + break pedantic builds. Closes bug 6043 (patch approved by + Havoc back in February). + +2006-06-12 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/src/qdbusintegrator.cpp: Fix bug in parsing async methods + that took a QDBusMessage parameter. + * qt/src/qdbusbus.h: Add a default flag for RequestName. + * qt/tools/dbus.cpp: Don't use automatic call because we might + be calling an async method: request a reply. + +2006-06-11 Thiago Macieira <thiago.macieira@trolltech.com> + + * test/qt/*: Update the testcases, including testing the new + functionality of sending null QByteArray and QString over the + bus. Add new headertest test and restore the old + qdbusxmlparser test. + +2006-06-11 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/tools/dbuscpp2xml.cpp: Compile on Windows. + * qt/tools/dbusidl2cpp.cpp: Add missing newline. + + * qt/examples/Makefile.am: + * qt/examples/chat.h: Use UI-generated files with the ui_*.h + form. + + * qt/src/qdbusmarshall.cpp: Allow sending of QString() and + QByteArray() (nulls) over the bus. + * qt/src/qdbusabstractinterface.cpp: Use the correct variable, + the one that has the signature suffix stripped. + * qt/src/qdbusreply.h: Make some methods const. + +2006-06-09 Thiago Macieira <thiago.macieira@trolltech.com> + + Patch from Timo Hoenig <thoenig@suse.de>. + + * qt/dbus/Makefile.am: New file. Fix "make dist", add all headers + required during build to EXTRA_DIST. + * qt/src/Makefile.am: Fix "make dist", add 'qdbus.h' to EXTRA_DIST. + * qt/Makefile.am: Fix "make dist", add 'dbus' to DIST_SUBDIRS. + * configure.in: Fix "make dist", take care that the Makefile for + qt/dbus is being generated. + +2006-06-07 John (J5) Palmieri <johnp@redhat.com> + + * bus/bus.c: Fix eavesdropping on method calls + +2006-06-07 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: + * dbus/dbus-userdb-util.c: + Add Solaris console owner patch from Artem Kachitchkine + +2006-06-07 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/Makfile.am: + * qt/src/Makefile.am: Fix the EXTRA_DIST after the + reorganisation. Thanks to Timo Hoenig for pointing this out. + +2006-06-06 Robert McQueen <robot101@debian.org> + + * glib/dbus-gtype-specialized.c: Fix obvious leak of GArray in every + call to dbus_g_type_get_struct. + +2006-06-06 Robert McQueen <robot101@debian.org> + + * glib/dbus-gvalue-utils.c: Fix the failing test where static string + pointers were put into a GPtrArray-based specialised collection, and + then freed along with the array. GValues which you add into + collections or maps which have the NOCOPY flag set are assumed to not + belong to the caller, so rather than the existing pointer-stealing + semantics, they are copied instead. Given that the main consumers of + this abstraction are the bindings themselves, I don't think this is + too bad, but others should watch their choice of take vs set_static. + +2006-06-06 Robert McQueen <robot101@debian.org> + + * glib/dbus-gvalue-utils.c: Spotted a warning about the return value + of g_slist_prepend not being used. Fixed copying of slist-based + specialised collections, then wrote a test case and found that it was + all broken. Went on to fix iterating and appending too. Good thing + nobody uses this code yet. + +2006-06-06 Robert McQueen <robot101@debian.org> + + * glib/dbus-gvalue-utils.c: Remove duplicated code by having all of + the iterators use gvalue_take_ptrarray_value (the GValues themselves + are discarded without unsetting, so it makes no difference whether + we take or set_static). Remove cases for G_TYPE_POINTER because + there really is nothing useful we can do with them in our + specialised types - we *need* boxed copy/free functions at the very + least. + +2006-06-05 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/dbus: Add directory. I had forgotten to add this + yesterday after the move... + + * qt/examples/Makefile.am: + * qt/examples/dbus.cpp: Moved to qt/tools/dbus.cpp. + + * qt/tools/Makefile.am: + * qt/tools/dbus.cpp: Moved from qt/examples/dbus.cpp. + Added feature to get and set properties. + Added validation of service, object path and interface names. + + * qt/tools/dbusidl2cpp.cpp: Two new features: + 1) Allow specifying both the header and the source file names, + by separating them with a colon. + 2) Don't write an interface output if the -p switch wasn't + given, but the -a was. + + * qt/src/*: Fix usage of Iterators and ConstIterators. + Fix shadowing of variables by other variables (-Wshadow). + Fix keyword-cleanliness in headers. + Fix ASCII-cast (QLatin1String, QLatin1Char). + Fix validation of member names. + Add extra checking of introspection data during XML parsing. + Various bug fixes. + +2006-06-04 Thiago Macieira <thiago.macieira@trolltech.com> + + * dbus/Makefile.am: + * dbus/qdbus.h: Remove unnecessary file. This is mirrored into + qt/dbus/qdbus.h now. + +2006-06-04 Thiago Macieira <thiago.macieira@trolltech.com> + + * configure.in: Make --disable-qt actually do + something. Patch inspired by Zack Rusin. + +2006-06-04 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/: Update to Subversion r548032. + This includes a big reorganisation of the files inside the + subdir. + +2006-05-30 Sjoerd Simons <sjoerd@luon.net> + + * dbus/dbus-sysdeps.c: Make tcp socket connection error somewhat more + clear: + "Failed to connect to socket <host>:<port> <error>" instead of + "Failed to connect to socket <host>: <error>:<port>" + + * dbus/dbus-transport-unix.c: Fix crash when no host option is given + for a tcp transport. + +2006-05-29 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/*: Update the QtDBus bindings up to revision 546310 in + Subversion. + This adds the dbuscpp2xml tool, that parses a C++ header and + outputs a D-BUS Introspection XML. + +2006-05-21 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gproxy.c: Put in a pile of assertions that the proxy name + is not NULL when it shouldn't be. Also a couple of possible fixes + for #4637 though I don't understand why the bug happens, to be + honest... also the object constructor has an assert name != NULL + and the name is only currently NULL for peer-to-peer proxies that + I don't think anyone uses? So it should be asserting. + Anyway, for now at least see if we get an earlier assertion failure. + + * glib/dbus-gvalue-utils.c: Put in a couple of assertions for + apparently broken code to be sure the tests fail and someone + will fix them... + +2006-05-07 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/qdbusmarshall.cpp: Fix a problem of demarshalling lists + and arrays when they had a single element: has_next returns + false, even before you read the element. So, instead, check + the array length. + +2006-05-06 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/qdbusmessage.cpp: + * qt/qdbustypehelper_p.h: + * qt/qdbusintegrator.cpp: gcc 3.4 doesn't like Q_FOREACH when + the list is a const-reference + +2006-05-03 John (J5) Palmieri <johnp@redhat.com> + + * Adding old doc patch that never got applied + + * dbus/bus.c (dbus_bus_add_match): Add documentation + + * doc/dbus-specification.xml: Add documentation for the match rules + and the AddMatch and RemoveMatch methods + +2006-05-02 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/dbusidl2cpp.cpp: There's no callAsync. Use the correct + call (r535506) + + * qt/dbusidl2cpp.cpp: + * qt/qdbusabstractadaptor.cpp: + * qt/qdbusabstractadaptor.h: Make QDBusAdaptorConnector be a + sibling of the QDBusAbstractAdaptor objects instead of the + parent. (r535848) + + * qt/dbusidl2cpp.cpp: + * qt/qdbusabstractinterface.cpp: + * qt/qdbusabstractinterface.h: + * qt/qdbusabstractinterface_p.h: + * qt/qdbusinterface.cpp: Make properties in interfaces + actually work. The code that was generated would not compile, + due to moc calls to functions that did not exist. They now + shall. (r536571) + +2006-04-30 Thiago Macieira <thiago.macieira@trolltech.com> + + * Makefile.am: + * configure.in: + * dbus-qt4-1.pc.in: Add a pkg-config file for libdbus-qt4-1. + Thanks to Brad Hards for providing the patch + +2006-04-29 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/dbusidl2cpp.cpp: There's no callAsync. Use the correct + call. (r535506) + +2006-04-29 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/examples/dbus.cpp: Enhance error messages and use + QDBusInterfacePtr. + +2006-04-29 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/qdbusinterface.h: Rename QDBusRef to QDBusInterfacePtr + and disable the copy operators. (r533772, r534746) + + * qt/qdbuserror.h: Remove the automatic cast to bool. (r533929) + + * qt/qdbusabstractinterface.cpp: + * qt/qdbusabstractinterface.h: Change the default call mode to + not use the event loop. Add convenience call() methods that + take a CallMode parameter. (r534042) + + * qt/qdbusconnection.h: Change the default call mode to not + use the event loop. (r534042) + + * qt/qdbusinterface.cpp: + * qt/qdbusinterface.h: Add a method to tell us if the + interface is valid (since we don't return a null pointer + anymore) (r534099) + + * qt/qdbusinterface_p.h: Don't crash if metaObject is 0 + (r534101) + + * qt/qdbusinternalfilters.cpp: Decouple the introspection + function in two so taht we get the chance to introspect + without having a QDBusMessage (r534102) + + * qt/qdbusbus.h: + * qt/qdbusconnection.cpp: + * qt/qdbusconnection_p.h: + * qt/qdbusintegrator.cpp: Keep a list of our own names to + avoid a round-trip to the server when attempting to introspect + one of our own objects. Also make sure the filter functions + match the empty interface as well. (r534108) + Don't keep the connection names. Instead, trust the unique + connection name (r534111) + Remove event loop usage (r534112) + +2006-04-29 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/qdbusintegrator.cpp: Fix assertion failure spotted by + Brad Hards. + +2006-04-28 Robert McQueen <robot101@debian.org> + + * glib/dbus-gproxy.c: Fix properties so that they can be given in + any order, making it easier for people who inherit from this + object. + +2006-04-28 Robert McQueen <robot101@debian.org> + + * glib/dbus-gvalue-utils.c: Patch from Jakub Stachowski to fix leaking + of memory from within pointer arrays and lists. Fixes bug #6300. + +2006-04-28 Robert McQueen <robot101@debian.org> + + * glib/dbus-gvalue.c: Patch from Jakub Stachowski to fix a leak in + generating struct signatures. Fixes bug #6083. + +2006-04-28 Robert McQueen <robot101@debian.org> + + * qt/Makefile.am: Tweak CLEANFILES from qdbusconnection.moc + to qdbusconnection_p.moc. + +2006-04-24 John (J5) Palmieri <johnp@redhat.com> + + * README, INSTALL: Doc fixes + Patch from Brad Hards <bradh at frogmouth.net> + +2006-04-23 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/examples/dbus.cpp: Use the new merged-interface mode for + the dynamic meta object. No need to guess which interface to + call. + +2006-04-23 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/qdbusconnection_p.h: + * qt/qdbusmetaobject.cpp: + * qt/qdbusmetaobject_p.h: + * qt/qdbusintegrator.cpp: Use the new merged-interface mode + for the dynamic meta object. No need to guess which + interface to call. + * qt/qdbusabstractinterface_p.h: + * qt/qdbusconnection.cpp: + * qt/qdbusintegrator.cpp: + * qt/qdbusinterface.cpp: + * qt/qdbusinterface.h: Make findInterface always return a non-null pointer. + Add a QDBusRef that looks and behaves like DCOPRef. + +2006-04-23 Thiago Macieira <thiago.macieira@trolltech.com> + + * dbus/dbus-connection.c: Interfaces are optional in method + calls, so don't give up if the interface parameter is NULL. + Patch reviewed by Havoc Pennington. + +2006-04-23 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/qdbusreply.h: Add default constructor and operator= + (r532625) + * qt/qdbustypehelper_p.h: Use a clean namespace: no foreach() + in public headers (r532952) + * qt/qdbusabstractinterface.cpp: + * qt/qdbusabstractinterface_p.h: Add the AutoDetect mode and + make it the default (r532951) + +2006-04-19 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-connection.c: Fix asserts + Patch from Tim Moloney <t.moloney at verizon.net> + +2006-04-19 John (J5) Palmieri <johnp@redhat.com> + + * mono/Connection.cs, mono/Message.cs: Check Target type + Patch from Aaron Bockover (abockover at novell.com) + +2006-04-13 Thiago Macieira <thiago.macieira@trolltech.com> + + * INSTALL: fine-tune the requirements for the Qt4 binding. + +2006-04-16 Daniel P. Berrange <dan@berrange.com> + + * tools/dbus-print-message.c: Added support for printing of all + remaining data types. Fixed logic for indentation of compound + data types. + +2006-04-15 Daniel P. Berrange <dan@berrange.com> + + * INSTALL: fill out content of file providing DBus specific + build installations, followed by generic Auto* INSTALL file + content + +2006-04-13 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/qdbusintegrator.cpp: Work around g++ 3.3 bug. + Patch by Stefan Eilers. (r529537) + +2006-04-13 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/qdbusinternalfilters.cpp: Don't show the parent's + contents (r528208) + +2006-04-10 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/Makefile.am: fix the dependency for + qdbusconnection_p.moc. It's included in qdbusintegrator.cpp, + not in qdbusconnection.cpp. + Thanks to Jakub Stachowski <stachowski@hypair.net> for + spotting this. + +2006-04-10 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/examples/listnames.cpp: + * qt/examples/Makefile.am: Three ways to list the names on the + bus. + +2006-04-10 Thiago Macieira <thiago.macieira@trolltech.com> + + * test/qt/tst_hal.cpp: Remove the waiting, since it's not + needed anymore. Requires Qt 4.1.3 to work properly. (r528148) + +2006-04-10 Thiago Macieira <thiago.macieira@trolltech.com> + + Merge from Subversion: + * qt/qt-dbus.qdocconf: Update Trolltech's webpage link to + something that exists (r526315) + * qt/qdbusinternalfilters.cpp: Correctly detect non-scriptable + slots/signals (r526316) + * qt/qdbusinternalfilters.cpp: Fix the setProperty call and + also return an unknown-method error if the parameters don't + match for org.freedesktop.DBus.Properties. (r526842) + * qt/examples/dbus.cpp: Allow passing of QVariants (r526843) + * qt/qdbusintegrator.cpp: Restore the proper order of + delivery: don't make method returns be delivered on priority + (r528150) + +2006-03-28 Thiago Macieira <thiago.macieira@trolltech.com> + + * configure.in qt/Makefile.am: add qt/examples + * qt/examples: Add QtDBus example programs: + - hello: Hello, World + - ping: Simple method-calling program + - pong: Simple object-exporting program (not using adaptors) + - complexping: Interactive method-calling program + (also gets and sets properties). + - complexpong: Sample program exporting methods, signals and + properties, using adaptors. + - dbus: Simple implementation of a generic method-calling + program, similar to 'dbus-send', but with semantics + similar to 'dcop'. + - chat: Simplistic chat program, implemented using signals + and the system bus. Looks like IRC. + +2006-03-28 Thiago Macieira <thiago.macieira@trolltech.com> + + * configure.in: Detect QtGui (necessary for one of the + example programs). Note: this increases the minimum required + version of Qt to 4.1.3. + +2006-03-28 Thiago Macieira <thiago.macieira@trolltech.com> + + * test/qt/*: Sync with KDE Subversion revision 523647. + Update the testcases to the new API. Remove testcases for + classes that are no longer public or have been removed. + +2006-03-28 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/*: + * dbus/qdbus.h: Sync with KDE Subversion revision + 523647. Hopefully, this will be the last of the + source-incompatible changes. Documentation has been improved; + support for QList<basic-types> has been added; QDBusObject is + gone; QDBus(Abstract)Interface is now a QObject with + auto-generated meta-object; QDBusIntrospection is marked + private, since QMetaObject can be used now; lots of bugfixes. + +2006-03-16 John (J5) Palmieri <johnp@redhat.com> + + Patch from Milosz Derezynski <internalerror at gmail.com> + + * configure.in: + Output the service directory in the configure summary + + * dbus-1.pc.in: + Add session_bus_services_dir + +2006-03-10 Ross Burton <ross@openedhand.com> + + * tools/dbus-print-message.c: + Add support for object paths and signatures. + +2006-03-06 Sjoerd Simons <sjoerd@luon.net> + + * bus/bus.c: (bus_context_reload_config): Flush the user database cache on + config reload. + * bus/dbus-daemon.1.in: Also note that SIGHUP flushes the user/group + information caches + * dbus/dbus-hash.c: (_dbus_hash_table_remove_all): + * dbus/dbus-hash.h: Add function to remove all entries from a hash table + * dbus/dbus-userdb.c: (_dbus_user_database_flush): + * dbus/dbus-userdb.h: Add function to flush all user/group information + caches. + +2006-03-06 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/dbusidl2cpp.cpp: + * qt/Makefile.am: add the dbusidl2cpp tool, the replacement + for dcopidl2cpp, found in the KDE installations (or the more + modern kalyptus): generate Qt4 C++ code for the input XML + introspection. Currently no IDL parsing. + +2006-03-06 Thiago Macieira <thiago.macieira@trolltech.com> + + * test/qt/*: Update the self-tests. + +2006-03-06 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/*: + * dbus/qdbus.h: Sync with KDE Subversion revision 516237. This + represents the first feature-complete version of the Qt4 + bindings since I took ove maintainership. + +2006-03-06 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/Doxyfile: Adding a Doxyfile for the Qt4 bindings + dir. This is C++, so we can't use the DBus ones. + +2006-03-02 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx: Remove refrence to sys/cdefs.h + (Patch from Artem Kachitchkine <Artem.Kachitchkin at Sun.COM>) + +2006-03-02 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-connection.c: + (_dbus_connection_block_pending_call): + Check to see if our data has already been read off the connection + by another blocking pending call before we block in poll. + (check_for_reply_and_update_dispatch_unlocked): + Code taken from _dbus_connection_block_pending_call - checks for + an already read reply and updates the dispatch if there is one. + + * test/name-test/test-pending-call-dispatch.c: + New test for making sure we don't get stuck polling a + dbus connection which has no data on the socket when + blocking out of order on two or more pending calls. + +2006-02-28 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/Makefile.am: Patch by Sjoerd Simons. More .moc issues: + make/automake don't detect that we're talking about the same + .lo file if I specify the full path to the source files. + +2006-02-26 Havoc Pennington <hp@redhat.com> + + * bus/dbus-daemon.1.in: improve the language in a couple spots I noticed + + * dbus/dbus-bus.c (internal_bus_get): in the error message if the + session bus variable is unset, suggest "man dbus-launch" and "man + dbus-daemon" to figure out how to fix the problem + +2006-02-25 Havoc Pennington <hp@redhat.com> + + * glib/dbus-glib-tool.c (usage): fix up the usage message, someone + should make this thing use the new glib options parser + +2006-02-25 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/Makefile.am: Patch by Sjoerd Simons. Fix the path to the + .lo files taking moc sources. + +2006-02-25 Havoc Pennington <hp@redhat.com> + + * dbus/dbus.h, dbus/Makefile.am: add dbus-signature.h to dbus.h + and install it as a public header + +2006-02-24 John (J5) Palmieri <johnp@redhat.com> + + * Released 0.61 + +2006-02-24 John (J5) Palmieri <johnp@redhat.com> + + * proxies.py: Fix the callchain + +2006-02-24 John (J5) Palmieri <johnp@redhat.com> + + * patch from Sjoerd Simons <sjoerd at debian.org>: + + * dbus/dbus-sysdeps-util.c (_dbus_group_info_free): Moved to + dbus/dbus-sysdeps.c + + * dbus/dbus-userdb.c (_dbus_group_info_free_allocated): Don't + call _dbus_group_info_free_allocated which causes infinite loop, + correctly call _dbus_group_info_free + +2006-02-20 Thiago Macieira <thiago.macieira@trolltech.com> + + * qt/qdbusinterface_p.h: + * qt/qdbusinterface.cpp: Use the standard + org.freedesktop.DBus.Method.NoReply annotation for the "async" + calls instead of creating one for us. + + * qt/qdbusconnection_p.h: + * qt/qdbusintegrator.cpp: Remove debugging code. + + * qt/qdbusintegrator.cpp: + * qt/qdbusmessage.cpp: + * qt/qdbusmessage_p.h: + * qt/qdbusmessage.h: Change the behaviour of automatic + reply-sending: now a reply is always sent, unless the caller + didn't request one or if the user slot has already sent one. + +2006-02-16 Robert McQueen <robot101@debian.org> + + * configure.in: Patch from Debian packages by Sjoerd Simons + <sjoerd@debian.org> to add --with-qt-moc and --with-qt3-moc + arguments so it's possible to build both bindings in the + same tree. + + * qt/Makefile.am: Fix truncated value so that make dist works. + +2006-02-16 Robert McQueen <robot101@debian.org> + + * acinclude.m4, configure.in: Patch from Brad Hards + <bradh@frogmouth.net> to avoid warnings from autoconf 1.9 by + improving quoting, re-ordering a few checks, and a few other + aesthetic tidy-ups. + +2006-02-16 Robert McQueen <robot101@debian.org> + + * dbus/dbus-message.c (dbus_message_iter_get_fixed_array): + Patch from Rob Taylor <rob.taylor@collabora.co.uk> to correct a bogus + assertion that the next element to read from the iter is fixed in + size. This is not the case when you are at the end of the iter, + because the next element type is INVALID. + + * dbus/dbus-string.c (_dbus_string_init_const_len): Correct a + a bogus assert which means that you may not initialise a 0-length + string unless you provide a non-NULL pointer. This prevented + you from marshalling messages containing zero-length arrays in + some cases. + + * glib/dbus-gvalue.c (demarshal_collection_array): Another patch + from Rob to correct bogus asserts when trying to demarshal an + array and get_fixed_array got you 0 elements. Append nothing to + the GArray in this case. + + * test/glib/test-dbus-glib.c: Add a test case for round-tripping + an empty array via the glib bindings. Without all of the above + patches, this new test fails. + +2006-02-16 Robert McQueen <robot101@debian.org> + + * glib/dbus-gmain.c: Make the previous commit compile. + + * python/_dbus.py, python/matchrules.py: Patch from Ole Andre + Ravnaas <ole.andre.ravnaas@collabora.co.uk> to allow you to + specify sender_keyword="foo", path_keyword="bar" when adding + a signal listener, so that you can bind to signals generically + but still do something useful in your callback. + + * python/dbus_bindings.pyx: Demarshal the byte type as unsigned + chars so that they're not cast to chars and made negative. Thanks + to Jakub Stachowski for reporting this and testing the fix. + +2006-02-15 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-glib.h: + * glib/dbus-gmain.h: + (dbus_g_connection_open): new method for openning + a connection to an arbitrary address in the glib bindings + + * ChangeLog: checkin last entry which doesn't seem to be commited + +2006-02-13 John (J5) Palmieri <johnp@redhat.com> + + * tools/dbus-launch.c: Fixed sh syntax output + +2006-02-13 Robert McQueen <robot101@debian.org> + + * glib/dbus-binding-tool-glib.c, glib/dbus-gmain.c, + glib/dbus-gsignature.c, glib/dbus-gtype-specialized.c, + glib/dbus-gtype-specialized.h, glib/dbus-gvalue-utils.c, + glib/dbus-gvalue-utils.h, glib/dbus-gvalue.c: + Patch from Rob Taylor <rob.taylor@collabora.co.uk> to add a big + missing piece of the glib bindings jigsaw puzzle. This modifies + the existing specialised types to have N type parameters (rather + than the current 1 or 2 for arrays and dictionaries respectively). + You can then use this to get a glib type to represent any arbitrary + D-Bus struct type using dbus_g_type_get_struct. The only + implementation of these types is with GValueArrays as before, + but it's now possible to store these in arrays, emit them in + signals, etc. + +2006-02-10 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-signature.c (dbus_signature_iter_recurse): Correctly + deal with nested arrays (Bug #5823) Patch by Thiago Macieira + <thiago.macieira at trolltech.com> + +2006-02-10 John (J5) Palmieri <johnp@redhat.com> + + * mono/doc/Makefile.am: Fix parallel make problem with mono-doc + (Bug #4213) Patch from Doug Goldstein <cardoe at gentoo.org> + +2006-02-10 John (J5) Palmieri <johnp@redhat.com> + + * bus/connection.c (bus_connections_expect_reply): Make + pending reply limit not common to all connections (Bug #5416) + Patch from Kimmo Hämäläinen <kimmo.hamalainen at nokia.com> + +2006-02-10 John (J5) Palmieri <johnp@redhat.com> + + * tools/dbus-launch.c: Fixed csh syntax output (Bug #5720) + +2006-02-10 John (J5) Palmieri <johnp@redhat.com> + + * gcj/Makefile.am: point to correct jar command (Bug #4529) + patch from Doug Goldstein <cardoe at gentoo.org> + +2006-02-09 Joe Shaw <joeshaw@novell.com> + + * mono/Arguments.cs: Fix a magic number in the mono bindings + that doesn't work on 64 bit arches. Patch from Peter Johanson. + +2006-01-27 Robert McQueen <robot101@debian.org> + + * glib/dbus-binding-tool-glib.[ch]: Patch based on Ricardo Kekki's + patch to use an annotation org.freedesktop.DBus.GLib.ClientCSymbol + when generating the client-side methods, instead of overloading + CSymbol which broke everything horribly. My apologies. + +2006-01-27 Robert McQueen <robot101@debian.org> + + * glib/dbus-gtype-specialized.[ch], glib/dbus-gvalue-utils.c: Patch + by me and Rob Taylor to add a simple_free function to D-Bus map + and collection types, which allows those types which can be freed + with a GDestroyNotify (such as GHashTables and GArrays, but not + GPtrArrays) to be stored as the values in hashtables. + + * test/glib/test-dbus-glib.c, test/glib/test-service-glib.{c,xml}: + Patch by Rob Taylor to add nested dicts to the glib tests to check + the above code works, and appears not to leak when called repeatedly. + +2006-01-27 Robert McQueen <robot101@debian.org> + + * glib/dbus-gvalue.c (demarshal_valuearray): Patch from Rob Taylor + to free a D-Bus allocated string with dbus_free () instead of + g_free (). + +2006-01-27 Iain Holmes <iain@openedhand.com> + + * glib/dbus-gproxy.c (dbus_g_proxy_dispose): Protect the dispose + method from being called multiple times. + +2006-01-19 Robert McQueen <robot101@debian.org> + + * glib/dbus-binding-tool-glib.c: Patch from Rob Taylor + <rob.taylor@collabora.co.uk> to add support for generating bindings + to arrays that are represented as GPtrArrays rather than GArrays (ie + size-variable things, such as strings, objects, structs, etc). + +2006-01-05 Robert McQueen <robot101@debian.org> + + * dbus/dbus-glib.h, glib/dbus-gproxy.c: Patch from Ricardo Kekki + <ricardo.kekki@movial.fi> to make it possible to inherit from + DBusGProxy, by splitting the DBusGProxy struct into a public part and + a private part, and moving the setting of the DBusGProxyManager into a + connection property, allowing proper GObject construction. + +2006-01-05 Robert McQueen <robot101@debian.org> + + * glib/dbus-binding-tool-glib.c: Patch from Ricardo Kekki + <ricardo.kekki@movial.fi> to make dbus-binding-tool heed C symbol name + annotations when generating glib client bindings. + +2005-12-19 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-shared.h: Call it shared constants instead of shared macros + + * dbus/dbus-protocol.h: add DOxygen markup to quiet warnings + +2005-12-19 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-shared.h: add DOxygen markup to quiet warnings + +2005-12-19 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-macros.h: correct DOxygen end of section (s/}@/@}) + +2005-12-19 Ross Burton <ross@openedhand.com> + + * doc/dbus-tutorial.xml: + Document the Glib client-side bindings, and list all possible annotations. + +2005-12-19 John (J5) Palmieri <johnp@redhat.com> + + * dbus/bus.c (dbus_bus_release_name): Add documentation + +2005-12-06 Robert McQueen <robot101@debian.org> + + * python/service.py: s/sucessful/successful/ so we're allocating to + and reading from the same variable. Oops. + +2005-11-30 John (J5) Palmieri <johnp@redhat.com> + + * Released 0.60 + +2005-11-30 John (J5) Palmieri <johnp@redhat.com> + + * test/qt/Makefile.am: build from srcdir + + * qt/qtconnection.cpp (requestName): Changed PROHIBIT_REPLACE to ALLOW_REPLACE + Note - this code is wrong and needs to be fixed by the Qt binding + developers. The flags should be treated as bitfields and not enums. + + * qt/qtconnection.h: Change ProhibitReplace to AllowReplace + +2005-11-30 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-list.c (_dbus_list_insert_after_link, _dbus_list_insert_after, + link_after): remove #ifdef DBUS_BUILD_TESTS since we use these methods + in production code + +2005-11-30 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-connection.c (dbus_connection_read_write): Add new + method for getting messages off the bus in the absence of a + mainloop. This method is much like + dbus_connection_read_write_dispatch except it does not dispatch + the messages to a registered filter function. Instead it + allows a developer to process messages by directly popping + them off the bus. + +2005-11-30 John (J5) Palmieri <johnp@redhat.com> + + * bus/desktop-file.c (parse_key_value): Ignore locales allowing + the parser to continue instead of returning error + (bus_desktop_file_load): Do not free parser data when + parse_section_start or parse_key_value fails because it was + already freed by parser_free (patch from Carlos Garcia Campos + <carlosgc at gnome.org>) + +2005-11-30 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-auth.c, dbus/dbus-connection.c, dbus/dbus-keyring.c, + dbus/dbus-server-debug-pipe.c, glib/dbus-binding-tool-glib.c + glib/dbus-glib-tool.c, glib/dbus-gparser.c, glib/dbus-gproxy.c + test/test-segfault.c, test/test-utils.c, + test/glib/test-dbus-glib.c, tools/dbus-cleanup-sockets.c + tools/dbus-launch.c, tools/dbus-tree-view.c, tools/dbus-viewer.c: + Various cleanup of dead code and compiler warnings (patch from + Kjartan Maraas <kmaraas at gnome.org>) + +2005-11-30 John (J5) Palmieri <johnp@redhat.com> + + * glib/dbus-gmain.c (connection_setup_add_watch): plugged a leak + (patch from Carlos Garnacho Parro <carlosg at gnome.org> + +2005-11-27 Robert McQueen <robot101@debian.org> + + * python/dbus_bindings.pyx: Repair my previous commit which reverted + part of the preceding one. Oops. Merge patch by Johan Hedberg + <johan.hedberg@nokia.com> to fix marshalling of 16-bit integer values + on big-endian platforms. + + * test/python/test-client.py: Add some 16-bit integers to the test + values. + +2005-11-27 Carlos Garcia Campos <carlosgc@gnome.org> + + * glib/dbus-gobject.c: Append a GValue instead of a basic type in + method return message for property getters + +2005-11-27 Robert McQueen <robot101@debian.org> + + * python/dbus_bindings.pyx: Fix a bug where doing a strict append + with type v of an instance of dbus.Variant(foo, type='x') caused + it to be boxed twice before sending over the bus. + + * python/dbus_bindings.pyx, python/service.py, + test/python/test-client.py: Update the constants for the new + request_name flags, and update comments/test cases now that queueing + is the default action. + +2005-11-22 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: + - Change version to 0.60 for impending release + - upped the sonames because of ABI and API breakage + +2005-11-22 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: Add test/name-test/Makefile to the generated + Makefile list + + * dbus/dbus-shared.h (#define DBUS_NAME_FLAG_ALLOW_REPLACEMENT): + New flag which replaces DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT + (#define DBUS_NAME_FLAG_DO_NOT_QUEUE): New flag for specifying + not to queue an ower if it can't be the primary owner + + * bus/bus.h: Add new internal BusOwner struct + + * bus/driver.c (bus_driver_handle_hello): Send flags (0 for default) + to bus_registry_ensure and don't set the prohibit_replacement flag + since they are now set per BusOwner and not per name. + (bus_driver_handle_list_queued_owners): bus method (ListQueuedOwners) + that returns the list of connections in a name's connection queue + + * bus/services.c (struct BusService): remove prohibit_replacement field + (struct BusOwner): new struct for keeping track of queued connections + and their associated flags for the queue + (struct BusRegistry): add a BusOwner memory pool + (bus_registry_new): initialize the BusOwner memory pool + (bus_registry_unref): free the BusOwner memory pool + (_bus_service_find_owner_link): new internal method for + searching the queue for a specific connection + (bus_owner_set_flags): new method for adding setting the flags on a + bus owner + (bus_owner_new): new method that creates a BusOwner object from the + pool and sets its flags + (bus_owner_ref, bus_owner_unref): ref counting for BusOwner objects + (bus_registry_ensure): Add the flags parameter + (bus_registry_acquire_service): Switch from using raw connections to + using the BusOwner struct + Add new state machine for dealing with the new set of flags + (bus_registry_set_service_context_table, struct OwnershipCancelData, + cancel_ownership, free_ownership_cancel_data, + add_cancel_ownership_to_transaction, struct OwnershipRestoreData, + restore_ownership, free_ownership_restore_data, + add_restore_ownership_to_transaction): Switch to using BusOwner + instead of raw connections + (bus_service_add_owner): Add flags parameter + Switch to using BusOwner instead of raw connections + Add state machine for dealing with the new set of flags + (bus_service_swap_owner): Swaps the first and second owners in the + queue. Used to make sure proper signals are sent when a service looses + or gains primary ownership. We never insert an owner at the top of the + queue. Instead we insert it in the second position and then swap. + (bus_service_remove_owner): Remove the owner from the queue sending + out the NameLost and NameOwnerChanged signals if the we were the + primary owner + (bus_service_get_primary_owners_connection): New method that extracts + the connection from the primary owner + (bus_service_get_primary_owner): Returns the BusOwner instead of the + connection + (bus_service_get_allow_replacement): Changed from the old + bus_service_get_prohibit_replacement method. Checks the flags of the + primary owner and returns if it can be replaced or not + (bus_service_set_prohibit_replacement): removed + (bus_service_has_owner): returns TRUE if and owner with + the specified connection exists in the queue + + * dbus/dbus-bus.c (dbus_bus_connection_get_unique_name): New helper + method that only compiles if tests are enabled. Allows us to get the + unique name of a connection so we can check it against the queue when + doing regression tests + + * bus/activation.c (bus_activation_send_pending_auto_activate), + bus/dispatch.c (bus_dispatch), + bus/driver.c (bus_driver_handle_get_service_owner, + bus_driver_handle_get_connection_unix_user, + bus_driver_handle_get_connection_unix_process_id, + bus_driver_handle_get_connection_selinux_security_context), + bus/signals.c (connection_is_primary_owner): + use bus_service_get_primary_owners_connection instead of + bus_service_get_primary_owner + + * dbus/dbus-sysdeps.c (_dbus_connect_unix_socket, + _dbus_listen_unix_socket): Calculate the length of the socket + path and use that instead of using a fixed length which was + causing socket names to contain many trailing Nul bytes. + + * dbus/dbus-glib-lowlevel.h, glib/dbus-gobject.c + (dbus_g_method_get_sender): New method for extracting the sender + from a DBusGMethodInvocation + (dbus_g_method_return_get_reply): changed name to + dbus_g_method_get_reply + (dbus_g_method_return_send_reply): changed name to + dbus_g_method_send reply + + * doc/dbus-specification.xml: New docs that describe how the new + queueing system works and talks about the changes to the how + we specify socket names + + * glib/examples/example-service.c, + glib/examples/example-signal-emitter.c, + glib/examples/statemachine/statemachine-server.c: + Changed the RequestName flags to the new system + + * test/name-test/ (test-names.c, run-test.sh, Makefile.am): New + regression test suite for testing various states of the new + queueing system + +2005-11-15 Robert McQueen <robot101@debian.org> + + * dbus/dbus-glib-lowlevel.h, glib/dbus-gobject.c: Patch from Rob + Taylor to add two methods, dbus_g_method_return_get_reply and + dbus_g_method_return_send_reply, to allow you to get the reply + message from a DBusGMethodInvocation, append arbitrary stuff to it, + and send it. The GLib bindings can't marshal a return value of + something like a(s) if the array is empty - ultimately they should be + made to heed the signature of the out arguments as the Python bindings + now can, but this is a workable interim solution which might have + other applications. + +2005-11-15 Robert McQueen <robot101@debian.org> + + * bus/driver.c, bus/services.c, bus/services.h: Add a ReleaseName + method to org.freedesktop.DBus to release a bus name or give up + waiting in the queue for it. + + * dbus/dbus-bus.c, dbus/dbus-bus.h, dbus/dbus-shared.h: Add a + dbus_bus_release_name method to send the ReleaseName method calls. + Add constants for the return values to dbus/dbus-shared.h. + + * doc/dbus-specification.xml: Document the new ReleaseName method + in the specification. + + * python/dbus_bindings.pyx: Add a low-level python binding for the + release name method. + + * python/exceptions.py, python/service.py: Make freeing BusName + objects release the name. Add a NameExistsException, and fix a + bug with creating UnknownMethodException. + + * test/python/test-client.py: Add tests for freeing BusName + objects causing names to be released. + +2005-11-14 Robert McQueen <robot101@debian.org> + + * python/service.py: Include the traceback in the error reply when we + send an exception over the bus. _BEST_ _PATCH_ _EVER_ + +2005-11-14 David Zeuthen <davidz@redhat.com> + + Patch from Timo Hoenig <thoenig@suse.de>. + + * bus/bus.c: I've recently investigated why the automatic reload + of configuration files does not work as expected. + + Currently, reloading configuration files does only work when + running dbus-daemon with --nodaemon. If we are running as daemon + we're hitting a dnotify bug once we fork the process. + + We're initializing the dnotify fds before calling fork(). Once + the child process forked it does still have the fds (and they + still show up in /proc/`pidof dbus-daemon`/fd/) but we're not + getting SIGIO as changes are made to the configuration files. + + The attached patch moves the initialization of the dnotify fds to + process_config_postinit(). This is safe for all current code + paths and solves the dnotify disfunction. If we're running + dbus-daemon as daemon the fds for dnotify are now being + initialized after fork() for the child process. + + * configure.in: The current configure.in check for dnotify probes + 'x$target_os' for being 'xlinux-gnu'. I've changed the check to + match for 'xlinux', too. Additionally I have adapted the configure + option's style to match with the others. + +2005-11-14 Robert McQueen <robot101@debian.org> + + * python/decorators.py, python/service.py: Add a new argument to the + dbus.service.method decorator called sender_keyword, which if set, + specifies the name of an argument which will be provided the bus + name of the method caller. + + * test/python/test-client.py, test/python/test-service.py: Add a + method and test to check the sender_keyword functionality. + +2005-11-07 John (J5) Palmieri <johnp@redhat.com> + + * bus/driver.c (bus_driver_handle_reload_config): Make sure we send an + empty reply so blocking calls don't block forever (Patch from Sjoerd + Simons <sjoerd at luon.net>) + + * AUTHORS: Add Robert McQueen for his work on the Python + Bindings and other parts of D-Bus + +2005-11-07 Robert McQueen <robot101@debian.org> + + * python/decorators.py: Change emit_signal function to use the + signature annotation of the signal when marhsalling the arguments from + the service. Fix a bug where the code checking signature length + against argument length referenced the wrong variable. + + * python/introspect_parser.py: Avoid adding the type signature of + signal arguments to any methods which occur after them in the + introspection data (!) by making the parser a little more careful + about its current state. + + * python/service.py: Remove debug prints from last commit (again :D). + + * test/python/test-client.py, test/python/test-service.py: Add test + signals with signature decorators to test the strict marshalling code + gives errors at the right time. Could do with checking the signals + actually get emitted too, given that the test does nothing with + signals at the moment... + +2005-11-07 Robert McQueen <robot101@debian.org> + + * python/_dbus.py: Add WeakReferenceDictionary cache of dbus.Bus + instances to stop madness of creating new instances representing + the same bus connection all the time, rendering any tracking of + match rules and bus names quite meaningless. Caught a bug where + the private argument to SessionBus() and friends was being passed + in as use_default_mainloop by mistake. Still some problems with + multiple dbus_binding.Connection instances representing the same + low-level connection (eg when you use both SessionBus() and + StarterBus() in same process), but it's a lot better now than it + was. + + * python/dbus_bindings.pyx: Add constants with the return values + for bus_request_name(). + + * python/service.py: Store bus name instances in a per-dbus.Bus cache + and retrieve the same instances for the same name, so deletion can be + done with refcounting. Also now throws some kind of error if you + don't actually get the name you requested, unlike previously... + + * test/python/test-client.py: Add tests for instance caching of buses + and bus name objects. + +2005-11-04 Robert McQueen <robot101@debian.org> + + * python/dbus_bindings.pyx, test/python/test-client.py: Fix + marshalling of boolean values. Add some booleans to the values in + the test client. + + * python/decorators.py, python/service.py: Add an 'async_callbacks' + argument to the dbus.service.method decorator, which allows you to + name arguments to take two callback functions for replying with + return values or an exception. + + * test/python/test-client.py, test/python/test-service.py: Add test + case using asynchronous method reply functions, both return values and + errors, and from within both the function itself and from a mainloop + callback. + + * python/decorators.py, python/service.py: Perform checking that the + number of method/signal arguments matches the number of types in the + signature at class loading time, not when you first introspect the + class. + + * python/service.py: Remove debug print left by the last commit. + +2005-11-03 Robert McQueen <robot101@debian.org> + + * python/service.py: Heavy refactoring of method invocation, with + hopefully no effect on functionality. Nuked _dispatch_dbus_method_call + in favour of a new _message_cb that uses seperate functions for + looking up the method to call, marshalling the return values, and + sending exceptions as errors, and is easier to follow as a + consequence. Fixes some corner cases about returning things that + don't match your declared out_signature, allows exceptions to define + _dbus_error_name and have it be sent over the bus as the error name, + and paves the way for cool stuff like heeding the message no reply + flag, asynchronous method implementations, informing the method of the + sender, and including backtraces in the error messages. + + * test/python/test-client.py: Catch and print exceptions thrown in the + async callback tests, rather than passing them to the low-level + bindings to be ignored in a noisy and frustrating manner. + +2005-11-03 Robert McQueen <robot101@debian.org> + + * python/_dbus.py, python/proxies.py, python/service.py: Add __repr__ + functions to dbus.Bus, dbus.service.BusName and dbus.service.Object, + tweak others to be consistent. + + * test/python/test-client.py: Tweak output of testInheritance. + +2005-10-29 Robert McQueen <robot101@debian.org> + + * python/service.py: Major changes to allow multiple inheritance + from classes that define D-Bus interfaces: + + 1. Create a new Interface class which is the parent class of + Object, and make the ObjectType metaclass into InterfaceType. + + 2. Patch written with Rob Taylor to replace use of method_vtable + with code that walks the class's __MRO__ (method resolution order) + to behave like Python does when invoking methods and allow + overriding as you'd expect. Code is quite tricky because + we have to find two methods, the one to invoke which has the + right name and isn't decorated with the /wrong/ interface, + and the one to pick up the signatures from which is decorated + with the right interface. + + The same caveats apply as to normal multiple inheritance - + this has undefined behaviour if you try and inherit from two + classes that define a method with the same name but are + decorated with different interfaces. You should decorate + your overriding method with the interface you want. + + 3. Replace grungy introspection XML generation code in the metaclass + with dictionaries that cope correctly with multiple inheritance + and the overriding of methods. This also uses the signature + decorations to provide correct introspection data, including + the debut appearance of the types of your return values. :D + + * test/python/test-client.py, test/python/test-service.py: Add a test + case to try invoking an method that overrides one inherited from a + D-Bus interface class. + +2005-10-29 Robert McQueen <robot101@debian.org> + + * python/dbus_bindings.pyx: Tweak 'raise AssertionError' to assert(). + Add checking for the end of struct character when marshalling a + struct in MessageIter.append_strict. + + * python/examples/example-service.py, + python/examples/gconf-proxy-service.py, + python/examples/gconf-proxy-service2.py: Update to use gobject + mainloop directly rather than appearing to depend on gtk. + + * python/test/test-client.py, python/test/test-server.py: Remove + obsolete and broken test scripts for old bindings. We have up to date + and working tests in test/python/. + +2005-10-29 Robert McQueen <robot101@debian.org> + + * python/decorators.py: Add optional arguments to the method and + signal decorators to allow you to specify the signature of arguments + and return values. Preserve the doc strings of signal functions in the + decorated version, for pydoc and friends. + + * python/dbus_bindings.pyx, python/proxies.py: Replace the + parse_signature_block function with an iterable dbus.Signature() + type. Fix a bug in MessageIter.append_strict where you could append + anything by claiming it was a string. + + * python/service.py: Use the out_signature decoration on methods to + marshal return values, meaning you no longer require dbus.Array() + or dbus.Dictionary() to indicate the type when returning empty + arrays or dictionaries. Fix a bug where exceptions which are defined + in __main__ are not turned into error replies. + + * test/python/test-client.py, test/python/test-service.py: Add test + for correct marshalling of return values according to out_signature. + Fix a bug in the async call test where the error_handler is missing a + self argument. + +2005-10-29 Robert McQueen <robot101@debian.org> + + * glib/Makefile.am, glib/examples/Makefile.am, + glib/examples/statemachine/Makefile.am: Merge patch from Ubuntu by + Daniel Stone to replace explicit calls to libtool with $(LIBTOOL). + + * test/python/.cvsignore: Add run-with-tmp-session-bus.conf. + + * tools/dbus-monitor.1, tools/dbus-monitor.c: Merge dbus-monitor patch + from Ubuntu by Daniel Silverstone to allow specifying match rules on + the command line. + +2005-10-27 Ross Burton <ross@openedhand.com> + + * dbus/dbus-marshal-header.c: + Remove dead code. + + * glib/dbus-gobject.c: + Stop compiler warning. + +2005-10-25 Ross Burton <ross@openedhand.com> + + * dbus/dbus-auth.c: + * dbus/dbus-server-unix.c: + * dbus/dbus-transport-unix.c: + * glib/dbus-gmain.c: + * glib/dbus-gobject.c: + Add some const keywords. + +2005-10-25 Ross Burton <ross@openedhand.com> + + * doc/dbus-specification.xml: + Document the NoReply annotation. + + * glib/dbus-binding-tool-glib.h: + * glib/dbus-binding-tool-glib.c: + Respect the NoReply annotation. + +2005-10-24 Robert McQueen <robot101@debian.org> + + * python/dbus_bindings.pyx (String, MessageIter): make D-Bus strings + derive from unicode instead of str, and encode/decode UTF-8 when + marshalling/unmarshalling bus messages + + * python/introspect_parser.py: encode introspection data as UTF-8 + before passing the buffer into libxml2 + + * test/python/test-client.py: add unicode test strings + + * test/data/valid-service-files/.cvsignore, test/python/.cvsignore: + ignore generated python test files + +2005-10-17 John (J5) Palmieri <johnp@redhat.com> + + * glib/dbus-gvalue-utils.c (hash_free_from_gtype): handle gdouble + and G_TYPE_VALUE_ARRAY (DBUS_TYPE_STRUCT) + (gvalue_from_hash_value, hash_value_from_gvalue): handle gdouble + + * glib/dbus-gvalue.c (dbus_gvalue_to_signature): add missing + DBUS_STRUCT_BEGIN_CHAR and DBUS_STRUCT_END_CHAR charaters + when constructing struct signatures + + * python/_dbus.py (Bus): handle private connections using the + private keyword in the constructor. defaults to private=False + (Bus::close): new method to close a connection to the bus + + * python/dbus_bindings.pyx (Connection::close): renamed method + was previously called disconnect + (bus_get): now supports getting a private connection + + * python/proxies.py (ProxyMethod::__call__): check if ignore_reply + keyword is set to True. if it is, execute the method without waiting + for a reply + (ProxyObject::_introspect_execute_queue): new method for executing + all the pending methods that were waiting for the introspect to + finish. this is called when introspect either succeeds or fails + (ProxyObject::_introspect_error_handler): call queued methods + +2005-10-14 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx (MessageIter::append_strict): check for + STRUCT_BEGIN not TYPE_STRUCT in indicate we are marshalling a struct + + * python/service.py (Object::_message_cb): handle exceptions correctly + by sending them over the wire to the calling app. This makes sure + the client returns immediately instead of waiting the 15 seconds to + timeout. + + * test/python/test-client.py (TestDBusBindings::testBenchmarkIntrospect): + Add a test to benchmark how long it takes to introspect a service and + call a method which returns a large element (pretty fast) + + * test/python/test-service.py (TestObject::GetComplexArray): new test + method which pushes a lot of data + +2005-10-13 John (J5) Palmieri <johnp@redhat.com> + + * python/service.py(ObjectType::_reflect_on_signal, _reflect_on_method): + reclaim memory outside of the loop and use del istead of just setting + the key to None + +2005-10-13 John (J5) Palmieri <johnp@redhat.com> + + * python/service.py (ObjectType::_reflect_on_signal): Always close + signal tag even when there are no arguments + +2005-10-13 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: Set mono, mono-docs and Qt3 to default + to no instead of auto when building. These bindings do not + have full time maintainers and will not be supported for the + 1.0 release. + +2005-10-12 John (J5) Palmieri <johnp@redhat.com> + + patches from Michael Krivoruchko <misha at sun.com>: + + * dbus/dbus-connection.c (_dbus_connection_queue_received_message_link, + _dbus_connection_message_sent, + _dbus_connection_send_preallocated_unlocked_no_update, + _dbus_connection_pop_message_link_unlocked): handle the case when path + is NULL when calling _dbus_verbose + + * configure.in: check for functions getpeerucred and getpeereid + + * dbus/dbus-sysdeps.c (_dbus_read_credentials_unix_socket): provides + support of auth EXTERNAL on Solaris 10+ (getpeerucred), FreeBSD 4.6+, + OpenBSD 3.0+ and FreeBSD 5.0+ as well as MacOSX 10.2+ (getpeereid). + Patch was only tested on Solaris 10 x86 so it might be issues + with other platforms (i.e. BSDs and MacOSX) + + +2005-10-05 John (J5) Palmieri <johnp@redhat.com> + + * glib/dbus-gvalue.c (marshal_variant): call _dbus_gvalue_marshal + instead of marshal basic so we can handle recursive types in a variant + + * test/glib/test-dbus-glib.c: Add test for marshaling recurive types + in variants + + * test/glib/test-service-glib.c, test-service-glib.xml + (my_object_echo_variant [EchoVariant], + my_object_process_variant_of_array_of_ints123 + [ProcessVariantOfArrayOfInts123]): + Add two test methods + + * python/introspect_parser.py: New module for parsing introspect + data. + + * python/dbus_bindings.pyx: + (various places): when throwing errors fix to use errormsg instead + of message local variable because Pyrex can get confused with other + message variables (initial patch by Robert McQueen + <robert.mcqueen at collabora.co.uk>) + (MessageIter::parse_signature_block): new method for getting the next + block in a signiture. + (MessageIter::append_strict): new method for appending values strictly + using the passed in signature instead of guessing at the type + (MessageItter:: append_dict, append_struct, append_array): use + signatures to marshal children if the signature is available + + * python/exceptions.py (IntrospectionParserException): new exception + + * python/proxies.py (ProxyMethod::__call__): Marshal args with + introspected signatures if available, else we fall back to the + old way of doing things. + (ProxyObject::_introspect_reply_handler ): parse introspection data + + * python/service.py (ObjectType::_reflect_on_method): Properly + terminate <method> if there are no args in the reflection data + + * test/python/test-client.py: add tests for talking with the GLib + test server. This gives us better coverage for introspection since + python to python will always generate arguments as variants. It also + allows us to test the robustness of the GLib bindings and interlanguage + communications. + + +2005-10-03 John (J5) Palmieri <johnp@redhat.com> + + * bus/driver.c (bus_driver_handle_introspect): Add signals + to the introspect data. (patch from Daniel P. Berrange + <dan at berrange.com>) + + * bus/dispatch.c (check_existent_ping): Add testcase for Ping + + * dbus/dbus-connection.c (_dbus_connection_peer_filter, + _dbus_connection_run_builtin_filters): Changed these to + be unlock_no_update functions and call + _dbus_connection_send_unlocked_no_update instead of + dbus_connection_send to avoid locking errors. + + * doc/TODO: Removed the make Ping test TODO + +2005-09-26 John (J5) Palmieri <johnp@redhat.com> + + * dbus/Python.pyx: Fixed memory leaks when throwing errors. + We now copy the message from a DBusError and then free + the error object befor throwing the error + + * glib/dbus-glib-tool.c: removed extra comma at the end of the + DBusBindingOutputMode enum which was causing a warning. + #include <time.h> so using time_t is explicitly defined + +2005-09-26 John (J5) Palmieri <johnp@redhat.com> + + * Integrate patches from Lennart Poettering <mzsqb at 0pointer.de>: + - dbus/dbus-bus.c + (internal_bus_get): new method that take over the heavy lifting + of dbus_bus_get and adds the ability to get a private connection + to the bus + (dbus_bus_get): wrapper to internal_bus_get that provides the same + interface as in previous versions + (dbus_bus_get_private): new method that is a wrapper to + internal_bus_get to get a private connection to the bus + + - dbus/dbus-bus.h + (dbus_bus_get_private): add as a public libdbus interface + + - dbus-1.pc.in: output system_bus_default_address and + sysconfdir variables so apps can use them when compiling + +2005-09-23 Harald Fernengel <harry@kdevelop.org> + * dbus/qt: New Qt bindings + +2005-09-12 Waldo Bastian <bastian@kde.org> + + * dbus/dbus-marshal-validate.c, + doc/dbus-specification.xml, test/Makefile.am, + test/test-names.c: allow hyphens in bus names. + +2005-09-11 Mark McLoughlin <mark@skynet.ie> + + * test/data/auth/fallback.auth-script: we don't + retry the EXTERNAL method when we know its going + to fail anymore. + +2005-09-11 Mark McLoughlin <mark@skynet.ie> + + * dbus/dbus-connection-internal.h: rename + (add|remove|toggle)_(watch|timeout) to unlocked() + + * dbus/dbus-connection.c: ditto. + + * dbus/dbus-timeout.c, dbus/dbus-transport-unix.c: + Update some callers for the renaming. + +2005-09-10 Mark McLoughlin <mark@skynet.ie> + + * dbus/dbus-auth.c: (record_mechanisms): don't + retry the first auth mechanism because we know + we're just going to get rejected again. + + * dbus/dbus-keyring.c: (_dbus_keyring_reload): + Fix thinko ... and what a nasty little bugger to + track down you were ... + + * dbus/dbus-connection.c: + (_dbus_connection_add_watch), + (_dbus_connection_remove_watch): add note about + these needing the connection to be locked. + (_dbus_connection_get_dispatch_status_unlocked): + set status to DATA_REMAINS when we queue the + disconnected message. + + * bus/dispatch.c: + (bus_dispatch): fix warning. + (check_existent_service_no_auto_start): + Expect ChildSignaled error too. + (check_existent_hello_from_self): fix another + couple of warnings. + +2005-09-08 Joe Shaw <joeshaw@novell.com> + + Patches from James Willcox <snorp@snorp.net> + + * mono/Makefile.am: Add Int16.cs and UInt16.cs + + * mono/DBusType/Array.cs: Handle multidimensional arrays, and + support array "out" parameters. + + * mono/DBusType/Int16.cs, mono/DBusType/UInt16.cs: New files, + for 16-bit int support. + +2005-09-06 John (J5) Palmieri <johnp@redhat.com> + + * Released 0.50 + + * Patch from Steve Grubb: + - bus/activation.c (bus_activation_service_reload_test): clean up + some indentation + - dbus/dbus-keyring.c (_dbus_keyring_reload): fix conditional + - dbus/dbus-message-factory.c (generate_special): fix a couple of + buffer overflows in the test suite. This is non critical because + it can not be exploited and this code is only run when doing a + make check. + + * Patch from Yaakov Selkowitz: Build fixes for Cygwin + - configure.in: Don't check and link against kdecore, only qt headers + - dbus/Makefile.am: Add -no-undefined to libdbus_1_la_LDFLAGS + - gcj/org/freedesktop/dbus/Makefile.am: + add libdbus_gcj_1_la_LDFLAGS = -no-undefined + - glib/Makefile.am: Add -no-undefined to libdbus_glib_1_la_LDFLAGS + and $(DBUS_GLIB_LIBS) to dbus_binding_tool_LDADD + - qt/Makefile.am: Add -no-undefined to libdbus_qt_1_la_LDFLAGS + - tools/Makefile.am: Add platform extentions to binaries + (i.e. .exe on windows) + + * configure.in: + - Make it so if no suitable version of python is found we only + disable building python instead of exiting the configure script + - Require version 2.4 of glib for glib bindings + - Up version to 0.50 + + * python/__init__.py: Sync version with libdbus to (0,50,0) + +2005-09-05 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-object-tree.c (find_subtree_recurse): + a couple of optimizations (bug #710): + - do a binary search in the tree + - insert a new child at the right place directly, no need for + qsort anymore + - do the "double alloc" thing when allocating children + +2005-08-31 John (J5) Palmieri <johnp@redhat.com> + + * python/Makefile.am: Break on pyrexc errors instead of ignoring them + + * python/dbus_bindings.pyx: Memory management foo + (global): remove hacky _user_data_references global list + (GIL_safe_cunregister_function_handler): userdata now stuffed into + tuples. Unref user_data + (GIL_safe_cmessage_function_handler): userdata now stuffed into tuples + (Connection::__del__): Remove and replace with __dealloc__ method + (Connection::add_filter): Stuff user_data into a tuple. Use Py_INCREF + to keep tuple from being deallocated instead of the global var hack + (Connection::register_object_path): Stuff user_data into a tuple. + Use Py_INCREF to keep tuple from being deallocated instead of the + global var hack + (Connection::register_fallback): Stuff user_data into a tuple. + Use Py_INCREF to keep tuple from being deallocated instead of the + global var hack + (GIL_safe_pending_call_notification): Don't unref the message + because it gets unreffed when going out of scope. Py_XDECREF + the user_data + (PendingCall::__del__): Remove and replace with __dealloc__ method + (PendingCall::set_notify): ref the pending call because we will + need it to stick around for when the notify callback gets called + (Message::__del__): Remove and replace with __dealloc__ method + + * python/dbus_glib_bindings.pyx (init_gthreads): Changed to + gthreads_init to match up with the dbus call + + * python/glib.py (init_threads): Changed to threads_init to match + up with gobject.threads_init(). init_threads is kept for backwards + compat but will most likely be deprecated in the future + + * test/python/test-client.py: + - revamp to use Python's unittest functionality + - add async call tests + - setup threads in glib and dbus so we make sure locks are working + +2005-08-30 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx + (_pending_call_notification, cunregister_function_handler, + cmessage_function_handler): All callback functions have been rearranged + to workaround a bug in Pyrex when working with the GIL which is Python's + global lock when dealing with threads. They have been split into + a wrapper function (which assumes the name of the old function) and + a _GIL_safe_<function name> function which contains the functionality + of the old function. This ensures that Pyrex does not write code + the lock is released. + + +2005-08-30 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx (_pending_call_notification): Obtain the + GIL global lock when calling back into Python + +2005-08-29 John (J5) Palmieri <johnp@redhat.com> + + * Release 0.36.2 + + * Add Havoc's patch that never got applied to HEAD (Bug #2436): + + * bus/policy.c (bus_policy_allow_user): change default "user is + allowed" to be "user has same uid as the bus itself"; any + allow/deny rules will override. + + * bus/session.conf.in: don't allow all users, since now by default + the user that ran the bus can connect. + +2005-08-26 Colin Walters <walters@verbum.org> + + * tools/dbus-print-message.c (print_message): Flush stdout + after printing a message, so that redirecting to a file, then + hitting Ctrl-C works. + +2005-08-25 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx: Tracked down a major memleak and fixed it + (EmptyMessage): new class that subclasses Message. This is a workaround + to a Pyrex bug that fails to call __del__ when the Message object goes out + of scope. For some reason subclassing Message fixes this bug + (Bus::send_with_reply_and_block): use EmptyMessage instead of Message + - s/Message(_create=0)/EmptyMessage everywhere else + + * test/python/test-{server|client}.py: add the python/.libs directory + to the lookup path so dbus_bindings and dbus_glib_bindings don't + get picked up from the system + +2005-08-25 Colin Walters <walters@verbum.org> + + * glib/dbus-gproxy.c (dbus_g_proxy_call): Doc update, thanks + to Ryan Lortie for the suggestion. + +2005-08-24 John (J5) Palmieri <johnp@redhat.com> + + * test/python: Add python regression test + + * configure.in: Add test/python/Makefile + + * test/Makefile.am: Add the python directory to SUBDIRS + +2005-08-24 John (J5) Palmieri <johnp@redhat.com> + + * Release 0.36.1 + + * python/_dbus.py: + (Interface::connect_to_signal): propigate keywords for match on args + (Bus::add_signal_receiver): Fix typo s/dbus_inteface/dbus_interface + + * python/proxies.py (ProxyObject::connect_to_signal): + propigate keywords for match on args + + * Makefile.am: point everything to pyexecdir since python borks + on multilib + +2005-08-23 John (J5) Palmieri <johnp@redhat.com> + + * Release 0.36 + +2005-08-23 Colin Walters <walters@verbum.org> + + * test/glib/Makefile.am: Don't multiply-define EXTRA_DIST. + +2005-08-23 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_glib_bindings.pyx: reorder imports and c definitions + to fix some wranings. We now use dbus_bindings.DBusConnection instead + of defining DBusConnection ourselves. + +2005-08-18 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus.pth: New path file to fix up problems when installing + c libraries to lib64 and python files to lib. + + * python/Makefile.am: install dbus.pth in the correct spot + +2005-08-17 John (J5) Palmieri <johnp@redhat.com> + * ChangeLog: clean up my last entry a bit + + * doc/introspect.xsl: New stylesheet for converting introspection data + into browser renderable xhtml. Contributed by Lennart Poettering. + + * doc/introspect.dtd: Fixups in the introspect format from Lennart + Poettering. + + * doc/dbus-tutorial.xml: + - Add Colin Walter to the Authors section for authoring the GLib + section + - Add descriptions of the new signature and type functionality + in the Python complex type mapping section + - Add a sidenote on the new args matching functionality in + the Python bindings + - Fixed up some of the examples to use the gobject.MainLoop + instead of gtk.main + + * python/_dbus.py: + (Bus::_create_args_dict): New. Converts a hash of arg matches + to a more useable format + (Bus::add_signal_receiver): add a **keywords parameter for catching + arg match parameters + (Bus::remove_signal_receiver): add a **keywords parameter for catching + arg match parameters + + * python/matchrules.py: + (MatchTree::exec_matches): Check for arg matches + (SignalMatchRule::add_args_match): New method + (SignalMatchRule::execute): Added args_list parameter as an optimization + so we don't have to marshal the args more than once + (SignalMatchRule::match_args_from_list): New method that checks to see + if the rule's arg matches match an argument list. Only arguments + set in the rule are checked. + (SignalMatchRule::match_args_from_rule): New method that checks to see + if the rule's arg matches match another rule's. All args have to match + in order for this method to return true. If either rule has more args + then it is not a match. + (SignalMatchRule::is_match): Add args match + (SignalMatchRule::repr): Add args to the final output if they exist + +2005-08-17 Ross Burton <ross@burtonini.com> + + * glib/dbus-gproxy.c: + (dbus_g_proxy_call_no_reply): unref the message once sent. + (dbus_g_proxy_call): protect against NULL proxy. + +2005-08-16 John (J5) Palmieri <johnp@redhat.com> + + * python/__init__.py: Version updated (0, 43, 0) + + * python/dbus_bindings.pyx: + - Fixed type objects to have self passed into __init__ + - Added the Variant type + - Add the ability to specify types or signatures for Array, Variant + and Dictionary + (Connection::send_with_reply_handlers): return a PendingCall object + (_pending_call_notification): handle the case when an error is returned + without an error message in the body + (MessageIter::get_boolean): return True or False instead of an integer + (MessageIter::python_value_to_dbus_sig): add direct checking of types + and add checks for objects with embeded signatures or types (Array, + Variant and Dictionary) + (MessageIter::append_byte): handle case when the value is a dbus.Byte + (MessageIter::append_dict): handle embeded types or signatures + (MessageIter::append_array): handle embeded types or signatures + (MessageIter::append_variant): new method + + * python/proxies.py: + (DeferedMethod): New. Dummy executable object used when queuing calls + blocking on introspection data + (ProxyMethod::__call__): add the timeout keyword for specifying longer + or shorter timeouts for method calls + (ProxyObject): Add first pass at an introspection state machine + (ProxyObject::__init__): Add introspect keyword for turing off an on + introspection. + (ProxyObject::_Introspect): Internal Introspect call that bypasses + the usual mechanisms for sending messages. This is to avoid a deadlock + where the Intospect call would be queued waiting for the Introspect + call to finish ;-) + (ProxyObject::_introspect_reply_handler): New. This method is called + when introspection returns with no error + (ProxyObject::_introspect_error_handler): New. This method is called + when introspection encounters an error + (ProxyObject::__getattr__): Code to handle different introspection + states. Queue async calls or block blocking calls if we are + introspecting. Pass through as normal if we are not or are done with + introspecting. + + * python/service.py: Import signal and method from decorators.py + + * python/types.py: Add Variant type + +2005-08-16 Colin Walters <walters@verbum.org> + + * glib/dbus-gobject.c (dbus_set_g_error): Don't lose if the + DBusError message is NULL. + +2005-08-09 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-errors.c: apply patch from Timo Teras to make a + malloc'd copy of the name parameter + +2005-08-09 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c (dbus_message_set_reply_serial): print + warning if the reply serial is set to 0 + +2005-08-04 Colin Walters <walters@verbum.org> + + * glib/dbus-gvalue-utils.h (_dbus_g_type_specialized_builtins_init) + (dbus_g_type_is_fixed, dbus_g_type_fixed_get_size) + (dbus_gvalue_set_from_pointer, dbus_g_hash_table_value_foreach) + (dbus_g_hash_table_insert_values, dbus_g_hash_table_insert_steal_values) + (dbus_gtype_is_valid_hash_key, dbus_gtype_is_valid_hash_value) + (dbus_g_hash_func_from_gtype, dbus_g_hash_free_from_gtype) + (dbus_g_hash_equal_from_gtype, dbus_gvalue_stor, dbus_gvalue_take): + * glib/dbus-gvalue.h (dbus_g_value_types_init) + (dbus_gvalue_demarshal, dbus_gvalue_demarshal_variant) + (dbus_gvalue_demarshal_message, dbus_gvalue_marshal): + + Prefix name with _ to ensure they're not exported. All callers + updated. + + * glib/dbus-gvalue.c (typecode_to_gtype) + (dbus_typecode_maps_to_basic, basic_typecode_to_gtype) + (signature_iter_to_g_type_dict) + (signature_iter_to_g_type_array) + (dbus_gtype_from_signature_iter, dbus_gtype_from_signature) + (dbus_gtypes_from_arg_signature): + Move to dbus-gsignature.c. + + * glib/dbus-binding-tool-glib.c (dbus_binding_tool_output_glib_server): Call + dbus_g_type_specialized_builtins_init instead of dbus_g_value_types_init. + (dbus_binding_tool_output_glib_client): Ditto. + + * glib/Makefile.am (DBUS_GLIB_INTERNALS): Add dbus-gsignature.c + and dbus-gsignature.h + + * test/glib/test-service-glib.c (my_object_rec_arrays): Delete + unused variable. + +2005-08-03 Colin Walters <walters@verbum.org> + + * glib/dbus-gobject.c: Add tests on hardcoded object info; this should + catch any incompatible changes accidentally made. + +2005-08-03 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_read_credentials_unix_socket): fix + typo, from Julien Puydt + + * bus/connection.c (bus_connection_disconnected): we were always + doing a wait_for_memory due to a buggy loop, found by Timo Hoenig + +2005-08-01 Colin Walters <walters@verbum.org> + + Patch from Joe Markus Clarke: + + * glib/dbus-gidl.c (property_info_unref, arg_info_unref): Fix + use-after-free. + +2005-08-01 Colin Walters <walters@verbum.org> + + Patch from Joe Markus Clarke: + + * tools/dbus-send.c (main): + + Don't use C99 style initializers (bug #3933). + +2005-08-01 Colin Walters <walters@verbum.org> + + Patch from Joe Markus Clarke: + + * glib/dbus-gvalue.c (dbus_g_value_types_init): + * glib/dbus-gvalue-utils.c (dbus_g_type_specialized_builtins_init) + * glib/dbus-gobject.c (write_interface): + + Don't use C99 style initializers (bug #3933). + +2005-07-31 Havoc Pennington <hp@redhat.com> + + * tools/dbus-viewer.c (load_child_nodes): fix invocation of + dbus_g_proxy_call, fix from Piotr Zielinski bug #3920 + +2005-07-30 Havoc Pennington <hp@redhat.com> + + * fix a bunch of Doxygen warnings and mistakes + +2005-07-30 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_string_parse_uint): remove #ifdef + DBUS_BUILD_TESTS since it's now used in production code + +2005-07-29 Havoc Pennington <hp@redhat.com> + + * test/glib/test-profile.c (write_junk): initialize the junk + buffer so valgrind doesn't have a breakdown + +2005-07-29 Havoc Pennington <hp@redhat.com> + + * bus/signals.c (bus_signals_test): add match_rule_equal() tests + (match_rule_matches): remove unused arg + (test_matching): add tests for match_rule_matches() + + * bus/signals.c (bus_match_rule_parse_arg_match): add ability to + do arg0='foo' arg5='bar' in the match rules + (match_rule_matches): don't match if the arg0='foo' doesn't match. + + * dbus/dbus-protocol.h (DBUS_MAXIMUM_MATCH_RULE_ARG_NUMBER): add this + +2005-07-29 Ross Burton <ross@openedhand.com> + + * dbus/dbus-connection.c: + Don't create a DBusCondVar which is never used. + +2005-07-27 Ross Burton <ross@openedhand.com> + + * dbus/dbus-message.c: + Reduce the size of the maximum cached message to 10K. + +2005-07-25 Ross Burton <ross@openedhand.com> + + * glib/dbus-gproxy.c: + Remove matches when all proxies are unregistered. + +2005-07-24 Colin Walters <walters@verbum.org> + + * glib/dbus-gvalue.c (signature_iter_to_g_type_array): Don't require + typedata; recursive arrays won't have it. + + * test/glib/test-dbus-glib.c: + * test/glib/test-service-glib.c: + * test/glib/test-service-glib.xml: Add recursive arrays tests. + +2005-07-20 John (J5) Palmieir <johnp@redhat.com> + + * python/_dbus.py, _util.py, decorators.py, extract.py, matchrules.py. + proxies.py, service.py: Cleanup of code after running it through the + pyflakes code checker mostly dealing with undefined names. + (Bug #3828, Patch from Anthony Baxter <anthony@interlink.com.au>) + +2005-07-17 John (J5) Palmieri <johnp@redhat.com> + + * NEWS: Update to 0.35.2 + +2005-07-17 John (J5) Palmieri <johnp@redhat.com> + + * python/_dbus.py: Remove import of the dbus.services + module as it no longer exists (patch from Dimitur Kirov) + + * python/service.py (Object::__init__): Fixed typo + s/name/bus_name (patch from Dimitur Kirov) + + * python/examples/example-signal-emitter.py: import dbus.glib + to get the main loop and use glib mainloop instead of gtk so + X doesn't have to be running. + + * python/examples/example-signal-recipient.py: import dbus.glib + to get the main loop and use glib mainloop instead of gtk so + X doesn't have to be running. Import the decorators module + directly. + + * test/glib/Makefile.am: Added DIST_EXTRA files that distcheck + didn't pick up on but are needed to build + + * configure.in: upped version to 0.35.2 + + * bus/driver.c, bus/selinux.c, bus/selinux.h, dbus/dbus-protocol.h: + added Colin Walters' SELinux API rename patch from head + s/unix sercurity context/selinux security context/ + +2005-07-16 John (J5) Palmieri <johnp@redhat.com> + + * python/Makefile.am: dbus_binding.pxd.in should be included + in EXTRA_DIST not dbus_binding.pxd + fix up $(srcdir) hopefully for the last time + + * NEWS: Update to 0.35.1 + +2005-07-16 Colin Walters <walters@verbum.org> + + * bus/driver.c (bus_driver_handle_get_connection_selinux_security_context): Renamed + from bus_driver_handle_get_connection_unix_security_context. Update for + error usage. + (message_handlers): Update for renames. + + * bus/selinux.c (bus_selinux_allows_send): Handle OOM on + _dbus_string_init failure correctly. + (bus_selinux_append_context): Convert SID to context. Append it + as a byte array. + (bus_selinux_shutdown): Handle the case where bus_selinux_full_init + hasn't been called. + + * bus/selinux.h: Update prototype. + + * dbus/dbus-protocol.h (DBUS_ERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN): Renamed + from DBUS_ERROR_UNIX_SECURITY_CONTEXT_UNKNOWN. + +2005-07-15 Colin Walters <walters@verbum.org> + + * doc/TODO: Add note about convenience wrappers. + +2005-07-15 John (J5) Palmieri <johnp@redhat.com> + + * NEWS: Update to 0.35 + +2005-07-15 John (J5) Palmieri <johnp@redhat.com> + + * glib/Makefile.am: Add make-dbus-glib-error-switch.sh to EXTRA_DIST + so distcheck doesn't fail + + * glib/examples/Makefile.am: Add example-service.xml and + example-signal-emitter.xml to EXTRA_DIST so distcheck doesn't fail + + * glib/examples/statemachine/Makefile.am: Add statemachine.xml and + statemachine-server.xml to EXTRA_DIST so distcheck doesn't fail + + * python/Makefile.am: Preprend $(srcdir)/ to source files so the + compiler looks in the right places during distcheck + +2005-07-15 John (J5) Palmieri <johnp@redhat.com> + + * glib/example/Makefile.am: Fix a typo which cause make distcheck + to fail + +2005-07-15 John (J5) Palmieri <johnp@redhat.com> + + * python/examples/example-service.py, + python/examples/example-signal-emitter.py: Fixed up examples + for API changes + +2005-07-15 John (J5) Palmieri <johnp@redhat.com> + + * python/__init__.py: Upped to version (0,42,0) because of + the API change + +2005-07-15 John (J5) Palmieri <johnp@redhat.com> + + * ChangeLog: fix date in last entry + + * configure.in, bus/system.conf.in: add the ability to configure + the system bus user at compiletime with the --with-dbus-user flag + (patch from Kristof Vansant) + +2005-07-15 John (J5) Palmieri <johnp@redhat.com> + + * bus/dispatch.c, test/test-service.c: Add testcase + for sending messages to oneself (TODO item). + + * python/service.py (class Object): Swap ordering of bus_name + and object_path parameters to better support inheritance. + + * doc/dbus-tutorial.xml: change Python docs to reflect change + in parameter ordering and fix the inheritance section. + + * doc/TODO: remove sending message to oneself TODO item + +2005-07-15 Ross Burton <ross@openedhand.com> + + * glib/dbus-gproxy.c: + Fix a leak when calling methods via the proxy. + +2005-07-15 Colin Walters <walters@verbum.org> + + * bus/selinux.c (bus_selinux_append_context): Wrap in + HAVE_SELINUX. + +2005-07-14 John (J5) Palmieri <johnp@redhat.com> + + * python/_dbus.py (Bus::remove_signal_receiver): + don't add a callback to the match if none has been passed in + + * python/matchrules.py (SignalMatchTree::remove): if the rule + being matched does not have a callback treat it as a wildcard + fix matching logic + + * doc/dbus-tutorial.xml: Add Python tutorial + +2005-07-14 Colin Walters <walters@verbum.org> + + * bus/driver.c + (bus_driver_handle_get_connection_unix_security_context): New function. + (message_handlers): Add. + + * bus/selinux.c (bus_selinux_append_context): New function; appends + security context to message. + + * bus/selinux.h: Prototype. + + * dbus/dbus-protocol.h (DBUS_ERROR_UNIX_SECURITY_CONTEXT_UNKNOWN): New. + +2005-07-14 John (J5) Palmieri <johnp@redhat.com> + + * bus/activation.c: clean up all tabs to be 8 spaces + (bus_activation_activate_service): make sure we clean up + if activation fails + + * bus/dispatch.c: clean up all tabs to be 8 spaces + (check_shell_fail_service_auto_start): New function + tests to make sure we get fail properly when trying to auto start a service + with a faulty command line + (check_shell_service_success_auto_start): New function tests to make sure + auto started services get the arguments on the command line + + * test/test-shell-service.c: Added service for testing auto-starting with + command line arguments + + * test/data/valid-service-files/debug-shell-echo-fail.service.in, + test/data/valid-service-files/debug-shell-echo-success.service.in: + Added service files for testing auto-starting with command line arguments + + * */.cvsignore: added a bunch of generated files to various .cvsignore files + +2005-07-14 Rodrigo Moya <rodrigo@novell.com> + + * dbus/dbus-shell.[ch]: copy/pasted code from GLib. + + * dbus/Makefile.am: added new files to build. + + * bus/activation.c (bus_activation_activate_service): support + activation commands with parameters. + + * test/shell-test.c: added test program for the shell parsing + code. + +2005-07-13 David Zeuthen <davidz@redhat.com> + + * tools/dbus-send.c (append_arg, type_from_name): Also support 16 and + 64 bit signed and unsigned parameters + +2005-07-13 John (J5) Palmieri <johnp@redhat.com> + + * python/.cvsignore: remove dbus_bindings.pyx, add dbus_bindings.pxd + + * python/service.py (class Name): renamed BusName to make it clearer + what the object is for (a name on the bus) + + * python/examples/example-service.py, + python/examples/example-signal-emitter.py: change the Name object to + BusName + +2005-07-12 Colin Walters <walters@verbum.org> + + Patch from Jim Gettys <Jim.Gettys@hp.com>. + + * tools/dbus-launch.c: Include sys/select.h. + +2005-07-12 John (J5) Palmieri <johnp@redhat.com> + * python/dbus_bindings.pyx.in: removed + + * python/dbus_bindings.pyx: Added. + - Fixed some memleaks (patch from + Sean Meiners <sean.meiners@linspireinc.com>) + - Broke out the #include "dbus_h_wrapper.h" and put it in its + own pxd file (Pyrex definition) + - Broke out glib dependancies into its own pyx module + + * python/dbus_bindings.pdx: Added. + - Defines C class Connection for exporting to other modules + + * python/dbus_glib_bindings.pyx: Added. + - New module to handle lowlevel dbus-glib mainloop integration + + * python/glib.py: Added. + - Registers the glib mainloop when you import this module + + * python/services.py: Removed (renamed to service.py) + + * python/service.py: Added. + - (class Server): renamed Name + + * python/__init__.py: Bump ro version (0,41,0) + -don't import the decorators or service module + by default. These now reside in the dbus.service namespace + + * python/_dbus.py (Bus::__init__): Add code run the main loop + setup function on creation + + * python/examples/example-service.py, + python/examples/example-signal-emitter.py: update examples + + * python/examples/gconf-proxy-service.py, + python/examples/gconf-proxy-service2.py: TODO fix these up + + * doc/TODO: Addition + - Added a Python Bindings 1.0 section + - added "Add match on args or match on details to match rules" + + +2005-07-12 Colin Walters <walters@verbum.org> + + * glib/examples/statemachine/Makefile.am (statemachine-server-glue.h) + (statemachine-glue.h): + * glib/examples/Makefile.am (example-service-glue.h) + (example-signal-emitter-glue.h): + * glib/Makefile.am (dbus-glib-error-switch.h): + Add libtool --mode=execute so we use the built library instead + of any installed one. + +2005-07-11 Colin Walters <walters@verbum.org> + + * glib/dbus-gvalue.c (struct _DBusGValue): Delete. + (dbus_g_value_types_init): Remove assertion. + (dbus_g_value_get_g_type, dbus_g_value_open) + (dbus_g_value_iterator_get_values, dbus_g_value_get_signature) + (dbus_g_value_copy, dbus_g_value_free): Delete unimplemented + functions related to DBusGValue. Now we marshal/demarshal + structures as GValueArray. + (dbus_gtype_from_signature_iter): Return G_TYPE_VALUE_ARRAY for + structures. + (signature_iter_to_g_type_array): Don't call + signature_iter_to_g_type_struct. + (signature_iter_to_g_type_struct): Delete. + (dbus_gvalue_to_signature): Delete. + (dbus_gvalue_to_signature): New function with same name as other + one; we can convert structures to signatures. + (demarshal_valuearray): New function. + (get_type_demarshaller): Use it. + (demarshal_recurse): Delete. + (marshal_proxy): New function. + (marshal_map): Warn if we can't determine signature from type. + (marshal_collection_ptrarray): Ditto. + (marshal_collection_array): Ditto. + (get_type_marshaller): Use marshal_valuearray. + (marshal_recurse): Delete. + (_dbus_gvalue_test): Add some tests. + + * dbus/dbus-glib.h (struct _DBusGValueIterator): + (dbus_g_value_get_g_type, DBUS_TYPE_G_VALUE) + (dbus_g_value_open, dbus_g_value_iterator_get_value) + (dbus_g_value_iterator_get_values, dbus_g_value_iterator_recurse) + (dbus_g_value_free): Remove prototypes. + + * glib/dbus-binding-tool-glib.c (dbus_g_type_get_lookup_function): Handle + G_TYPE_VALUE_ARRAY. + + * glib/examples/example-service.c: + * glib/examples/example-client.c: Implement GetTuple. + + * test/glib/test-dbus-glib.c: + * test/glib/test-service-glib.c: + * test/glib/test-service-glib.xml: Add structure tests. + +2005-07-10 Colin Walters <walters@verbum.org> + + * doc/TODO: Knock off some GLib items with this patch. + + * glib/dbus-gvalue-utils.c (_dbus_gtype_can_signal_error) + (_dbus_gvalue_signals_error): New functions. + + * glib/dbus-gvalue-utils.h: Prototype them. + + * glib/dbus-gobject.c (arg_iterate): Update to handle return vals + and change to not output const/retval flags for input args. All + callers updated. + (invoke_object_method): Refactor to handle return values. Add + some more comments in various places. Remove debug g_print. + + * glib/dbus-binding-tool-glib.h (DBUS_GLIB_ANNOTATION_RETURNVAL): New. + + * glib/dbus-binding-tool-glib.c (dbus_g_type_get_marshal_name): + Handle G_TYPE_NONE. + (compute_gsignature): New function; refactored from code from + compute_marshaller and compute_marshaller_name. Enhance to + handle return values and async ops more cleanly. Update for + async ops returning NONE instead of BOOLEAN. + (compute_marshaller, compute_marshaller_name): Call compute_gsignature + and output appropriate string. + (generate_glue): Handle return value annotation. Also don't dump + constness flag for input arguments. + + * glib/Makefile.am (DBUS_GLIB_INTERNALS): New variable; contains + files shared between installed library and utilities. + (libdbus_glib_1_la_SOURCES): Move some stuf into DBUS_GLIB_INTERNALS. + (libdbus_gtool_la_SOURCES): Suck in DBUS_GLIB_INTERNALS so the + binding tool can access gtype utility functions. + + * test/glib/test-service-glib.c: + * test/glib/test-service-glib.xml: + * test/glib/test-dbus-glib.c: Add some tests for return values. + +2005-07-09 Colin Walters <walters@verbum.org> + + * glib/dbus-gparser.c (parse_annotation): Add annotations to + argument if available, not method. + + * glib/dbus-gobject.c (arg_iterate): More verbose warnings. + (invoke_object_method): First, remove some redundant + GValues (object_value, error_value) in favor of working on + array directly. Second, rework constness to be less buggy. + Now we iterate directly over the argument metadata instead + of parallel iterating over output signature and metadata. + + * glib/dbus-glib-tool.h: Add INVALID_ANNOTATION error. + + * glib/dbus-binding-tool-glib.c (generate_glue): Barf on const + annotation on input args. + +2005-07-09 Colin Walters <walters@verbum.org> + + * glib/dbus-binding-tool-glib.h (DBUS_GLIB_ANNOTATION_CONST): + Define. + + * glib/dbus-binding-tool-glib.c (generate_glue): Handle Const + annotation. + + * glib/dbus-gobject.c (arg_iterate): Update to parse constval too. + (method_dir_signature_from_object_info): Handle arg_iterate change. + (write_interface): Ditto. + (lookup_object_info): Don't barf if format_version is > 0. + (invoke_object_method): Handle arg constness. + + * glib/dbus-gidl.c (struct ArgInfo): Add annotations. + (arg_info_new): Create. + (arg_info_unref): Destroy. + (arg_info_get_annotations, arg_info_get_annotation) + (arg_info_add_annotation): New functions. + + * glib/dbus-gidl.h: Prototype them. + + * glib/dbus-gparser.c (parse_annotation): Allow annotations in + args, disallow them in properties. + (parse_annotation): Handle arg annotations. + + * test/glib/test-service-glib.xml: + * test/glib/test-service-glib.c: Update to make some methods + const. + +2005-07-08 Colin Walters <walters@verbum.org> + + * test/glib/test-service-glib.xml: + * test/glib/test-service-glib.c: + * test/glib/test-dbus-glib.c: Test a{sv}. + + * glib/examples/statemachine/statemachine.c: + * glib/examples/statemachine/statemachine-server.c: + * glib/examples/statemachine/statemachine-client.c: Fix some bugs, + add progress bar, etc. + + * glib/dbus-gvalue.c (register_array, register_dict): Delete; not + needed anymore due to generic array/map marshalling. + (dbus_g_value_types_init): Don't register basic arrays or the + string/string hash. + (dbus_gtype_from_signature_iter): Don't try to recurse into + variants. + (dbus_gtype_to_signature): Check collection/map before type + metadata. + (demarshal_garray_basic): Renamed to demarshal_collection_array. + (demarshal_ghashtable): Renamed to demarshal_map; fix to use new + generic map creation/append functions instead of hash table + specifically. + (get_type_demarshaller): Handle maps. + (demarshal_collection): Dispatch on collection type to either + demarshal_collection_ptrarray or demarshal_collection_array. + (get_type_marshaller): Handle maps. + (marshal_collection): Dispatch collection type to either + marshal_collection_ptrarray or marshal_collection_array. + (_dbus_gvalue_test): New test. + + * glib/dbus-gvalue-utils.c (unset_and_free_g_value): New function. + (hash_free_from_gtype): Use it to free GValues. + (hashtable_append): New function. + (ptrarray_append): Fix prototype. + (slist_append): Ditto. + (_dbus_gvalue_utils_test): Extend tests. + + * glib/dbus-gtype-specialized.c + (dbus_g_type_specialized_init_append): Renamed from + dbus_g_type_specialized_collection_init_append. Remove const from + value, since we steal it. + (dbus_g_type_specialized_map_append): New function. + + * glib/dbus-gtype-specialized.h: Update prototypes. + Add DBusGTypeSpecializedMapAppendFunc. + + * glib/dbus-gtest.c (dbus_glib_internal_do_not_use_run_tests): Run + _dbus_gvalue_test. + + * glib/dbus-gtest.h: Prototype it. + +2005-07-08 Ross Burton <ross@openedhand.com> + + * dbus/dbus-glib.h: + Add DBysGAsyncData for the async bindings. + + * glib/dbus-binding-tool-glib.c: + Re-enable the async bindings. + + * test/glib/test-dbus-glib.c: + Add a test for the generated async bindings. + +2005-07-08 Colin Walters <walters@verbum.org> + + * doc/TODO: Update GLib todo bits, also add a post-1.0 TODO for a + connection concept. + +2005-07-08 Colin Walters <walters@verbum.org> + + * tools/Makefile.am: Kill of print-introspect in favor of using + dbus-send --print-reply=literal. + + * test/glib/test-service-glib.xml: + * test/glib/test-service-glib.c (my_object_get_objs): New test + for "ao". + + * test/glib/test-dbus-glib.c (echo_received_cb): Free echo data. + (main): Test GetObjs. + + * glib/examples/statemachine/Makefile.am: + * glib/examples/statemachine/sm-marshal.list: + * glib/examples/statemachine/statemachine-client.c: + * glib/examples/statemachine/statemachine-server.c: + * glib/examples/statemachine/statemachine-server.xml: + * glib/examples/statemachine/statemachine.c: + * glib/examples/statemachine/statemachine.h: + * glib/examples/statemachine/statemachine.xml: + + New example. + + * glib/examples/example-service.c (main): Move invocation + of dbus_g_object_type_install_info earlier, to emphasize it + should only be done once. + + * glib/examples/example-signal-emitter.c (main): Ditto. + + * glib/examples/Makefile.am (SUBDIRS): Include statemachine. + + * glib/dbus-gvalue.h (dbus_gtype_to_signature) + (dbus_gvalue_marshal): Update prototypes. + + * glib/dbus-gvalue.c: Update all marshalling functions to take + const GValue instead of GValue. + (signature_iter_to_g_type_array): Return a GPtrArray for nonfixed + types. + (dbus_gvalue_to_signature): Update for dbus_gtype_to_signature + change. + (dbus_gtype_to_signature): Handle generic collecitons and maps. + Return a newly-allocated string. + (demarshal_proxy, demarshal_object_path, demarshal_object) + (demarshal_strv, demarshal_ghashtable): Set error, don't assert if + we get the wrong types from message. + (get_type_demarshaller): New function, extracted from + dbus_gvalue_demarshal. + (demarshal_collection): New function, demarshals generic + collection. + (dbus_gvalue_demarshal): Just invoke result of + get_type_demarshaller. Throw error if we don't have one. + (marshal_garray_basic): Abort on OOM. + (get_type_marshaller): New function, extracted from + dbus_gvalue_marshal. + (collection_marshal_iterator, marshal_collection): New functions; + implements generic marshalling for an iteratable specialized + collection. + (dbus_gvalue_marshal): Just invoke result of get_type_marshaller. + + * glib/dbus-gvalue-utils.c (gvalue_from_ptrarray_value): Handle + G_TYPE_STRING. + (ptrarray_value_from_gvalue): Ditto. + (ptrarray_append, ptrarray_free): New functions. + (slist_constructor, slist_iterator, slist_copy_elt, slist_copy) + (slist_append, slist_end_append, slist_free): New functions. + (dbus_g_type_specialized_builtins_init): Add append fuctions + for GPtrArray and GSList. Register GSList. + (test_specialized_hash, _dbus_gvalue_utils_test): New functions. + + * glib/dbus-gtype-specialized.h (DBusGTypeSpecializedAppendContext): + New. + (dbus_g_type_specialized_collection_init_append) + (dbus_g_type_specialized_collection_append) + (dbus_g_type_specialized_collection_end_append): Prototype. + (DBusGTypeSpecializedCollectionVtable): Add append_func and + end_append_func. + + * glib/dbus-gtype-specialized.c (dbus_g_type_specialized_collection_init_append) + (dbus_g_type_specialized_collection_append) + (dbus_g_type_specialized_collection_end_append): New functions. + (dbus_g_type_map_value_iterate): Take const GValue. + (dbus_g_type_collection_value_iterate): Ditto. + + * glib/dbus-gtest.c (dbus_glib_internal_do_not_use_run_tests): Run + _dbus_gvalue_utils_test. + + * glib/dbus-gtest.h: Prototype it. + + * glib/dbus-gproxy.c (dbus_g_proxy_manager_filter): Avoid + using uninitialized owner_list. + (dbus_g_proxy_begin_call_internal): Move return_if_fail to + public API. + (dbus_g_proxy_end_call_internal): Update to use error set + from dbus_gvalue_demarshal instead of setting it here. + (dbus_g_proxy_begin_call): Move return_if_fail here. + + * glib/dbus-gobject.c (write_interface): Update for + dbus_gtype_to_signature returning new string. + + * configure.in: Add glib/examples/statemachine. + +2005-07-08 Joe Shaw <joeshaw@novell.com> + + * configure.in: Add a configure option, --with-console-auth-dir + + * dbus/dbus-sysdeps-util.c (_dbus_user_at_console): Use the + new setting. Patch from Kay Sievers. + +2005-07-06 Colin Walters <walters@verbum.org> + + * dbus/dbus-glib.h (DBusGPendingCall, DBusGPendingCallNotify) + (DBUS_TYPE_G_PENDING_CALL, dbus_g_pending_call_get_g_type) + (dbus_g_pending_call_ref, dbus_g_pending_call_unref): Delete. + (dbus_g_pending_call_set_notify, dbus_g_pending_call_cancel): + Delete in favor of dbus_g_proxy_begin_call and + dbus_g_proxy_cancel_call. + (DBusGProxyCall, DBusGProxyCallNotify): New. + (dbus_g_proxy_begin_call): Change prototype to take callback, user + data, and destroy function. This replaces + dbus_g_pending_call_set_notify. + (dbus_g_proxy_cancel_call): Prototype. + (DBusGAsyncData): Delete, shouldn't be needed anymore. + + * glib/dbus-gproxy.c (struct _DBusGProxy): Add call_id_counter and + pending_calls map. + (struct _DBusGProxyManager): Add bus_proxy member, which is an + internal proxy for calls to the bus. Remove + pending_nameowner_calls, now the internal proxy keeps track. + (dbus_g_proxy_manager_unref): Unref bus proxy, remove reference to + pending_nameowner_calls. + (got_name_owner_cb): Update prototype, and use + dbus_g_proxy_end_call. + (got_name_owner_cb): Remove reference to pending_nameowner_calls. + (dbus_g_proxy_manager_register): Delete directly libdbus code in + favor of using internal proxy. + (dbus_g_proxy_manager_unregister): Update to use + dbus_g_proxy_cancel_call for any pending GetNameOwner call. + (dbus_g_proxy_init): Initialize pending calls map. + (dbus_g_proxy_constructor): New. + (dbus_g_proxy_class_init): Add get/set property functions, + constructor, and add NAME, PATH, and INTERFACE properties. + (cancel_pending_call): New function. + (dbus_g_proxy_dispose): Iterate over any outstanding calls and + cancel them. + (dbus_g_proxy_set_property, dbus_g_proxy_get_property): New. + (GPendingNotifyClosure): New structure. + (d_pending_call_notify, d_pending_call_free): Moved here from + dbus-glib.c. + (DBUS_G_VALUE_ARRAY_COLLECT_ALL): Moved around to satisfy function + ordering. + (manager_begin_bus_call): New internal function for talking to + internal bus proxy. + (dbus_g_proxy_new): Construct object using GObjet properties. + (dbus_g_proxy_begin_call_internal): Update to take user data, etc. + Create closure of same, and insert call into map of pending calls. + (dbus_g_proxy_end_call_internal): Take call id instead of pending + call. Look up pending call in current set. Remove it when we've + completed. + (dbus_g_pending_call_end, dbus_g_proxy_end_call_internal): Delete. + (dbus_g_proxy_begin_call): Change API to take callback, user data, + and destroy function directly. + (dbus_g_proxy_end_call): Update to take DBusGProxyCall. + (dbus_g_proxy_call): Invoke with NULL callback. + (dbus_g_proxy_cancel_call): New function, replaces + dbus_g_pending_call_cancel. + + * glib/dbus-gparser.c (validate_signature): Fix call to + dbus_set_g_error. + + * glib/dbus-gobject.c (dbus_g_object_type_dbus_metadata_quark): + New quark for attaching metadata to GType. + (info_hash): Delete. + (lookup_object_info): Look up using quark. + (dbus_g_object_type_install_info): Check that a type is classed, + not that it's an object. Also just install type data using quark + instead of using global hash. + + * glib/dbus-glib.c (dbus_g_pending_call_ref) + (dbus_g_pending_call_unref, dbus_pending_call_get_g_type) + (GPendingNotifyClosure): Delete. + (d_pending_call_notify, d_pending_call_free): Move to dbus-gproxy.c. + (dbus_g_pending_call_set_notify, dbus_g_pending_call_cancel): Delete. + + * glib/dbus-binding-tool-glib.c (generate_client_glue): Disable async + client method generation until we can fix it... + + * tools/dbus-viewer.c (load_child_nodes): Use dbus_g_proxy_call. + (load_from_service_thread_func): Ditto. + + * tools/dbus-names-model.c (struct NamesModel): Hold + DBusGProxyCall. + (have_names_notify): Update prototype, use + dbus_g_proxy_cancel_call. + (names_model_reload): Update for new dbus_g_proxy_begin_call API. + + * tools/dbus-monitor.c (filter_func): Update for print_message + API change. + + * test/glib/test-dbus-glib.c: Add more tests for async + invocations. Update many begin_call/end_call pairs to just use + dbus_g_proxy_call. + + * tools/dbus-send.c (main): Add --print-reply=literal mode. This + allows us to dump print-introspect.c. + + * tools/dbus-print-message.h (print_message): Add literal argument + to print_message which is intended to allow printing arguments without + metadata like "string=". + + * tools/dbus-print-message.c (print_iter): Add literal argument. + (print_message): Allow printing string messages literally. + +2005-07-05 Colin Walters <walters@verbum.org> + + * glib/dbus-gproxy.c (marshal_dbus_message_to_g_marshaller): + Remove value refcount leak, original patch from Jorn Baayen + <jorn@openedhand.com>. Also remove useless extra value in favor + of prepending to value array directly. + +2005-07-02 Colin Walters <walters@verbum.org> + + * glib/dbus-gmain.c (_dbus_gmain_test): Fix test. + +2005-07-01 Colin Walters <walters@verbum.org> + + Patch from Jonathan Matthew <jonathan@kaolin.hn.org> + + * glib/dbus-gvalue.c (basic_typecode_to_gtype): Fix return type. + (dbus_g_value_types_init): Marshal G_TYPE_CHAR as DBUS_TYPE_BYTE, + G_TYPE_LONG as DBUS_TYPE_INT32, G_TYPE_ULONG as DBUS_TYPE_UINT32, + and G_TYPE_FLOAT as DBUS_TYPE_DOUBLE. + +2005-06-30 Colin Walters <walters@verbum.org> + + * test/glib/test-dbus-glib.c: + * test/glib/test-service-glib.c: + * test/glib/test-service-glib.xml: Update tests for new error + setting bits, also add async tests (patch from Ross Burton). + + * test/glib/Makefile.am (test_service_glib_LDADD): Add + DBUS_GLIB_THREADS_LIBS. + + * glib/dbus-gproxy.c (get_name_owner) + (dbus_g_pending_call_end_valist): Ditto. + + * glib/dbus-gobject.c (error_metadata): New mapping from GError + domain (GQuark) to DBusGErrorInfo. + (gerror_domaincode_to_dbus_error_name): Attempt to look up error + quark in error_metadata. Take message interface as default + error message interface. + (gerror_to_dbus_error_message): Pass message interface. + (dbus_set_g_error): Resurrected. + (dbus_g_error_info_free): New function. + (dbus_g_object_type_install_info): Use g_type_class_ref instead + of _peek to actually create the object class if it hasn't been + created yet. + (dbus_g_error_domain_register): New function. + + * glib/dbus-gmain.c (dbus_g_bus_get): Switch to dbus_set_g_error. + + * glib/dbus-gparser.c (validate_signature): Ditto. + + * dbus/dbus-glib.h (dbus_g_error_set): Delete. + (dbus_g_error_domain_register): Prototype. + + * glib/dbus-glib.c (dbus_g_error_set): Delete. + Update tests. + +2005-06-29 Colin Walters <walters@verbum.org> + + * dbus/dbus-glib.h: Delete DBUS_TYPE_G_PROXY_ARRAY. Add + DBUS_TYPE_G_OBJECT_PATH. + + * glib/dbus-gvalue.c (dbus_g_value_types_init): Remove marshallers + for G_TYPE_OBJECT and DBUS_TYPE_G_PROXY_ARRAY (the latter should + be handled more generically). Add DBUS_TYPE_G_OBJECT_PATH. + (dbus_g_object_path_get_g_type): New function. + (dbus_gtype_from_signature_iter): Map DBUS_TYPE_OBJECT_PATH + to DBUS_TYPE_G_OBJECT_PATH by default. + (demarshal_proxy): Remove unused name variable. + (demarshal_object_path, marshal_object_path): New functions. + (demarshal_proxy_array, marshal_proxy_array): Delete. + + * glib/dbus-binding-tool-glib.c (dbus_g_type_get_c_name): Map + DBUS_TYPE_G_OBJECT_PATH to char *. + (dbus_g_type_get_lookup_function): Map builtin + DBUS_TYPE_G_OBJECT_PATH. + + * test/glib/test-dbus-glib.c + * test/glib/test-service-glib.c (my_object_objpath): + Adapt tests to new object path marshalling. + +2005-06-29 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: force check for Python >= 2.4 + +2005-06-29 Colin Walters <walters@verbum.org> + + Patch from Ross Burton <ross@openedhand.com> + + * glib/dbus-gobject.c (invoke_object_method): Unset object + value in all cases, not only in async case. + +2005-06-29 Colin Walters <walters@verbum.org> + + * glib/dbus-gproxy.c (struct _DBusGProxy): Add new member + name_call for keeping track of any outgoing GetNameOwner call. + Also add for_owner and associated. + (struct _DBusGProxyManager): Add owner_names, which is hash table + that maps a base name to a list of names it owns (that we're + interested in). Add pending_nameowner_calls which is a list of + all outstanding GetNameOwner; avoids us having to iterate over + every proxy. Add unassociated_proxies which keeps track of name + proxies with no associated name owner. + (dbus_g_proxy_manager_unref): Destroy owner_names. + (struct DBusGProxyNameOwnerInfo): New struct for keeping track of + name refcounts. + (find_name_in_info, name_owner_foreach) + (dbus_g_proxy_manager_lookup_name_owner, insert_nameinfo) + (dbus_g_proxy_manager_monitor_name_owner) + (dbus_g_proxy_manager_unmonitor_name_owner) + (unassociate_proxies, dbus_g_proxy_manager_replace_name_owner): + New functions; they manipulate the owner_names mapping. + (got_name_owner_cb): New function. + (get_name_owner): New function, extracted from + dbus_g_proxy_new_for_name_owner. + (dbus_g_proxy_manager_register): For now we need to keep track of + all NameOwnerChanged. Also if the proxy is for a name, if we + don't already know the name owner, queue a new GetNameOwner + request and add it to our list of unassociated proxies. Otherwise + inc the refcount. + (dbus_g_proxy_manager_unregister): If this proxy is for a name, + cancel any pending GetNameOwner call, etc. + (dbus_g_proxy_manager_filter): Handle NameOwnerChanged. Also use + the owner_names mapping to look up the current names for the + signal source, and dispatch to any proxies for that name. + (dbus_g_proxy_new): Initialize new members. + (dbus_g_proxy_new_for_name): Delete unused proxy variable. + (dbus_g_proxy_new_for_name_owner): Use get_name_owner. + (dbus_g_pending_call_end_valist): New function, extracted from + dbus_g_proxy_end_call_internal. Useful when we don't have a proxy + but want to use the GLib infrastructure. Also note how many + arguments in reply were over. + (dbus_g_pending_call_end): New function, just call + dbus_g_pending_call_end_valist. + (dbus_g_proxy_end_call_internal): Just call + dbus_g_pending_call_end_valist. + + * glib/dbus-gobject.c (_dbus_gobject_lookup_marshaller): Fix lookup + of builtin marshaller for STRING_STRING_STRING. + + * test/glib/test-dbus-glib.c: + * test/glib/test-service-glib.c: + * test/glib/test-service-glib.xml: + Extend tests to cover name proxies, destruction of owner proxies, + etc. + + * glib/examples/example-signal-recipient.c + (dbus_g_proxy_new_for_name_owner): Create a name proxy. + + * tools/dbus-send.c (main): Print D-BUS error name in addition + to message. + +2005-06-28 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx.in (cunregister_function_handler, + cmessage_function_handler): Patch from + Anthony Baxter <anthony@interlink.com.au> fixes threading problems + by using the Py_GILState_Ensure/Release to synchronize with the + python runtime. + +2005-06-28 Ray Strode <rstrode@redhat.com> + + * dbus/dbus-spawn.c (_dbus_babysitter_unref): kill + babysitter helper process on last unref, bug #2813. + +2005-06-27 Colin Walters <walters@verbum.org> + + * test/glib/test-dbus-glib.c: + * test/glib/test-service-glib.c: + * test/glib/test-service-glib.xml: + Test hash table signal emitting. + + * glib/dbus-gobject.c (_dbus_gobject_lookup_marshaller): Convert + types to their fundamental basis types, since this is what + marshallers operate on. Also add an entry for VOID__BOXED. + (dbus_g_object_register_marshaller_array): Convert to fundamental. + +2005-06-26 Havoc Pennington <hp@redhat.com> + + * doc/dbus-tutorial.xml: fix names of interface/service/path, fix + from Don Park + +2005-06-26 Colin Walters <walters@verbum.org> + + * glib/dbus-glib.c (dbus_set_g_error): Delete. + (dbus_g_error_set): New public function from its ashes; used by + both service-side method implementation and GLib bindings + internals. + (dbus_g_error_has_name, dbus_g_error_get_name): New function. + (_dbus_glib_test): Add some tests. + + * test/glib/test-dbus-glib.c (main): Test dbus_g_error_has_name. + + * test/glib/test-service-glib.c (my_object_throw_error): Use + dbus_g_error_set. + + * glib/dbus-gobject.c (gerror_to_dbus_error_message): Handle + errors thrown by dbus_g_error_set. + + * glib/dbus-gmain.c (dbus_g_bus_get): Change to dbus_g_error_set. + + * glib/dbus-gparser.c (validate_signature): Ditto. + + * glib/dbus-gproxy.c (dbus_g_proxy_new_for_name_owner) + (dbus_g_proxy_end_call_internal): Ditto. + + * glib/Makefile.am: Generate dbus-glib-error-switch.h, which + converts DBUS_ERROR_x to DBUS_GERROR_x. + (libdbus_glib_1_la_SOURCES, BUILT_SOURCES, CLEANFILES): Add it. + + * doc/TODO: Remove error TODO. + + * doc/dbus-tutorial.xml: Update with documentation about error + handling. + + * dbus/make-dbus-glib-error-enum.sh: Tighten up regexp to make + sure we only change DBUS_ERROR to DBUS_GERROR, not all ERROR to + GERROR. Also add DBUS_GERROR_REMOTE_EXCEPTION. + +2005-06-22 Colin Walters <walters@verbum.org> + + Patch from Ross Burton <ross@openedhand.com> + + * glib/dbus-gobject.c (dbus_g_method_return): Free out_sig. + +2005-06-20 Colin Walters <walters@verbum.org> + + * configure.in: Add glib/examples. + + * glib/Makefile.am: Add examples/ + + * glib/examples/.cvsignore + * glib/examples/Makefile.am + * glib/examples/example-client.c + * glib/examples/example-service.c + * glib/examples/example-service.xml + * glib/examples/example-signal-emitter.c + * glib/examples/example-signal-emitter.xml + * glib/examples/example-signal-recipient.c: + New files; GLib binding examples, ported from + python/examples. + +2005-06-20 Colin Walters <walters@verbum.org> + + * dbus/dbus-glib.h: + * glib/dbus-gproxy.c: Rename dbus_g_proxy_invoke to + dbus_g_proxy_call. + + * glib/dbus-binding-tool-glib.c: + * doc/dbus-tutorial.xml: + * test/glib/test-dbus-glib.c: Update for rename. + +2005-06-20 Colin Walters <walters@verbum.org> + + Patch suggested by Ross Burton <ross@openedhand.com> + + * glib/dbus-gobject.c (export_signals): Free signal name. + (g_value_init): Use G_VALUE_NOCOPY_CONTENTS to plug + memory leak. Add a bit of documentation. + (dbus_g_method_return_error): Free context, and note we do + so. + +2005-06-18 Murray Cumming <murrayc@murrayc.com> + + * dbus/dbus-glib.h: + * glib/dbus-gobject.c: + * glib/dbus-gproxy.c: + * glib/dbus-gvalue.c: Predeclare structs as + typedef struct _Something Something instead of + typedef struct Something Something, so we can + redeclare the prototypes. Other GNOME libraries + do this already. + +2005-06-17 Colin Walters <walters@verbum.org> + + * tools/dbus-names-model.c (have_names_notify): Fix call + to dbus_g_proxy_end_call. + +2005-06-17 Colin Walters <walters@verbum.org> + + * glib/dbus-gproxy.c (dbus_g_proxy_emit_remote_signal): Don't + spew warnings if we get malformed remote signals. + + * glib/dbus-gobject.c (propsig_iterate): New function. + (lookup_object_info): New function, extracted from + lookup_object_and_method. + (introspect_properties, introspect_signals): Delete; these + are merged into write_interface. + (write_interface): Write out signals and properties here; + dump the org.gtk.object stuff and use the interface given + in the introspection data blob. Also fix up property XML. + (lookup_values): New function. + (introspect_interfaces): Gather a mapping from interface to a + list of its methods, signals, and properties, then write out + each interface. + (lookup_object_and_method): Use lookup_object_info. + (struct DBusGSignalClosure): Add interface. + (dbus_g_signal_closure_new): Add interface. Don't dup signame; + we can just use the constant data. + (dbus_g_signal_closure_finalize): Don't free signal name. + (signal_emitter_marshaller): Use interface from signal closure. + (export_signals): Only export signals mentioned in introspection + blob. + (dbus_g_connection_register_g_object): Warn if we have no + introspection data for an object. + (funcsig_equal): Remove unused variable. + (dbus_g_object_register_marshaller): Take varargs instead of + list. + (dbus_g_object_register_marshaller_array): New function, + extracted from old dbus_g_object_register_marshaller. + + * glib/dbus-binding-tool-glib.c (struct DBusBindingToolCData): Add + signals and property data. + (write_quoted_string): New function, extracted from generate_glue. + (generate_glue): Write signals and properties to introspection + blob. + + * dbus/dbus-glib.h (struct DBusGObjectInfo): Include + exported_signals and exported_properties. + (dbus_g_object_register_marshaller): Update prototype. + (dbus_g_object_register_marshaller_array): Prototype. + + * test/glib/test-dbus-glib.c: Extend testing to cover new signals. + + * test/glib/test-service-glib.c: Add new test signals and method + to emit them. + + * test/glib/test-service-glib.xml: Add some test signals. + + * test/glib/Makefile.am (BUILT_SOURCES): Add my-object-marshal.c + and my-object-marshal.h + (test_service_glib_SOURCES, test_dbus_glib_SOURCES): Add + my-object-marshal.c. + (my-object-marshal.c, my-object-marshal.h): Implement. + + * test/glib/.cvsignore: Update. + + * doc/TODO: Remove two GLib TODO items fixed by this + patch. + +2005-06-16 Colin Walters <walters@verbum.org> + + * doc/TODO: Update for GLib bindings. + +2005-06-16 Colin Walters <walters@verbum.org> + + * glib/dbus-binding-tool-glib.c: + * glib/dbus-gobject.c: + * glib/dbus-gproxy.c: Add Nokia copyright; Patch + from Ross Burton, for his GLib bindings work. + +2005-06-16 Colin Walters <walters@verbum.org> + + * glib/dbus-gobject.c (funcsig_hash, funcsig_equal): Use n_params + to iterate instead of walking to G_TYPE_INVALID. + + Patch based on a patch from Ryan Gammon. + +2005-06-16 Colin Walters <walters@verbum.org> + + * bus/bus.c (bus_context_new): Set parser to NULL + after we unref it (Patch from Chris Boscolo, #2174). + +2005-06-16 Colin Walters <walters@verbum.org> + + * python/dbus_bindings.pyx.in: Import size_t, + __int64_t, __uint64_t, and __signed. + + * dbus/dbus-sysdeps.c <HAVE_CMSGCRED> (write_credentials_byte): + Define cmsg struct, output it. + (_dbus_read_credentials_unix_socket): + Use cmsg struct. + + Patch from Joe Markus Clarke for FreeBSD support. + +2005-06-16 Colin Walters <walters@verbum.org> + + * tools/dbus-send.c (append_array): Use strtok. + (append_dict): New function. + (type_from_name): New function, extracted from main. + (main): Handle sending dicts. + + * tools/dbus-print-message.c (print_iter): Print dict + entries. + +2005-06-16 Colin Walters <walters@verbum.org> + + * glib/dbus-gvalue.c (marshal_basic): Marshal NULL string + values as the empty string (#2948). + +2005-06-16 Colin Walters <walters@verbum.org> + + * dbus/Makefile.am: + * mono/doc/Makefile.am: + * test/glib/Makefile.am: + + Fix srcdir != builddir issues (Patch from Chris Wilson, #3477) + +2005-06-16 Colin Walters <walters@verbum.org> + + * dbus/dbus-marshal-header.c (_dbus_header_load): Set + header byte order from expected byte order (Patch from Chris Wilson, #3475). + + * dbus/dbus-marshal-byteswap.c (byteswap_body_helper): + Increment pointer after swapping fixed array. Add assertion + for array length. + +2005-06-15 Colin Walters <walters@verbum.org> + + * dbus/dbus-sysdeps.c <HAVE_CMSGCRED> (_dbus_read_credentials_unix_socket): + Fix call to dbus_set_error. (Patch from Michael Banck, #3461) + +2005-06-15 John (J5) Palmieri <johnp@redhat.com> + + * NEWS: Update to 0.34 + +2005-06-15 David Zeuthen <davidz@redhat.com> + + * configure.in (LT_CURRENT): Revert back to 1 as the library + hasn't changed and we've certainly not committed to protocol + stability yet. All this does is to break ABI. See commit note + from hp@redhat.com 2005-05-05 for details. + +2005-06-15 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-connection.c (_dbus_connection_peer_filter): New method + (_dbus_connection_run_builtin_filters): New method + (dbus_connection_dispatch): Run the builtin filters which in turn + runs the peer filter which handles Ping messages. + + * doc/TODO: + - Ping isn't handled: This patch fixes it + + - Add a test case for the Ping message: added TODO item + +2005-06-15 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-message.c: + (dbus_message_has_path): New method + (dbus_message_has_interface): New method + (dbus_message_has_member): New method + + * dbus/dbus/dbus-sysdeps.c (_dbus_check_dir_is_private_to_user): + New method + + * dbus/dbus-keyring.c (_dbus_keyring_reload): Check to see that + the keyring directory is private to the user + + * doc/TODO: + - The convenience functions in dbus-bus.h should perhaps have + the signatures that they would have if they were autogenerated + stubs. e.g. the acquire service function. We should also evaluate + which of these functions to include, in light of the fact that + GLib/Qt native stubs will probably also exist.: Punted + + - add dbus_message_has_path(), maybe has_member/interface: + fixed in this patch + + - in dbus-keyring.c, enforce that the keyring dir is not + world readable/writable: Fixed in this patch + +2005-06-15 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-marshal-validate.h: Added a new validation + error code DBUS_VALIDITY_UNKNOWN_OOM_ERROR = -4 for + out of memory errors when validating signitures + + * dbus/dbus-marshal-header.c: use DBUS_VALIDITY_UNKNOWN_OOM_ERROR + in places where we previously used DBUS_VALID and a FALSE return + value to indicate OOM + + * dbus/dbus-marshal-validate.c (_dbus_validate_signature_with_reason): + Use a stack to track the number of elements inside containers. The + stack values are then used to validate that dict entries have only two + elements within them. + (validate_body_helper): check the reason for failure when validating + varients + + * dbus/dbus-message.c (load_message): use + DBUS_VALIDITY_UNKNOWN_OOM_ERROR in places where we previously used + DBUS_VALID and a FALSE return value to indicate OOM + + * doc/TODO: remove "- validate dict entry number of fields" as this + patch fixes it + +2005-06-14 David Zeuthen <davidz@redhat.com> + + * bus/bus.c (process_config_every_time): Drop existing conf-dir + watches (if applicable) and add new watches + + * bus/main.c (signal_handler): Handle SIGIO if using D_NOTIFY + (main): Setup SIGIO signal handler if using D_NOTIFY + + * bus/config-parser.h: Add prototype bus_config_parser_get_conf_dirs + + * bus/config-parser.c (struct BusConfigParser): Add conf_dirs list + (merge_included): Also merge conf_dirs list + (bus_config_parser_unref): Clear conf_dirs list + (include_dir): Add directory to conf_dirs list + (bus_config_parser_get_conf_dirs): New function + + * bus/dir-watch.[ch]: New files + + * bus/Makefile.am (BUS_SOURCES): Add dir-watch.[ch] + + * configure.in: Add checks for D_NOTIFY on Linux + +2005-06-14 Colin Walters <walters@verbum.org> + + * glib/dbus-binding-tool-glib.c: + * glib/dbus-gobject.c: + * glib/dbus-gvalue.c: Fix indentation and brace style. + +2005-06-14 Ross Burton <ross@openedhand.com>. + + * glib/dbus-glib.h: Make DBusGMethodInvocation + a private structure. Rearrange prototypes a bit. + + * glib/dbus-gproxy.c (dbus_g_proxy_invoke): Add + documentation for first_arg_type. + + * glib/dbus-gobject.c: Move DBusGMethodInvocation + here, add documentation. Move dbus_g_method_return + and dbus_g_method_return_error into public API + section. + +2005-06-14 Colin Walters <walters@verbum.org> + + * glib/dbus-gobject.c (_dbus_gobject_lookup_marshaller): + Add missing return statements, noticed by Ross Burton. + +2005-06-13 Ross Burton <ross@openedhand.com>. + + * glib/dbus-gobject.c: Handle errors on message + demarshalling by sending error message back. + * glib/dbus-gvalue.c: Initialize return variables. + +2005-06-13 Colin Walters <walters@verbum.org> + + * glib/Makefile.am: Fix thinko in last patch. + +2005-06-13 Colin Walters <walters@verbum.org> + + * glib/Makefile.am: Move dbus-gtype-specialized.c + and dbus-gtype-specialized.h into a _HEADERS variable, + install them. + +2005-06-12 Colin Walters <walters@verbum.org> + + Async signals and various bugfixes and testing by + Ross Burton <ross@openedhand.com>. + + * glib/dbus-gvalue.h: (struct DBusBasicGValue): Delete. + (dbus_gvalue_genmarshal_name_from_type) + (dbus_gvalue_ctype_from_type): Moved to dbus-binding-tool-glib.c. + (dbus_gtype_to_dbus_type): Renamed to dbus_gtype_from_signature. + (dbus_g_value_types_init, dbus_gtype_from_signature) + (dbus_gtype_from_signature_iter, dbus_gtype_to_signature) + (dbus_gtypes_from_arg_signature): New function prototypes. + (dbus_gvalue_demarshal): Take context and error arguments. + (dbus_gvalue_demarshal_variant): New function. + (dbus_gvalue_demarshal_message): New function. + (dbus_gvalue_store): Delete. + + * glib/dbus-gvalue.c: + + File has been almost entirely rewritten; now we special-case + more types such as DBUS_TYPE_SIGNATURE, handle arrays and + hash tables correctly, etc. Full support for recursive values + is not yet complete. + + * glib/dbus-gproxy.c (dbus_g_proxy_class_init): Change last + argument of signal to G_TYPE_POINTER since we now pass a + structure. + (lookup_g_marshaller): Delete in favor of + _dbus_gobject_lookup_marshaller. + (marshal_dbus_message_to_g_marshaller): Use + _dbus_gobject_lookup_marshaller and dbus_gvalue_demarshal_message + to handle remote signal callbacks. + (dbus_g_proxy_new_from_proxy): New function; creates a new + DBusGProxy by copying an existing one. + (dbus_g_proxy_get_interface, dbus_g_proxy_set_interface) + (dbus_g_proxy_get_path): New functions. + (dbus_g_proxy_marshal_args_to_message): New function; + factored out of existing code. + (DBUS_G_VALUE_ARRAY_COLLECT_ALL): Collect all arguments + from a varargs array. + (dbus_g_proxy_begin_call_internal): New function. + (dbus_g_proxy_end_call_internal): New function. + (dbus_g_proxy_begin_call): Take GTypes instead of DBus types + as arguments; simply invoke dbus_g_proxy_begin_call_internal + after collecting args into value array. + (dbus_g_proxy_end_call): Take GTypes instead of DBus types; + invoke dbus_g_proxy_end_call_internal. + (dbus_g_proxy_invoke): Simply invoke begin_call_interanl and + end_call_internal. + (dbus_g_proxy_call_no_reply): Take GTypes instead of DBus + types. + (array_free_all): New function. + (dbus_g_proxy_add_signal): Take GTypes. + + * glib/dbus-gobject.h: + (_dbus_glib_marshal_dbus_message_to_gvalue_array): Delete. + (_dbus_gobject_get_path, _dbus_gobject_lookup_marshaller): + Prototype. + + * glib/dbus-gobject.c: Add a global marshal_table hash which + stores mappings from type signatures to marshallers. Change lots + of invocations of dbus_gtype_to_dbus_type to + dbus_gtype_to_signature. + (_dbus_glib_marshal_dbus_message_to_gvalue_array): Delete. + (introspect_signals): Fix test for query.return_type. + (set_object_property): Update invocation of dbus_gvalue_demarshal. + (invoke_object_method): Many changes. Handle asynchronous + invocations. Convert arguments with + dbus_gvalue_demarshal_message. Handle errors. Use + DBusSignatureIter instead of strlen on args. Handle all arguments + generically. Special-case variants. + (dbus_g_method_return, dbus_g_method_return_error): New function. + (DBusGSignalClosure): New structure, closes over signal + information. + (dbus_g_signal_closure_new): New function. + (dbus_g_signal_closure_finalize): New function. + (signal_emitter_marshaller): New function; is special marshaller + which emits signals on bus. + (export_signals): New function; introspects object signals and + connects to them. + (dbus_g_object_type_install_info): Take GType instead of + GObjectClass. + (dbus_g_connection_register_g_object): Invoke export_signals. + (dbus_g_connection_lookup_g_object): New function. + (DBusGFuncSignature) New structure; used for mapping type + signatures to marshallers. + (funcsig_hash): New function; hashes DBusGFuncSignature. + (funcsig_equal): New function; compares DBusGFuncSignature. + (_dbus_gobject_lookup_marshaller): New function. + (dbus_g_object_register_marshaller): New function; used to + register a marshaller at runtime for a particular signature. + + * glib/dbus-gmain.c (_dbus_gmain_test): Add various tests. + + * glib/dbus-binding-tool-glib.h: Add DBUS_GLIB_ANNOTATION_ASYNC + which notes a server method implementation should be + asynchronous. + + * glib/dbus-binding-tool-glib.c + (dbus_binding_tool_output_glib_server): Call + dbus_g_value_types_init. + (write_formal_parameters): Use dbus_gtype_from_signature. Handle + variants specially. + (dbus_g_type_get_lookup_function): Turn GType into an invocation + of a lookup function. + (write_args_for_direction): Use dbus_g_type_get_lookup_function. + (write_untyped_out_args): New method; write output arguments. + (write_formal_declarations_for_direction): Function for + writing prototypes. + (write_formal_parameters_for_direction): Function for + writing implementations. + (write_typed_args_for_direction): Function for writing + arguments prefixed with GTypes. + (write_async_method_client): Write out async version + of method. + + * glib/dbus-binding-tool-glib.c: Include dbus-gvalue-utils.h. + (dbus_g_type_get_marshal_name): Move mapping from GType + to marshal name into here. + (dbus_g_type_get_c_name): Move into here. + (compute_marshaller): Convert signature to type with + dbus_gtype_from_signature, use dbus_g_type_get_marshal_name. + (compute_marshaller_name): Ditto. + (compute_marshaller): Handle async signal annotations. + (gather_marshallers): Return if we don't have a known + prefix. + (generate_glue): Collect introspection blob here, and + write all of the blob at the end. This allows an object + with multiple interfaces to work. + Mark async methods in introspection blob. + + * glib/Makefile.am (libdbus_glib_1_la_SOURCES): Add + dbus-gtype-specialized.c, dbus-gtype-specialized.h, + dbus-gvalue-utils.h, dbus-gvalue-utils.c. + + * dbus/dbus-glib.h: Don't include dbus-protocol.h; this + avoids people accidentally using DBUS_TYPE_* which should + not be necessary anymore. + Do include dbus-gtype-specialized.h, which are utilities + for GLib container types. + Add various #defines for types such as + DBUS_TYPE_G_BOOLEAN_ARRAY. + (DBusGValueIterator, DBusGValue): Define, not fully used + yet. + (dbus_g_value_get_g_type): Type for recursive value. + (dbus_g_value_open, dbus_g_value_iterator_get_value) + (dbus_g_value_iterator_get_values, dbus_g_value_iterator_recurse) + (dbus_g_value_free): Prototypes. + (dbus_g_object_register_marshaller, dbus_g_proxy_new_from_proxy): Prototype. + (dbus_g_proxy_set_interface): Prototype. + (dbus_g_proxy_begin_call, dbus_g_proxy_end_call) + (dbus_g_proxy_call_no_reply): Take GLib types instead of DBus + types. + (dbus_g_proxy_get_path, dbus_g_proxy_get_interface): + Accessors. + (DBusGAsyncData, DBusGMethodInvocation): Structures for + doing async invocations. + (dbus_g_method_return, dbus_g_method_return_error): + Prototypes. + * doc/dbus-tutorial.xml: Update GLib section. + + * tools/dbus-viewer.c (load_child_nodes): Update + for new invocation type of dbus_g_proxy_end_call. + (load_from_service_thread_func): Ditto. + + * tools/print-introspect.c (main): Ditto. + + * tools/dbus-names-model.c (have_names_notify) + (names_model_reload, names_model_set_connection) + Use GTypes. + + * python/Makefile.am (INCLUDES): Define DBUS_COMPILATION, + needed since Python bindings use GLib bindings. + + * test/glib/Makefile.am (INCLUDES): Define DBUS_COMPILATION. + Add --prefix argument. + + * tools/Makefile.am: Define DBUS_COMPILATION. Remove + unneeded --ignore-unsupported arg. + + * test/glib/test-service-glib.c: + * test/glib/test-service-glib.xml: + * test/glib/test-dbus-glib.c: Add many more tests. + +2005-06-06 David Zeuthen <davidz@redhat.com> + + * doc/TODO: Add item about need to remove deprecated functions. + + * dbus/dbus-connection.h: Add prototype for dbus_connection_disconnect + + * dbus/dbus-connection.c (dbus_connection_disconnect): New function + to repair the ABI which was broken with the last commit. + +2005-06-02 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-connection.c, dbus/dbus-connection.h + (dbus_connection_disconnect): renamed to dbus_connection_close + for API symmetry with dbus_connection_open + (_dbus_connection_open_internal): + s/dbus_connection_disconnect/dbus_connection_close + + * dbus/dbus-bus.c (dbus_bus_get): + s/dbus_connection_disconnect/dbus_connection_close + + * bus/connection.c (bus_connections_unref, + bus_connections_setup_connection, bus_connections_expire_incomplete): + s/dbus_connection_disconnect/dbus_connection_close + + * bus/dispatch.c (bus_dispatch, kill_client_connection, + kill_client_connection_unchecked, check_hello_connection): + s/dbus_connection_disconnect/dbus_connection_close + + * bus/bus.c (new_connection_callback): + s/dbus_connection_disconnect/dbus_connection_close + + * tools/dbus-send.c (main): + s/dbus_connection_disconnect/dbus_connection_close + + * test/glib/test-profile.c (no_bus_thread_func, with_bus_thread_func): + s/dbus_connection_disconnect/dbus_connection_close + + * test/test-service.c (path_message_func, filter_func): + s/dbus_connection_disconnect/dbus_connection_close + + * doc/TODO: remove connection_open/connection_disconnect lacks symmetry item that was just fixed + +2005-05-25 Colin Walters <walters@verbum.org> + + * dbus/dbus-protocol.h: Move various bus service #defines such + as DBUS_SERVICE_DBUS and DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT to + dbus/dbus-shared.h. + * dbus/dbus-shared.h: Various defines moved here. + * dbus/dbus-marshal-header.c: Include dbus-shared.h. + +2005-05-25 John (J5) Palmieri <johnp@redhat.com> + + * python/__init__.py: Python bindings deserve a minor version + update. Upped to (0, 40, 2) + +2005-05-24 John (J5) Palmieri <johnp@redhat.com> + + * python/decorators.py: add explicitly_pass_message decorator + for passing in the dbus message as keyword for edge case signal + handling + + * python/matchrules.py (SignalMatchRule.__repr__): fix output + to conform with what dbus expects for match rules + (SignalMatchRule.execute): add the dbus message as a keyword + if the signal handler has requested it + + * python/examples/example/signal-recipient.py: added some more + examples on how to hook up to signals + +2005-05-23 John (J5) Palmieri <johnp@redhat.com> + + * python/decorators.py: import dbus_bindings + + * python/matchrules.py (SignalMatchRule, SignalMatchTree, + SignalMatchNode): new classes that implement wildcard signal + callback matching using a tree lookup. Heavily modified from a + patch sent by Celso Pinto (fd.o bug #3241) + + * _dbus.py (add_signal_receiver, remove_signal_receiver, _signal_func): + use new match classes to handle signals. + +2005-05-19 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx.in: s/TYPE_PATH/TYPE_OBJECT_PATH + +2005-05-18 Havoc Pennington <hp@redhat.com> + + * configure.in: use GLIB_GNU_GETTEXT to get INTLLIBS and require + gettext. Not really worth requiring yet perhaps, but any + production quality 1.0 would require it so we should go ahead and + get things set up. We do have a couple token calls to + bindtextdomain in the code already. + +2005-05-16 John (J5) Palmieri <johnp@redhat.com> + + * glib/dbus-gmain.c (io_handler_dispatch): fix deadlock + when using recursive g_main_loops + + * python/_dbus.py (class Bus): add the ProxyObjectClass + alias for ProxyObject to make it easier for the Twisted + networking framework to integrate dbus. + + * python/proxies.py (class ProxyObject): add the ProxyMethodClass + alias for ProxyMethod to make it easier for the Twisted + networking framework to integrate dbus. + +2005-05-11 Ross Burton <ross@openedhand.com> + + * glib/dbus-glib-tool.c: Add --prefix argument. + * glib/dbus-binding-tool-glib.h: Add prefix argument. + * glib/dbus-binding-tool-glib.c (compute_marshaller_name): + Add prefix argument. + (generate_glue): Pass prefix argument down. + (dbus_binding_tool_output_glib_server): Pass prefix to + glib-genmarshal. + +2005-05-11 Colin Walters <walters@verbum.org> + + * tools/dbus-send.c (append_array): New function. + (append_arg): Broken out from main. + (main): Add cheesy hack to send arrays and variants. + (usage): Update. + * tools/dbus-print-message.c (print_iter): Broken out + from main. + +2005-05-11 Colin Walters <walters@verbum.org> + + * dbus/dbus-signature.c (dbus_signature_iter_get_signature): + New function, returns signature string for signature iter. + * dbus/dbus-signature.h: Prototype it. + * dbus/dbus-message.c (dbus_message_iter_get_signature): + New function, returns signature string for message iter. + (dbus_message_iter_get_array_len): New function, returns + length of array. + (dbus_message_iter_get_fixed_array): Fix assertion; this + function should be used when the iter is pointing to the + contents of an array + * dbus/dbus-message.h: Prototypes. + * dbus/dbus-marshal-recursive.c (_dbus_type_reader_get_array_length): + New function; returns length of an array. + * dbus/dbus-marshal-recursive.h: Prototype it. + +2005-05-11 Colin Walters <walters@verbum.org> + + * dbus/dbus-sysdeps-util.c <!HAVE_POSIX_GETPWNAM_R>: Fix + compilation error. + +2005-05-08 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps-util.c (_dbus_become_daemon): write the + daemon's pid, not the parent's pid, to the file descriptor. + Reported by Taj Morton. + +2005-05-05 Havoc Pennington <hp@redhat.com> + + * configure.in (LT_*): add notes on how the libtool versioning + works to save thinking. Increment soname to indicate protocol + breakage (though really the library interface hasn't changed I + guess) + + * dbus/dbus-transport.c (_dbus_transport_get_is_authenticated): + verify the GUID received from server matches what we were + expecting, if we had an expectation + + * dbus/dbus-auth.c (send_ok): send GUID along with the OK command + (_dbus_auth_get_guid_from_server): new function + (send_begin): parse the OK args + + * doc/dbus-specification.xml: add GUID to the auth protocol + +2005-05-05 John (J5) Palmieri <johnp@redhat.com> + + * Fix my name in previous changelog ;) + + * python/proxies.py (ProxyObject.__getattr__): add further patch + from Anthony Baxter to throw an AttributeError when python + __special__ functions are called instead of marshling them over + the bus (Bug#1685 comment 3). + +2005-05-04 John (J5) Palmieri <johnp@redhat.com> + + * python/Makefile.am: changed to use pyexecdir for the binding + shared libraries (Bug#2494) + + * python/exceptions.py: bring exceptions over from the bindings + so they can be used in applications (Bug#2036) + Make all exceptions derive from DBusException + + * python/_dbus.py, python/proxies.py: implement __repr__ in a couple + of classes so that print obj doesn't throw an exception (Bug #1685) + +2005-05-03 Ross Burton <ross@openedhand.com> + + * glib/dbus-gobject.c (dbus_g_connection_register_g_object): + Return if we get an error during registration. Set up a + weak reference on object to unregister if object is destroyed. + (unregister_gobject): New function. + +2005-05-01 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx.in: + - added new type classes for hinting to the marashaler what type + to send over the wire + - added int16 and uint16 marshalers + - Fixed a bug in the type constants that caused int32 to go out + as uint16 over the wire + * python/dbus.py: split up into different files and renamed _dbus.py + * python/__init__.py, python/_util.py, python/decorators.py, + python/exceptions.py, python/proxies.py, python/services.py, + python/types.py: new files split off from dbus.py + * python/Makefile.am: Add new files, remove dbus.py and + install all python files to <python module dir>/dbus + * python/examples/*: Added #!/usr/bin/env python to the top of + every example. Patch provided by Tatavarty Kalyan + +2005-04-25 John (J5) Palmieri <johnp@redhat.com> + + * NEWS: Update to 0.33 + +2005-04-25 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx.in (send_with_reply_handlers): New send + method for doing async calls + (_pending_call_notification): New C function for handling pendning call + callbacks + (set_notify): New method for setting pending call notification + + * python/dbus.py: new version tuple "version" is set at (0, 40, 0) + Async capabilities added to remote method calls + (Sender): class removed + (RemoteService): class removed + (ObjectTree): class removed for now + (RemoteObject): Renamed to ProxyObject + (RemoteMethod): Renamed to ProxyMethod + (method): Decorator added for decorating python methods as dbus methods + (signal): Decorator added for decorating python methods as signal emitters + (ObjectType): Metaclass added for generating introspection data and the + method callback vtable + (Interface): Wrapper class added to wrap objects in a dbus interface + (Object): Uses ObjectType as its metaclass and exports Introspect + of the org.freedesktop.DBus.Introspectable interface + (ValidationException, UnknownMethodException): new exceptions + + * python/examples/*: Modified to fit with the new bindings + +2005-04-23 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c (dbus_message_append_args): fix doc comment, + reported by Tony Houghton + + * test/test-service.c (main): test + dbus_connection_get_object_path_data() + + * dbus/dbus-object-tree.c (find_handler): be sure we always init + the exact_match + (_dbus_object_tree_get_user_data_unlocked): new function used by + dbus_connection_get_object_path_data() + (do_register): add assertion test for get_user_data_unlocked + (object_tree_test_iteration): more tests + + * dbus/dbus-connection.c (dbus_connection_get_object_path_data): + new function from Dan Reed to let you get the user data from + dbus_connection_register_object_path() + +2005-04-23 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-marshal-recursive-util.c: Fixed buffer overflow + in numerous places that did not account for the NULL terminator + (signature_from_seed): changed the manual string copy loop to + just use strcpy instead + make check should now pass + +2005-04-19 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-marshal-header.c (_dbus_header_create): Fix assert + so that it allows messages that are not signals to pass in + NULL as the interface. + +2005-04-18 David Zeuthen <davidz@redhat.com> + + * glib/dbus-gmain.c (io_handler_destroy_source): + (timeout_handler_destroy_source, connection_setup_free): + Also unref the source to avoid memory leaks. + +2005-04-13 David Zeuthen <davidz@redhat.com> + + * bus/config-parser.c (bus_config_parser_new): Bump this to a + more reasonable, yet still totally arbitrary, value :-). + +2005-04-13 David Zeuthen <davidz@redhat.com> + + * doc/TODO: Added an "important for 1.0" item about selinux + allow/deny messages + +2005-04-13 David Zeuthen <davidz@redhat.com> + + * bus/selinux.c: Add c-file-style to top of file + (log_audit_callback): Don't free the data here anymore + (bus_selinux_check): Don't take spid and tpid since appending + that to auxdata may OOM. + (bus_selinux_allows_acquire_service): Handle OOM and signal back + to the caller if we are OOM by taking an error object. + (bus_selinux_allows_send): -do- + + * bus/selinux.h: Fix prototypes for bus_selinux_allows_acquire_service + and bus_selinux_allows_send + + * bus/bus.c (bus_context_check_security_policy): Pass error and + pass on OOM thrown by bus_selinux_allows_send() + + * bus/services.c (bus_registry_acquire_service): Pass error and + pass on OOM thrown by bus_selinux_allows_acquire_service() + +2005-04-13 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gmain.c (message_queue_dispatch): only dispatch one + message at a time to avoid monopolizing the main loop, bug + #2953 from Benjamin Otte + +2005-04-09 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-string.c (copy): change a memcpy to memmove due to + possible overlap, fix from Daniel Reed + (fixup_alignment): fix signedness warnings + (_dbus_string_append_unichar): ditto + +2005-04-09 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message-util.c (_dbus_message_test): fix signedness warning + + * glib/dbus-glib-tool.c (main): fix warning + + * glib/dbus-binding-tool-glib.c (generate_glue): fix warning + + * dbus/dbus-connection.c (dbus_connection_read_write_dispatch): + add a new function that can be used in simple applications that + don't have a main loop and are willing to block + +2005-04-05 David Zeuthen <davidz@redhat.com> + + Fix https://bugs.freedesktop.org/show_bug.cgi?id=2889 + + * glib/dbus-gmain.c: + (io_handler_destroy_source): Remove from list of IO handlers + of the ConnectionSetup object + (timeout_handler_destroy_source): -do- for timeout handlers + (io_handler_source_finalized): Don't remove from list since + we now do that in io_handler_destroy_source(). Renamed from + io_handler_source_destroyed + (timeout_handler_source_destroyed): -do- for timeout handlers + (connection_setup_free): It is now safe to iterate over all + IO and timeout handlers as the _destroy_source removes them + from the list synchronously + +2005-03-30 Havoc Pennington <hp@redhat.com> + + * configure.in: change check to gtk 2.4 + + * tools/dbus-viewer.c (name_combo_changed_callback): remove + gtk_combo_box_get_active_text() usage to decrement GTK requirement + to 2.4 + +2005-03-29 John (J5) Palmieri <johnp@redhat.com> + + * News: Update 0.32 + + * HACKING: Fixed realease instructions. configure.in should be updated to + the next release by the person who made the last release. + +2005-03-29 John (J5) Palmieri <johnp@redhat.com> + + * python/lvalue_cast_post_process.py - removed. Patch has been + submitted to Pyrex maintainers that fixes gcc4.0 errors + + * python/Makefile.am: removed refrences to lvalue_cast_post_process.py + +2005-03-24 Daniel Reed <n@ml.org> + + * tools/Makefile.am: Make print-introspect and + dbus-bus-introspect.xml building conditional on HAVE_GLIB. + +2005-03-22 John (J5) Palmieri <johnp@redhat.com> + + * tools/Makefile.am: Patch by Colin Walters that fixes distcheck + + * dbus/dbus-userdb.c, dbus/dbus-userdb-util.c: Add patch we have + had in Red Hat packages for a while but for some reason never + got merged upstream + (_dbus_is_a_number): New checks if a string + can be converted to a number and does the conversion if it can + (_dbus_user_database_lookup): Add check to see if the given username + is a udi. This allows udi's to be used instead of usernames in the + config file. + (_dbus_user_database_lookup_group): Add check to see if the given groupname + is a gdi. This allows gdi's to be used instead of groupnames in the + config file. + +2005-03-21 John (J5) Palmieri <johnp@redhat.com> + + * python/lvalue_cast_post_process.py - added post processor to fix Pyrex + code so that it compiles with gcc4.0 + + * python/Makefile.am: Added lvalue_cast_post_process.py to EXTRA_DIST + run dbus_bindings.c through lvalue_cast_post_process.py and copy the + results back to dbus_binding.c + +2005-03-20 Colin Walters <walters@verbum.org> + + Patch suggested by Inguva Rajasekhar <ringuva@novell.com>. + + * configure.in: Require GTK+ 2.6. + +2005-03-20 Colin Walters <walters@verbum.org> + + * Makefile.am (SUBDIRS, DIST_SUBDIRS): Build tools before test. + +2005-03-17 Tom Parker <palfrey@tevp.net> + + * dbus/dbus-userdb.c (_dbus_user_database_lookup): Don't + print DBUS_UID_UNSET; instead print passed username. Also + be sure to actually use gid looked up in cache. + + * dbus/dbus-userdb-util.c (_dbus_user_database_lookup_group): Ditto + for DBUS_GID_UNSET and groupname. + +2005-03-17 Colin Walters <walters@verbum.org> + + * bus/print-introspect.c: Move to tools/. + * bus/run-with-tmp-session-bus.sh: Ditto. + + * glib/Makefile.am (dbus-glib-bindings.h): Move + generation to tools/Makefile.am. + + * test/glib/run-test.sh: Update to handle move + of run-with-tmp-session-bus.sh. + + * test/glib/test-service-glib.c: Update to handle + move of dbus-glib-bindings.h. + + * tools/print-introspect.c: Moved here + from bus/, and ported to GLib bindings. + + * tools/run-with-tmp-session-bus.sh: Moved here + from bus/. + + * tools/Makefile.am: Generate dbus-glib-bindings.h + and dbus-bus-introspect.xml here. + + * tools/.cvsignore, glib/.cvsignore, bus/.cvsignore: + Update. + +2005-03-17 Colin Walters <walters@verbum.org> + + * bus/driver.c (write_args_for_direction): Use + _dbus_string_get_const_data to retrieve string; + _dbus_string_get_const_data_len doesn't actually return + a NULL-terminated substring. + + * test/glib/test-service-glib.c: Include dbus-glib-bindings.h. + (main): Change to use org_freedesktop_DBus_request_name + instead of using g_proxy_begin_call/end_call. + +2005-03-15 Joe Shaw <joeshaw@novell.com> + + * mono/ProxyBuilder.cs (BuildFinalizer): Fix some invalid IL when + generating the finalizer. Fixes from Ben Maurer. + +2005-03-12 Joe Shaw <joeshaw@novell.com> + + * mono/BusDriver.cs: Update method names: ListServices + becomes ListNames; GetOwner becomes GetNameOwner. + + * mono/ProxyBuilder.cs (BuildFinalizer): Need to load arg 0 + onto the eval stack when removing the delegate. + +2005-03-12 Joe Shaw <joeshaw@novell.com> + + * mono/dbus-sharp.dll.config.in: Don't hardcode 0 for + LT_CURRENT. Set it to the autoconf variable. + + * mono/ProxyBuilder.cs: Add a finalizer to the generated proxy + classes that disconnects the signal handler delegate from the + service object. Fixes a big leak of proxy objects on the + client side of things. Patch from Ben Maurer + <bmaurer@ximian.com> + +2005-03-12 Colin Walters <walters@verbum.org> + + * bus/driver.c (write_args_for_direction): New function, + parses a type signature into arguments and outputs to + XML. + (bus_driver_handle_introspect): Use it instead of + hardcoding XML for certain signatures. + + * bus/Makefile.am (dbus-bus-introspect.xml): Add + dependency on dbus-daemon. + + * glib/dbus-glib-tool.c (main): Parse ignore_unsupported + argument, pass it to dbus_binding_tool_output_glib_client. + + * glib/dbus-binding-tool-glib.c + (generate_client_glue): Protect against multiple inclusion. + (dbus_binding_tool_output_glib_client): Add + G_BEGIN_DECLS/G_END_DECLS. + + * glib/dbus-binding-tool-glib.c (compute_client_method_name): + Change to just take iface prefix directly. + (write_formal_parameters): Clarify error message. + (check_supported_parameters): New function; checks to see type + signatures of method parameters are supported. + (generate_client_glue): Handle ignore_unsupported flag. + (dbus_binding_tool_output_glib_client): Handle ignore_unsupported + parameter. + + * glib/Makefile.am (dbus-glib-bindings.h): Pass + --ignore-unsupported by default until glib bindings + support arrays. + +2005-03-11 Colin Walters <walters@verbum.org> + + * glib/Makefile.am: Generate dbus-glib-bindings.h and + install it. + + * bus/print-introspect.c: New file; prints introspection + data for a given name and object path. + + * bus/run-with-tmp-session-bus.sh: New file, refactored + from test/glib/run-test.sh. Creates a temporary session + bus and runs another program. + + * test/glib/run-test.sh: Refactor to invoke + run-with-tmp-session-bus.sh. + + * bus/driver.c (bus_driver_handle_introspect): Fix to print new + introspection format. Also change to use DBUS_TYPE_x_AS_STRING + macros instead of hardcoding. + + * glib/.cvsignore, bus/.cvsignore, test/glib/.cvsignore: Update. + +2005-03-11 Joe Shaw <joeshaw@novell.com> + + * dbus/dbus-connection.c (dbus_connection_send_with_reply): Remove + this unref; it doesn't match up evenly in some codepaths. + (_dbus_connection_block_pending_call): Unref at every exitpoint; + this evenly matches with the ref near the top of this function. + +2005-03-09 Joe Shaw <joeshaw@novell.com> + + * dbus/dbus-object-tree.c + (_dbus_object_tree_unregister_and_unlock): If checks are enabled + and we try to unregister a path that's not registered, still go + through the process of unlocking and don't just return. + +2005-03-09 Colin Walters <walters@verbum.org> + + * glib/dbus-gproxy.c (dbus_g_proxy_invoke): New method; calls + to this are generated for client-side wrappers. Invokes a + D-BUS method and returns reply values. + + * glib/dbus-binding-tool-glib.c (write_args_sig_for_direction): New + function; writes signature string for argument direction. + (write_args_for_direction): Change to pass input values directly + instead of via address, and fix indentation. + (generate_client_glue): Change to invoke dbus_g_proxy_invoke. Also + make generated wrappers inlineable. + + * dbus/dbus-message.c (dbus_message_iter_get_fixed_array): Add + note about using dbus_type_is_fixed. + + * dbus/dbus-marshal-basic.c (_dbus_type_is_fixed): Moved to + dbus/dbus-signature.c as dbus_type_is_fixed. + + All callers updated. + + * dbus/dbus-signature.c (dbus_type_is_fixed): Moved here + from dbus/dbus-marshal-basic.c:_dbus_type_is_fixed. + + * dbus/dbus-signature.h: Prototype. + + * glib/dbus-binding-tool-glib.c (compute_marshaller_name): Fix + error printf code. + + * test/glib/test-dbus-glib.c (main): Be sure to clear error as + appropriate instead of just freeing it. + (main): Free returned strings using g_free. + + * test/glib/Makefile.am (test-service-glib-glue.h) + (test-service-glib-bindings.h): Add dependency on dbus-binding-tool. + + * glib/dbus-gvalue.c (MAP_BASIC): Refactored from MAP_BASIC_INIT; + simply maps a simple D-BUS type to GType. + (dbus_dbus_type_to_gtype): Function which maps D-BUS type to + GType. + (dbus_gvalue_init): Just invoke dbus_dbus_type_to_gtype and + initialize the value with it. + (dbus_gvalue_binding_type_from_type): Unused, delete. + (dbus_gvalue_demarshal): Switch to hardcoding demarshalling for + various types instead of unmarshalling to value data directly. + Remove can_convert boolean. + (dbus_gvalue_marshal): Remove duplicate initialization; switch to + returning directly instead of using can_convert boolean. + (dbus_gvalue_store): New function; not related to D-BUS per-se. + Stores a GValue in a pointer to a value of its corresponding C + type. + + * glib/dbus-gvalue.h: Remove dbus_gvalue_binding_type_from_type, + add dbus_gvalue_store. + +2005-03-08 Joe Shaw <joeshaw@novell.com> + + Fix a bunch of lifecycle and memory management problems + in the mono bindings. + + * mono/Arguments.cs (Arguments): Implement IDisposable + + * mono/Bus.cs (Bus): Don't allow public instantiation. This is + strictly a static class. + + * mono/Connection.cs: Move the DBusObjectPathVTable and associated + delegates into this file. + (Connection): Implement IDisposable. + (Dispose): Disconnect the connection and set the raw connection + pointer to IntPtr.Zero. + (~Connection): Call Dispose(). + (RegisterObjectPath): Added. Manages the registration of object + paths so we can cleanly disconnect them at dispose/finalize time. + (UnregisterObjectPath): Ditto. + (set_RawConnection): Unregister all of the object paths when + changing the underlying DBusConnection. Add them back onto the + new connection, if any. + + * mono/Handler.cs: Don't implement IDisposable; it doesn't use any + more unmanaged resources anymore, so it's not necessary. Move all + the DBusObjectPathVTable stuff out of here. + (Handler): Save references to our delegates so that they don't get + finalized. Call Connection.RegisterObjectPath() instead of + dbus_connection_register_object_path() directly. + (Message_Called): Dispose the message after we're finished with + it. + + * mono/Message.cs (Message): Implement IDisposable. + (Dispose): Dispose the Arguments, and set the RawMessage to + IntPtr.Zero. + (SendWithReplyAndBlock): We own the ref to the reply that comes + back from dbus_connection_send_with_reply_and_block() so add a + comment about that and unref it after we've constructed a managed + MethodReturn class around it. Fixes a big, big leak. + + * mono/ProxyBuilder.cs: Reflect into Message to get the Dispose + method. + (BuildSignalHandler): After we've sent the Signal message, dispose + of it. + (BuildMethod): Dispose of the method call and reply messages after + we've sent the message and extracted the data we want from the + reply. + + * mono/Service.cs (UnregisterObject): Don't call handler.Dispose() + anymore. + (Service_FilterCalled): Dispose of the message after we're + finished with it. + +2005-03-08 Joe Shaw <joeshaw@novell.com> + + * dbus/dbus-connection.c (dbus_connection_send_with_reply): + After we attach our pending call to the connection, unref + it. Fixes a leak. + + * mono/Connection.cs (set_RawConnection): Disconnect our + filter and match callbacks from the old connection and + reconnect them to the new connection, if any. + + * mono/DBusType/Array.cs: "Code" is a static member, so + don't use "this" to refer to it. Fix for stricter checking + in Mono 1.1.4. + + * mono/DBusType/ObjectPath.cs (Append): Don't leak the + object path that we pass into unmanaged code. + + * mono/DBusType/String.cs (Append): Don't leak the string + that we pass into unmanged code. + +2005-03-07 John (J5) Palmieri <johnp@redhat.com> + * NEWS: Update for 0.31 + + * configure.in: Release 0.31 + add LT_CURRENT, LT_REVISION, LT_AGE for easy soname bumping + + * qt/Makefile.am: fixed build + + * dbus/Makefile.am: soname bump for libdbus + + * glib/Makefile.am: soname bump for libdbus-glib + +2005-03-05 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c: + (pseudorandom_generate_random_bytes_buffer): fix to have no return + value + (_dbus_generate_random_bytes_buffer): fix return value + + * dbus/dbus-sysdeps-util.c: s/GETPWNAME/GETPWNAM/ so configure + checks actually work, from Tom Parker <fdo@tevp.net> + +2005-03-01 Colin Walters <walters@verbum.org> + + * test/glib/test-dbus-glib.c (lose, lose_gerror): Utility + functions copied from dbus-glib-tool.c. + (main): Convert lots of error code to use them. + Also add some testing for introspection bits. + +2005-03-01 Colin Walters <walters@verbum.org> + + * doc/TODO: Remove introspection signature TODO. + +2005-02-27 Colin Walters <walters@verbum.org> + + * glib/dbus-gidl.c (property_info_get_type, arg_info_get_type): + Change return value to const char * instead of int so we can do + full signatures. + (struct PropertyInfo, struct ArgInfo): Store char *. + (property_info_new, arg_info_new): Update parameters, strdup. + (property_info_unref, arg_info_unref): Free. + + * glib/dbus-gidl.h: Update prototypes. + + * glib/dbus-gparser.c (basic_type_from_string): Delete. + (validate_signature): New function, just validates signature and + sets GError. + (parse_property, parse_arg): Invoke validate_signature. Store + signature instead of just type code. + + * glib/dbus-gvalue.c (base_type_from_signature): New utility + function to return a primary type for a signature, dropping + information about types in container types. + (dbus_gvalue_genmarshal_name_from_type) + (dbus_gvalue_binding_type_from_type) + (dbus_gvalue_ctype_from_type): Update to take full signature + instead of type code. + (dbus_gtype_to_dbus_type): Moved here from glib/dbus-gobject.c. + + * glib/dbus-gvalue.h: Update prototypes for above. + + * glib/dbus-gobject.c (gtype_to_dbus_type): Moved to + glib/dbus-gvalue.c as dbus_gtype_to_dbus_type. + (introspect_properties, introspect_signals, write_interface): + Update to handle signatures, and remove usage of + _dbus_gutils_type_to_string. + (handle_introspect): Print out type codes instead of e.g. "string" + in hardcoded introspection XML; also use x_AS_STRING constants + instead of hardcoding in string. + + * glib/dbus-glib-tool.c (pretty_print): Handle signature change + to string. Remove usage of _dbus_gutils_type_to_string. + + * glib/dbus-gutils.c (_dbus_gutils_type_to_string): Delete. + + * glib/dbus-gutils.h (_dbus_gutils_type_to_string): Update for + deletion. + + * glib/dbus-binding-tool-glib.c (compute_marshaller) + (compute_marshaller_name, generate_glue): Handle signature change + to string. + (write_formal_parameters, write_args_for_direction): Ditto, and + remove FIXME. + + * tools/dbus-tree-view.c (type_to_string): Delete. + (info_set_func_text): Update to print full signatures. + + * test/glib/test-service-glib.xml: Change types to new + introspection format. + +2005-02-26 Havoc Pennington <hp@redhat.com> + + * doc/TODO: remove the "guid" item + + * test/glib/test-profile.c (no_bus_thread_func): use open_private + (with_bus_thread_func): use open_private + + * dbus/dbus-connection.c (dbus_connection_open_private): new + function that works like the old dbus_connection_open() + (dbus_connection_open): now returns an existing connection if + possible + + * dbus/dbus-server-unix.c (handle_new_client_fd_and_unlock): pass + through the GUID to the transport + + * dbus/dbus-server.c (_dbus_server_init_base): keep around the + GUID in hex-encoded form. + + * dbus/dbus-server-debug-pipe.c (_dbus_transport_debug_pipe_new): + pass GUID argument in to the transport + + * dbus/dbus-transport-unix.c (_dbus_transport_new_for_fd): add + guid argument + + * dbus/dbus-transport.c (_dbus_transport_init_base): add guid argument + + * dbus/dbus-auth.c (_dbus_auth_server_new): add guid argument + +2005-02-25 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.xml: document the GUID thing + + * dbus/dbus-server.c (_dbus_server_init_base): initialize a + globally unique ID for the server, and put a "guid=hexencoded" + field in the address + + * dbus/dbus-bus.c: fix missing #include of dbus-threads-internal.h + + * dbus/dbus-message.c: ditto + + * dbus/dbus-dataslot.c: ditto + + * dbus/dbus-list.c: ditto + + * dbus/dbus-internals.h: wait, just include + dbus-threads-internal.h here + + * dbus/dbus-string.c (_dbus_string_copy_to_buffer): move back for + use in main library + + * dbus/dbus-sysdeps.c (_dbus_generate_random_bytes_buffer): new function + +2005-02-24 Colin Walters <walters@verbum.org> + + * test/glib/Makefile.am (EXTRA_DIST): Add test-service-glib.xml + +2005-02-24 John (J5) Palmieir <johnp@redhat.com> + + * glib/Makefile.am: added dbus-gobject.h to sources list + so distcheck doesn't fail + +2005-02-24 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-server.c, dbus/dbus-server-unix.c: change semantics so + you must disconnect before unref, since locking and other things + are screwed up otherwise. Fix assorted other locking stuff. + + * dbus/dbus-signature.c (dbus_signature_iter_get_element_type): + fix compilation + + * dbus/dbus-threads-internal.h: move the mutex/condvar wrappers + into a private header and don't export from the library + + * throughout - call _dbus_thread_stuff vs. dbus_thread_stuff + +2005-02-24 Colin Walters <walters@verbum.org> + + * dbus/dbus-signature.c: New file; implements various functions + related to type signatures. Includes an interator for parsing, + validation functions. + (dbus_type_is_basic): Moved here from + dbus-marshal-basic.c:_dbus_type_is_basic. + (dbus_type_is_container): Moved here from + dbus-marshal-basic.c:_dbus_type_is_container. + + All callers of _dbus_type_is_container and _dbus_type_is_basic + updated, and include dbus-signature.h. + + * dbus/dbus-signature.h: New file; prototypes for the above. + + * dbus/Makefile.am (DBUS_LIB_SOURCES): Add dbus-signature.c, + dbus-signature.h. + + * dbus/dbus-marshal-basic.c (map_type_char_to_type): New utility + function factored out of _dbus_first_type_in_signature. + (_dbus_first_type_in_signature_c_str): New function; returns first + type code for a type signature character. + + * dbus/dbus-marshal-basic.h: Prototype _dbus_first_type_in_signature_c_str, + handle function moves. + + * dbus/dbus-marshal-recursive.h: Export _dbus_type_signature_next. + + * dbus/dbus-marshal-recursive.c (_dbus_type_signature_next): New + function; skips to next complete type in type signature. + Implemented using previous skip_one_complete_type. Now + skip_one_complete_type just delegates to + _dbus_type_signature_next. + + * dbus/dbus-marshal-basic.c (_dbus_type_is_basic): Moved + to dbus-signature.c + (_dbus_type_is_container): Ditto. + + * doc/dbus-specification.xml: Update introspection sample to + use real type signatures. + + * dbus/dbus-test.h: Prototype signature test. + + * dbus/dbus-test.c (dbus_internal_do_not_use_run_tests): Run + signature tests. + + * dbus/dbus-protocol.h (DBUS_ERROR_INVALID_SIGNATURE): New error. + +2005-02-23 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx.in (PendingCall::get_reply): + s/dbus_pending_call_get_reply/dbus_pending_call_steal_reply + +2005-02-21 Colin Walters <walters@verbum.org> + + * dbus/dbus-test-main.c (main): Take optional specific test + argument. + + * dbus/dbus-test.c (run_test): New function, runs a test function + with no data directory. + (run_data_test): Like above, but takes data directory. + (dbus_internal_do_not_use_run_tests): Take + specific test argument. Replace lots of cut n' paste code + with run_test and run_data_test. + + * dbus/dbus-test.h: Update prototype for + dbus_internal_do_not_use_run_tests. + +2005-02-20 Havoc Pennington <hp@redhat.com> + + Fix bugs reported by Daniel P. Berrange + + * dbus/dbus-server.c (_dbus_server_unref_unlocked): new function + (protected_change_watch): new function + (_dbus_server_toggle_watch, _dbus_server_remove_watch) + (_dbus_server_add_watch): change to work like the + dbus-connection.c equivalents; like those, probably kind of + busted, but should at least mostly work for now + (dbus_server_disconnect): drop the lock if we were already + disconnected, patch from Daniel P. Berrange + + * dbus/dbus-server.c (_dbus_server_toggle_timeout) + (_dbus_server_remove_timeout, _dbus_server_add_timeout): all the + same stuff + + * doc/TODO: todo about unscrewing this mess + +2005-02-19 Colin Walters <walters@verbum.org> + + * glib/dbus-binding-tool-glib.c + (dbus_binding_tool_output_glib_server): Fix iochannel refcounting. + + * glib/dbus-glib-tool.c: Include dbus-glib-tool.h, as well + as errno.h and sys/stat.h. + (lose): New function, prints error with + newline and exits. + (lose_gerror): Similar, but takes GError for message. + (main): Add --output argument to specify output file to write to, + instead of always printing to stdout. In this mode, determine + timestamps on source files to see whether any are newer than the + target file. If not, exit. Also convert a number of error + messages to use lose (since it's shorter), and switch to using + g_io_channel_shutdown. + +2005-02-19 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gobject.c + (_dbus_glib_marshal_dbus_message_to_gvalue_array): add docs + + * glib/dbus-glib.c: fix doxygen warnings + + * glib/dbus-gparser.c (parse_annotation): error if an annotation + is found on an <arg> + +2005-02-17 Colin Walters <walters@verbum.org> + + * glib/dbus-gobject.h: Don't export + _dbus_glib_marshal_dbus_message_to_gvalue_array. + + * glib/dbus-gobject.c (_dbus_glib_marshal_dbus_message_to_gvalue_array): Do rename. + (invoke_object_method): Handle it. + + * glib/dbus-gproxy.c (marshal_dbus_message_to_g_marshaller): + Handle rename. + +2005-02-17 Colin Walters <walters@verbum.org> + + * bus/.cvsignore, doc/.cvsignore + * test/data/valid-service-files/.cvsignore, test/glib/.cvsignore: + Update. + +2005-02-17 Colin Walters <walters@verbum.org> + + * dbus/dbus-protocol.h (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS): + Rename to DBUS_SERVICE_DBUS. + (DBUS_PATH_ORG_FREEDESKTOP_DBUS): Rename to DBUS_PATH_DBUS. + (DBUS_PATH_ORG_FREEDESKTOP_LOCAL): Rename to DBUS_PATH_LOCAL. + Change the value from "org.freedesktop.Local" + to "org.freedesktop.DBus.Local". + (DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS): Rename to DBUS_INTERFACE_DBUS. + (DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE): Rename to + DBUS_INTERFACE_INTROSPECTABLE. + Change the value from "org.freedesktop.Introspectable" + to "org.freedesktop.DBus.Introspectable". + (DBUS_INTERFACE_ORG_FREEDESKTOP_PROPERTIES): Rename to + DBUS_INTERFACE_PROPERTIES. + Change the value from "org.freedesktop.Properties" + to "org.freedesktop.DBus.Properties". + (DBUS_INTERFACE_ORG_FREEDESKTOP_PEER): Rename to + DBUS_INTERFACE_PEER. + Change the value from "org.freedesktop.Peer" + to "org.freedesktop.DBus.Peer". + (DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL): + DBUS_INTERFACE_LOCAL. + Change the value from "org.freedesktop.Local" + to "org.freedesktop.DBus.Local". + + All other users of those constants have been changed. + + * bus/driver.c (bus_driver_handle_introspect): Use constants. + + * glib/dbus-gobject.c (handle_introspect): Use constants. + + * doc/dbus-faq.xml, doc/dbus-specification.xml: Update for rename. + +2005-02-17 Colin Walters <walters@verbum.org> + + * glib/dbus-gparser.c (struct Parser): Add in_annotation boolean. + (parse_node, parse_interface, parse_method, parse_signal) + (parse_property, parse_annotation): Lose if we're currently in an + annotation. + (parse_annotation): New function. + (parser_start_element, parser_end_element): Handle annotation. + (parse_method, parse_interface): Remove support for c_name attribute, + switch to annotations. + + * glib/dbus-gidl.h (interface_info_get_binding_names) + (method_info_get_binding_names) + (interface_info_get_binding_name, method_info_get_binding_name) + (interface_info_set_binding_name, method_info_set_binding_name): + Remove. + (interface_info_get_annotations, method_info_get_annotations) + (interface_info_get_annotation, method_info_get_annotation) + (interface_info_add_annotation, method_info_add_annotation): + Prototype. + + * glib/dbus-gidl.c (struct InterfaceInfo): Substitute "annotations" + for "bindings". + (struct MethodInfo): Ditto. + Straightfoward conversion of binding methods into annotation methods + as prototyped. + + * glib/dbus-glib-tool.c (pretty_print): Print annotations. + + * glib/dbus-binding-tool-glib.h (DBUS_GLIB_ANNOTATION_C_SYMBOL): Define. + + * glib/dbus-binding-tool-glib.c (gather_marshallers, generate_glue): + Use new annotation API. + + * doc/introspect.dtd: Fix a number of DTD syntax errors. Add + annotation element. + + * doc/dbus-specification.xml: Discuss introspection annotations, + include list of well-known annotations. + + * test/glib/test-service-glib.xml: Make validate against new DTD. + +2005-02-17 Colin Walters <walters@verbum.org> + + This patch is based on initial work from + Paul Kuliniewicz <kuliniew@purdue.edu>. + + * glib/dbus-gvalue.c (dbus_gvalue_init): New function; move + initialization of GValue from dbus type to here. + (dbus_gvalue_genmarshal_name_from_type): New function; generates a string + for the "glib-genmarshal" program from a DBus type. + (dbus_gvalue_binding_type_from_type): New function; turns a DBus type + into the C name for it we use in the glib bindings. + (dbus_gvalue_ctype_from_type): New function; maps a DBus type into a + glib C type (not GValue). + (dbus_gvalue_demarshal): invoke dbus_gvalue_init. + + * glib/dbus-gutils.c (_dbus_gutils_wincaps_to_uscore): Moved here + from dbus-gobject.c. + + * glib/dbus-gutils.h: Prototype it. + + * glib/dbus-gproxy.c: Include new dbus-gobject.h. + (marshal_dbus_message_to_g_marshaller): Use new shared function + dbus_glib_marshal_dbus_message_to_gvalue_array. + + * glib/dbus-gparser.c (parse_interface, parse_method): Handle c_name attribute. + Will be changed once we have annotations. + + * glib/dbus-gobject.c: Change info_hash_mutex from GStaticMutex to + GStaticRWLock. Callers updated. + (wincaps_to_uscore): Move to dbus-gutils.c. Callers updated. + (string_table_next): New function for iterating over zero-terminated + string value array. + (string_table_lookup): New function; retrieves specific entry in + array. + (get_method_data): New function; look up method data in object data chunk. + (object_error_domain_prefix_from_object_info) + (object_error_code_from_object_info): New functions, but not implemented yet. + (method_interface_from_object_info): New function; retrieve interface name. + (method_name_from_object_info): New function; retrieve method name. + (method_arg_info_from_object_info): New function; retrieve argument data. + (arg_iterate): New function; iterates over serialized argument data. + (method_dir_signature_from_object_info): New function; returns a + GString holding type signature for arguments for just one + direction (input or output). + (method_input_signature_from_object_info) + (method_output_signature_from_object_info): New functions. + (dbus_glib_marshal_dbus_message_to_gvalue_array): New shared function; + converts dbus message arguments into a GValue array. Used for both + signal handling and method invocation. + (struct DBusGlibWriteIterfaceData): New utility structure. + (write_interface): New function; generate introspection XML for + an interface. + (introspect_interfaces): New function; gathers all interface->methods, + generates introspection XML for them. + (handle_introspect): Invoke introspect_interfaces. + (get_object_property): Be sure to zero-initalize stack-allocated GValue. + (lookup_object_and_method): New function; examines an incoming message + and attempts to match it up (via interface, method name, and argument + signature) with a known object and method. + (gerror_domaincode_to_dbus_error_name): New function; converts a + GError domain and code into a DBus error name. Needs GError data + added to object introspection to work well. + (gerror_to_dbus_error_message): Creates a DBusMessage error return from + GError. + (invoke_object_method): New function to invoke an object method + looked up via lookup_object_and_method. Parses the incoming + message, turns it into a GValue array, then invokes the marshaller + specified in the DBusGMethodInfo. Creates a new message with + either return values or error message as appropriate. + (gobject_message_function): Invoke lookup_object_and_method and + invoke_object_method. + + * glib/dbus-glib-tool.c: Include dbus-binding-tool-glib.h. + (enum DBusBindingOutputMode): New enum for binding output modes. + (pretty_print): Print binding names. + (dbus_binding_tool_error_quark): GError bits. + (version): Fix typo. + (main): Create GIOChannel for output. Parse new --mode argument, + possible values are "pretty-print", "glib-server", "glib-client". + Use mode to invoke appropriate function. + + * glib/dbus-gobject.h: Prototype dbus_glib_marshal_dbus_message_to_gvalue_array. + + * glib/dbus-glib-tool.h: New header, just includes GError bits + for now. + + * glib/dbus-gidl.c (struct InterfaceInfo): Add bindings hashtable; + maps binding style to name. + (struct MethodInfo): Ditto. + (get_hash_keys, get_hash_key): Utility function, returns keys for + a GHashTable. + (interface_info_new, method_info_new): Initialize bindings. + (interface_info_unref, method_info_unref): Destroy bindings. + (method_info_get_binding_names, method_info_get_binding_name) + (interface_info_get_binding_names, interface_info_get_binding_name): + Functions for retrieving binding names. + (method_info_set_binding_name, interface_info_set_binding_name): + Functions for setting binding names. + + * glib/dbus-binding-tool-glib.h: New file, has prototypes + for glib binding generation. + + * glib/dbus-binding-tool-glib.c: New file, implements server-side + and client-side glib glue generation. + + * glib/Makefile.am (dbus_binding_tool_SOURCES): Add + dbus-binding-tool-glib.c, dbus-binding-tool-glib.h, + dbus-glib-tool.h. + + * dbus/dbus-glib.h (struct DBusGMethodMarshaller): Remove in favor + of using GClosureMarshal directly. + (struct DBusGObjectInfo): Add n_infos member. + + * test/glib/test-service-glib.xml: New file; contains introspection data + for MyTestObject used in test-service-glib.c. + + * test/glib/test-service-glib.c (enum MyObjectError): New GError enum. + (my_object_do_nothing, my_object_increment, my_object_throw_error) + (my_object_uppercase, my_object_many_args): New test methods. + (main): Use dbus_g_object_class_install_info to include generated object + info. + + * test/glib/Makefile.am: Generate server-side glue for test-service-glib.c, + as well as client-side bindings. + + * test/glib/test-dbus-glib.c: Include test-service-glib-bindings.h. + (main): Activate TestSuiteGLibService; test invoke a bunch of its methods + using both the dbus_gproxy stuff directly as well as the generated bindings. + +2005-02-15 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c (dbus_connection_dispatch): always + complete a pending call, don't run filters first. + + * glib/dbus-gproxy.c (dbus_g_proxy_end_call): change to use + dbus_pending_call_steal_reply + + * dbus/dbus-pending-call.c (dbus_pending_call_block): just call + _dbus_connection_block_pending_call + (dbus_pending_call_get_reply): change to steal_reply and return a + ref + + * dbus/dbus-connection.c + (dbus_connection_send_with_reply_and_block): port to work in terms + of DBusPendingCall + (_dbus_connection_block_pending_call): replace block_for_reply + with this + +2005-02-14 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-userdb-util.c (_dbus_user_database_lookup_group): + properly handle looking up group information by name; fix + from j@bootlab.org + +2005-02-13 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c (dbus_connection_return_message) + (dbus_connection_borrow_message): hold dispatch lock while message + is outstanding + (_dbus_connection_block_for_reply): hold dispatch lock while we + block for the reply, so nobody steals our reply + (dbus_connection_pop_message): hold the dispatch lock while we + pluck the message + +2005-02-13 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c (_dbus_connection_acquire_dispatch) + (_dbus_connection_release_dispatch) + (_dbus_connection_acquire_io_path) + (_dbus_connection_release_io_path): make the mutex and condvar + control access to the "acquired" flag. Drop the connection lock + while waiting on the condvar. Hopefully these are baby steps in + roughly the right direction. + +2005-02-13 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c: use separate mutexes for the condition + variables; this is some kind of baseline for sanity, but the + condition variables still aren't used correctly afaict + +2005-02-13 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-object-tree.c (handle_default_introspect_and_unlock): + fix a double-unlock + + * dbus/dbus-connection.c + (_dbus_connection_detach_pending_call_unlocked): add this + + Initial semi-correct pass through to fix thread locking; there are + still some issues with the condition variable paths I'm pretty + sure + + * dbus/dbus-server.c: add a mutex on DBusServer and appropriate + lock/unlock calls + + * dbus/dbus-connection.c (_dbus_connection_do_iteration_unlocked): + rename to add _unlocked + (struct DBusConnection): move "dispatch_acquired" and + "io_path_acquired" to use only one bit each. + (CONNECTION_LOCK, CONNECTION_UNLOCK): add checks with !DBUS_DISABLE_CHECKS + (dbus_connection_set_watch_functions): hacky fix to reentrancy + (_dbus_connection_add_watch, _dbus_connection_remove_watch) + (_dbus_connection_toggle_watch, _dbus_connection_add_timeout) + (_dbus_connection_remove_timeout) + (_dbus_connection_toggle_timeout): drop lock when calling out to + user functions; done in a hacky/bad way. + (_dbus_connection_send_and_unlock): add a missing unlock + (_dbus_connection_block_for_reply): add a missing unlock + + * dbus/dbus-transport.c (_dbus_transport_get_is_authenticated): + drop lock in a hacky probably unsafe way to call out to user + function + +2005-02-12 Havoc Pennington <hp@redhat.com> + + * tools/dbus-tree-view.c (info_set_func_text): display more + details on args + + * bus/driver.c (bus_driver_handle_list_services): list the bus + driver + + * glib/dbus-gparser.c (parse_arg): generate an arg name if none is supplied + + * glib/dbus-gidl.c (signal_info_get_n_args): new function + (method_info_get_n_args): new function + +2005-02-12 Havoc Pennington <hp@redhat.com> + + * bus/driver.c (bus_driver_handle_introspect): add introspection + for bus driver + +2005-02-12 Havoc Pennington <hp@redhat.com> + + * bus/driver.c: put the signature of each bus driver method in the + table of handlers and check it on incoming calls; this isn't + really useful, but going to add introspect support in a minute. + +2005-02-11 Joe Shaw <joeshaw@novell.com> + + * mono/Connection.cs: The unpredictability of finalizers in mono + prevents us from deterministically disconnecting the filters from + the Service class's finalizer, so move tracking of filters and + matches here. Add API for that. + + * mono/Service.cs: Remove the code, add code which calls the + methods now on the Connection class. + +2005-02-11 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus.py (class Sender): added to support dbus signals better + (Bus::add_signal_receiver): added expand_args parameter which defaults + to True. When expand args is True the signal handler will pass the + message arguments as parameters to the signal handler. If False + revert to previous behavior where the signal handler must get the + argument list from the message. This is to help port applications + like HAL that have a tendancy to send variable length argument lists. + self._match_rule_to_receivers is now a dict of dicts. + (Bus::remove_signal_receiver): pop handler off the dict intead of + removing it from a list + (Bus::_signal_func): change signal handlers so that interface, + signal_name, service, path and message are packed into a Sender + object and that is passed to the handler. If expand_args is True + extract the args list from the message and append it to the parameter + list + + * python/dbus_bindings.pyx.in (class Signature): added to support + signiature types + (MessageIter::__init__): changed iteration limit to match D-BUS + (MessageIter::get*): added INT16, UINT16, SIGNATURE, DICT_ENTRY, + STRUCT and VARIENT type support + (MessageIter::python_value_to_dbus_sig): made recursive to support + recursive types + (MessageIter::append*): added Signature, dict, tuple + support + + * python/examples/example-client.py: added examples of getting tuples + and dicts + + * python/examples/example-service.py: added examples of sending tuples + and dicts + + * python/examples/example-signal-recipient.py: Fixed to handle new + signal callback format + +2005-02-10 Havoc Pennington <hp@redhat.com> + + * test/glib/test-dbus-glib.c (main): fix so this test doesn't fail + (call dbus_g_proxy_add_signal) + + * dbus/dbus-server-unix.c (_dbus_server_new_for_tcp_socket): + escape the hostname + (_dbus_server_new_for_domain_socket): escape the path + + * dbus/dbus-address.c (dbus_address_escape_value): new + (dbus_address_unescape_value): new + (dbus_parse_address): unescape values + + * dbus/dbus-string.c (_dbus_string_append_byte_as_hex): new function + + * doc/dbus-specification.xml: explain how to escape values in + addresses + +2005-02-10 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message-factory.c (generate_special): modify test to + avoid using a non-basic dict key + + * dbus/dbus-marshal-validate-util.c: add test for the below + + * doc/dbus-specification.xml: require that dict keys are a basic + type + + * dbus/dbus-marshal-validate.c + (_dbus_validate_signature_with_reason): require that dict key is a + basic type + +2005-02-10 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-object-tree.c (handle_default_introspect_and_unlock): + change to be _and_unlock instead of _unlocked + + * dbus/dbus-connection.c + (_dbus_connection_send_preallocated_unlocked_no_update): rename to + have no_update so we can find this bug quickly in future + +2005-02-10 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message-util.c (verify_test_message): tests for string + array + + * dbus/dbus-message.c (dbus_message_append_args_valist): add + support for arrays of string/signature/path + +2005-02-10 Joe Shaw <joeshaw@novell.com> + + * dbus/dbus-connection.c + (_dbus_connection_queue_received_message_link, + _dbus_connection_message_sent): Add the path to + the verbose output. + (_dbus_connection_send_preallocated_and_unlock): Added. Calls + _dbus_connection_send_preallocated_unlocked(), updated the + dispatch status, and unlocks. Fixes a bug where certain + situations (like a broken pipe) could cause a Disconnect message + to not be sent, tricking the bus into thinking a service was still + there when the process had quit. + (_dbus_connection_send_preallocated): Call + _dbus_connection_send_preallocated_and_unlock(). + (_dbus_connection_send_and_unlock): Added. Calls + _dbus_connection_send_preallocated_and_unlock(). + (dbus_connection_send): Call _dbus_connection_send_and_unlock(). + (dbus_connection_send_with_reply): Update the dispatch status and + unlock. + + * mono/Service.cs (~Service): Added. Removes the filter so that + we don't get unmanaged code calling back into a GCed delegate. + (RemoveFilter); Added. + +2005-02-09 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-message.c (dbus_message_iter_open_container): + - Removed check for iterator type being an array because + get_arg_type does not work with writer iterators + - Pass NULL to _dbus_type_writer_recurse if signiture is NULL + +2005-02-07 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.xml: some more language cleanups; add + stuff about how to deal with invalid protocol and extension + points; add _ to allowed chars in auth commands; add EXTENSION_ + auth command prefix + +2005-02-06 Havoc Pennington <hp@redhat.com> + + * s/expected/required/ in a couple places for clarity + +2005-02-07 Colin Walters <walters@verbum.org> + + * bus/selinux.c (bus_selinux_allows_send): Handle NULL for + sender or proposed_recipient. + +2005-02-06 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message-factory.c (generate_special): more tests + + * dbus/dbus-marshal-validate.c (validate_body_helper): detect + array length that exceeds the maximum + +2005-02-05 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message-factory.c (generate_special): more test cases, + increasing coverage + + * dbus/dbus-marshal-validate.c (validate_body_helper): return the + reason why a signature was invalid + + * dbus/dbus-marshal-header.c (load_and_validate_field): fix to + skip the length of the string before we look at it in validation + + * dbus/dbus-string-util.c (_dbus_string_test): add tests for + equal_substring + + * dbus/dbus-message.c (_dbus_message_loader_new): default + max_message_length to DBUS_MAXIMUM_MESSAGE_LENGTH + +2005-02-05 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-marshal-validate.c (validate_body_helper): fix crash + if the signature of a variant was empty + (_dbus_validate_signature_with_reason): catch "(a)" (array inside + struct with no element type) + + * dbus/dbus-message-factory.c (generate_uint32_changed): add more + mangled messages to break things + +2005-02-04 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gproxy.c (dbus_g_proxy_disconnect_signal): use + g_quark_try_string() so it actually can return 0 + (dbus_g_proxy_connect_signal): ditto + +2005-02-04 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gproxy.c (dbus_g_proxy_emit_remote_signal): fix a + bogus warning + (tristring_from_message): assert cleanly on null path/interface + (should not be possible though I decided later) + (dbus_g_proxy_dispose): move proxy manager unregistration here + (DBUS_G_PROXY_DESTROYED): add this macro, and use it in a bunch of + g_return_if_fail() checks + +2005-02-04 Havoc Pennington <hp@redhat.com> + + * doc/Makefile.am (EXTRA_DIST): add DTDs to makefile + + * doc/introspect.dtd: add introspect.dtd from David A. Wheeler + (with some minor changes) + + * doc/dbus-specification.xml: add deprecated attribute to + introspection format + +2005-01-31 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gproxy.c: rewrite how signals work again, this time I + think it's sort of right + +2005-01-30 Havoc Pennington <hp@redhat.com> + + * tools/dbus-viewer.c: kind of half-ass hook up the option menu. + +2005-01-30 Havoc Pennington <hp@redhat.com> + + * tools/dbus-names-model.c: dynamically watch NameOwnerChanged + + * autogen.sh: change to autotools 1.9 + + * glib/dbus-gproxy.c: completely change how signals work + (dbus_g_proxy_add_signal): new function to specify signature of a + signal + (dbus_g_proxy_emit_received): marshal the dbus message to GValues, + and g_warning if the incoming message has the wrong signature. + +2005-01-30 Havoc Pennington <hp@redhat.com> + + * tools/dbus-names-model.c (have_names_notify): fix this + + * dbus/dbus-message.c (_dbus_message_iter_get_args_valist): clean + up the string array handling a bit + +2005-01-30 Havoc Pennington <hp@redhat.com> + + * glib/dbus-glib.c (dbus_g_pending_call_set_notify): new function + (dbus_g_pending_call_cancel): new function + + * dbus/dbus-glib.h: move GType decls for connection/message here; + * dbus/dbus-glib.c: move all the g_type and ref/unref stuff in + here, just kind of rationalizing how we handle all that + + * tools/dbus-names-model.c: new file for a tree model listing the + services on a bus + + * tools/dbus-tree-view.c (model_new): use proper typing on the + model rows + +2005-01-30 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gmain.c: add a custom GSource back that just checks + whether the message queue has anything in it; otherwise, there are + cases where we won't see messages in the queue since there was no + IO visible to the glib main loop + + * dbus/dbus-connection-internal.h (_DBUS_DEFAULT_TIMEOUT_VALUE): + increase default message timeout to 25 seconds + +2005-01-30 Havoc Pennington <hp@redhat.com> + + * test/glib/test-profile.c (no_bus_stop_server): remove the + warning about the g_warning that I just fixed + + * glib/dbus-gmain.c: rewrite the main loop stuff to avoid the + custom source, seems to be a lot easier to understand and work + better. + +2005-01-30 Havoc Pennington <hp@redhat.com> + + I think this main loop thing is conceptually broken, but here are + some band aids. I'll maybe rewrite it in a minute. + + * glib/dbus-gmain.c (add_timeout): timeout stuff doesn't use the + custom GSource, so don't pass it in; confusing + (gsource_server_finalize, gsource_connection_finalize): add + finalize handlers that remove all the watches. + +2005-01-30 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gobject.c (introspect_properties): fix the XML + generated + + * dbus/dbus-message.c (dbus_message_unref): add an in_cache flag + which effectively detects the use of freed messages + + * glib/dbus-gobject.c (handle_introspect): modify and return the + reply message instead of the incoming message + + * dbus/dbus-object-tree.c (handle_default_introspect_unlocked): + gee, maybe it should SEND THE XML instead of just making a string + and freeing it again ;-) + + * tools/dbus-print-message.c (print_message): improve printing of + messages + + * configure.in: add debug-glib.service to the output + +2005-01-30 Havoc Pennington <hp@redhat.com> + + dbus-viewer introspected and displayed the bus driver + + * dbus/dbus-object-tree.c + (object_tree_test_iteration): add tests for a handler registered on "/" + + * dbus/dbus-object-tree.c + (_dbus_decompose_path): fix to handle path "/" properly + (run_decompose_tests): add tests for path decomposition + + * glib/dbus-gutils.c (_dbus_gutils_split_path): fix to handle "/" + properly + + * glib/dbus-gobject.c (handle_introspect): fix quotes + + * test/glib/run-test.sh: support launching the bus, then running + dbus-viewer + + * test/glib/test-service-glib.c (main): put in a trivial gobject + subclass and register it on the connection + + * bus/driver.c (bus_driver_handle_introspect): implement + introspection of the bus driver service + + * dbus/dbus-protocol.h: add #defines for the XML namespace, + identifiers, doctype decl + + * bus/driver.c (bus_driver_handle_get_service_owner): handle + attempts to get owner of DBUS_SERVICE_ORG_FREEDESKTOP_DBUS by + returning the service unchanged. + (bus_driver_handle_message): remove old check for reply_serial in + method calls, now the message type deals with that + (bus_driver_handle_message): handle NULL interface + + * glib/dbus-gproxy.c (dbus_g_proxy_get_bus_name): new function + + * glib/dbus-gloader-expat.c (description_load_from_string): allow + -1 for len + + * tools/dbus-viewer.c: add support for introspecting a service on + a bus + + * glib/dbus-gproxy.c (dbus_g_pending_call_ref): add + (dbus_g_pending_call_unref): add + +2005-01-29 Havoc Pennington <hp@redhat.com> + + * tools/dbus-tree-view.c: add support for displaying properties. + (run dbus-viewer with an introspect xml file as arg, then resize + the window so the tree elements show up, not sure what that is) + + * glib/dbus-gobject.c (handle_introspect): return + org.freedesktop.Properties and org.freedesktop.Introspectable + interfaces when we are introspected. + + * doc/dbus-specification.xml: allow empty interface name when + Get/Set a property + +2005-01-29 Havoc Pennington <hp@redhat.com> + + * glib/Makefile.am: rename dbus-glib-tool to dbus-binding-tool; + though it uses glib, it could be extended for any binding in + principle + + * glib/dbus-gobject.c (gobject_message_function): change to the + new way properties work + + * dbus/dbus-protocol.h: add the new interfaces + + * doc/dbus-specification.xml: document the introspection format, + Introspectable interface, and add an org.freedesktop.Properties + interface. + + * glib/dbus-gparser.c: add support for a <property> element + + * glib/dbus-gidl.c: add PropertyInfo + + * glib/dbus-gobject.c (handle_introspect): put the outermost + <node> outside the signal and property descriptions. + (introspect_properties): export properties as <property> rather + than as method calls + +2005-01-28 Havoc Pennington <hp@redhat.com> + + * doc/TODO, doc/dbus-specification.xml: spec and TODO tweaks + related to authentication protocol + +2005-01-28 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx.in: Updated to handle new D-BUS type system + - BUS_ACTIVATION -> BUS_STARTER + - DBUS_BUS_ACTIVATION -> DBUS_BUS_STARTER + - class MessageIter (__init__): Added recursion checking + so we throw a nice error instead of just disconnecting from the + bus. + (get): Added arg_type parameter for recursion. + Removed the nil type + Added signiture type placeholder (not implemented) + Added struct type placeholder (not implemented) + Added varient type placeholder (not implemented) + Commented out dict type for now + (get_element_type): renamed from get_array_type + (get_*): changed to use the dbus_message_iter_get_basic API + (get_*_array): removed in favor of recursive get_array method + (get_array): new recursive method which calls get to marshal + the elements of the array + (value_to_dbus_sig): New method returns the corrasponding + dbus signiture to a python value + (append): Comment out dict handling for now + Handle lists with the new recursive API + Comment out None handling for now + (append_nil): removed + (append_*): changed to use dbus_message_iter_append_basic API + (append_*_array): removed in favor of recursive append_array + method + (__str__): Make it easier to print out recursive iterators + for debugging + - class Message (__str__): moved type inspection to the + MessageIter class' __str__ method + (get_iter): Added an append parameter wich defaults to False + If True use the new API's to create an append iterator + + * python/dbus.py: Update to use new bindings API + - TYPE_ACTIVATION -> TYPE_STARTER + - class Bus (_get_match_rule): GetServiceOwner -> GetNameOwner + - class ActivationBus -> class StarterBus + - class RemoteObject (__call__): get an append iterator + - (_dispatch_dbus_method_call): get an append iterator + - class Object (emit_signal): get an append iterator + + * python/examples/: Fixed up the examples to work with the new API + +2005-01-28 Joe Shaw <joeshaw@novell.com> + + * configure.in: Bump version up to 0.30. + + * HACKING: Add a release item to bump the version number up after + a release. + +2005-01-28 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.xml: update to describe 16-bit types and + dict entries + + * dbus/dbus-marshal-basic.c (_dbus_unpack_uint16): fix broken + assertion + + * dbus/dbus-protocol.h (DBUS_TYPE_DICT_ENTRY): add DICT_ENTRY as a + type + + * dbus/dbus-marshal-recursive.c: implement + +2005-01-27 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-arch-deps.h.in: add 16/32-bit types + + * configure.in: find the right type for 16 and 32 bit ints as well + as 64 + + * dbus/dbus-protocol.h (DBUS_TYPE_INT16, DBUS_TYPE_UINT16): add + the 16-bit types so people don't have to stuff them in 32-bit or + byte arrays. + +2005-01-27 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c: byteswap the message if you init an + iterator to read/write from it + + * dbus/dbus-marshal-byteswap.c: new file implementing + _dbus_marshal_byteswap() + + * dbus/dbus-marshal-basic.c: add _dbus_swap_array() + +2005-01-26 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-marshal-validate-util.c: break this out (and fix + build, apparently - nobody noticed?) + +2005-01-26 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-marshal-recursive.h: remove todo comment + +2005-01-25 Joe Shaw <joeshaw@novell.com> + + * Land the mono binding changes to conform to the new APIs. + + * mono/Makefile.am: Remove Custom.cs, DBusType/Custom.cs, + DBusType/Dict.cs, and DBusType/Nil.cs from the build. + + * mono/Arguments.cs (GetCodeAsString): Added. Returns the dbus + type code as a string. + (InitAppending): Rename dbus_message_append_iter_init() to + dbus_message_iter_init_append(). + + * mono/BusDriver.cs: Rename ServiceEventHandler to + NameOwnerChangedHandler. Rename GetServiceOwner to GetOwner. + Rename ServiceOwnerChanged to NameOwnerChanged. + + * mono/Connection.cs: Rename BaseService to UniqueName, and the + underlying C call. + + * mono/Custom.cs: Removed. The CUSTOM type has been removed. + + * mono/Service.cs: Rename Exists to HasOwner, internally rename + dbus_bus_acquire_service() to dbus_bus_request_name(). + + * mono/DBusType/Array.cs (ctor): Use Type.GetElementType() instead + of Type.UnderlyingSystemType to get the correct element type for + the array. + (ctor): Update code for new APIs: use dbus_message_iter_recurse(), + dbus_message_get_{element|arg}_type() instead of + dbus_message_iter_init_array_iterator(). + (Append): Replace dbus_message_iter_append_array() with + dbus_message_iter_open_container() and + dbus_message_iter_close_container(). + + * mono/DBusType/Custom.cs, mono/DBusType/Nil.cs: Removed. These + types have been removed. + + * mono/DBusType/*.cs: Replace calls of + dbus_message_iter_get_[type]() to dbus_message_iter_get_basic(), + but specify the type in the DllImport extern declaration. Ditto + for dbus_message_iter_append_[type]() -> + dbus_message_iter_append_basic(). + + * mono/example/BusListener.cs: Update for ServiceEventHandler -> + NameOwnerChangedHandler. + +2005-01-25 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx.in: Rename of methods and bindings + - get_base_service -> get_unique_name + - bus_get_base_service -> bus_get_unique_name + - dbus_bus_get_base_service -> dbus_bus_get_unique_name + - ACTIVATION_REPLY_ACTIVATED -> DBUS_START_REPLY_SUCCESS + - ACTIVATION_REPLY_ALREADY_ACTIVE -> DBUS_START_REPLY_ALREADY_RUNNING + - bus_activate_service -> bus_start_service_by_name + - dbus_bus_activate_service -> dbus_bus_start_service_by_name + - bus_acquire_service -> bus_request_name + - dbus_bus_acquire_service -> dbus_bus_request_name + - bus_service_exists -> bus_name_has_owner + - dbus_bus_service_exists -> dbus_bus_name_has_owner + + * python/dbus.py: Rename of methods + - activate_service -> start_service_by_name + - bus_acquire_service -> bus_request_name + - ACTIVATION_REPLY_ACTIVATED -> START_REPLY_SUCCESS + - ACTIVATION_REPLY_ALREADY_ACTIVE -> START_REPLY_ALREADY_RUNNING + + +2005-01-24 Joe Shaw <joeshaw@novell.com> + + * dbus/dbus-connection.c (dbus_connection_dispatch): Print out the + signature for the method that can't be found. + + * dbus/dbus-message.c (dbus_message_iter_init): To check to see if + the message has any arguments, we need to call + _dbus_type_reader_get_current_type(), not + _dbus_type_reader_has_next(). + +2005-01-24 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message-factory.c: more testing of message validation + + * dbus/dbus-protocol.h (DBUS_MINIMUM_HEADER_SIZE): move to this + header + +2005-01-23 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message-factory.c, dbus/dbus-message-util.c: + get this all working, not many tests in the framework yet though + +2005-01-22 Havoc Pennington <hp@redhat.com> + + * doc/dbus-faq.xml, doc/dbus-tutorial: add a FAQ and update + tutorial, based on work from David Wheeler. + +2005-01-21 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-bus.c: add more return_if_fail checks + + * dbus/dbus-message.c (load_message): have the "no validation" + mode (have to edit the code to toggle the mode for now though) + + * dbus/dbus-marshal-header.c (_dbus_header_load): have a mode that + skips all validation; I want to use this at least for benchmark + baseline, I'm not sure if it should be a publicly-available switch. + +2005-01-21 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gmain.c: don't put the GLib bindings in the same + toplevel doxygen group as the low-level API stuff + + * dbus/dbus.h: note that libdbus is the low-level API + +2005-01-20 Havoc Pennington <hp@redhat.com> + + * update-dbus-docs.sh: script to update docs on the web site, only + works for me though. neener. + +2005-01-20 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_poll): amazingly, trying to compile + code can reveal bugs in it + +2005-01-20 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_poll): fix several bugs in the + select() version, patches from Tor Lillqvist + +2005-01-20 Havoc Pennington <hp@redhat.com> + + * doc/dbus-tutorial.xml: replace > with > + + * bus/services.c (bus_registry_acquire_service): validate the name + and return a better error if it's no good. + + * doc/dbus-specification.xml: note NO_AUTO_START change + + * dbus/dbus-protocol.h (DBUS_HEADER_FLAG_NO_AUTO_START): change + from AUTO_START, we're toggling the default + + * bus/dispatch.c: adapt the tests to change of auto-start default + +2005-01-18 Havoc Pennington <hp@redhat.com> + + * rename dbus-daemon-1 to dbus-daemon throughout + +2005-01-18 Havoc Pennington <hp@redhat.com> + + * Throughout, grand renaming to strip out the use of "service", + just say "name" instead (or "bus name" when ambiguous). Did not + change the internal code of the message bus itself, only the + programmer-facing API and messages. + + * doc/dbus-specification.xml: further update the message bus section + + * bus/config-parser.c (all_are_equiv): fix bug using freed string + in error case + +2005-01-17 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-types.h: remove 16-bit types since we don't use them + ever + + * dbus/dbus-marshal-validate.c (_dbus_validate_path): disallow any + "invalid name character" not only non-ASCII + + * doc/dbus-specification.xml: further update spec, message bus + parts are still out-of-date but the marshaling etc. stuff is now + accurate-ish + +2005-01-17 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.xml: partially update spec + +2005-01-17 Havoc Pennington <hp@redhat.com> + + * Throughout, align variant bodies according to the contained + type, rather than always to 8. Should save a fair bit of space in + message headers. + + * dbus/dbus-marshal-validate.c (_dbus_validate_body_with_reason): + fix handling of case where p == end + + * doc/TODO: remove the dbus_bool_t item and variant alignment items + +2005-01-17 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-types.h: hardcode dbus_bool_t to 32 bits + + * Throughout: modify DBUS_TYPE_BOOLEAN to be a 32-bit type instead + of an 8-bit type. Now dbus_bool_t is the type to use whenever you + are marshaling/unmarshaling a boolean. + +2005-01-16 Havoc Pennington <hp@redhat.com> + + This is about it on what can be disabled/deleted from libdbus + easily, back below 150K anyhow. Deeper cuts are more work than + just turning the code off as I've done here. + + * dbus/dbus-marshal-basic.c (_dbus_pack_int32): we don't need the + signed int convenience funcs + + * dbus/dbus-internals.c (_dbus_verbose_real): omit when not in + verbose mode + + * dbus/dbus-string-util.c, dbus/dbus-string.c: more breaking + things out of libdbus + + * dbus/dbus-sysdeps.c, dbus/dbus-sysdeps-util.c: same + + * dbus/dbus-hash.c: purge the TWO_STRINGS crap (well, make it + tests-enabled-only, though it should probably be deleted) + + * dbus/dbus-message-util.c: same stuff + + * dbus/dbus-auth-util.c: same stuff + +2005-01-16 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-userdb-util.c: split out part of dbus-userdb.c + + * dbus/dbus-sysdeps.c (_dbus_uid_from_string): move here to pave + way for stripping down dbus-userdb.c stuff included in libdbus. + Rename _dbus_parse_uid for consistency. + +2005-01-16 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-internals.c (_dbus_real_assert): print the function + name the assertion failed in + + * dbus/dbus-internals.h (_dbus_return_if_fail) + (_dbus_return_val_if_fail): assert that the name of the function + containing the check doesn't start with '_', since we only want to + use checks on public functions + + * dbus/dbus-connection.c (_dbus_connection_ref_unlocked): change + checks to assertions + + * dbus/dbus-marshal-header.c (_dbus_header_set_field_basic): + change checks to asserts for private function + + * dbus/dbus-message.c (_dbus_message_set_serial): checks + to asserts for private function + + * dbus/dbus-marshal-recursive.c (skip_one_complete_type): remove + broken assertion that was breaking make check + (_dbus_type_reader_array_is_empty): remove this rather than fix + it, was only used in assertions + +2005-01-16 Havoc Pennington <hp@redhat.com> + + * test/unused-code-gc.py: hacky script to find code that's used + only by the bus (not libdbus) or used only by tests or not used at + all. It has some false alarms, but looks like we can clean up a + lot of size from libdbus. + + * dbus/dbus-sysdeps.c, dbus/dbus-sysdeps-utils.c, + dbus/Makefile.am: initially move 10K of binary size out of libdbus + +2005-01-16 Havoc Pennington <hp@redhat.com> + + * Add and fix docs according to Doxygen warnings throughout + source. + + * dbus/dbus-marshal-recursive.c + (_dbus_type_reader_array_is_empty): change this to just call + array_reader_get_array_len() and make it static + + * dbus/dbus-message.c (dbus_message_iter_get_element_type): rename + from get_array_type + (dbus_message_iter_init_append): rename from append_iter_init + + * dbus/dbus-marshal-recursive.c + (_dbus_type_reader_get_element_type): rename from + _dbus_type_reader_get_array_type + +2005-01-15 Havoc Pennington <hp@redhat.com> + + * test/glib/test-profile.c (with_bus_server_filter): fix crash + + * dbus/dbus-marshal-basic.c (_dbus_unpack_uint32): inline as macro + when DBUS_DISABLE_ASSERT + (_dbus_marshal_set_basic): be sure we align for the string length + + * dbus/dbus-marshal-recursive.c (skip_one_complete_type): make + this look faster + + * dbus/dbus-string.c (_dbus_string_get_const_data_len): add an + inline macro version + (_dbus_string_set_byte): provide inline macro version + +2005-01-15 Havoc Pennington <hp@redhat.com> + + * Land the new message args API and type system. + + This patch is huge, but the public API change is not + really large. The set of D-BUS types has changed somewhat, + and the arg "getters" are more geared toward language bindings; + they don't make a copy, etc. + + There are also some known issues. See these emails for details + on this huge patch: + http://lists.freedesktop.org/archives/dbus/2004-December/001836.html + http://lists.freedesktop.org/archives/dbus/2005-January/001922.html + + * dbus/dbus-marshal-*: all the new stuff + + * dbus/dbus-message.c: basically rewritten + + * dbus/dbus-memory.c (check_guards): with "guards" enabled, init + freed blocks to be all non-nul bytes so using freed memory is less + likely to work right + + * dbus/dbus-internals.c (_dbus_test_oom_handling): add + DBUS_FAIL_MALLOC=N environment variable, so you can do + DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or + DBUS_FAIL_MALLOC=10 to make it really, really, really slow and + thorough. + + * qt/message.cpp: port to the new message args API + (operator<<): use str.utf8() rather than str.unicode() + (pretty sure this is right from the Qt docs?) + + * glib/dbus-gvalue.c: port to the new message args API + + * bus/dispatch.c, bus/driver.c: port to the new message args API + + * dbus/dbus-string.c (_dbus_string_init_const_len): initialize the + "locked" flag to TRUE and align_offset to 0; I guess we never + looked at these anyhow, but seems cleaner. + + * dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING): + move allocation padding macro to this header; use it to implement + (_DBUS_STRING_STATIC): ability to declare a static string. + + * dbus/dbus-message.c (_dbus_message_has_type_interface_member): + change to return TRUE if the interface is not set. + + * dbus/dbus-string.[hc]: move the D-BUS specific validation stuff + to dbus-marshal-validate.[hc] + + * dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from + dbus-internals.c + + * dbus/Makefile.am: cut over from dbus-marshal.[hc] + to dbus-marshal-*.[hc] + + * dbus/dbus-object-tree.c (_dbus_decompose_path): move this + function here from dbus-marshal.c + +2005-01-12 Joe Shaw <joeshaw@novell.com> + + * NEWS: Update for 0.23. + + * configure.in: Release 0.23. + +2005-01-12 Joe Shaw <joeshaw@novell.com> + + * mono/Makefile.am, mono/example/Makefile.am: Always build the + dbus DLL with --debug. Clean up after the .mdb files this leaves + behind. + + * mono/doc/Makefile.am: Need to uninstall the docs on "make + uninstall" + + * mono/Arguments.cs (GetDBusTypeConstructor): If the type + is an enum, get the enum's underlying type. Another mono + 1.1.3 fix. + +2005-01-11 Joe Shaw <joeshaw@novell.com> + + Patch from Sjoerd Simons <sjoerd@luon.net> + + * mono/Makefile.am, mono/example/Makefile.am: Don't redefine + DESTDIR. It breaks stuff. + +2005-01-11 Joe Shaw <joeshaw@novell.com> + + Patch from Tambet Ingo <tambet@ximian.com> + + * mono/DBusType/Array.cs (Get): Get the underlying element type by + calling type.GetElementType(). The code previously depended on + broken Mono behavior, which was fixed in Mono 1.1.3. + + * mono/DBusType/Dict.cs (constructor): Fix the parameters for + Activator.CreateInstance() so that the class's constructor is + called with the right parameters. + +2005-01-11 Joe Shaw <joeshaw@novell.com> + + Patch from Timo Teräs <ext-timo.teras@nokia.com> + + * dbus/dbus-connection.c + (_dbus_connection_queue_received_message_link): Call + _dbus_connection_remove_timeout() instead of the _locked() + variant, since it's always called from + _dbus_connection_handle_watch(), which handles the locking. + Removed the _locked() variant since it's no longer used. + +2005-01-03 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-internals.h: I'm an idiot, _dbus_assert certainly can + return + +2004-12-26 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-internals.h: add _DBUS_GNUC_NORETURN to _dbus_assert + +2005-01-03 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_sysdeps_test): fix using == on + floating point + + * dbus/dbus-string.c (_dbus_string_insert_alignment): new function + +2005-01-02 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-internals.h (_DBUS_ALIGN_OFFSET): new macro + +2005-01-01 Havoc Pennington <hp@redhat.com> + + * configure.in: add -Wfloat-equal + +2005-01-01 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.h: add _DBUS_DOUBLES_BITWISE_EQUAL macro, + for a variety of reasons '==' doesn't do this. + +2004-12-31 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-string.c (_dbus_string_equal_substrings): new function + I keep wishing I had + +2004-12-30 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus.py: s/ACTIVATION_REPLY_ACTIVE/ACTIVATION_REPLY_ACTIVATED + +2004-12-30 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx.in: Change DBUS_ACTIVATION_REPLY_ACTIVATED + and DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE to match the values in + dbus-protocol.h. Because they are defines and not enums they are not + autogenerated. + +2004-12-26 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx.in (bus_activate_service): Bind + dbus_bus_activate_service + + * python/dbus.py (Bus.activate_service): activate a service on the + bus. + +2004-12-24 Havoc Pennington <hp@redhat.com> + + * test/decode-gcov.c: change to use .gcno and .gcda files, but the + file format has also changed and I haven't adapted to that yet + + * Makefile.am: load .gcno files from latest gcc + +2004-12-23 John (J5) Palmieri <johnp@redhat.com> + * Patch from Rob Taylor <robtaylor@fastmail.fm> + + * python/dbus_bindings.pyx.in (bus_get_unix_user): New + lowlevel binding + + * python/dbus.py (get_unix_user): Added binding to + call dbus_bindings.bus_get_unix_user + + * python/extract.py: Modified the proto_pat regex to + handle unsigned long + +2004-12-21 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/make-dbus-glib-error-enum.sh: omit the function keyword for + better POSIX compliance. + +2004-12-19 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-string.c (_dbus_string_insert_4_aligned) + (_dbus_string_insert_8_aligned): new functions + + * dbus/dbus-string.c (_dbus_string_alloc_space): new function + +2004-12-18 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-string.c (_dbus_string_validate_ascii): use ISASCII + macro + + * dbus/dbus-message.c: fix a comment, and add a still-unused + not-implemented function + + * dbus/dbus-marshal.h: fix comment + + * dbus/dbus-internals.h (_DBUS_ISASCII): new macro + +2004-12-17 Joe Shaw <joeshaw@novell.com> + + * mono/DBusType/Byte.cs, mono/DBusType/Int32.cs, + mono/DBusType/Int64.cs, mono/DBusType/UInt32.cs, + mono/DBusType/UInt64.cs: Use Enum.GetUnderlyingType() instead of + Type.UnderlyingSystemType to get the actual system type + underneath. This code previously depended on the broken Mono + behavior, which was fixed in 1.1.3. + +2004-11-27 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-string.h (_dbus_string_get_byte): inline when asserts + are disabled + (_dbus_string_get_const_data): inline when asserts are disabled + + * dbus/dbus-message.c: record the _dbus_current_generation of + creation so we can complain if dbus_shutdown() is used improperly. + Do this only if checks are enabled. + + * dbus/dbus-connection.c: ditto + +2004-11-26 Havoc Pennington <hp@redhat.com> + + * test/glib/test-profile.c: add with_bus mode to profile echoes + that go through the bus. + + * test/glib/run-test.sh: add ability to run test-profile + + * bus/dbus-daemon-1.1.in: fix to say that SIGHUP causes partial + config file reload. + +2004-11-26 Havoc Pennington <hp@redhat.com> + + * test/glib/test-profile.c: clean up how the fake_malloc_overhead + thing was implemented + +2004-11-26 Havoc Pennington <hp@redhat.com> + + * test/glib/test-profile.c: tweak a bit, add support for some + made-up minimal malloc overhead with plain sockets, since in + real life some sort of buffers are unavoidable thus we could + count them in the theoretical best case + +2004-11-26 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c (dbus_message_cache_or_finalize): fix bug + where I was trying to cache one too many messages + +2004-11-26 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c: reimplement message cache as an array which + makes the cache about twice as fast and saves maybe 1.5% overall + +2004-11-26 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-threads.c (init_global_locks): forgot to put the + message cache lock here + +2004-11-26 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c (struct DBusMessage): put the locked bit and + the "char byte_order" next to each other to save 4 bytes + (dbus_message_new_empty_header): reduce preallocation, since the + message cache should achieve a similar effect + (dbus_message_cache_or_finalize, dbus_message_get_cached): add a + message cache that keeps a few DBusMessage around in a pool, + another 8% speedup or so. + + * dbus/dbus-dataslot.c (_dbus_data_slot_list_clear): new function + +2004-11-25 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-transport-unix.c (unix_do_iteration): if we're going + to write, without reading or blocking, try it before the poll() + and skip the poll() if nothing remains to write. This is about a + 3% speedup in the echo client/server + +2004-11-25 Havoc Pennington <hp@redhat.com> + + The primary change here is to always write() once before adding + the write watch, which gives us about a 10% performance increase. + + * dbus/dbus-transport-unix.c: a number of modifications to cope + with removing messages_pending + (check_write_watch): properly handle + DBUS_AUTH_STATE_WAITING_FOR_MEMORY; adapt to removal of + messages_pending stuff + (check_read_watch): properly handle WAITING_FOR_MEMORY and + AUTHENTICATED cases + (unix_handle_watch): after writing, see if the write watch can be + removed + (unix_do_iteration): assert that write_watch/read_watch are + non-NULL rather than testing that they aren't, since they + aren't allowed to be NULL. check_write_watch() at the end so + we add the watch if we did not finish writing (e.g. got EAGAIN) + + * dbus/dbus-transport-protected.h: remove messages_pending call, + since it resulted in too much inefficient watch adding/removing; + instead we now require that the transport user does an iteration + after queueing outgoing messages, and after trying the first + write() we add a write watch if we got EAGAIN or exceeded our + max bytes to write per iteration setting + + * dbus/dbus-string.c (_dbus_string_validate_signature): add this + function + + * dbus/dbus-server-unix.c (unix_finalize): the socket name was + freed and then accessed, valgrind flagged this bug, fix it + + * dbus/dbus-message.c: fix several bugs where HEADER_FIELD_LAST was taken + as the last valid field plus 1, where really it is equal to the + last valid field. Corrects some message corruption issues. + + * dbus/dbus-mainloop.c: verbosity changes + + * dbus/dbus-keyring.c (_dbus_keyring_new_homedir): handle OOM + instead of aborting in one of the test codepaths + + * dbus/dbus-internals.c (_dbus_verbose_real): fix a bug that + caused not printing the pid ever again if a verbose was missing + the newline at the end + (_dbus_header_field_to_string): add HEADER_FIELD_SIGNATURE + + * dbus/dbus-connection.c: verbosity changes; + (dbus_connection_has_messages_to_send): new function + (_dbus_connection_message_sent): no longer call transport->messages_pending + (_dbus_connection_send_preallocated_unlocked): do one iteration to + try to write() immediately, so we can avoid the write watch. This + is the core purpose of this patchset + (_dbus_connection_get_dispatch_status_unlocked): if disconnected, + dump the outgoing message queue, so nobody will get confused + trying to send them or thinking stuff is pending to be sent + + * bus/test.c: verbosity changes + + * bus/driver.c: verbosity/assertion changes + + * bus/dispatch.c: a bunch of little tweaks to get it working again + because this patchset changes when/where you need to block. + +2004-11-23 Havoc Pennington <hp@redhat.com> + + * test/glib/test-profile.c: modify to accept a plain_sockets + argument in which case it will bench plain sockets instead of + libdbus, for comparison purposes. + +2004-11-22 Havoc Pennington <hp@redhat.com> + + * test/glib/test-profile.c (N_CLIENT_THREADS): run multiple + threads for more time, so sysprof can get a grip on it. + + * dbus/dbus-string.c (_dbus_string_validate_utf8): remove + pointless variable + +2004-11-13 Havoc Pennington <hp@redhat.com> + + * test/glib/test-profile.c: fix this thing up a bit + + * dbus/dbus-message.c (dbus_message_new_empty_header): increase + preallocation sizes by a fair bit; not sure if this will be an + overall performance win or not, but it does reduce reallocs. + + * dbus/dbus-string.c (set_length, reallocate_for_length): ignore + the test hack that forced constant realloc if asserts are + disabled, so we can profile sanely. Sprinkle in some + _DBUS_UNLIKELY() which are probably pointless, but before I + noticed the real performance problem I put them in. + (_dbus_string_validate_utf8): micro-optimize this thing a little + bit, though callgrind says it didn't help; then special-case + ascii, which did help a lot; then be sure we detect nul bytes as + invalid, which is a bugfix. + (align_length_then_lengthen): add some more _DBUS_UNLIKELY + superstition; use memset to nul the padding instead of a manual + loop. + (_dbus_string_get_length): inline this as a + macro; it showed up in the profile because it's used for loop + tests and so forth + +2004-11-10 Colin Walters <walters@verbum.org> + + * dbus/dbus-spawn.c (check_babysit_events): Handle EINTR, + for extra paranoia. + +2004-11-09 Colin Walters <walters@verbum.org> + + * dbus/dbus-string.c (_dbus_string_get_length): New + function, writes DBusString to C buffer. + + * dbus/dbus-string.h: Prototype it. + + * dbus/dbus-message.c (dbus_message_type_to_string): New + function, converts message type into C string. + + * dbus/dbus-message.h: Prototype it. + + * bus/selinux.c (bus_selinux_check): Take source pid, + target pid, and audit data. Pass audit data to + avc_has_perm. + (log_audit_callback): New function, appends extra + audit information. + (bus_selinux_allows_acquire_service): Also take + service name, add it to audit data. + (bus_selinux_allows_send): Also take message + type, interface, method member, error name, + and destination, and add them to audit data. + (log_cb): Initialize func_audit. + + * bus/selinux.h (bus_selinux_allows_acquire_service) + (bus_selinux_allows_send): Update prototypes + + * bus/services.c (bus_registry_acquire_service): Pass + service name to bus_selinux_allows_acquire_service. + + * bus/bus.c (bus_context_check_security_policy): Pass + additional audit data. Move assignment of dest + to its own line. + +2004-11-07 Colin Walters <walters@verbum.org> + + * dbus/dbus-transport-unix.c (do_authentication): Always + initialize auth_completed. + +2004-11-07 Colin Walters <walters@verbum.org> + + * bus/bus.c (load_config): Break into three + separate functions: process_config_first_time_only, + process_config_every_time, and process_config_postinit. + (process_config_every_time): Move call of + bus_registry_set_service_context_table into + process_config_postinit. + (process_config_postinit): New function, does + any processing that needs to happen late + in initialization (and also on reload). + (bus_context_new): Instead of calling load_config, + open config parser here and call process_config_first_time_only + and process_config_every_time directly. Later, after + we have forked but before changing UID, + invoke bus_selinux_full_init, and then call + process_config_postinit. + (bus_context_reload_config): As in bus_context_new, + load parse file inside here, and call process_config_every_time + and process_config_postinit. + + * bus/services.h, bus/services.c + (bus_registry_set_service_context_table): Rename + from bus_registry_set_sid_table. Take string hash from config + parser, and convert them here into SIDs. + + * bus/config-parser.c (struct BusConfigParser): Have + config parser only store a mapping of service->context + string. + (merge_service_context_hash): New function. + (merge_included): Merge context string hashes instead + of using bus_selinux_id_table_union. + (bus_config_parser_new): Don't use bus_selinux_id_table_new; + simply create a new string hash. + (bus_config_parser_unref): Unref it. + (start_selinux_child): Simply insert strings into hash, + don't call bus_selinux_id_table_copy_over. + + * bus/selinux.h, bus/selinux.c (bus_selinux_id_table_union) + (bus_selinux_id_table_copy_over): Delete. + +2004-11-03 Colin Walters <walters@verbum.org> + + * bus/selinux.c (bus_selinux_pre_init): Kill some unused + variables. + +2004-11-03 Colin Walters <walters@verbum.org> + + * bus/test-main.c (test_pre_hook): Fix test logic, + thanks Joerg Barfurth <Joerg.Barfurth@Sun.COM>. + +2004-11-02 Colin Walters <walters@redhat.com> + + * bus/selinux.c (bus_selinux_init): Split into two functions, + bus_selinux_pre_init and bus_selinux_post_init. + (bus_selinux_pre_init): Just determine whether SELinux is + enabled. + (bus_selinux_post_init): Do everything else. + + * bus/main.c (main): Call bus_selinux_pre_init before parsing + config file, and bus_selinux_post_init after. This ensures that + we don't lose the policyreload notification thread that + bus_selinux_init created before forking previously. + + * bus/test-main.c (test_pre_hook): Update for split. + +2004-10-31 Owen Fraser-Green <owen@discobabe.net> + + Patch from Johan Fischer <linux@fischaz.com> + + * mono/doc/Makefile.am (install-data-local): Added directory + install for DESTDIR + +2004-10-29 Colin Walters <walters@redhat.com> + + * dbus/dbus-sysdeps.h (_dbus_become_daemon): Also take + parameter for fd to write pid to. + + * dbus/dbus-sysdeps.c (_dbus_become_daemon): Implement it. + + * bus/bus.c (bus_context_new): Pass print_pid_fd + to _dbus_become_daemon (bug #1720) + +2004-10-29 Colin Walters <walters@redhat.com> + + Patch from Ed Catmur <ed@catmur.co.uk> + + * mono/doc/Makefile.am (install-data-local): Handle + DESTDIR. + +2004-10-29 Colin Walters <walters@redhat.com> + + * bus/.cvsignore, qt/.cvsignore: Update. + +2004-10-29 Colin Walters <walters@redhat.com> + + Patch from Kristof Vansant <de_lupus@pandora.be> + + * configure.in: Detect Slackware. + * bus/Makefile.am (SCRIPT_IN_FILES): Add rc.messagebus.in. + * bus/rc.messagebus.in: New file. + +2004-10-29 Colin Walters <walters@redhat.com> + + * tools/dbus-monitor.c (filter_func): Return + DBUS_HANDLER_RESULT_HANDLED in filter function + for now. See: + http://freedesktop.org/pipermail/dbus/2004-August/001433.html + +2004-10-29 Colin Walters <walters@redhat.com> + + Patch from Matthew Rickard <mjricka@epoch.ncsc.mil> + + * bus/services.c (bus_registry_acquire_service): + Correctly retrieve service name from DBusString + for printing. + +2004-10-29 Colin Walters <walters@redhat.com> + + * dbus/dbus-glib.h: Update documentation to not + refer to internal APIs. + +2004-10-27 Joe Shaw <joeshaw@novell.com> + + * mono/Arguments.cs (GetDBusTypeConstructor): + type.UnderlyingSystemType will return "System.Byte" if you do it + on "byte[]", which is not what we want. So check the type.IsArray + property and use System.Array instead. + +2004-10-25 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-sysdeps.c (fill_user_info): On errors do not free + the DBusUserInfo structure since this is passed into the function. + This would cause a double free when the function that allocated + the structure would try to free it when an error occured. + + * (bus/session.conf.in, bus/Makefile.am, dbus/configure.in): + use /usr/share/dbus-1/services instead of /usr/lib/dbus-1.0/services + for service activation to avoid 32bit/64bit parallel install issues + +2004-10-21 Colin Walters <walters@verbum.org> + + * AUTHORS: Fix my email address, the @gnu.org one + has been bouncing for some time. Also add J5. + +2004-10-21 Colin Walters <walters@verbum.org> + + * dbus/dbus-transport-unix.c (do_authentication): Return + authentication status to callers. + (unix_handle_watch): If we completed authentication this round, + don't do another read. Instead wait until the next iteration, + after we've read any pending data in the auth buffer. + (unix_do_iteration): Ditto. + (unix_handle_watch): Updated for new do_authentication prototype. + +2004-10-18 Colin Walters <walters@verbum.org> + + * bus/selinux.c (bus_selinux_enabled): Handle + --disable-selinux case. + +2004-10-18 Colin Walters <walters@verbum.org> + + * bus/selinux.h: Add bus_selinux_enabled. + + * bus/selinux.c (bus_selinux_enabled): Implement it. + + * bus/config-parser.c (struct include): Add + if_selinux_enabled member. + (start_busconfig_child): Parse if_selinux_enabled + attribute for include. + (bus_config_parser_content): Handle it. + + * bus/session.conf.in, bus/system.conf.in: Add + inclusion of context mapping to default config files; + conditional on SELinux being enabled. + + * doc/busconfig.dtd: Add to if_selinux_enabled to default DTD. + + * test/data/invalid-config-files/badselinux-1.conf, + test/data/invalid-config-files/badselinux-2.conf: + Test files for bad syntax. + +2004-10-17 Colin Walters <walters@verbum.org> + + * dbus/dbus-memory.c (_dbus_initialize_malloc_debug, check_guards) + (dbus_malloc, dbus_malloc0, dbus_realloc): Fix up printf + format specifier mismatches. + +2004-10-07 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-sysdeps.c (_dbus_file_get_contents): fix an incorrect + format string. + + * glib/dbus-dbus-gmain.c (dbus_g_bus_get): do not mangle NULL + pointer (bug #1540, Leonardo Boiko). + +2004-09-28 Jon Trowbridge <trow@ximian.com> + + * mono/BusDriver.cs: Changed BusDriver struct to remove + the ServiceCreated and ServiceDeleted events and replace them + with the new ServiceOwnerChanged event. + + * mono/example/BusListener.cs: Added a new example program, + which listens for and reports any ServiceOwnerChanged events + on the bus driver. + + * mono/example/Makefile.am (DESTDIR): Build changes for the + new BusListener.cs example. + +2004-09-27 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * bus/signals.c (bus_match_rule_parse): validate the components of + match rules (bug #1439). + + * dbus/dbus-bus.c (dbus_bus_add_match): add a missing OOM test. + +2004-09-24 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * doc/dbus-specification.xml: document ServiceOwnerChanged + signal. + + * bus/driver.c, bus/driver.h, bus/services.c: Use + ServiceOwnerChanged signal instead of ServiceCreated and + ServiceDeleted. + + * bus/dispatch.c: update testcase for the new signal. + +2004-09-20 Jon Trowbridge <trow@ximian.com> + + Patch from Nat Friedman <nat@novell.com> + + * mono/Makefile.am: A number of small build fixes to allow "make + distcheck" to succeed. + + * mono/example/Makefile.am: "make distcheck" fixes. + + * mono/AssemblyInfo.cs.in: When signing the assembly, look for the + key in @srcdir@. + + * test/Makefile.am: "make distcheck" fixes. + +2004-09-17 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-sysdeps.c (_dbus_user_at_console): fix memleak in OOM. + + * doc/busconfig.dtd: update the DTD for the at_console attribute. + + * bus/driver.c (bus_driver_handle_hello): correctly handle Hello + messages after the first one (bug #1389). + + * bus/dispatch.c (check_double_hello_message): add a test case for + the double hello message bug. + (check_existent_service_activation): fix check of spawning error. + +2004-09-16 David Zeuthen <david@fubar.dk> + + * python/dbus_bindings.pyx.in: Add support for int64 and uint64 + +2004-09-12 David Zeuthen <david@fubar.dk> + + Patch from Kay Sievers <kay.sievers@vrfy.org> + + * bus/bus.c (bus_context_new): + * bus/bus.h: + * bus/main.c (usage) + (main): + Add commandline option --nofork to override configuration file + setting. + +2004-09-09 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-*.h: remove the ; after DBUS_(BEGIN|END)_DECLS. Some C + compilers don't like it (bug #974). + +2004-09-04 Harald Fernengel <harry@kdevelop.org> + + * qt/connection.*: Applied patch by Jérôme Lodewyck + <lodewyck@clipper.ens.fr> to integrate an existing + connection into the Qt eventloop + +2004-08-30 Jon Trowbridge <trow@ximian.com> + + * mono/BusDriver.cs: Added. This is a class for interacting with + the org.freedesktop.DBus service. + + * mono/Message.cs: Added a mechanism to expose the message that is + currently being dispatched via the static Message.Current + property. Added Message.Sender and Message.Destination + properties. + + * mono/Handler.cs: Expose the dispatched message via + Message.Current when handling method calls. + + * mono/Service.cs: Expose the dispatched message via + Message.Current when handling signal emissions. + + * mono/Connection.cs: Bind dbus_bus_get_base_service via the + Connection.BaseService property. + +2004-08-28 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-userdb.c (_dbus_is_console_user): remove unused variable + + More fixes from Steve Grubb + + * dbus/dbus-sysdeps.c (_dbus_connect_tcp_socket): fix fd leak + (_dbus_listen_tcp_socket): fix fd leak + + * dbus/dbus-spawn.c (read_pid, read_ints): move the "again:" for + EINTR to a bit lower in the code + +2004-08-26 Jon Trowbridge <trow@ximian.com> + + * bus/driver.c (bus_driver_handle_service_exists): Respond with + TRUE if we are inquiring about the existence of the built-in + org.freedesktop.DBus service. + +2004-08-25 John Palmieri <johnp@redhat.com> + * bus/config-parser.c: + (struct PolicyType): Add POLICY_CONSOLE + (struct Element.d.policy): s/gid_or_uid/gid_uid_or_at_console + (start_busconfig_child): Sets up console element when + <policy at_console=""> is encountered in a policy file + (append_rule_from_element): Convert console elements to console + rules. + + * bus/policy.c: + (bus_policy_create_client_policy): Add console rules to the client + policy based on if the client is at the console + (bus_policy_append_console_rule): New function for adding a + console rule to a policy + (bus_policy_merge): Handle console rule merging + + * dbus/dbus-sysdeps.h: Added the DBUS_CONSOLE_DIR constant + where we check for console user files + + * dbus/dbus-sysdeps.c: + (_dbus_file_exists): New function which checks if the given + file exists + (_dbus_user_at_console): New function which does the system + specific process of checking if the user is at the console + + * dbus/dbus-userdb.c: + (_dbus_is_console_user): New function converts a UID to user name + and then calls the system specific _dbus_user_at_console to + see if the user is at the console and therefor a console user + +2004-08-25 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * bus/config-parser.c (set_limit): + * bus/dbus-daemon-1.1.in: + * test/data/valid-config-files/many-rules.conf: set the + max_match_rules_per_connection limt from the config file. + + * doc/busconfig.dtd: update the DTD. + + * bus/driver.c: remove some unused variables. + +2004-08-24 Mikael Hallendal <micke@imendio.com> + + * dbus/dbus-glib-lowlevel.h: Removed dbus_bus_get_with_g_main since + it's been replaced by dbus_g_bus_get + +2004-08-23 Colin Walters <walters@redhat.com> + + Updated SELinux support from Matthew Rickard <mjricka@epoch.ncsc.mil> + + * bus/selinux.h: Prototype bus_selinux_get_policy_root. + + * bus/selinux.c: Create a thread for policy reload notification. + (bus_selinux_get_policy_root): Implement. + + * bus/config-parser.c (start_busconfig_child) + (bus_config_parser_content): Support SELinux-root relative + inclusion. + + * configure.in <HAVE_SELINUX>: Add -lpthread. + + * bus/test-main.c (test_pre_hook, test_post_hook): New. + (test_post_hook): Move memory checking into here. + (test_pre_hook, test_post_hook): Move SELinux checks in + here, but conditional on a DBUS_TEST_SELINUX environment + variable. Unfortunately we can't run the SELinux checks + as a normal user, since they won't have any permissions + for /selinux. So this will have to be tested manually + for now, until we have virtualization for most of + libselinux. + +2004-08-23 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_change_identity): add setgroups() to + drop supplementary groups, suggested by Steve Grubb + +2004-08-20 Colin Walters <walters@redhat.com> + + * bus/config-parser.c (start_busconfig_child): Remove some unused + variables. + + * bus/selinux.c (bus_selinux_id_table_insert): Avoid compiler + warning. + +2004-08-17 Joe Shaw <joeshaw@novell.com> + + * configure.in: If --enable-mono is passed in, if we can't find + mono error out. + + * mono/Makefile.am: Use /gacutil to install assemblies into the + GAC and not /root. + +2004-08-12 Havoc Pennington <hp@redhat.com> + + * NEWS: update for 0.22 + + * configure.in: release 0.22 + +2004-08-11 Colin Walters <walters@redhat.com> + + * tools/dbus-send.c (main, usage): Add --reply-timeout + argument. + +2004-08-10 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * bus/bus.c (process_config_first_time_only): get rid of an unused + DBusError that was causing a memoy leak (bug #989). + + * dbus/dbus-keyring.c, dbus/dbus-message.c: + fix compilation on Solaris/Forte C (bug #974) + + * bus/main.c (main): plug two minuscule memleaks. + +2004-08-10 Havoc Pennington <hp@redhat.com> + + * doc/dbus-tutorial.xml: add some more info on GLib bindings + +2004-08-09 Havoc Pennington <hp@redhat.com> + + * COPYING: switch to Academic Free License version 2.1 instead of + 2.0, to resolve complaints about patent termination clause. + +2004-07-31 John (J5) Palmieri <johnp@redhat.com> + + * README: added documentation for the --enable-python + configure switch. + +2004-07-31 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * bus/config-parser.c (bus_config_parser_new): fix an invalid + _unref in the SELinux support. + + * doc/busconfig.dtd: update DTD for SELinux support. + + * bus/config-loader-libxml.c: fix error handler and parser + initialisation/cleanup. OOM test now works with libxml2 HEAD. + + * configure.in: remove the warning about libxml2. + + * dbus/dbus-bus.c: silence doxygen warning. + +2004-07-31 Colin Walters <walters@redhat.com> + + * configure.in: Move #error in SELinux check to its own line. + +2004-07-31 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-internals.h (_DBUS_SET_OOM): + * bus/utils.h (BUS_SET_OOM): use dbus_error_set_const instead of + dbus_error_set. + + * bus/dispatch.c (check_send_exit_to_service): fix the test case, + broken by the change in the _SET_OOM macros. + +2004-07-31 Colin Walters <walters@redhat.com> + + * bus/selinux.c <HAVE_SELINUX>: Include utils.h to get + BUS_SET_OOM. + +2004-07-31 Colin Walters <walters@redhat.com> + + * configure.in: Use AC_TRY_COMPILE instead of AC_EGREP_HEADER + to correctly detect DBUS__ACQUIRE_SVC. Also add an + AC_MSG_CHECKING. + +2004-07-24 Havoc Pennington <hp@redhat.com> + + SELinux support from Matthew Rickard <mjricka@epoch.ncsc.mil> + + * bus/selinux.c, bus/selinux.h: new file encapsulating selinux + functionality + + * configure.in: add --enable-selinux + + * bus/policy.c (bus_policy_merge): add FIXME to a comment + + * bus/main.c (main): initialize and shut down selinux + + * bus/connection.c: store SELinux ID on each connection, to avoid + repeated getting of the string context and converting it into + an ID + + * bus/bus.c (bus_context_get_policy): new accessor, though it + isn't used + (bus_context_check_security_policy): check whether the security + context of sender connection can send to the security context of + recipient connection + + * bus/config-parser.c: add parsing for <selinux> and <associate> + + * dbus/dbus-transport.c (_dbus_transport_get_unix_fd): to + implement dbus_connection_get_unix_fd() + + * dbus/dbus-connection.c (dbus_connection_get_unix_fd): new + function, used by the selinux stuff + +2004-07-29 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * bus/config-loader-libxml.c: complete the implementation of + libxml backend for config file loader. Doesn't work with full OOM + test yet. + + * configure.in: change error when selecting libxml into a warning. + + * test/data/invalid-config-files: add two non-well-formed XML + files. + + * glib/Makefile.am: libdbus_gtool always uses expat, not libxml. + + * dbus/dbus-transport-unix.c (unix_handle_watch): do not + disconnect in case of DBUS_WATCH_HANGUP, several do_reading() may + be necessary to read all the buffer. (bug #894) + + * bus/activation.c (bus_activation_activate_service): fix a + potential assertion failure (bug #896). Small optimization in the + case of auto-activation messages. + + * dbus/dbus-message.c (verify_test_message, _dbus_message_test): + add test case for byte-through-vararg bug (#901). patch by Kimmo + Hämäläinen. + +2004-07-28 Anders Carlsson <andersca@gnome.org> + + * python/dbus.py: + * python/dbus_bindings.pyx.in: + Add dbus.init_gthreads (), allow emit_signal to pass + arguments to the signal. + +2004-07-24 Havoc Pennington <hp@redhat.com> + + * AUTHORS: add some people, not really comprehensively, let me + know if I missed you + +2004-07-24 Havoc Pennington <hp@redhat.com> + + * Makefile.am (DIST_SUBDIRS): add DIST_SUBDIRS, problem solved by + Owen + + * test/Makefile.am (DIST_SUBDIRS): here also + +2004-07-22 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-sysdeps.c (fill_user_info): fix inexistent label name, + breaking build on Solaris, reported by Farhad Saberi on the ML. + + * dbus/dbus-message.c (dbus_message_append_args_valist): fix the + va_arg invocation to account for integer promotion in the case of + DBUS_TYPE_BYTE (unsigned char is promoted to int). (bug #901) + + * bus/services.c (bus_service_remove_owner): fix bug #902, use + _dbus_list_get_first_link, not _dbus_list_get_first. + + * dbus/dbus-bus.c (dbus_bus_service_exists): plug a memory leak. + + * dbus/dbus-object-tree.c (free_subtree_recurse): always null + handler functions so that the asserts in _dbus_object_subtree_unref + do not fail. + + * dbus/dbus-transport-unix.c (do_reading): + _dbus_transport_queue_messages return value is of type + dbus_bool_t, not DBusDispatchStatus. + +2004-07-19 David Zeuthen <david@fubar.dk> + + * dbus/dbus-protocol.h: Add DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN + + * bus/dispatch.c: + (check_get_connection_unix_user): Debug says GetProperty; but the + method is called GetConnectionUnixUser + (check_get_connection_unix_process_id): New function + (bus_dispatch_test): Actually call check_get_connection_unix_user(); + also call check_get_connection_unix_process_id() + + * bus/driver.c: + (bus_driver_handle_get_connection_unix_process_id): New function, + handles GetConnectionUnixProcessID on the org.freedesktop.DBus + interface + + * dbus/dbus-auth.c: + (handle_server_data_external_mech): Set pid from the credentials + obtained from the socket + + * dbus/dbus-connection.c: + (dbus_connection_get_unix_process_id): New function + + * dbus/dbus-connection.h: + Add prototype for dbus_connection_get_unix_process_id + + * dbus/dbus-transport.c: + (_dbus_transport_get_unix_process_id): New function + + * dbus/dbus-transport.h: + Add prototype for _dbus_transport_get_unix_process_id + +2004-07-19 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-message.c: Message counter fix, patch by Christian + Hammond <chipx86@gnupdate.org> + +2004-07-18 Seth Nickell <seth@gnome.org> + + * python/dbus.py: + * python/dbus_bindings.pyx.in: + * python/tests/test-client.py: + + Add dbus.ByteArray and dbus_bindings.ByteArray + types so that byte streams can be passed back. + + Give jdahlin the heaps of credit that are so + rightfully his. + +2004-07-12 Seth Nickell <seth@gnome.org> + + * python/dbus.py: + + Add message argument to the default object_method_handler + function. + + * python/dbus_bindings.pyx.in: + + Automatically return NIL when passed an empty list + (we can't pass back a list since lists are typed + and we don't have any idea what type the the client + intended the list to be... :-( ) + +2004-07-10 Seth Nickell <seth@gnome.org> + + * python/examples/Makefile.am: + + Fix distcheck breakage caused by new examples. + +2004-07-10 Seth Nickell <seth@gnome.org> + + * python/dbus.py: + + Add "message" argument to service-side dbus.Object + methods. This will break existing services written + using the python bindings, but will allow extraction + of all the message information (e.g. who its from). + + Add improved "object oriented" signal handling/emission. + + * python/examples/example-service.py: + + Nix this example. + + * python/examples/example-signal-emitter.py: + * python/examples/example-signal-recipient.py: + + Two new examples that show how to emit and receive + signals using the new APIs. + + * python/examples/example-signals.py: + * python/examples/gconf-proxy-service.py: + * python/examples/gconf-proxy-service2.py: + + Add "message" argument to service methods. + +2004-06-28 Kay Sievers <kay.sievers@vrfy.org> + + * bus/driver.c (bus_driver_handle_get_connection_unix_user) + * dbus/bus.c (dbus_bus_get_unix_user) + * doc/dbus-specification.xml: implement GetConnectionUnixUser + method of org.freedesktop.DBus interface. + + * bus/dispatch.c: test case + +2004-06-23 John (J5) Palmieri <johnp@redhat.com> + + * python/Makefile.am: switched include directory from glib/ to dbus/ + since dbus-glib.h moved + +2004-06-22 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * configure.in: prevent building the gcj stuff and libxml loader + since they are broken. + +2004-06-20 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-glib-error-enum.h: autogenerate the GError enum + codes from the dbus error names + + * glib/dbus-glib.h: move to subdir dbus/ since it's included + as dbus/dbus-glib.h and that breakage is now visible due to + including dbus/dbus-glib.h in dbus-glib-lowlevel.h + + * glib/dbus-glib.h: s/gproxy/g_proxy/ + + * dbus/dbus-shared.h: new header to hold stuff shared with + binding APIs + + * dbus/dbus-protocol.h (DBUS_ERROR_*): move errors here rather + than dbus-errors.h + + * glib/dbus-glib.h (dbus_set_g_error): move to + dbus-glib-lowlevel.h + + * glib/dbus-glib.h: remove dbus/dbus.h from here; change a bunch + of stuff to enable this + + * dbus/dbus-glib-lowlevel.h: put dbus/dbus.h here + + * a bunch of other changes with the same basic "separate glib + bindings from dbus.h" theme + +2004-06-10 Owen Fraser-Green <owen@discobabe.net> + + * dbus-sharp.pc.in: Removed glib-sharp inclusion in Libs. + + * python/examples/Makefile.am: Fixed typo in EXTRA_DIST. + +2004-06-09 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * bus/driver.c, dbus/dbus-bus.c: use BOOLEAN instead of UINT32 for + the reply value of the ServiceExists message. + +2004-06-07 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus_bindings.pyx.in: No longer need to parse path + elements and pass them as arrays of strings. The C API now + accepts plain path strings. + (_build_parsed_path): removed + +2004-06-07 Havoc Pennington <hp@redhat.com> + + * doc/TODO: remove auto-activation item since it's done; sort + items by importance/milestone + +2004-06-07 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message-builder.c (_dbus_message_data_load): append + random signature when using REQUIRED_FIELDS (this hack won't work + in the long term) + + * dbus/dbus-message.c: change the signature to be a header field, + instead of message->signature special-case string. Incremental + step forward. Then we can fix up code to send the signature in the + message, then fix up code to validate said signature, then fix up + code to not put the typecodes inline, etc. + (load_one_message): don't make up the signature after the fact + (decode_header_data): require signature field for the known + message types + + * dbus/dbus-marshal.c (_dbus_marshal_string_len): new + + * dbus/dbus-protocol.h: add DBUS_HEADER_FIELD_SIGNATURE + +2004-06-07 Owen Fraser-Green <owen@discobabe.net> + + * mono/DBusType/ObjectPath.cs: Renamed PathName argument to Path + + * mono/Handler.cs: Updated to follow new path argument for + (un-)registering objects. + + * mono/example/Makefile.am: + * mono/Makefile.am: + * configure.in: Bumped required version for mono and use new -pkg + syntax for deps + +2004-06-05 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-connection.h, dbus/dbus-connection.c: have object path + registration functions take the path argument as char* instead of + char**. + + * dbus/dbus-marshal.h, dbus/dbus-marshal.c (_dbus_decompose_path): + split off the path decompostion part of + _dbus_demarshal_object_path. Some misc. fixes to silence compiler + warnings. + + * glib/dbus-gobject.c, test/test-service.c: update accordingly. + +2004-06-02 Kristian Høgsberg <krh@redhat.com> + + * dbus/dbus-auth.c: Rewrite auth protocol handling to use a state + machine approach. A state is implemented as a function that + handles incoming events as specified for that state. + + * doc/dbus-specification.xml: Update auth protocol state machine + specification to match implementation. Remove some leftover + base64 examples. + +2004-06-02 Kristian Høgsberg <krh@redhat.com> + + * glib/dbus-gproxy.c, glib/dbus-gmain.c, dbus/dbus-string.c, + dbus/dbus-object-tree.c, dbus/dbus-message.c: add comments to + quiet doxygen. + + * Doxyfile.in: remove deprecated options. + + * dbus/dbus-message-handler.c, dbus/dbus-message-handler.h, + glib/test-thread.h, glib/test-thread-client.c, + glib/test-thread-server.c, glib/test-profile.c, + glib/test-dbus-glib.c: remove these unused files. + +2004-06-01 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-object-tree.c + (_dbus_object_tree_dispatch_and_unlock): fix dispatch for + non-fallback handlers (bug #684). + (_dbus_object_subtree_new): initialize invoke_as_fallback field. + (find_subtree_recurse): report wether the returned subtree is an + exact match or a "fallback" match higher up in the tree. + (object_tree_test_iteration): update test case. + +2004-06-01 Seth Nickell <seth@gnome.org> + + * python/dbus_bindings.pyx.in: + * python/tests/test-client.py: + + Round off basic type support. Add dicts (yay!), and + remaining array types. + + Make MessageIter more general so it works for dicts too. + + Mark all loop variables as C integers. + +2004-05-31 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gidl.c (method_info_add_arg): keep args sorted with + "in" before "out" + + * glib/dbus-gobject.c (dbus_type_to_string): move to dbus-gutils.c + + * glib/dbus-glib-tool.c (main): set up to have a --self-test + option that runs the tests, and start filling in some code + including for starters just dumping the interfaces to stdout + + * glib/Makefile.am (INCLUDES): define DBUS_LOCALEDIR + + * test/data/valid-introspection-files/lots-of-types.xml: test of + an example introspection file + + * glib/dbus-gparser.c (parser_check_doctype): doctype should be + "node" (I think...) + +2004-05-31 Seth Nickell <seth@gnome.org> + + * python/dbus_bindings.pyx.in: + * python/tests/test-client.py: + + Test Suite: 1 + Python Bindings: 0 + + Fix string array memory trashing bug... oops... + +2004-05-30 Seth Nickell <seth@gnome.org> + + * python/dbus.py: + + Add a nicer-but-less-flexible alternate API for handling + calls to virtual objects in dbus.ObjectTree. + + Screw up the argument order to the dbus.Object constructor + for consistency with dbus.ObjectTree (and to make dbus_methods + optional for future extension) + + * python/examples/Makefile.am: + * python/examples/gconf-proxy-service.py: + * python/examples/gconf-proxy-service2.py: + + Alternate implementation of gconf-proxy-service using the + nicer dbus.ObjectTree API. + + * python/examples/example-service.py: + * python/tests/test-server.py + + Reverse the argument order to deal with dbus.Object constructor + changes. + +2004-05-30 Seth Nickell <seth@gnome.org> + + * python/examples/example-client.py: + * python/examples/example-service.py: + + Take it back. Lists seem to work but they're broken + in the test suite. Make the base examples use + lists (works fine). + +2004-05-30 Seth Nickell <seth@gnome.org> + + * python/dbus_bindings.pyx.in: + * python/tests/test-client.py: + + Add some more tests and fix errors that crop up. + Unfortunately, currently it seems like marshalling + and unmarshalling of lists is completely broken :-( + +2004-05-30 Seth Nickell <seth@gnome.org> + + * python/dbus_bindings.pyx.in: + + Add support for ObjectPath type. + + * python/dbus.py: + + Refactor message handling code to a common function. + + * python/tests/test-client.py: + * python/tests/test-server.py: + + Add tests that check to make sure values of all types + can be echoed from a service w/o mangling. + +2004-05-29 Seth Nickell <seth@gnome.org> + + * python/dbus.py: + + Add ObjectTree class which allows implementation + of trees of "virtual" objects. Basically the python + wrapper for "register_fallback". + + * python/examples/Makefile.am + * python/examples/gconf-proxy-client.py: + * python/examples/gconf-proxy-service.py: + + Implement a simple GConf proxy service that supports + get/set on string and int GConf keys using the ObjectTree. + +2004-05-29 Seth Nickell <seth@gnome.org> + + * python/dbus.py: + * python/examples/example-client.py: + * python/examples/example-service.py: + * python/examples/list-system-services.py: + + Add SessionBus, SystemBus and ActivationBus classes + so you don't need to know the special little BUS_TYPE + flag. + +2004-05-29 Havoc Pennington <hp@redhat.com> + + * bus/config-parser.c (process_test_valid_subdir): temporarily + stop testing config parser OOM handling, since expat has issues + http://freedesktop.org/pipermail/dbus/2004-May/001153.html + + * bus/dbus-daemon-1.1.in: change requested_reply to + send_requested_reply/receive_requested_reply so we can send the + replies, not just receive them. + + * bus/config-parser.c: parse the new + send_requested_reply/receive_requested_reply + + * bus/policy.c (bus_client_policy_check_can_send): add + requested_reply argument and use it + + * bus/bus.c (bus_context_check_security_policy): pass through + requested_reply status to message send check + + * bus/system.conf.in: adapt to requested_reply change + +2004-05-28 Havoc Pennington <hp@redhat.com> + + * test/glib/test-service-glib.c (main): remove unused variable + + * glib/dbus-gidl.c (base_info_ref): fix a silly compiler warning + + * dbus/dbus-auth.h (enum): remove AUTHENTICATED_WITH_UNUSED_BYTES + from the enum, no longer in use. + + * dbus/dbus-sysdeps.h: include config.h so DBUS_VA_COPY actually + works right. + + * dbus/dbus-message.c: add various _dbus_return_val_if_fail for + whether error_name passed in is a valid error name. + +2004-05-28 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-message.c (dbus_message_get_args): Added support for + OBJECT_PATH and OBJECT_PATH_ARRAY + +2004-05-28 Seth Nickell <seth@gnome.org> + + * python/examples/Makefile.am: + + Forget to add Makefile.am. Do not pass go. + +2004-05-28 Michael Meeks <michael@ximian.com> + + * glib/dbus-gvalue.c (dbus_gvalue_marshal, dbus_gvalue_demarshal): + fix no int64 case. + + * dbus/dbus-string.c (_dbus_string_parse_basic_type): impl. + + * dbus/dbus-message.c (_dbus_message_iter_get_basic_type), + (_dbus_message_iter_get_basic_type_array): impl. + drastically simplify ~all relevant _get methods to use these. + (_dbus_message_iter_append_basic_array), + (dbus_message_iter_append_basic): impl + drastically simplify ~all relevant _append methods to use these. + + * dbus/dbus-message-builder.c (parse_basic_type) + (parse_basic_array, lookup_basic_type): impl. + (_dbus_message_data_load): prune scads of duplicate / + cut & paste coding. + + * dbus/dbus-marshal.c (_dbus_demarshal_basic_type_array) + (_dbus_demarshal_basic_type): implement, + (demarshal_and_validate_len/arg): beef up debug. + (_dbus_marshal_basic_type, _dbus_marshal_basic_type_array): impl. + +2004-05-27 Seth Nickell <seth@gnome.org> + + * configure.in: + * python/Makefile.am: + + Include the example python apps in the tarball. + + * python/examples/list-system-services.py + + Add a python new example that fetches the list of services + from the system bus. + +2004-05-27 Seth Nickell <seth@gnome.org> + + * python/dbus.py: + * python/dbus_bindings.pyx.in: + + Fix failure to notify that a signal was not handled, + resulted in hung functions. + +2004-05-25 Colin Walters <walters@redhat.com> + + * tools/dbus-monitor.c (main): Monitor all types of messages. + +2004-05-23 Owen Fraser-Green <owen@discobabe.net> + + * mono/Handler.cs, mono/Service.cs: Added UnregisterObject method + which unregisters the object path and disposes the handler. + +2004-05-23 Kristian Høgsberg <krh@redhat.com> + + Patch from Timo Teräs <ext-timo.teras@nokia.com> (#614): + + * dbus/dbus-message.c (dbus_message_iter_get_args_valist): Swap + operands to && so we call dbus_message_iter_next () for the last + argument also. + +2004-05-21 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-object-tree.c + (_dbus_object_tree_list_registered_unlock, lookup_subtree): return + children even if the requested path isn't registered. + (object_tree_test_iteration): test object_tree_list_registered. + + * configure.in: undefine HAVE_ABSTRACT_SOCKETS instead of defining + it to 0. + +2004-05-20 Kristian Høgsberg <krh@redhat.com> + + * doc/TODO: Remove resolved items. + + * bus/expirelist.h (struct BusExpireList): remove unused n_items + field. + + * bus/connection.c (bus_connections_expect_reply): Enforce the + per-connection limit on pending replies. + + Patch from Jon Trowbridge <trow@ximian.com>: + + * bus/main.c (setup_reload_pipe): Added. Creates a pipe and sets + up a watch that triggers a config reload when one end of the pipe + becomes readable. + (signal_handler): Instead of doing the config reload in our SIGHUP + handler, just write to the reload pipe and let the associated + watch handle the reload when control returns to the main loop. + + * bus/driver.c (bus_driver_handle_reload_config): Added. + Implements a ReloadConfig method for requesting a configuration + file reload via the bus driver. + +2004-05-19 Owen Fraser-Green <owen@discobabe.net> + + * HACKING: Updated release instructions concerning the wiki page. + +2004-05-18 Kristian Høgsberg <krh@redhat.com> + + * dbus/dbus-auth.c (client_try_next_mechanism): Remove logic to + filter against auth->allowed_mechs; we only add allowed mechs in + record_mechanisms(). + + * dbus/dbus-auth-script.c (_dbus_auth_script_run): Add an + ALLOWED_MECHS to auth-script format so we can set the list of + allowed mechanisms. + + * data/auth/client-out-of-mechanisms.auth-script: New test to + check client disconnects when it is out of mechanisms to try. + + * dbus/dbus-auth.c (process_command): Remove check for lines + longer that 1 MB; we only buffer up maximum 16 kB. + + * dbus/dbus-transport.c, dbus/dbus-transport-unix.c, + dbus/dbus-auth-script.c, dbus/dbus-auth.c, dbus/dbus-auth.h: + Remove auth state AUTHENTICATED_WITH_UNUSED_BYTES, instead always + assume there might be unused bytes. + + * dbus/dbus-auth.c (_dbus_auth_do_work): Remove check for + client-out-of-mechs, it is handled in process_reject(). Move check + for max failures to send_rejected(), as it's a server-only thing. + + * dbus/dbus-auth.c: Factor out protocol reply code into functions + send_auth(), send_data(), send_rejected(), send_error(), + send_ok(), send_begin() and send_cancel(). + +2004-05-17 Kristian Høgsberg <krh@redhat.com> + + Remove base64 encoding, replace with hex encoding. Original patch + from trow@ximian.com, added error handling. + + * dbus/dbus-string.c (_dbus_string_base64_encode) + (_dbus_string_base64_decode): Remove. + (_dbus_string_hex_decode): Add end_return argument so we can + distinguish between OOM and invalid hex encoding. + (_dbus_string_test): Remove base64 tests and add test case for + invalid hex. + + * dbus/dbus-keyring.c, dbus/dbus-auth-script.c, dbus/dbus-auth.c: + Replace base64 with hex. + + * test/data/auth/invalid-hex-encoding.auth-script: New test case + for invalid hex encoded data in auth protocol. + +2004-05-17 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-connection.c (check_for_reply_unlocked): plug a memory + leak. + +2004-05-15 Owen Fraser-Green <owen@discobabe.net> + + * mono/dbus-sharp.dll.config.in: Added for GAC + * mono/dbus-sharp.snk: Added for GAC + * mono/Assembly.cs.in: Added for GAC + * mono/Makefile.am: Changes for GAC installation + * configure.in: Added refs for dbus-sharp.dll.config.in and + Assembly.cs.in. More fixes for mono testing + * mono/example/Makefile.am: Changed var to CSC + * Makefile.am: Changed flag name to DBUS_USE_CSC + +2004-05-15 Owen Fraser-Green <owen@discobabe.net> + + * mono/Makefile.am: Added SUBDIRS for docs. Changed SUBDIRS order + * mono/doc/*: Added documentation framework + * configure.in: Added monodoc check + * README: Added description of mono configure flags + +2004-05-11 John (J5) Palmieri <johnp@redhat.com>: + + * doc/dbus-specification.xml: Added a "Required" column to the + header fields table and changed the "zero or more" verbage in + the above paragraph to read "The header must contain the required + named header fields and zero or more of the optional named header + fields". + * test/data/invalid-messages/*.message: Added the required PATH + named header field to the tests so that they don't fail on + 'Missing path field' + +2004-05-07 John (J5) Palmieri <johnp@redhat.com> + + * python/dbus-bindings.pyx.in: Stopped the bindings from trashing + the stack by implicitly defining variable and parameter types and + removing the hack of defining C pointers as python objects and later + casting them. + +2004-05-02 Owen Fraser-Green <owen@discobabe.net> + + * mono/Makefile.am: Removed test-dbus-sharp.exe from all target + +2004-05-01 Owen Fraser-Green <owen@discobabe.net> + + * mono/DBusType/Dict.cs: Handle empty dicts + * mono/DBusType/Array.cs: Handle empty arrays + * mono/Arguments.cs: Handle empty arguments + +2004-04-30 Owen Fraser-Green <owen@discobabe.net> + + * dbus-sharp.pc.in: Modified to include include Libs and Requires + field + +2004-04-25 Kristian Høgsberg <krh@redhat.com> + + * test/data/valid-messages/standard-*.message: Update message + test scripts to new header field names. + +2004-04-22 John (J5) Palmieri <johnp@redhat.com> + + * test/break-loader.c (randomly_do_n_things): tracked down buffer + overflow to times_we_did_each_thing array which would chop off the + first character of the failure_dir string. Increased the size of + the array to 7 to reflect the number of random mutation functions + we have. + +2004-04-21 Kristian Høgsberg <krh@redhat.com> + + * dbus/dbus-server-unix.c (unix_finalize): Don't unref + unix_server->watch here, it is unreffed in disconnect. + (_dbus_server_new_for_tcp_socket): convert NULL host to + "localhost" here so we don't append NULL to address. + + * dbus/dbus-server.c (_dbus_server_test): Add test case for + various addresses, including tcp with no explicit host. + +2004-04-21 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-message.c (decode_header_data, decode_string_field): + fix incorrect setting of .name_offset in the HeaderField (it was + off by two bytes, positioned right after the name and typecode) + + * bus/bus.c (bus_context_new, bus_context_unref): test before + calling dbus_server_free_data_slot and _dbus_user_database_unref + in case of an error. + + * tools/Makefile.am: add $(DBUS_GLIB_TOOL_LIBS), xml libs needed + by libdbus-gtool. + +2004-04-19 Kristian Høgsberg <krh@redhat.com> + + * dbus/dbus-transport-unix.c (unix_do_iteration): Rewrite to use + _dbus_poll() instead of select(). + +2004-04-15 Jon Trowbridge <trow@ximian.com> + + * bus/main.c (signal_handler): Reload the configuration files + on SIGHUP. + (main): Set up our SIGHUP handler. + + * bus/bus.c (struct BusContext): Store the config file, user and + fork flag in the BusContext. + (process_config_first_time_only): Added. Contains the code + (previously in bus_context_new) for setting up the BusContext from + the BusConfigParser that should only be run the first time the + config files are read. + (process_config_every_time): Added. Contains the code (previously + in bus_context_new) for setting up the BusContext from the + BusConfigParser that should be run every time the config files are + read. + (load_config): Added. Builds a BusConfigParser from the config + files and passes the resulting structure off to + process_config_first_time_only (assuming this is the first time) + and process_config_every_time. + (bus_context_new): All of the config-related code has been moved + to process_config_first_time_only and process_config_every_time. + Now this function just does the non-config-related initializations + and calls load_config. + (bus_context_reload_config): Added. + +2004-04-15 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * bus/driver.c (bus_driver_handle_get_service_owner): + implement a GetServiceOwner method. + * doc/dbus-specification.xml: document it. + * dbus/dbus-errors.h: add a 'ServiceHasNoOwner' error. + + * glib/dbus-gproxy.c (dbus_gproxy_new_for_service_owner): + implement, using the bus GetServiceOwner method. + + * test/glib/test-dbus-glib.c: + use dbus_gproxy_new_for_service_owner so that we can receive the + signal. + +2004-04-15 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-internals.c, dbus/dbus-message-builder.c, + dbus/dbus-message.c, dbus/dbus-protocol.h + (DBUS_HEADER_FIELD_SERVICE): renamed DBUS_HEADER_FIELD_DESTINATION + + * dbus/dbus-internals.c, dbus/dbus-message-builder.c, + dbus/dbus-message.c, dbus/dbus-protocol.h + (DBUS_HEADER_FIELD_SENDER_SERVICE): renamed DBUS_HEADER_FIELD_SENDER + + * dbus/dbus-internals.c (_dbus_header_field_to_string): + DBUS_HEADER_FIELD_DESTINATION resolves to "destination" + DBUS_HEADER_FIELD_SENDER resolves to "sender" + + * doc/dbus-specification.xml (Header Fields Table): + s/SERVICE/DESTINATION + s/SENDER_SERVICE/SENDER + + +2004-04-14 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * test/glib/test-dbus-glib.c (timed_exit): fail the test after + a few seconds. + +2004-04-13 Michael Meeks <michael@ximian.com> + + * glib/dbus-gobject.c (handle_introspect): split out + (introspect_properties): this. + (handle_introspect): implement this. + + * test/glib/Makefile.am: use the absolute path so the bus + daemon's chdir ("/") doesn't kill us dead. + + * configure.in: subst ABSOLUTE_TOP_BUILDDIR + +2004-04-12 Jon Trowbridge <trow@ximian.com> + + * bus/config-parser.c (struct BusConfigParser): Added + included_files field. + (seen_include): Added. Checks whether or not a file has already + been included by any parent BusConfigParser. + (bus_config_parser_new): Copy the parent's included_files. + (include_file): Track which files have been included, and fail on + circular inclusions. + (process_test_valid_subdir): Changed printf to report if we are + testing valid or invalid conf files. + (all_are_equiv): Changed printf to be a bit clearer about + what we are actually doing. + (bus_config_parser_test): Test invalid configuration files. + +2004-04-09 Jon Trowbridge <trow@ximian.com> + + * bus/config-parser.c (bus_config_parser_new): Added a 'parent' + argument. If non-null, the newly-constructed BusConfigParser will + be initialized with the parent's BusLimits instead of the default + values. + (include_file): When including a config file, pass in + the current parser as the parent and then copy the BusLimits + from the included BusConfigParser pack to the current parser. + (process_test_valid_subdir): Renamed from process_test_subdir. + (process_test_equiv_subdir): Added. Walks through a directory, + descending into each subdirectory and loading the config files + it finds there. If any subdirectory contains two config files + that don't produce identical BusConfigParser structs, fail. + For now, the BusConfigParser's BusPolicies are not compared. + (bus_config_parser_test): Call both process_test_valid_subdir and + process_test_equiv_subdir. + + * bus/config-loader-libxml.c (bus_config_load): Take a parent + argument and pass it along to the call to bus_config_parser_new. + Also made a few small changes to allow this code to compile. + + * bus/config-loader-expat.c (bus_config_load): Take a parent + argument and pass it along to the call to bus_config_parser_new. + + * bus/bus.c (bus_context_new): Load the config file + with a NULL parent argument. + +2004-03-29 Michael Meeks <michael@ximian.com> + + * glib/dbus-gobject.c (introspect_properties): split + out, fix mangled 'while' flow control. + (introspect_signals): implement. + (handle_introspect): update. + +2004-03-29 Michael Meeks <michael@ximian.com> + + * glib/dbus-gobject.c (set_object_property): split out / + re-work, use the property type, and not the message type(!) + (get_object_property): ditto. + + * glib/dbus-gvalue.c (dbus_gvalue_demarshal), + (dbus_gvalue_marshal): make this code re-usable, needed + for signals too, also on both proxy and server side. + Re-write for more efficiency / readability. + +2004-03-29 Michael Meeks <michael@ximian.com> + + * dbus/dbus-message.c + (dbus_message_new_error_printf): impl. + + * dbus/dbus-connection.c + (dbus_connection_unregister_object_path): fix warning. + + * configure.in: fix no-mono-installed situation. + +2004-03-27 Havoc Pennington <hp@redhat.com> + + Patch from Timo Teräs: + + * tools/dbus-send.c (main): if --print-reply, assume type is + method call; support boolean type args + + * dbus/dbus-connection.c (dbus_connection_send_with_reply): fix a + bunch of memleak and logic bugs + +2004-03-23 Owen Fraser-Green <owen@discobabe.net> + + * mono/Arguments.cs: + * mono/Introspector.cs: + * mono/Handler.cs: + * mono/InterfaceProxy.cs: + * mono/Message.cs + * mono/ProxyBuilder.cs: + * mono/Service.cs: + Added InterfaceProxy class to avoid building proxies for every + object. + + * dbus-message.h: + * dbus-message.c (dbus_message_append_args_valist) + (dbus_message_iter_get_object_path) + (dbus_message_iter_get_object_path_array) + (dbus_message_iter_append_object_path) + (dbus_message_iter_append_object_path_array): + Added object_path iter functions to handle OBJECT_PATH arguments + +2004-03-23 Owen Fraser-Green <owen@discobabe.net> + + First checkin of mono bindings. + * configure.in: + * Makefile.am: + Build stuff for the bindings + * dbus-sharp.pc.in: Added for pkgconfig + +2004-03-21 Havoc Pennington <hp@redhat.com> + + * test/test-service.c (main): remove debug spew + +2004-03-21 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-marshal.c (_dbus_marshal_validate_arg): accept empty + arrays + + * dbus/dbus-message.h, bus/dbus-message.c (dbus_message_iter_init) + (dbus_message_iter_init_array_iterator) + (dbus_message_iter_init_dict_iterator): return a dbus_bool_t to + indicate whether the iterator is empty + + * dbus/dbus-pending-call.c, dbus/dbus-server.c: silence compiler + warnings + +2004-03-19 Havoc Pennington <hp@redhat.com> + + * NEWS: 0.21 updates + + * configure.in: 0.21 + + * doc/Makefile.am: add all XMLTO usage to DBUS_XML_DOCS_ENABLED + + * python/Makefile.am: change to avoid dist of dbus_bindings.c so + you don't need pyrex to make dist + + * qt/Makefile.am (libdbus_qt_1_la_SOURCES): add integrator.h to + sources; run moc + +2004-03-18 Richard Hult <richard@imendio.com> + + * dbus/dbus-message.c (dbus_message_get_auto_activation) + (dbus_message_set_auto_activation): Add doxygen docs. + +2004-03-16 Richard Hult <richard@imendio.com> + + * bus/activation.c: (bus_activation_service_created), + (bus_activation_send_pending_auto_activation_messages), + (bus_activation_activate_service): + * bus/activation.h: + * bus/dispatch.c: (bus_dispatch), + (check_nonexistent_service_auto_activation), + (check_service_auto_activated), + (check_segfault_service_auto_activation), + (check_existent_service_auto_activation), (bus_dispatch_test): + * bus/driver.c: (bus_driver_handle_activate_service): + * bus/services.c: (bus_registry_acquire_service): + * dbus/dbus-message.c: (dbus_message_set_auto_activation), + (dbus_message_get_auto_activation): + * dbus/dbus-message.h: + * dbus/dbus-protocol.h: Implement auto-activation. + + * doc/dbus-specification.xml: Add auto-activation to the spec. + +2004-03-12 Olivier Andrieu <oliv__a@users.sourceforge.net> + + * dbus/dbus-marshal.c (_dbus_marshal_get_arg_end_pos): + fix a bug with CUSTOM types. + + * dbus/dbus-message.c (message_iter_test, _dbus_message_test): add + a unit test for this bug (used to fail). + +2004-03-12 Mikael Hallendal <micke@imendio.com> + + * bus/activation.c: + (babysitter_watch_callback): notify all pending activations waiting for + the same exec that the activation failed. + (bus_activation_activate_service): shortcut the activation if we + already waiting for the same executable to start up. + +2004-03-12 Mikael Hallendal <micke@imendio.com> + + * bus/activation.c: + - Added service file reloading. + Each service files directory is kept in an hash table in + BusActivation and each BusActivationEntry knows what .service-file it + was read from. So when you try to activate a service the bus will + check if it's been updated, removed or if new .service-files has + been installed. + - Test code at the bottom for the service file reloading. + * bus/test-main.c: (main): + * bus/test.h: + - added service reloading test. + * dbus/dbus-sysdeps.c: + * dbus/dbus-sysdeps.h: (_dbus_delete_directory): Added. + +2004-03-08 Michael Meeks <michael@ximian.com> + + * dbus/dbus-connection.c (_dbus_connection_block_for_reply): + bail immediately if disconnected, to avoid busy loop. + + * dbus/dbus-message.c (dbus_message_iter_get_args_valist): + cleanup cut/paste/inefficiency. + +2004-03-01 David Zeuthen <david@fubar.dk> + + * dbus/dbus-string.c (_dbus_string_append_printf_valist): Fix a + bug where args were used twice. This bug resulted in a segfault + on a Debian/PPC system when starting the messagebus daemon. Include + dbus-sysdeps.h for DBUS_VA_COPY + + * dbus/dbus-sysdeps.h: Define DBUS_VA_COPY if neccessary. From GLib + + * configure.in: Check for va_copy; define DBUS_VA_COPY to the + appropriate va_copy implementation. From GLib + +2004-02-24 Joe Shaw <joe@ximian.com> + + * bus/services.c (bus_registry_acquire_service): We need to pass + in the service name to dbus_set_error() to prevent a crash. + +2003-12-26 Anders Carlsson <andersca@gnome.org> + + * AUTHORS: Reveal my True identity. + +2003-12-17 Mikael Hallendal <micke@imendio.com> + + * dbus/dbus-message.c: (dbus_message_append_args_valist): + - Added case for DBUS_TYPE_BYTE, patch from Johan Hedberg. + +2003-12-13 Mikael Hallendal <micke@imendio.com> + + * doc/TODO: Added not about better error check of configuration files. + +2003-12-02 Richard Hult <richard@imendio.com> + + * Update AFL version to 2.0 throughout the source files to reflect + the update that was done a while ago. + +2003-12-02 Richard Hult <richard@imendio.com> + + * dbus/dbus-message.c (dbus_message_iter_append_dict): Set + wrote_dict_key to FALSE on the iter that the dict is appended to, + just like when appending other types. Fixes a bug where a dict + couldn't be put inside a dict. + (dbus_message_iter_append_dict_key): Fix typo in warning message. + (message_iter_test, _dbus_message_test): Add test case for dict + inside dict. + +2003-12-01 David Zeuthen <david@fubar.dk> + + * python/dbus.py: Add the actual message when calling the reciever + of a signal such that parameters can be inspected. Add the method + remove_signal_receiver + +2003-11-26 Mikael Hallendal <micke@imendio.com> + + * bus/*.[ch]: + * dbus/*.[ch]: + * glib/*.[ch]: Made ref functions return the pointer + +2003-11-25 Zack Rusin <zack@kde.org> + + * qt/integrator.h, qt/integrator.cpp: Adding handling of DBusServer, + + * qt/server.h, qt/server.cpp, qt/Makefile.am: Adding DBusServer + wrappers, + + * qt/connection.h, qt/connection.cpp: Adjusting to changes in + the Integrator and to better fit with the server, + +2003-11-24 Zack Rusin <zack@kde.org> + + * qt/connection.h, qt/connection.cpp: removing initDbus method since + the integrator handles it now + + * qt/integrator.h, qt/integrator.cpp: reworking handling of timeouts, + since QTimer wasn't really meant to be used the way DBusTimeout is + +2003-11-24 Zack Rusin <zack@kde.org> + + * qt/integrator.h, qt/integrator.cpp, Makefile.am: Adding + Integrator class which integrates D-BUS with the Qt event loop, + + * qt/connection.h, qt/connection.cpp: Move all the code which + was dealing with D-BUS integration to the Integrator class, + and start using Integrator, + +2003-11-23 Zack Rusin <zack@kde.org> + + * qt/connection.h, qt/connection.cpp: Adding the DBusConnection + wrapper + + * qt/message.h, qt/message.cpp: updating to the current D-BUS api, + switching namespaces to DBusQt, reworking the class, + + * Makefile.cvs: switching dependencies so that it matches KDE + schematics, + + * qt/Makefile.am: adding connection.{h,cpp} and message.{h,cpp} to + the library + +2003-11-19 Havoc Pennington <hp@redhat.com> + + * NEWS: update + + * configure.in: bump version to 0.20 + + * configure.in (have_qt): add yet another place to look for qt + (someone hand trolltech a .pc file...) + +2003-11-01 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.xml: add state machine docs on the auth + protocol; just a first draft, I'm sure it's wrong. + +2003-10-28 David Zeuthen <david@fubar.dk> + + * python/dbus_bindings.pyx.in: add get_dict to handle dictionaries + return types. Fixup TYPE_* to reflect changes in dbus/dbus-protocol.h + +2003-10-28 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c (get_next_field): delete unused function + +2003-10-28 Havoc Pennington <hp@redhat.com> + + * bus/expirelist.c (do_expiration_with_current_time): detect + failure of the expire_func due to OOM + + * bus/connection.c (bus_pending_reply_expired): return FALSE on OOM + + * bus/dispatch.c (check_send_exit_to_service): fix to handle the + NoReply error that's now created by the bus when the service exits + +2003-10-28 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c (_dbus_message_test): enable and fix the + tests for set_path, set_interface, set_member, etc. + + * dbus/dbus-string.c (_dbus_string_insert_bytes): allow 0 bytes + + * dbus/dbus-message.c (set_string_field): always just delete and + re-append the field; accept NULL for deletion + (re_align_fields_recurse): reimplement + +2003-10-26 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c: fix docs to properly describe the + disconnected message + (_dbus_connection_notify_disconnected): remove this function; + we can't synchronously add the disconnected message, we have to + do it after we've queued any remaining real messages + (_dbus_connection_get_dispatch_status_unlocked): queue the + disconnect message only if the transport has finished queueing all + its real messages and is disconnected. + (dbus_connection_disconnect): update the dispatch status here + +2003-10-22 Havoc Pennington <hp@redhat.com> + + * bus/bus.c (bus_context_check_security_policy): fix up assertion + + * bus/connection.c (bus_transaction_send_from_driver): set the + destination to the connection's base service + +2003-10-20 Havoc Pennington <hp@redhat.com> + + hmm, make check is currently not passing. + + * doc/dbus-specification.xml: add requirement that custom type + names follow the same rules as interface names. + + * dbus/dbus-protocol.h: change some of the byte codes, to avoid + duplication and allow 'c' to be 'custom'; dict is now 'm' for + 'map' + + * doc/dbus-specification.xml: update type codes to match + dbus-protocol.h, using the ASCII byte values. Rename type NAMED to + CUSTOM. Add type OBJECT_PATH to the spec. + +2003-10-17 Havoc Pennington <hp@redhat.com> + + * bus/driver.c (create_unique_client_name): use "." as separator + in base service names instead of '-' + + * dbus/dbus-string.c (_dbus_string_get_byte): allow getting nul + byte at the end of the string + + * dbus/dbus-internals.h (_DBUS_LIKELY, _DBUS_UNLIKELY): add + optimization macros since string validation seems to be a slow + point. + + * doc/dbus-specification.xml: restrict valid + service/interface/member/error names. Add test suite code for the + name validation. + + * dbus/dbus-string.c: limit service/interface/member/error names + to [0-9][A-Z][a-z]_ + + * dbus/dbus-connection.c (dbus_connection_dispatch): add missing + format arg to verbose spew + + * glib/dbus-gproxy.c (dbus_gproxy_call_no_reply): if not out of + memory, return instead of g_error + + * test/test-service.c (path_message_func): support emitting a + signal on request + + * dbus/dbus-bus.c (init_connections_unlocked): only fill in + activation bus type if DBUS_BUS_ACTIVATION was set; default to + assuming the activation bus was the session bus so that services + started manually will still register. + (init_connections_unlocked): fix so that in OOM situation we get + the same semantics when retrying the function + + * test/test-service.c (main): change to use path registration, to + test those codepaths; register with DBUS_BUS_ACTIVATION rather + than DBUS_BUS_SESSION + +2003-10-16 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gtest-main.c: bracket with #ifdef DBUS_BUILD_TESTS + + * Makefile.am (GCOV_DIRS): remove "test", we don't care about test + coverage of the tests + (coverage-report.txt): don't move the .da and .bbg files around + +2003-10-16 Havoc Pennington <hp@redhat.com> + + * bus/bus.c (struct BusContext): remove struct field I didn't mean + to put there + +2003-10-16 Havoc Pennington <hp@redhat.com> + + * bus/connection.c (bus_pending_reply_expired): either cancel or + execute, not both + (bus_connections_check_reply): use unlink, not remove_link, as we + don't want to free the link; fixes double free mess + + * dbus/dbus-pending-call.c (dbus_pending_call_block): fix in case + where no reply was received + + * dbus/dbus-connection.c (_dbus_pending_call_complete_and_unlock): + fix a refcount leak + + * bus/signals.c (match_rule_matches): add special cases for the + bus driver, so you can match on sender/destination for it. + + * dbus/dbus-sysdeps.c (_dbus_abort): print backtrace if + DBUS_PRINT_BACKTRACE is set + + * dbus/dbus-internals.c: add pid to assertion failure messages + + * dbus/dbus-connection.c: add message type code to the debug spew + + * glib/dbus-gproxy.c (gproxy_get_match_rule): match rules want + sender=foo not service=foo + + * dbus/dbus-bus.c (dbus_bus_get): if the activation bus is the + session bus but DBUS_SESSION_BUS_ADDRESS isn't set, use + DBUS_ACTIVATION_ADDRESS instead + + * bus/activation.c: set DBUS_SESSION_BUS_ADDRESS, + DBUS_SYSTEM_BUS_ADDRESS if appropriate + + * bus/bus.c (bus_context_new): handle OOM copying bus type into + context struct + + * dbus/dbus-message.c (dbus_message_iter_get_object_path): new function + (dbus_message_iter_get_object_path_array): new function (half + finished, disabled for the moment) + + * glib/dbus-gproxy.c (dbus_gproxy_end_call): properly handle + DBUS_MESSAGE_TYPE_ERROR + + * tools/dbus-launch.c (babysit): support DBUS_DEBUG_OUTPUT to + avoid redirecting stderr to /dev/null + (babysit): close stdin if not doing the "exit_with_session" thing + + * dbus/dbus-sysdeps.c (_dbus_become_daemon): delete some leftover + debug code; change DBUS_DEBUG_OUTPUT to only enable stderr, not + stdout/stdin, so things don't get confused + + * bus/system.conf.in: fix to allow replies, I modified .conf + instead of .conf.in again. + +2003-10-14 David Zeuthen <david@fubar.dk> + + * python/dbus_bindings.pyx.in (MessageIter.get): fixed typo in + argtype to arg_type when raising unknown arg type exception. + Changed type list to reflect the changes in dbus-protocol.h so + the bindings actually work. + +2003-10-14 Havoc Pennington <hp@redhat.com> + + * test/decode-gcov.c: support gcc 3.3 also, though gcc 3.3 seems + to have a bug keeping it from outputting the .da files sometimes + (string_get_string): don't append garbage nul bytes to the string. + +2003-10-15 Seth Nickell <seth@gnome.org> + + * python/Makefile.am: + + Include dbus_h_wrapper.h in the dist tarball. + +2003-10-14 Havoc Pennington <hp@redhat.com> + + * bus/bus.c (bus_context_check_security_policy): revamp this to + work more sanely with new policy-based requested reply setup + + * bus/connection.c (bus_transaction_send_from_driver): set bus + driver messages as no reply + + * bus/policy.c (bus_client_policy_check_can_receive): handle a + requested_reply attribute on allow/deny rules + + * bus/system.conf: add <allow requested_reply="true"/> + + * bus/driver.c (bus_driver_handle_message): fix check for replies + sent to the bus driver, which was backward. How did this ever work + at all though? I think I'm missing something. + + * dbus/dbus-message.c (decode_header_data): require error and + method return messages to have a reply serial field to be valid + (_dbus_message_loader_queue_messages): break up this function; + validate that reply serial and plain serial are nonzero; + clean up the OOM/error handling. + (get_uint_field): don't return -1 from this + (dbus_message_create_header): fix signed/unsigned bug + + * bus/connection.c (bus_connections_expect_reply): save serial of + the incoming message, not reply serial + +2003-10-14 Havoc Pennington <hp@redhat.com> + + * bus/connection.c: implement pending reply tracking using + BusExpireList + + * bus/bus.c (bus_context_check_security_policy): verify that a + reply is pending in order to allow a reply to be sent. Deny + messages of unknown type. + + * bus/dbus-daemon-1.1.in: update to mention new resource limits + + * bus/bus.c (bus_context_get_max_replies_per_connection): new + (bus_context_get_reply_timeout): new + +2003-10-13 Seth Nickell <seth@gnome.org> + + * python/Makefile.am: + + Pass "make distcheck": remove a couple files from DIST_FILES + that weren't included in the final version. + +2003-10-12 Havoc Pennington <hp@pobox.com> + + Added test code that 1) starts an actual bus daemon and 2) uses + DBusGProxy; fixed bugs that were revealed by the test. Lots + more testing possible, but this is the basic framework. + + * glib/dbus-gproxy.c (dbus_gproxy_manager_unregister): remove + empty proxy lists from the proxy list hash + + * dbus/dbus-message.c (dbus_message_iter_get_args_valist): add a + couple of return_if_fail checks + + * dbus/dbus-pending-call.c (_dbus_pending_call_new): use dbus_new0 + to allocate, so everything is cleared to NULL as it should be. + + * glib/dbus-gmain.c (dbus_connection_setup_with_g_main): pass + source as data to dbus_connection_set_timeout_functions() as the + timeout functions expected + + * test/glib/run-test.sh: add a little script to start up a message + bus and run tests using it + + * tools/dbus-launch.1: updates + + * tools/dbus-launch.c (main): add --config-file option + + * tools/dbus-launch.c (main): remove confusing else if (runprog) + that could never be reached. + + * dbus/dbus-message.c (dbus_message_new_method_return) + (dbus_message_new_error, dbus_message_new_signal): set the + no-reply-expected flag on all these. Redundant, but may + as well be consistent. + +2003-10-11 Havoc Pennington <hp@pobox.com> + + * test/decode-gcov.c (function_solve_graph): make broken block + graph a nonfatal error since it seems to be broken. Need to debug + this. + + * dbus/dbus-marshal.c (_dbus_type_is_valid): new function since we + can't just check type > INVALID < LAST anymore + + * dbus/dbus-message.c (dbus_message_get_signature): new function + (dbus_message_has_signature): new function + (struct DBusMessage): add signature field (right now it isn't sent + over the wire, just generated on the fly) + (dbus_message_copy): copy the signature, and init strings to + proper length to avoid some reallocs + (dbus_message_iter_init_array_iterator): return void, since it + can't fail + (dbus_message_iter_init_dict_iterator): return void since it can't fail + (_dbus_message_loader_queue_messages): add silly temporary hack to + fill in message->signature on load + + * dbus/dbus-protocol.h: change DBUS_TYPE_* values to be ASCII + characters, so they are relatively human-readable. + +2003-10-11 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c (_dbus_message_test): add more test + coverage, but #if 0 for now since they uncover a bug + not fixed yet; I think in re_align_field_recurse() + (re_align_field_recurse): add FIXME about broken assertion + + * dbus/dbus-sysdeps.c (_dbus_sysdeps_test): add more test coverage + + * bus/connection.c: share a couple code bits with expirelist.c + + * bus/expirelist.h, bus/expirelist.c: implement a generic + expire-items-after-N-seconds facility, was going to share between + expiring connections and replies, decided not to use for expiring + connections for now. + + * COPYING: include AFL 2.0 (still need to change all the file headers) + +2003-10-09 Havoc Pennington <hp@redhat.com> + + * configure.in: define DBUS_HAVE_GCC33_GCOV if we have + gcc 3.3. Not that we do anything about it yet. + + * bus/signals.c (bus_match_rule_parse): impose max length on the + match rule text + + * dbus/dbus-protocol.h: add DBUS_MAXIMUM_MATCH_RULE_LENGTH + +2003-10-09 Havoc Pennington <hp@redhat.com> + + Make matching rules theoretically work (add parser). + + * bus/bus.c (bus_context_check_security_policy): fix up to handle + the case where destination is explicitly specified as bus driver + and someone else is eavesdropping. + + * bus/policy.c (bus_client_policy_check_can_receive): fix up + definition of eavesdropping and assertion + + * tools/dbus-send.c (main): use dbus_message_type_from_string + + * bus/signals.c (bus_match_rule_parse): implement + + * dbus/dbus-message.c (dbus_message_type_from_string): new + + * dbus/dbus-errors.h (DBUS_ERROR_MATCH_RULE_INVALID): add + +2003-10-02 Havoc Pennington <hp@pobox.com> + + * glib/dbus-gproxy.c (dbus_gproxy_call_no_reply): rename from + dbus_gproxy_oneway_call + + * glib/dbus-gmain.c (dbus_connection_setup_with_g_main) + (dbus_server_setup_with_g_main): fix to allow calling them more + than once on the same args + (dbus_bus_get_with_g_main): new function + +2003-10-02 Havoc Pennington <hp@redhat.com> + + * doc/dbus-tutorial.xml: write some stuff + +2003-09-29 Havoc Pennington <hp@pobox.com> + + * configure.in: split checks for Doxygen from XML docs, check for + xmlto + + * doc/Makefile.am: XML-ify all the docs, and add a blank + dbus-tutorial.xml + +2003-09-29 Havoc Pennington <hp@pobox.com> + + * Merge dbus-object-names branch. To see the entire patch + do cvs diff -r DBUS_OBJECT_NAMES_BRANCHPOINT -r dbus-object-names, + it's huuuuge though. + To revert, I tagged DBUS_BEFORE_OBJECT_NAMES_MERGE. + +2003-09-28 Havoc Pennington <hp@pobox.com> + + * HACKING: update to reflect new server + +2003-09-26 Seth Nickell <seth@gnome.org> + + * python/dbus.py: + * python/examples/example-signals.py: + + Start implementing some notions of signals. The API + is really terrible, but they sort of work (with the + exception of being able to filter by service, and to + transmit signals *as* a particular service). Need to + figure out how to make messages come from the service + we registered :-( + + * python/dbus_bindings.pyx.in: + + Removed duplicate message_handler callbacks. + +2003-09-25 Havoc Pennington <hp@redhat.com> + + * bus/session.conf.in: fix my mess + +2003-09-25 Havoc Pennington <hp@pobox.com> + + * bus/session.conf.in: fix security policy, reported by Seth Nickell + +2003-09-25 Seth Nickell <seth@gnome.org> + + * python/examples/example-service.py: + + Johan notices complete wrong code in example-service, but + completely wrong in a way that works exactly the same (!). + Johan is confused, how could this possibly work? Example + code fails to serve purpose of making things clear. + Seth fixes. + +2003-09-25 Mark McLoughlin <mark@skynet.ie> + + * doc/dbus-specification.sgml: don't require header fields + to be 4-byte aligned and specify that fields should be + distinguished from padding by the fact that zero is not + a valid field name. + + * doc/TODO: remove re-alignment item and add item to doc + the OBJECT_PATH type. + + * dbus/dbus-message.c: + (HeaderField): rename the original member to value_offset + and introduce a name_offset member to keep track of where + the field actually begins. + (adjust_field_offsets): remove. + (append_int_field), (append_uint_field), + (append_string_field): don't align the start of the header + field to a 4-byte boundary. + (get_next_field): impl finding the next marhsalled field + after a given field. + (re_align_field_recurse): impl re-aligning a number of + already marshalled fields. + (delete_field): impl deleting a field of any type and + re-aligning any following fields. + (delete_int_or_uint_field), (delete_string_field): remove. + (set_int_field), (set_uint_field): no need to re-check + that we have the correct type for the field. + (set_string_field): ditto and impl re-aligning any + following fields. + (decode_header_data): update to take into account that + the fields aren't 4-byte aligned any more and the new + way to distinguish padding from header fields. Also, + don't exit when there is too much header padding. + (process_test_subdir): print the directory. + (_dbus_message_test): add test to make sure a following + field is re-aligned correctly after field deletion. + + * dbus/dbus-string.[ch]: + (_dbus_string_insert_bytes): rename from insert_byte and + allow the insert of multiple bytes. + (_dbus_string_test): test inserting multiple bytes. + + * dbus/dbus-marshal.c: (_dbus_marshal_set_string): add + warning note to docs about having to re-align any + marshalled values following the string. + + * dbus/dbus-message-builder.c: + (append_string_field), (_dbus_message_data_load): + don't align the header field. + + * dbus/dbus-auth.c: (process_test_subdir): print the + directory. + + * test/break-loader.c: (randomly_add_one_byte): upd. for + insert_byte change. + + * test/data/invalid-messages/bad-header-field-alignment.message: + new test case. + + * test/data/valid-messages/unknown-header-field.message: shove + a dict in the unknown field. + +2003-09-25 Seth Nickell <seth@gnome.org> + + * python/dbus.py: + * python/dbus_bindings.pyx.in: + + Handle return values. + + * python/examples/example-client.py: + * python/examples/example-service.py: + + Pass back return values from the service to the client. + +2003-09-24 Seth Nickell <seth@gnome.org> + + * python/dbus.py: + + Connect Object methods (when you are sharing an object) up... pass + in a list of methods to be shared. Sharing all the methods just + worked out too weird. You can now create nice Services over the + DBus in Python. :-) + + * python/dbus_bindings.pyx.in: + + Keep references to user_data tuples passed into C functions so + Python doesn't garbage collect on us. + + Implement MethodReturn and Error subclasses of Message for creating + DBusMessage's of those types. + + * python/examples/example-client.py: + * python/examples/example-service.py: + + Simple example code showing both how create DBus services and objects, + and how to use them. + +2003-09-23 Havoc Pennington <hp@pobox.com> + + * glib/dbus-gproxy.c (dbus_gproxy_manager_filter): implement + +2003-09-23 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gproxy.c (dbus_gproxy_connect_signal): implement + (dbus_gproxy_disconnect_signal): implement + (dbus_gproxy_manager_remove_signal_match): implement + (dbus_gproxy_manager_add_signal_match): implement + (dbus_gproxy_oneway_call): implement + +2003-09-23 Havoc Pennington <hp@pobox.com> + + * glib/dbus-gproxy.c (struct DBusGProxy): convert to a GObject + subclass. This means dropping the transparent thread safety of the + proxy; you now need a separate proxy per-thread, or your own + locking on the proxy. Probably right anyway. + (dbus_gproxy_ref, dbus_gproxy_unref): nuke, just use g_object_ref + +2003-09-22 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gproxy.c (dbus_gproxy_manager_get): implement + +2003-09-21 Seth Nickell <seth@gnome.org> + + First checkin of the Python bindings. + + * python/.cvsignore: + * python/Makefile.am: + * python/dbus_bindings.pyx.in: + * python/dbus_h_wrapper.h: + + Pieces for Pyrex to operate on, building a dbus_bindings.so + python module for low-level access to the DBus APIs. + + * python/dbus.py: + + High-level Python module for accessing DBus objects. + + * configure.in: + * Makefile.am: + + Build stuff for the python bindings. + + * acinclude.m4: + + Extra macro needed for finding the Python C header files. + +2003-09-21 Havoc Pennington <hp@pobox.com> + + * glib/dbus-gproxy.c (dbus_gproxy_manager_new): start + implementing the proxy manager, didn't get very far. + + * dbus/dbus-bus.c (dbus_bus_add_match): new + (dbus_bus_remove_match): new + + * glib/dbus-gproxy.c (dbus_gproxy_new_for_service): add a + path_name argument; adjust the other not-yet-implemented + gproxy constructors to be what I think they should be. + +2003-09-21 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-bus.c (dbus_bus_get): set exit_on_disconnect to TRUE + by default for message bus connections. + + * dbus/dbus-connection.c (dbus_connection_dispatch): exit if + exit_on_disconnect flag is set and we process the disconnected + signal. + (dbus_connection_set_exit_on_disconnect): new function + +2003-09-21 Havoc Pennington <hp@pobox.com> + + Get matching rules mostly working in the bus; only actually + parsing the rule text remains. However, the client side of + "signal connections" hasn't been started, this patch is only the + bus side. + + * dbus/dispatch.c: fix for the matching rules changes + + * bus/driver.c (bus_driver_handle_remove_match) + (bus_driver_handle_add_match): send an ack reply from these + method calls + + * glib/dbus-gproxy.c (dbus_gproxy_begin_call): fix order of + arguments, reported by Seth Nickell + + * bus/config-parser.c (append_rule_from_element): support + eavesdrop=true|false attribute on policies so match rules + can be prevented from snooping on the system bus. + + * bus/dbus-daemon-1.1.in: consistently use terminology "sender" + and "destination" in attribute names; fix some docs bugs; + add eavesdrop=true|false attribute + + * bus/driver.c (bus_driver_handle_add_match) + (bus_driver_handle_remove_match): handle AddMatch, RemoveMatch + messages + + * dbus/dbus-protocol.h (DBUS_SERVICE_ORG_FREEDESKTOP_BROADCAST): get + rid of broadcast service concept, signals are just always broadcast + + * bus/signals.c, bus/dispatch.c, bus/connection.c, bus/bus.c: + mostly implement matching rules stuff (currently only exposed as signal + connections) + +2003-09-21 Mark McLoughlin <mark@skynet.ie> + + * doc/dbus-specification.sgml: Change the header field name + to be an enum and update the rest of the spec to reference + the fields using the conventinal name. + + * dbus/dbus-protocol.h: update to reflect the spec. + + * doc/TODO: add item to remove the 4 byte alignment requirement. + + * dbus/dbus-message.c: Remove the code to generalise the + header/body length and serial number header fields as named + header fields so we can reference field names using the + protocol values. + (append_int_field), (append_uint_field), (append_string_field): + Append the field name as a byte rather than four chars. + (delete_int_or_uint_field), (delete_string_field): reflect the + fact that the field name and typecode now occupy 4 bytes instead + of 8. + (decode_string_field), (decode_header_data): update to reflect + protocol changes and move the field specific encoding from + decode_string_field() back into decode_header_data(). + + * dbus/dbus-internals.[ch]: (_dbus_header_field_to_string): + Add utility to aid debugging. + + * dbus/dbus-message-builder.c: + (append_string_field), (_dbus_message_data_load): Update to + reflect protocol changes; Change the FIELD_NAME directive + to HEADER_FIELD and allow it to take the field's conventional + name rather than the actual value. + + * test/data/*/*.message: Update to use HEADER_FIELD instead + of FIELD_NAME; Always align the header on an 8 byte boundary + *before* updating the header length. + +2003-09-15 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-pending-call.c: add the get/set object data + boilerplate as for DBusConnection, etc. Use generic object data + for the notify callback. + + * glib/dbus-gparser.c (parse_node): parse child nodes + + * tools/dbus-viewer.c: more hacking on the dbus-viewer + + * glib/dbus-gutils.c (_dbus_gutils_split_path): add a file to + contain functions shared between the convenience lib and the + installed lib + + * glib/Makefile.am (libdbus_glib_1_la_LDFLAGS): add + -export-symbols-regex to the GLib library + + * dbus/dbus-object-tree.c (_dbus_object_tree_dispatch_and_unlock): + fix the locking in here, and add a default handler for + Introspect() that just returns sub-nodes. + +2003-09-14 Havoc Pennington <hp@pobox.com> + + * glib/dbus-gthread.c (dbus_g_thread_init): rename to make g_foo + rather than gfoo consistent + + * glib/dbus-gproxy.h: delete for now, move contents to + dbus-glib.h, because the include files don't work right since we + aren't in the dbus/ subdir. + + * glib/dbus-gproxy.c (dbus_gproxy_send): finish implementing + (dbus_gproxy_end_call): finish + (dbus_gproxy_begin_call): finish + + * glib/dbus-gmain.c (dbus_set_g_error): new + + * glib/dbus-gobject.c (handle_introspect): include information + about child nodes in the introspection + + * dbus/dbus-connection.c (dbus_connection_list_registered): new + function to help in implementation of introspection + + * dbus/dbus-object-tree.c + (_dbus_object_tree_list_registered_and_unlock): new function + +2003-09-12 Havoc Pennington <hp@pobox.com> + + * glib/dbus-gidl.h: add common base class for all the foo_info + types + + * tools/dbus-viewer.c: add GTK-based introspection UI thingy + similar to kdcop + + * test/Makefile.am: try test srcdir -ef . in addition to test + srcdir = ., one of them should work (yeah lame) + + * glib/Makefile.am: build the "idl" parser stuff as a convenience + library + + * glib/dbus-gparser.h: make description_load routines return + NodeInfo* not Parser* + + * Makefile.am (SUBDIRS): build test dir after all library dirs + + * configure.in: add GTK+ detection + +2003-09-07 Havoc Pennington <hp@pobox.com> + + * Make Doxygen contented. + +2003-09-07 Havoc Pennington <hp@pobox.com> + + * doc/dbus-specification.sgml: more updates + +2003-09-06 Havoc Pennington <hp@pobox.com> + + * doc/dbus-specification.sgml: partial updates + + * bus/dbus-daemon-1.1.in: fix the config file docs for the + zillionth time; hopefully I edited the right file this time. + + * bus/config-parser.c (append_rule_from_element): support + send_type, send_path, receive_type, receive_path + + * bus/policy.c: add message type and path to the list of things + that can be "firewalled" + +2003-09-06 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c (dbus_connection_register_fallback): add this + (dbus_connection_register_object_path): make this not handle + messages to paths below the given path + +2003-09-03 Havoc Pennington <hp@pobox.com> + + * test/glib/Makefile.am: add this with random glib-linked test + programs + + * glib/Makefile.am: remove the random test programs from here, + leave only the unit tests + + * glib/dbus-gobject.c (_dbus_gobject_test): add test for + uscore/javacaps conversion, and fix + (get_object_property, set_object_property): change to .NET + convention for mapping props to methods, set_FooBar/get_FooBar, + since one language has such a convention we may as well copy it. + Plus real methods in either getFooBar or get_foo_bar style won't + collide with this convention. + +2003-09-01 Havoc Pennington <hp@pobox.com> + + * glib/dbus-gparser.c: implement + + * glib/dbus-gobject.c: start implementing skeletons support + + * configure.in: when disabling checks/assert, also define + G_DISABLE_ASSERT and G_DISABLE_CHECKS + +2003-09-01 Havoc Pennington <hp@pobox.com> + + * glib/Makefile.am: rearrange a bunch of files and get "make + check" framework set up + +2003-08-31 Havoc Pennington <hp@pobox.com> + + * fix build with --disable-tests + +2003-08-30 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c: purge DBusMessageHandler + + * dbus/dbus-message-handler.c: remove DBusMessageHandler, just + use callbacks everywhere + +2003-08-30 Havoc Pennington <hp@pobox.com> + + * test/data/valid-config-files/system.d/test.conf: change to + root for the user so warnings don't get printed + + * dbus/dbus-message.c: add dbus_message_get_path, + dbus_message_set_path + + * dbus/dbus-object-tree.c (do_test_dispatch): add test of + dispatching to a path + + * dbus/dbus-string.c (_dbus_string_validate_path): add + + * dbus/dbus-marshal.c (_dbus_demarshal_object_path): implement + (_dbus_marshal_object_path): implement + + * dbus/dbus-protocol.h (DBUS_HEADER_FIELD_PATH): new header field + to contain the path to the target object + (DBUS_HEADER_FIELD_SENDER_SERVICE): rename + DBUS_HEADER_FIELD_SENDER to explicitly say it's the sender service + +2003-08-30 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-object-tree.c: write tests and fix the discovered bugs + +2003-08-29 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-object-tree.c: modify to allow overlapping paths to be + registered + (struct DBusObjectSubtree): shrink this + a lot, since we may have a lot of them + (_dbus_object_tree_free_all_unlocked): implement + (_dbus_object_tree_dispatch_and_unlock): implement + +2003-08-29 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-internals.h: fix _DBUS_N_GLOBAL_LOCKS + +2003-08-28 Havoc Pennington <hp@pobox.com> + + purge DBusObjectID + + * dbus/dbus-connection.c: port to no ObjectID, create a + DBusObjectTree, rename ObjectTree to ObjectPath in public API + + * dbus/dbus-connection.h (struct DBusObjectTreeVTable): delete + everything except UnregisterFunction and MessageFunction + + * dbus/dbus-marshal.c: port away from DBusObjectID, + add DBUS_TYPE_OBJECT_PATH + + * dbus/dbus-object-registry.[hc], dbus/dbus-object.[hc], + dbus/dbus-objectid.[hc]: remove these, we are moving to + path-based object IDs + +2003-08-25 Havoc Pennington <hp@pobox.com> + + Just noticed that dbus_message_test is hosed, I wonder when I + broke that. I thought make check was passing earlier... + + * dbus/dbus-object-tree.c: add new "object tree" to match DCOP + container tree, will replace most of dbus-object-registry + + * dbus/dbus-string.c (_dbus_string_append_printf_valist): fix C99 + screwup + +2003-08-19 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c (decode_string_field): support FIELD_SENDER + (dbus_message_is_error): fix this function + + * bus/dbus-daemon-1.1: clarify logic on when <deny>/<allow> rules + match + + * bus/policy.c (bus_client_policy_check_can_receive): fix code to + reflect clarified man page + (bus_client_policy_check_can_send): ditto + + * bus/session.conf.in: fixup + + * bus/system.conf.in: fixup + +2003-08-18 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-hash.c (_dbus_hash_table_insert_two_strings): fix + + * dbus/dbus-message.c (_dbus_message_loader_queue_messages): fix + dumb bug created earlier (wrong order of args to + decode_header_data()) + + * tools/dbus-send.c: port + + * tools/dbus-print-message.c (print_message): port + + * test/data/*messages: port all messages over + + * dbus/dbus-message-builder.c: support including + message type + + * bus/driver.c: port over + + * bus/dispatch.c: port over to new stuff + + * dbus/dbus-connection.c (_dbus_connection_new_for_transport): + rename disconnect signal to "Disconnected" + +2003-08-17 Havoc Pennington <hp@pobox.com> + + This doesn't compile yet, but syncing up so I can hack on it from + work. What are branches for if not broken code? ;-) + + * dbus/dbus-protocol.h: remove DBUS_HEADER_FIELD_NAME, add + DBUS_HEADER_FIELD_INTERFACE, DBUS_HEADER_FIELD_MEMBER, + DBUS_HEADER_FIELD_ERROR_NAME + + * dbus/dbus-hash.c: Introduce DBUS_HASH_TWO_STRINGS as hack to use + for the interface+member pairs + (string_hash): change to use g_str_hash algorithm + (find_direct_function, find_string_function): refactor these to + share most code. + + * dbus/dbus-message.c: port all of this over to support + interface/member fields instead of name field + + * dbus/dbus-object-registry.c: port over + + * dbus/dbus-string.c (_dbus_string_validate_interface): rename + from _dbus_string_validate_name + + * bus/dbus-daemon-1.1: change file format for the + <deny>/<allow> stuff to match new message naming scheme + + * bus/policy.c: port over + + * bus/config-parser.c: parse new format + +2003-08-16 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-object-registry.c (add_and_remove_objects): remove + broken assertion + + * glib/dbus-gproxy.c: some hacking + +2003-08-15 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-pending-call.c (dbus_pending_call_block): implement + + * dbus/dbus-connection.c + (dbus_connection_send_with_reply_and_block): factor out internals; + change to convert any error replies to DBusError instead of + returning them as a message + +2003-08-15 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c, + dbus/dbus-pending-call.c: Finish the pending call stuff + +2003-08-14 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-pending-call.c: start on new object that will replace + DBusMessageHandler and ReplyHandlerData for tracking outstanding + replies + + * dbus/dbus-gproxy.c: start on proxy object used to communicate + with remote interfaces + + * dbus/dbus-gidl.c: do the boring boilerplate in here + +2003-08-12 Havoc Pennington <hp@pobox.com> + + * bus/dispatch.c (bus_dispatch): make this return proper + DBusHandlerResult to avoid DBUS_ERROR_UNKNOWN_METHOD + + * dbus/dbus-errors.c (dbus_set_error): use + _dbus_string_append_printf_valist + + * dbus/dbus-string.c (_dbus_string_append_printf_valist) + (_dbus_string_append_printf): new + + * dbus/dbus-errors.h (DBUS_ERROR_UNKNOWN_MESSAGE): change to + UNKNOWN_METHOD + + * dbus/dbus-connection.c (dbus_connection_dispatch): handle + DBUS_HANDLER_RESULT_NEED_MEMORY; send default error reply if a + message is unhandled. + +2003-08-11 Havoc Pennington <hp@pobox.com> + + * bus/test.c (client_disconnect_handler): change to return + HANDLED (would have been REMOVE_MESSAGE) + + * dbus/dbus-object.h (enum DBusHandlerResult): rename to + HANDLED/NOT_YET_HANDLED instead of + REMOVE_MESSAGE/ALLOW_MORE_HANDLERS to make it clearer how it + should be used. + +2003-08-10 Havoc Pennington <hp@pobox.com> + + * tools/dbus-send.c (main): add --type argument, for now + supporting only method_call and signal types. + + * tools/dbus-print-message.c: print message type + + * dbus/dbus-connection.c (_dbus_connection_new_for_transport): + init connection->objects + + * doc/dbus-specification.sgml: fix sgml + + * bus/*.c: port over to object-instance API changes + + * test/test-service.c: ditto + + * dbus/dbus-message.c (dbus_message_create_header): allow #NULL + name, we will have to fix up the rest of the code to also handle + this + (dbus_message_new): generic message-creation call + (set_string_field): allow appending name field + +2003-08-06 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-object-registry.c: implement signal connection + and dispatch + + * dbus/dbus-connection.c (_dbus_connection_unref_unlocked): new + + * dbus/dbus-internals.c (_dbus_memdup): new function + +2003-08-02 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c (dbus_message_get_no_reply) + (dbus_message_set_no_reply): add these and remove + set_is_error/get_is_error + + * dbus/dbus-protocol.h, doc/dbus-specification.sgml: + remove the ERROR flag, since there's now an ERROR type + +2003-08-01 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-object-registry.c (_dbus_object_registry_handle_and_unlock): + implement + + * dbus/dbus-message.c (dbus_message_get_type): new function + + * doc/dbus-specification.sgml: add "type" byte to messages + +2003-08-01 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-protocol.h (DBUS_MESSAGE_TYPE_*): introduce + a message type enum to distinguish kinds of message + (DBUS_HEADER_FLAG_NO_REPLY_EXPECTED): flag for a message + that need not be replied to + +2003-08-01 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-marshal.c: adapt to DBusObjectID changes + (unpack_8_octets): fix no-64-bit-int bug + + * dbus/dbus-object-registry.c (validate_id): validate the + connection ID bits, not just the instance ID. + + * dbus/dbus-connection.c (_dbus_connection_init_id): initialize + the connection-global 33 bits of the object ID + + * dbus/dbus-object-registry.c (info_from_entry): fill in + object ID in the new way + + * dbus/dbus-objectid.h: rather than high/low bits, specifically + define server/client/instance bits. + +2003-07-30 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c (dbus_connection_register_object): fix + build + +2003-07-13 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-object.h (struct DBusObjectVTable): add padding + fields to DBusObjectVTable and DBusObjectInfo + +2003-07-12 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-object-registry.c: implement unit test, + fix bugs discovered in process + + * dbus/dbus-connection.c: remove handler_table and + register_handler(), add DBusObjectRegistry usage + + * dbus/dbus-objectid.c (dbus_object_id_is_null) + (dbus_object_id_set_null): new functions + +2003-07-08 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-object.c: implement some of this + + * dbus/dbus-object-registry.c + (_dbus_object_registry_add_and_unlock): fill in the object_id out + param + (_dbus_object_registry_new): handle OOM + +2003-07-08 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-object.h: sketch out an API for registering objects + with a connection, that allows us to use as little as 24 bytes + per object and lets application code represent an object in + any conceivable way. + + * dbus/dbus-object-registry.c: implement the hard bits of the + DBusConnection aspect of object API. Not yet wired up. + +2003-07-06 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-marshal.c (_dbus_marshal_set_object_id): new function + (_dbus_marshal_object_id): new + (_dbus_demarshal_object_id): new + (_dbus_marshal_get_arg_end_pos): support object ID type, and + consolidate identical switch cases. Don't conditionalize handling + of DBUS_TYPE_UINT64, need to handle the type always. + (_dbus_marshal_validate_arg): consolidate identical cases, and + handle DBUS_TYPE_OBJECT_ID + + * dbus/dbus-objectid.c: new file with DBusObjectID data type. + + * dbus/dbus-protocol.h: add DBUS_TYPE_OBJECT_ID + +2003-09-28 Havoc Pennington <hp@pobox.com> + + * real 0.13 release + +2003-09-28 Havoc Pennington <hp@pobox.com> + + * doc/Makefile.am (dbus-specification.html): testing a funky hack + to work with Debian db2html + +2003-09-28 Havoc Pennington <hp@pobox.com> + + * configure.in: 0.13 + + * doc/Makefile.am (dbus-test-plan.html): accept nonexistence of + stylesheet-images for benefit of Debian + + Change back to using filesystem-linked sockets for the system + bus, so only root can create the default system bus address. + + * bus/system.conf.in: change to use + DBUS_SYSTEM_BUS_DEFAULT_ADDRESS + + * dbus/Makefile.am (INCLUDES): remove DBUS_SYSTEM_BUS_PATH define + from here. + + * configure.in: define DBUS_SYSTEM_BUS_DEFAULT_ADDRESS + here, and AC_DEFINE DBUS_SYSTEM_PATH + +2003-08-09 Anders Carlsson <andersca@codefactory.se> + + * doc/TODO: + * doc/busconfig.dtd: + Add busconfig DTD. + +2003-08-09 Anders Carlsson <andersca@codefactory.se> + + * doc/dbus-specification.sgml: + Add activation reply values. + +2003-08-05 Havoc Pennington <hp@redhat.com> + + * configure.in: 0.12 + +2003-08-05 Anders Carlsson <andersca@codefactory.se> + + * glib/dbus-gmain.c: (watch_fd_new), (watch_fd_ref), + (watch_fd_unref), (dbus_gsource_check), (dbus_gsource_dispatch), + (add_watch), (remove_watch), (create_source): + Refcount fds, fixes some reentrancy issues. + +2003-07-30 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-bus.c (init_connections_unlocked): fix default system + bus address to be abstract if we have abstract sockets + + * NEWS: update + +2003-07-28 Havoc Pennington <hp@redhat.com> + + * bus/messagebus.in: fix to avoid processname/servicename + confusion, from Michael Kearey + https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=100965 + +2003-07-23 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c (dbus_message_iter_get_named): + fix from Andy Hanton to remove broken "+1" + +2003-07-16 Havoc Pennington <hp@pobox.com> + + * tools/dbus-launch.c (babysit): close stdout/stderr in the + babysitter process, as suggested by Thomas Leonard, so + an "eval `dbus-launch --exit-with-session`" will actually + return + +2003-07-16 Havoc Pennington <hp@pobox.com> + + * configure.in: print out EXPANDED_* variables in the summary at + the end; clean up the code that computes EXPANDED_ variables and + get the ones using exec_prefix right. Should make things work + when you build without --prefix + +2003-06-29 Havoc Pennington <hp@pobox.com> + + * mono/Test.cs (class Test): fire up a main loop and run it + + * mono/DBus.cs (DBus): don't g_thread_init since it can only be + done once, the app has to do it + +2003-06-26 Havoc Pennington <hp@pobox.com> + + * mono/Connection.cs: set up connection with the glib main loop + +2003-07-01 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.sgml: clarify the format of a type code, + change suggested by Jim Blandy + +2003-06-29 Miloslav Trmac <mitr@volny.cz> + + * doc/Makefile.am: + * tools/Makefile.am: Don't assume srcdir == builddir. + + * dbus/dbus-memory.c (dbus_realloc): Don't check guards after shrinking + the allocated block. + (_dbus_memory_test): New function. + * dbus/dbus-test.h: Add _dbus_memory_test (). + * dbus/dbus-test.c (dbus_internal_do_not_use_run_tests): Call it. + + * dbus/dbus-message.c (decode_header_data): Use %.4s instead + of %c%c%c%c. + (dbus_message_new): Remove obsolete @todo. + + * dbus/dbus-marshal.c (_dbus_marshal_set_int64) + (_dbus_marshal_set_uint64): Fix comment. + + * dbus/dbus-message.c (append_int_field, append_uint_field): Don't + hardcode FIELD_REPLY_SERIAL. + + * dbus/dbus-mainloop.c (_dbus_loop_remove_watch) + (_dbus_loop_remove_timeout): Cast function pointers to (void *) for %p + + * configure.in: Add -D_POSIX_C_SOURCE=199309L -DBSD_SOURCE to CFLAGS + and disable DBUS_USE_ATOMIC_INT_486 when --enable-ansi is used + +2003-06-24 Havoc Pennington <hp@pobox.com> + + * mono/*.cs: Use IntPtr.Zero instead of ((IntPtr) 0) + +2003-06-23 Anders Carlsson <andersca@codefactory.se> + + * configure.in: + * gcj/.cvsignore: + * gcj/Hello.java: + * gcj/Makefile.am: + * gcj/TestMessage.java: (TestMessage), (TestMessage.main): + * gcj/org/.cvsignore: + * gcj/org/Makefile.am: + * gcj/org/freedesktop/.cvsignore: + * gcj/org/freedesktop/Makefile.am: + * gcj/org/freedesktop/dbus/.cvsignore: + * gcj/org/freedesktop/dbus/Makefile.am: + * gcj/org/freedesktop/dbus/Message.java: (Message), + (Message.Message): + * gcj/org/freedesktop/dbus/natMessage.cc: + Fix the build system. + +2003-06-22 Havoc Pennington <hp@pobox.com> + + * mono/Connection.cs: add more bindings + + * dbus/dbus-threads.c (dbus_threads_init): allow calling this + more than once. + +2003-06-22 Havoc Pennington <hp@pobox.com> + + * mono/Connection.cs, mono/DBus.cs, mono/Error.cs: + Start wrapping more stuff. + +2003-06-22 Havoc Pennington <hp@pobox.com> + + * mono/Message.cs: implement Message.Wrap() that ensures we only + have a single C# wrapper per DBusMessage, assuming it works which + it probably doesn't. + + * dbus/dbus-message.c (dbus_message_allocate_data_slot): new + (dbus_message_free_data_slot): new + (dbus_message_set_data): new + (dbus_message_get_data): new + +2003-06-22 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-dataslot.c (_dbus_data_slot_allocator_unref) + (_dbus_data_slot_allocator_alloc): rework these to keep a + reference count on each slot and automatically manage a global + slot ID variable passed in by address + + * bus/bus.c: convert to new dataslot API + + * dbus/dbus-bus.c: convert to new dataslot API + + * dbus/dbus-connection.c: convert to new dataslot API + + * dbus/dbus-server.c: convert to new dataslot API + + * glib/dbus-gmain.c: ditto + + * bus/test.c: ditto + + * bus/connection.c: ditto + +2003-06-22 Anders Carlsson <andersca@codefactory.se> + + * configure.in: Add AM_PROG_GCJ and move AM_PROG_LIBTOOL + after the gcj checks so that the correct configuration tags + will be added to libtool. + + * dbus-glib-1.pc.in: No need to specify any includes since + dbus-1.pc.in has those. + +2003-06-22 Havoc Pennington <hp@pobox.com> + + * mono/*, gcj/*, configure.in, Makefile.am: + Check in makefiles and subdirs for mono and gcj bindings. + Neither binding actually exists, just trying to get through + all the build and other boring bits. + +2003-06-21 Philip Blundell <philb@gnu.org> + + * tools/dbus-monitor.1: Updated. + + * tools/dbus-send.1: Likewise. + +2003-06-20 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-transport-unix.c (unix_handle_watch): Check + for hangup and error after checking read so we won't discard + pending data if both hangup and read are set. + +2003-06-19 Philip Blundell <philb@gnu.org> + + * tools/dbus-print-message.c (print_message): Handle BOOLEAN. + + * tools/dbus-send.c: Accept both --system and --session. + + * tools/dbus-monitor.c: Same here. + +2003-06-19 Anders Carlsson <andersca@codefactory.se> + + * glib/dbus-glib.h: Fix so that dbus-glib.h can be used + from C++ (Patch by Miloslav Trmac). + +2003-06-15 Joe Shaw <joe@assbarn.com> + + * configure.in: Check for socklen_t. + + * dbus/dbus-sysdeps.c: Define socklen_t if it's not defined. + + * test/test-segfault.c: Add #include <sys/time.h> + + * tools/Makefile.am: Add DBUS_X_CFLAGS to the INCLUDES since + dbus-launch needs it. + +2003-06-09 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_listen_unix_socket): don't use + SUN_LEN, it breaks abstract socket usage + + * dbus/dbus-internals.c (_dbus_verbose_real): only print PID at + starts of lines. + +2003-06-04 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-server.c (dbus_server_listen): allow abstract sockets + using unix:abstract=/foo, and when listening in a tmpdir + i.e. unix:tmpdir=/tmp, always use abstract sockets if we can. + + * dbus/dbus-transport.c (_dbus_transport_open): support + unix:abstract=/foo + + * dbus/dbus-server-unix.c (_dbus_server_new_for_domain_socket): + support abstract sockets + + * dbus/dbus-transport-unix.c + (_dbus_transport_new_for_domain_socket): support abstract sockets + + * dbus/dbus-sysdeps.c (_dbus_connect_unix_socket): add "abstract" + toggle as an argument, implement abstract namespace support + (_dbus_listen_unix_socket): ditto + + * configure.in: add --enable-abstract-sockets and implement + a configure check for autodetection of the right value. + +2003-06-01 Havoc Pennington <hp@pobox.com> + + * tools/dbus-cleanup-sockets.c: add utility to clean up sockets + in /tmp (though on Linux this will end up being useless, + when we add abstract namespace support) + + * configure.in: define DBUS_SESSION_SOCKET_DIR in addition to + subst'ing it + +2003-05-28 Colin Walters <walters@verbum.org> + + * tools/dbus-monitor.c (main): Fix silly typo (s/--session/--system/). + +2003-05-18 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-message.c (dbus_message_new): Remove @todo. + +2003-05-17 Colin Walters <walters@gnu.org> + + * tools/dbus-send.c: Don't exit with an error code if --help was + passed. Default to using the session bus instead of the system + one. + + * tools/dbus-launch.c: Ditto. + + * tools/dbus-monitor.c: Ditto. + + * tools/dbus-send.1: Update with new arguments. + + * tools/dbus-launch.c: Emit code to export variables. New + arguments -s and -c to specify shell syntax, and a bit of code to + autodetect syntax. Also, allow specifying a program to run. + + * tools/dbus-launch.1: Update with new arguments. + + * tools/dbus-send.1: Ditto. + + * tools/dbus-monitor.1: Ditto. + +2003-05-17 Havoc Pennington <hp@pobox.com> + + * bus/config-parser.c (merge_included): merge in policies from + child configuration file. + + * bus/policy.c (bus_policy_merge): function to merge two policies + together + +2003-05-16 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c: disable verbose lock spew + + * tools/dbus-send.c: add --print-reply command line option + + * tools/dbus-print-message.h (print_message): new util function + shared by dbus-send and dbus-monitor + + * tools/dbus-monitor.c (handler_func): exit on disconnect + + * dbus/dbus-transport-unix.c (do_reading): if the transport is + disconnected, don't try to use the read_watch + + * dbus/dbus-watch.c (dbus_watch_get_enabled): assert watch != NULL + so we can find this bug more easily + +2003-05-16 Havoc Pennington <hp@redhat.com> + + * bus/policy.c (free_rule_list_func): avoid a crash when passed + NULL as DBusHashTable is annoyingly likely to do. + +2003-05-16 Colin Walters <walters@verbum.org> + + * tools/dbus-monitor.c: Add --session argument and usage() + function. + + * tools/dbus-monitor.1: Update with new --session arg. + + * bus/Makefile.am (install-data-hook): Create + $(libdir)/dbus-1.0/services so that the session bus is happy. + +2003-05-15 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_atomic_dec, _dbus_atomic_inc): work + on non-x86. ifdef's are evil. + +2003-05-15 Havoc Pennington <hp@redhat.com> + + * configure.in: 0.11 + + * NEWS: update + + * bus/Makefile.am (initddir): apparently we are supposed to put + init scripts in /etc/rc.d/init.d not /etc/init.d + + * bus/Makefile.am: remove the "you must --enable-tests to make + check" as it broke distcheck + + * bus/Makefile.am (install-data-hook): create /etc/dbus-1/system.d + +2003-05-13 James Willcox <jwillcox@gnome.org> + + * configure.in: + * bus/activation.c: (bus_activation_service_created), + (bus_activation_activate_service): + * bus/driver.c: (bus_driver_send_service_deleted), + (bus_driver_send_service_created), (bus_driver_send_service_lost), + (bus_driver_send_service_acquired), + (bus_driver_send_welcome_message), + (bus_driver_handle_list_services): + * bus/session.conf.in: + * dbus/dbus-bus.c: (dbus_bus_acquire_service), + (dbus_bus_service_exists), (dbus_bus_activate_service): + * dbus/dbus-bus.h: + + Add some convenience API which lets you activate a service, and did a + bunch of s/0/DBUS_TYPE_INVALID/ in calls to dbus_message_append_args() + and dbus_message_get_args() + +2003-05-11 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-marshal.c (_dbus_marshal_validate_arg): fix to avoid + calling _dbus_marshal_validate_arg() for every byte in a byte + array, etc. + + * dbus/dbus-message-handler.c: use atomic reference counting to + reduce number of locks slightly; the global lock in here sucks + + * dbus/dbus-connection.c + (_dbus_connection_update_dispatch_status_and_unlock): variant of + update_dispatch_status that can be called with lock held; then use + in a couple places to reduce locking/unlocking + (dbus_connection_send): hold the lock over the whole function + instead of acquiring it twice. + + * dbus/dbus-timeout.c (_dbus_timeout_new): handle OOM + + * bus/connection.c (bus_connections_setup_connection): fix access + to already-freed memory. + + * dbus/dbus-connection.c: keep a little cache of linked list + nodes, to avoid using the global linked list alloc lock in the + normal send-message case. Instead we just use the connection lock + that we already have to take. + + * dbus/dbus-list.c (_dbus_list_find_last): new function + + * dbus/dbus-sysdeps.c (_dbus_atomic_inc, _dbus_atomic_dec): + change to use a struct for the atomic type; fix docs, + they return value before increment, not after increment. + + * dbus/dbus-string.c (_dbus_string_append_4_aligned) + (_dbus_string_append_8_aligned): new functions to try to + microoptimize this operation. + (reallocate_for_length): break this out of set_length(), to + improve profile info, and also so we can consider inlining the + set_length() part. + + * dbus/dbus-message.c (dbus_message_new_empty_header): init data + strings with some preallocation, cuts down on our calls to realloc + a fair bit. Though if we can get the "move entire string to empty + string" optimization below to kick in here, it would be better. + + * dbus/dbus-string.c (_dbus_string_move): just call + _dbus_string_move_len + (_dbus_string_move_len): add a special case for moving + an entire string into an empty string; we can just + swap the string data instead of doing any reallocs. + (_dbus_string_init_preallocated): new function + +2003-05-11 Havoc Pennington <hp@pobox.com> + + Write a "test-profile" that does echo client-server with threads; + profile reveals lock contention, memcpy/realloc of buffers, and + UTF-8 validation as hot spots. 20% of lock contention eliminated + with dbus_atomic_inc/dec implementation on x86. Much remaining + contention is global mempool locks for GList and DBusList. + + * dbus/dbus-sysdeps.c (_dbus_atomic_inc, _dbus_atomic_dec): add + x86 implementation + + * dbus/dbus-connection.c (struct DBusConnection): use + dbus_atomic_t for the reference count + + * dbus/dbus-message.c (struct DBusMessage): declare + dbus_atomic_t values as volatile + + * configure.in: code to detect ability to use atomic integer + operations in assembly, from GLib patch + + * dbus/dbus-internals.c (_dbus_verbose_real): call getpid every + time, tired of it being wrong in threads and forked processes + + * glib/test-profile.c: a little program to bounce messages back + and forth between threads and eat CPU + + * dbus/dbus-connection.c: add debug spew macros for debugging + thread locks; include config.h at top; fix deadlock in + dbus_connection_flush() + +2003-05-08 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-spawn.c: s/_exit/exit/ because it was keeping gcov + data from getting written, and there wasn't a good reason to + use _exit really. + + * test/decode-gcov.c (mark_inside_dbus_build_tests): don't count + dbus_verbose lines in test coverage + (main): add list of functions sorted by # of untested blocks + to the coverage report + + * dbus/dbus-mempool.c: put some test-only code in DBUS_BUILD_TESTS + + * dbus/dbus-marshal.c (_dbus_marshal_test): extend test coverage + + * dbus/dbus-message-handler.c (_dbus_message_handler_test): + extend test coverage + + * test/data/auth/cancel.auth-script: test canceling an + authentication + + * dbus/Makefile.am: remove dbus-server-debug.[hc] for now, as they + aren't used. in CVS history if we end up needing them. + +2003-05-04 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message-handler.c (_dbus_message_handler_test): add + unit test + + * dbus/dbus-marshal.c (_dbus_demarshal_string_array): fix this + function, which assumed length was in # of strings, not bytes + + * dbus/dbus-message.c (_dbus_message_test): add tests for some + missing coverage + + * dbus/dbus-connection.c + (_dbus_connection_queue_received_message): disable function for + now, we are only using it in test mode + + * dbus/dbus-message.c (_dbus_message_loader_queue_messages): + remove a mistaken FIXME + +2003-05-04 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c (dbus_connection_preallocate_send): + unlock mutex on successful return, patch from Anders Gustafsson + +2003-05-04 Havoc Pennington <hp@pobox.com> + + * dbus-glib-1.pc.in (Requires): fix dependencies, from + Anders Gustafsson + +2003-05-04 Havoc Pennington <hp@pobox.com> + + * tools/dbus-launch.c: implement + + * bus/main.c (main), bus/bus.c (bus_context_new): + implement --print-pid and --fork + +2003-05-03 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-address.c (dbus_parse_address): fix bug when a key in + the address had no value, and add to test suite. Fix and + regression test from Miloslav Trmac + +2003-05-03 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-watch.c (dbus_watch_handle): warn and return if a + watch is invalid when handled + + * tools/Makefile.am, tools/dbus-launch.c, tools/dbus-launch.1: add + dbus-launch utility to launch the bus from a shell script. Didn't + actually implement dbus-launch yet, it's just a placeholder still. + +2003-05-03 Havoc Pennington <hp@pobox.com> + + * bus/Makefile.am, bus/dbus-daemon-1.1.in: man page for the + daemon; also documents daemon config file, so replaces + doc/config-file.txt. Corrected some stuff from config-file.txt in + the process of moving it. + +2003-05-03 Havoc Pennington <hp@pobox.com> + + * tools/Makefile.am, tools/dbus-send.1, tools/dbus-monitor.1: + add some man pages + +2003-05-03 Colin Walters <walters@verbum.org> + + * dbus/dbus-sysdeps.c (fill_user_info): Test against + DBUS_UID_UNSET to determine whether to do a uid lookup or not. + + * Makefile.am: Update to use new .pc versioning scheme. + +2003-05-02 Havoc Pennington <hp@redhat.com> + + * bus/system.conf.in: allow send/receive to/from message bus + service + +2003-04-30 Havoc Pennington <hp@redhat.com> + + * configure.in: print a note when building with unit tests and + without assertions + +2003-04-30 Havoc Pennington <hp@redhat.com> + + * Makefile.am: add a check-local that complains if you didn't + configure with --enable-tests + +2003-04-29 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gmain.c: docs cleanups + + * dbus/dbus-types.h: add docs on int64 types + + * dbus/dbus-memory.c: fix docs to avoid putting private API in + public API docs section + +2003-04-29 Havoc Pennington <hp@redhat.com> + + * dbus-1.pc.in, dbus-glib-1.pc.in: rename these from + dbus-1.0.pc.in, dbus-glib-1.0.pc.in. As these change with the + parallel install API version, not with the D-BUS package version. + + * HACKING: move some of README over here + + * README: updates, and document API/ABI policy + + * configure.in: reindentation + +2003-04-29 Havoc Pennington <hp@redhat.com> + + * dbus/dbus.h: add "you have to define DBUS_API_SUBJECT_TO_CHANGE + to use this library" to be sure people have the right + expectations. + +2003-04-28 Havoc Pennington <hp@redhat.com> + + * configure.in: add --enable-docs which by default is auto yes if + doxygen and db2html found, no otherwise; but can be forced on/off + + * doc/Makefile.am: conditionalize whether to build docs on + --enable-docs + +2003-04-28 Havoc Pennington <hp@redhat.com> + + * configure.in: 0.10 + + * NEWS: update + + * bus/system.conf.in: add <includedir>system.d</includedir> + + * dbus/dbus-userdb.c (_dbus_user_database_lookup): fix bug when + username was provided but not uid + + * bus/config-parser.c (struct BusConfigParser): keep track of + whether the parser is toplevel or was included; change some + of the error handling if it's included. + +2003-04-27 Havoc Pennington <hp@pobox.com> + + Unbreak my code... + + * dbus/dbus-transport.c (_dbus_transport_get_dispatch_status): + report correct status if we finish processing authentication + inside this function. + + * bus/activation.c (try_send_activation_failure): use + bus_transaction_send_error_reply + + * bus/connection.c (bus_connection_get_groups): return an error + explaining the problem + + * bus/bus.c (bus_context_check_security_policy): implement + restriction here that inactive connections can only send the + hello message. Also, allow bus driver to send anything to + any recipient. + + * bus/connection.c (bus_connection_complete): create the + BusClientPolicy here instead of on-demand. + (bus_connection_get_policy): don't return an error + + * dbus/dbus-message.c (dbus_message_new_error_reply): allow NULL + sender field in message being replied to + + * bus/bus.c (bus_context_check_security_policy): fix silly typo + causing it to return FALSE always + + * bus/policy.c (bus_client_policy_check_can_send): fix bug where + we checked sender rather than destination + +2003-04-25 Havoc Pennington <hp@redhat.com> + + test suite is slightly hosed at the moment, will fix soon + + * bus/connection.c (bus_connections_expire_incomplete): fix to + properly disable the timeout when required + (bus_connection_set_name): check whether we can remove incomplete + connections timeout after we complete each connection. + + * dbus/dbus-mainloop.c (check_timeout): fix this up a bit, + probably still broken. + + * bus/services.c (bus_registry_acquire_service): implement max + number of services owned, and honor allow/deny rules on which + services a connection can own. + + * bus/connection.c (bus_connection_get_policy): report errors here + + * bus/activation.c: implement limit on number of pending + activations + +2003-04-25 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-transport.c (_dbus_transport_get_unix_user): fix bug + where we used >= 0 instead of != DBUS_UID_UNSET. + +2003-04-25 Havoc Pennington <hp@redhat.com> + + * glib/dbus-gmain.c (remove_watch): fix for a crash when watches + were toggled without add/remove, fix from Anders Gustafsson + +2003-04-24 Havoc Pennington <hp@redhat.com> + + * test/data/valid-config-files/basic.conf: add <limit> tags to + this test + + * bus/config-parser.h, bus/config-parser.c, bus/bus.c: Implement + <limit> tag in configuration file. + +2003-04-24 Havoc Pennington <hp@redhat.com> + + * bus/dispatch.c: somehow missed some name_is + + * dbus/dbus-timeout.c (_dbus_timeout_set_enabled) + (_dbus_timeout_set_interval): new + + * bus/connection.c (bus_connections_setup_connection): record time + when each connection is first set up, and expire them after the + auth timeout passes. + +2003-04-24 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c (dbus_message_name_is): rename + (dbus_message_service_is): rename + (dbus_message_sender_is): rename + (dbus_message_get_service): rename + +2003-04-24 Havoc Pennington <hp@redhat.com> + + * configure.in: add --enable-checks + + * dbus/dbus-message.c (dbus_message_new): reverse name/service arguments + + * dbus/dbus-connection.c (dbus_connection_preallocate_send): fix + to use thread locks. + (_dbus_connection_handler_destroyed_locked): move some private + functions into proper docs group + + * dbus/dbus-internals.h: add _dbus_return_if_fail, + _dbus_return_val_if_fail + + Throughout: use dbus_return_if_fail + +2003-04-23 James Willcox <jwillcox@gnome.org> + + * glib/dbus-glib.h: + * glib/dbus-gmain.c: (add_timeout), (wakeup_main), (create_source), + (dbus_connection_setup_with_g_main), + (dbus_server_setup_with_g_main): + * glib/test-dbus-glib.c: (main): + * glib/test-thread-client.c: (main): + * glib/test-thread-server.c: (new_connection_callback), (main): + * tools/dbus-monitor.c: (main): + + Added a GMainContext argument to dbus_connection_setup_with_g_main() + and dbus_server_setup_with_g_main(). + +2003-04-20 Havoc Pennington <hp@pobox.com> + + * doc/dbus-specification.sgml: document the restrictions on + message and service names + +2003-04-22 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c, dbus/dbus-marshal.c: add 64-bit integer + support, and do some code cleanups to share more code and + speed up array marshal/demarshal. + + * dbus-1.0.pc.in (Cflags): put libdir include file in cflags + + * configure.in: generate dbus-arch-deps.h + + * dbus/dbus-protocol.h (DBUS_TYPE_INT64, DBUS_TYPE_UINT64): add + 64-bit typecodes + +2003-04-22 Havoc Pennington <hp@redhat.com> + + * test/data/valid-messages/opposite-endian.message: fix test + to use proper type for rply field + + * test/data/invalid-messages: add tests for below validation + + * dbus/dbus-message.c (decode_header_data): validate field types, + and validate that named fields are valid names + (decode_name_field): consider messages in the + org.freedesktop.Local. namespace to be invalid. + + * dbus/dbus-string.c (_dbus_string_validate_name): new + +2003-04-19 Havoc Pennington <hp@pobox.com> + + * bus/driver.c (bus_driver_handle_hello): check limits and + return an error if they are exceeded. + + * bus/connection.c: maintain separate lists of active and inactive + connections, and a count of each. Maintain count of completed + connections per user. Implement code to check connection limits. + + * dbus/dbus-list.c (_dbus_list_unlink): export + + * bus/bus.c (bus_context_check_security_policy): enforce a maximum + number of bytes in the message queue for a connection + +2003-04-18 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-auth.c (record_mechanisms): memleak fixes + + * dbus/dbus-sysdeps.c (_dbus_string_save_to_file): fix some + memleaks + + * dbus/dbus-keyring.c (add_new_key): fix a memleak, and + on realloc be sure to update the pointer in the keyring + + * dbus/dbus-string.c (_dbus_string_zero): compensate for align + offset to avoid writing to unallocated memory + + * dbus/dbus-auth.c (process_rejected): return FALSE if we fail to + try the next mechanism, so we properly handle OOM + + * dbus/dbus-keyring.c (_dbus_keyring_new_homedir): fix double-free + on OOM. + (_dbus_keyring_new): fix OOM bug + (_dbus_keyring_new_homedir): always set error; impose a maximum + number of keys we'll load from the file, mostly to speed up the + test suite and make its OOM checks more useful, but also for + general sanity. + + * dbus/dbus-auth.c (process_error_server): reject authentication + if we get an error from the client + (process_cancel): on cancel, send REJECTED, per the spec + (process_error_client): send CANCEL if we get an error from the + server. + +2003-04-18 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-mainloop.c (_dbus_loop_iterate): fix UMR in verbose + debug spew + + * dbus/dbus-auth.c (handle_client_data_cookie_sha1_mech): fix OOM + handling problem + + * dbus/dbus-keyring.c (_dbus_keyring_new_homedir): only whine + about DBUS_TEST_HOMEDIR once + + * bus/Makefile.am (TESTS_ENVIRONMENT): put DBUS_TEST_HOMEDIR in + the environment + + * bus/dispatch.c (bus_dispatch_sha1_test): actually load sha1 + config file so we test the right thing + + Throughout: assorted docs improvements + +2003-04-18 Havoc Pennington <hp@pobox.com> + + * glib/dbus-gmain.c: adapt to watch changes + + * bus/bus.c, bus/activation.c, etc.: adjust to watch changes + + * dbus/dbus-server.h: remove dbus_server_handle_watch + + * dbus/dbus-connection.h: remove dbus_connection_handle_watch + + * dbus/dbus-watch.c (dbus_watch_handle): change DBusWatch to work + like DBusTimeout, so we don't need dbus_connection_handle_watch + etc. + +2003-04-17 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-userdb.c, dbus/dbus-sysdeps.c: redo all the passwd + database usage so it all goes via the DBusUserDatabase cache. + +2003-04-17 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-mainloop.c (_dbus_loop_iterate): fix logic so that if + there was an OOM watch we skipped, we always return TRUE so we + iterate again to have a look at it again. Fixes test suite hang. + Code rearrangement also lets us lose some memset and only iterate + over callbacks once. + + * bus/driver.c (bus_driver_handle_message): sense of test for + reply was backward + +2003-04-16 Havoc Pennington <hp@pobox.com> + + * doc/dbus-specification.sgml: make spec say serials are unsigned + + * dbus/dbus-message.h: change message serials to unsigned + + * dbus/dbus-connection.c: adapt to message serials being unsigned + +2003-04-15 Havoc Pennington <hp@pobox.com> + + * bus/bus.c: create and keep around a shared DBusUserDatabase + object. + + * bus/connection.c (bus_connection_get_groups): don't cache + groups for user in the connection object, since user database + object now does that. + +2003-04-16 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c (_dbus_message_add_size_counter): keep a + list of size counters + (_dbus_message_loader_putback_message_link): put back a popped link + + * dbus/dbus-connection.c + (dbus_connection_set_max_live_messages_size): rename + max_received_size + (dbus_connection_get_outgoing_size): get size of outgoing + queue + (_dbus_connection_set_connection_counter): remove this cruft + +2003-04-14 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-userdb.c: user database abstraction, mostly to get + caching, but at some point we might want to be able to use a + different database. + + * bus/dispatch.c (bus_dispatch_sha1_test): add a test that uses + SHA1 conf file to test the sha1 auth mechanism, since the regular + test always uses EXTERNAL when available. + + * configure.in, + test/data/valid-config-files/debug-allow-all-sha1.conf.in: + add conf file that requires use of sha1 auth + +2003-04-13 Havoc Pennington <hp@pobox.com> + + * tools/dbus-send.c, tools/dbus-monitor.c: two utility programs + from Philip Blundell to send messages and monitor them. + +2003-04-13 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-mainloop.c: fix some reentrancy issues by refcounting + callbacks + + * test/data/valid-config-files/debug-allow-all.conf.in: allow all + users + + * dbus/dbus-transport.c (_dbus_transport_get_dispatch_status): + fix to only recover unused bytes if we're already authenticated + (_dbus_transport_get_is_authenticated): fix to still mark us + authenticated if there are unused bytes. + + * bus/dispatch.c: implement security policy checking + + * bus/connection.c (bus_transaction_send_from_driver): new + + * bus/bus.c (bus_context_check_security_policy): new + + * bus/dispatch.c (send_service_nonexistent_error): delete this, + now we just set the DBusError and it gets converted to an error + reply. + + * bus/connection.c (allow_user_function): enable code using actual + data from the config file + + * bus/policy.c (list_allows_user): handle wildcard rules for + user/group connection perms + +2003-04-13 Havoc Pennington <hp@pobox.com> + + * bus/config-parser.c: Load up the BusPolicy and BusPolicyRules + + * dbus/dbus-sysdeps.c (_dbus_get_user_id): new function + + * bus/policy.c (bus_policy_append_mandatory_rule) + (bus_policy_append_default_rule, bus_policy_append_user_rule) + (bus_policy_append_group_rule): new functions + +2003-04-12 Havoc Pennington <hp@pobox.com> + + * bus/config-parser.c (bus_config_parser_new): fix a memleak + + * dbus/dbus-sysdeps.c: change DBusCredentials to use longs for + the pid/gid/uid, just for paranoia. + + * test/break-loader.c (randomly_do_n_things): find a byte + containing a type code, and randomly change it to a different + type code. + +2003-04-12 Havoc Pennington <hp@pobox.com> + + * bus/policy.h: change BusPolicy to be the thing from the config + file, and rename old BusPolicy to BusClientPolicy + + * bus/bus.c, bus/connection.c, bus/config-parser.c: change to + match change in how policy works + + * dbus/dbus-internals.h: mark assert_not_reached as + __attribute((noreturn))__ + +2003-04-11 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.sgml: fix a spot with the wrong name for + the broadcast service. Use boolean return for ServiceExists. + +2003-04-11 Havoc Pennington <hp@redhat.com> + + * configure.in: add another directory to look for qt in. + +2003-04-11 Havoc Pennington <hp@redhat.com> + + * AUTHORS: add Colin Walters + +2003-04-11 Havoc Pennington <hp@redhat.com> + + * NEWS: update + + * configure.in: 0.9 + +2003-04-11 Havoc Pennington <hp@redhat.com> + + * bus/messagebus.in: remove pid file when stopping the + message bus, since the bus won't have privileges to remove it + itself. + +2003-04-11 Havoc Pennington <hp@redhat.com> + + * bus/bus.c (bus_context_new): move credentials change after + creating pidfile + +2003-04-11 Havoc Pennington <hp@pobox.com> + + * test/decode-gcov.c: add "below average functions" to the + coverage report, and change how some of the code works. + + * bus/test-main.c: bracket some stuff in DBUS_BUILD_TESTS so it's + not in the coverage stats. + + * test/test-service.c (main): use _dbus_verbose not fprintf in a + couple places so running the test suite doesn't result in megaspam. + +2003-04-11 Havoc Pennington <hp@pobox.com> + + * bus/dispatch.c (check_existent_service_activation): accept a no + memory error in a place we didn't before + + * bus/test.c (bus_test_run_everything): remove hacky "do it twice + in case the first one failed," since the test suite is less + broken now. + +2003-04-10 Havoc Pennington <hp@pobox.com> + + * bus/dispatch.c (check_segfault_service_activation): add test + for launching an executable that just crashes. + + * test/test-segfault.c (main): try setting coredumpsize to 0 so we + don't leave a million cores. We'll see how portable this is. + +2003-04-10 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-spawn.c (_dbus_spawn_async_with_babysitter): move all + the possible parent failures before we fork, so that we don't + fail to create a babysitter after creating the child. + + * bus/activation.c (bus_activation_activate_service): kill child + if we don't successfully complete the activation. + +2003-04-10 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c (dbus_connection_flush): don't spin on + the connection if it's disconnected + + * bus/activation.c (bus_activation_service_created): use new + transaction features to roll back removal of pending activation if + we don't successfully create the service after all. Don't remove + pending activation if the function fails. + + * dbus/dbus-list.c (_dbus_list_insert_before_link) + (_dbus_list_insert_after_link): new code to facilitate + services.c fixes + + * dbus/dbus-hash.c (_dbus_hash_table_insert_string_preallocated): + new functionality, so we can preallocate the ability to insert + into a hash table. + + * bus/connection.c (bus_transaction_add_cancel_hook): new function + allowing us to put custom hooks in a transaction to be used for + cancelling said transaction + + * doc/dbus-specification.sgml: add some discussion of secondary + service owners, and disallow zero-length service names + + * bus/services.c (bus_registry_acquire_service): new function, + splits out part of bus_driver_handle_acquire_service() and fixes + a bug where we didn't remove the service doing the acquiring + from the secondary queue if we failed to remove the current owner + from the front of the queue. + +2003-04-10 Alexander Larsson <alexl@redhat.com> + + * doc/dbus-specification.sgml: + s/org.freedesktop.Broadcast/org.freedesktop.DBus.Broadcast/ + +2003-04-10 Alexander Larsson <alexl@redhat.com> + + * bus/.cvsignore: + * glib/.cvsignore: + * test/.cvsignore: + Added files to cvsignore + + * dbus/dbus-message.h: + * dbus/dbus-message.c: (dbus_message_iter_get_named): + Make get_named() take two out argument and return a boolean. + (dbus_message_iter_get_args_valist): + Update usage of get_named(). + (dbus_message_iter_append_byte): + Fix typo + (dbus_message_iter_append_named) + Fix typo + (message_iter_test), (check_message_handling_type), (_dbus_message_test): + More tests. + +2003-04-10 Alexander Larsson <alexl@redhat.com> + + * dbus/dbus-marshal.[ch]: + Add array_type_pos argument to _dbus_marshal_validate_arg. + Let you pass a NULL end_pos to _dbus_marshal_validate_type. + + * dbus/dbus-message.[ch]: + Multi-dimensional arrays have full type specification in the + outermost array. Iter code re-arranged to handle this. + Added some more iter tests. + + * doc/dbus-specification.sgml: + Add me to authors. + Remove old FIXME. + Update new array encoding description. + Correct DBUS_SERVICE_FLAGS_REPLACE_EXISTING description. + + * test/data/invalid-messages/array-with-mixed-types.message: + * test/data/valid-messages/array-of-array-of-uint32.message: + Change to the new array format. + + * test/data/invalid-messages/too-short-dict.message: + Fix bug in test. + + * test/data/valid-messages/recursive-types.message: + Fix up and extend test. + +2003-04-10 Havoc Pennington <hp@pobox.com> + + * bus/dispatch.c: lots of fixes + + * dbus/dbus-mainloop.c (_dbus_loop_dispatch): export + (_dbus_loop_iterate): remove old "quit if no callbacks" code, + that was crack, broke the test service. + + * dbus/dbus-transport.c (_dbus_transport_open): fix error + handling to avoid piling up errors if we get a failure on the + first address. + + * dbus/dbus-internals.c (_dbus_real_assert_not_reached): include + pid in assertion failures. + + * dbus/dbus-mainloop.c (_dbus_loop_iterate): use static arrays up + to some fixed size of file descriptor array. Don't return TRUE + anytime a timeout exists, that led to lots of busy loop silliness + in the tests. + +2003-04-09 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-mainloop.c (check_timeout): fix timeouts, I thought + I'd checked this in earlier but hadn't. + +2003-04-09 Havoc Pennington <hp@redhat.com> + + * bus/dispatch.c (bus_dispatch_test): get a bit further through + the activation test (man this is getting old!) + +2003-04-09 Havoc Pennington <hp@redhat.com> + + * test/test-utils.c: use dispatch status function to fix this up + + * bus/connection.c (connection_watch_callback): don't dispatch + from here + (connection_timeout_callback): don't dispatch from here + (bus_connections_setup_connection): set the dispatch status function + (bus_connection_disconnected): unset it + + * dbus/dbus-mainloop.c (_dbus_loop_queue_dispatch): new function + used to add a connection to be dispatched + (_dbus_loop_iterate): do the dispatching at the end of each + iteration + + * dbus/dbus-connection.c + (dbus_connection_set_dispatch_status_function): new function + allowing us to fix up main loop usage + (_dbus_connection_last_unref): free all the various function + user data + (dbus_connection_dispatch): call the DispatchStatusFunction + whenever this function returns + (dbus_connection_handle_watch): call DispatchStatusFunction + (dbus_connection_send_with_reply_and_block): call DispatchStatusFunction + (reply_handler_timeout): call DispatchStatusFunction + (dbus_connection_flush): call DispatchStatusFunction + +2003-04-09 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-bus.c (dbus_bus_register): fix up error handling and + a memory leak + + * bus/dispatch.c (check_service_activated): fix bug in test + + * dbus/dbus-mainloop.c (check_timeout): fix this up + + * dbus/dbus-internals.c (_dbus_verbose_real): include PID in + verbose output so we can sort out output from different processes, + e.g. in the activation case. + +2003-04-08 Colin Walters <walters@gnu.org> + + * bus/bus.c (struct BusContext) [pidfile]: New member, to store + the pid file. + (bus_context_new): Set it. + (bus_context_unref): Use it to delete the pid file. + +2003-04-08 Havoc Pennington <hp@redhat.com> + + * test/data/invalid-messages/array-with-mixed-types.message: + regression test that fails for the moment + + * dbus/dbus-test.c (dbus_internal_do_not_use_run_tests): reorder + tests for convenience + + * dbus/dbus-marshal.c (_dbus_marshal_validate_arg): don't allow + array of nil, it broke things. + + * test/data/invalid-messages/array-of-nil.message: regression test + + * test/data/valid-messages/array-of-array-of-uint32.message: + happened to write this so added it to suite + +2003-04-08 Havoc Pennington <hp@redhat.com> + + * bus/driver.c (bus_driver_handle_acquire_service): init + retval/reply before checking name + + * dbus/dbus-marshal.c (_dbus_marshal_validate_arg): add a + recursion depth argument + + * dbus/dbus-message.h (struct DBusMessageIter): put some padding + in the public struct for future extension + + * dbus/dbus-message-builder.c (_dbus_message_data_load): fix + typo + + * dbus/dbus-marshal.c (_dbus_marshal_validate_arg): fix a verbose + message + + * doc/dbus-specification.sgml: fix typo + +2003-04-08 Alexander Larsson <alexl@redhat.com> + + Implemented recursive types, named types and new-style iters + + * bus/driver.c: + * glib/test-thread-client.c: (thread_func): + * glib/test-thread-server.c: (handle_test_message): + * test/test-service.c: (handle_echo): + Update to new api + + * dbus/Makefile.am: + * dbus/dbus-dict.c: + * dbus/dbus-dict.h: + * dbus/dbus.h + Remove DBusDict + + * dbus/dbus-internals.c: (_dbus_type_to_string): + Update for new types. + + * dbus/dbus-marshal.[ch]: + Implement recursive types and the new marshalling format. + Remove hardcoded dict marshalling. + Marshal named types. + + * dbus/dbus-message-builder.c: + Add BYTE_ARRAY. + Remove references to old types + + * dbus/dbus-message.[ch]: + New non-refcounted iter API that supports recursive iters. + Use iters for appending, including support for recursive + iters. + Add byte and named type support. + Update everything to new marshalling formats. + Add tests for new API. + + * dbus/dbus-protocol.h: + Remove old array types. + Add types: BYTE, ARRAY, DICT, NAMED + + * dbus/dbus-string.c: + * dbus/dbus-sysdeps.c: + Make parse_double locale safe. + + * dbus/dbus-test-main.c: + Call setlocale. + + * dbus/dbus-test.c: + Kill dict test + + * doc/dbus-specification.sgml: + Update spec + + * test/data/incomplete-messages/missing-body.message: + * test/data/invalid-messages/bad-boolean.message: + * test/data/invalid-messages/bad-boolean-array.message: + * test/data/invalid-messages/boolean-array-length-too-long.message-raw: + * test/data/invalid-messages/boolean-has-no-value.message-raw: + * test/data/invalid-messages/too-short-dict.message: + * test/data/valid-messages/dict-simple.message: + * test/data/valid-messages/dict.message: + * test/data/valid-messages/emptiness.message: + * test/data/valid-messages/lots-of-arguments.message: + * test/data/valid-messages/no-padding.message: + * test/data/valid-messages/recursive-types.message: + Add missing NAME fields + Fix up dicts & arrays + + * test/data/invalid-messages/dict-with-nil-value.message: + Removed, this is not invalid anymore. + + * test/data/valid-messages/recursive-types.message: + Add new test for deeply recursive types. + +2003-04-07 Havoc Pennington <hp@pobox.com> + + * bus/driver.c (bus_driver_handle_acquire_service): return an + error if you try to acquire a service that starts with ':' + +2003-04-07 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.sgml: require that base service names + start with ':' and that the base service is created/deleted + as first and last things a connection does on the bus + + * bus/dispatch.c (check_existent_service_activation): lots more + work on the activation test; it doesn't fully pass yet... + + * test/test-service.c (main): fix so we don't memleak the + connection to the message bus + (filter_func): accept a message asking us to exit + +2003-04-06 Havoc Pennington <hp@pobox.com> + + * qt/Makefile.am (dbusinclude_HEADERS): install dbus-qt.h, + from Colin Walters + + * configure.in: fixes to Qt detection from Colin Walters + + * doc/Makefile.am: Only remove generated docbook dirs if they + exist, from Colin Walters + + * dbus/dbus-bus.c: change how we set well-known connections to + NULL, so that it works if a single connection is stored in + two well-known array slots. + + * test/Makefile.am: remove a lot of stuff that isn't immediately + useful, it's in CVS history if we want it. + + * test/test-service.c: use dbus-mainloop instead of that + watch.[hc] crack + +2003-04-06 Havoc Pennington <hp@pobox.com> + + * dbus/Makefile.am: split lists of sources into stuff that goes in + the library, util functions that go in the lib and are also used + elsewhere, and util functions that are used in tests/daemon but + don't go in the lib. + + * dbus/dbus-mainloop.h, dbus/dbus-mainloop.c: move bus/loop.[hc] + here so it can be used in test binaries also + +2003-04-06 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-sysdeps.c (_dbus_become_daemon): write the pidfile + here in the parent process, so we can return an error if it + fails. Also, move some of the code into the child so the parent + is less hosed if we fail midway through. + + * bus/bus.c (bus_context_new): move pidfile detection further up + in the function, before we start overwriting sockets and such. + + * bus/messagebus.in: adjust this a bit, not sure if it will work. + + * configure.in: add --with-system-pid-file and --with-system-socket + +2003-04-06 Colin Walters <walters@verbum.org> + + * configure.in (DBUS_SYSTEM_PID_FILE): New variable. + + * bus/system.conf.in: Declare a pidfile. + + * bus/bus.c (bus_context_new): Test for an existing pid file, and + create one (if appropriate). + + * bus/config-parser.c (enum ElementType) [ELEMENT_PIDFILE]: New. + (struct BusConfigParser) [pidfile]: New. + (element_type_to_name, merge_included, start_busconfig_child) + (bus_config_parser_end_element, bus_config_parser_content): Handle it. + (bus_config_parser_unref): Free it. + (bus_config_parser_get_pidfile): New function. + + * bus/config-parser.h (_dbus_write_pid_file): Prototype. + + * dbus/dbus-errors.h (DBUS_ERROR_PIDFILE_EXISTS): New error. + + * dbus/dbus-sysdeps.c (_dbus_write_pid_file): New function. + + * dbus/dbus-sysdeps.h: Prototype it. + +2003-04-06 Havoc Pennington <hp@pobox.com> + + * bus/bus.c (bus_context_new): print the address in here, rather + than in main(), because we need to do it before forking the daemon + + * bus/dispatch.c (send_service_nonexistent_error): set the sender + on the service nonexistent error + + * bus/driver.c (bus_driver_handle_acquire_service): set the + sender on the AcquireService reply + + * test/data/valid-config-files/debug-allow-all.conf.in: Make test + server also listen on a UNIX socket so services can connect to it. + +2003-04-06 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-threads.c: Redo how the fake debug mutexes are done + so it detects deadlocks and also we actually init threads when + debugging. + +2003-04-06 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-server-unix.c (_dbus_server_new_for_domain_socket): + save the domain socket name, and unlink it when we disconnect the + server. Means that at least when we exit normally, we won't leave + a bunch of junk in /tmp + + * dbus/dbus-transport-unix.c + (_dbus_transport_new_for_domain_socket): code cleanup (nicer + memory management). (I was making a real change here but then + didn't) + +2003-04-06 Havoc Pennington <hp@pobox.com> + + * bus/bus.c (bus_context_new): fix wrong handling of + server_data_slot_unref() in the error case. + + * dbus/dbus-internals.h (_dbus_assert): change so it passes + "(condition) != 0" to _dbus_real_assert so that + "_dbus_assert (pointer)" doesn't cause a warning + + * bus/main.c (main): accept --print-address option to print out + the message bus address + + * dbus/dbus-sysdeps.c (_dbus_generate_random_ascii): export this + + * dbus/dbus-transport.c (_dbus_transport_open): special error for + "tmpdir" option to unix: address on client side + + * dbus/dbus-server.c (dbus_server_listen): handle "tmpdir" option + to unix: address + + * configure.in (TEST_SOCKET_DIR): locate a temporary directory + we can use to create sockets in the test suite. + + * bus/main.c (signal_handler): on SIGTERM, exit the daemon + cleanly. To be used for testing. + + * dbus/dbus-spawn.c (babysit): use _dbus_set_signal_handler() + + * dbus/dbus-sysdeps.c (_dbus_set_signal_handler): new + + * dbus/dbus-server-debug-pipe.c (_dbus_transport_debug_pipe_new): + handle trying to call this when there's no servers active + +2003-04-05 Havoc Pennington <hp@pobox.com> + + * NEWS: update + + * configure.in: 0.8 + +2003-04-05 Havoc Pennington <hp@pobox.com> + + * bus/bus.c (setup_server): fix this so dbus-daemon-1 doesn't + crash on startup. Need to get "try starting the daemon" + in the test suite I guess. ;-) + + * dbus/dbus-server.h, dbus/dbus-server.c: remove the stuff that + tracked the number of open connections; it's better done in + application-specific code as you want it to span all servers etc. + +2003-04-05 Havoc Pennington <hp@pobox.com> + + * bus/Makefile.am (install-data-hook): add missing DESTDIR, + patch from Colin Walters + +2003-04-05 Havoc Pennington <hp@pobox.com> + + * doc/config-file.txt (Elements): fix docs of <auth> to reflect + reality; in fact multiple mechanisms are allowed. + + * dbus/dbus-internals.c (_dbus_real_assert) + (_dbus_real_assert_not_reached): move guts of _dbus_assert() and + _dbus_assert_not_reached() into functions, so that they don't show + up in basic block counts for test coverage, and don't use up as + much disk space. Does mean slower execution speed though, so + assumes --disable-asserts is the normal production case. + +2003-04-05 Havoc Pennington <hp@pobox.com> + + * test/Makefile.am (dist-hook): also dist *.in files + + * NEWS: update + + * configure.in: 0.7 + +2003-04-05 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-string.c: docs warning + + * dbus/dbus-spawn.c: missing docs + + * dbus/dbus-memory.c (struct ShutdownClosure): missing docs + +2003-04-05 Havoc Pennington <hp@pobox.com> + + * bus/loop.c (bus_loop_iterate): fix the timeout code, using + magic from GLib + + * dbus/dbus-spawn.c (_dbus_babysitter_unref): set sitter_pid + to -1 once we've reaped the babysitter + (_dbus_babysitter_handle_watch): do as much work as we can, not + just one go of it + + * bus/activation.c: add code using DBusBabysitter so that we + handle it when a service fails to start up properly. + (bus_activation_service_created): don't remove the activation + entries as we go, just let them get removed when we free the pending + activation. Unref reply messages after sending them. + +2003-04-05 Havoc Pennington <hp@pobox.com> + + * test/decode-gcov.c (main): print per-directory stats in the report + + * Makefile.am (coverage-report.txt): don't include test/* in gcov stats + +2003-04-05 Havoc Pennington <hp@pobox.com> + + * Makefile.am (coverage-report.txt): add target "coverage-report.txt" + + * test/decode-gcov.c: hack up a little program to suck data + out of gcov files. Yes this is sort of silly. + + * configure.in: define something in config.h and do an + AM_CONDITIONAL when gcov is enabled + +2003-04-04 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-spawn.c, dbus/dbus-spawn.h: Change dbus_spawn to + return a "babysitter" object that is used to monitor the status of + the spawned process and reap it when required. + + * test/test-segfault.c, test/test-exit.c, + test/test-sleep-forever.c: binaries that do various lame things, + used in the test suite. + + * dbus/dbus-sysdeps.c: kill _dbus_errno_to_string() + +2003-04-03 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-spawn.c: Move dbus-spawn into a separate file + in preparation for modifying it, dbus-sysdeps is getting + a bit unmanageable. + +2003-04-03 Havoc Pennington <hp@redhat.com> + + * bus/loop.h, bus/loop.c: make the mainloop an object so we can + have multiple ones + + * bus/*.[hc]: adapt to mainloop change + +2003-04-03 Havoc Pennington <hp@redhat.com> + + * bus/activation.c (load_directory): fix up memleaks + (bus_activation_entry_free): free the entry + + * dbus/dbus-bus.c (dbus_bus_acquire_service): return an error if + we get one from the message bus; fix memleaks. + + * dbus/dbus-message.c (dbus_set_error_from_message): new function + +2003-04-03 Havoc Pennington <hp@pobox.com> + + * bus/config-parser.c (bus_config_parser_unref): free + list of mechanisms, bug discovered by test suite enhancements + (putting system.conf and session.conf into suite) + + * test/Makefile.am, test/test-service.c: add placeholder for a + test service that we'll activate as part of test suite. Doesn't + do anything yet. + + * dbus/dbus-sysdeps.c (_dbus_setenv): support unsetenv by + setting NULL value, and use system malloc not dbus_malloc() + when we have unavoidable memleakage. + + * dbus/dbus-bus.c (dbus_bus_get): fix bug where bus type of 0 + didn't work, and support DBUS_BUS_ACTIVATION. + + * bus/activation.c (child_setup): pass our well-known bus type to + the child + + * bus/config-parser.c: support <type> to specify well-known type + + * doc/dbus-specification.sgml: document the env variables to + locate well-known buses and find service activator + +2003-04-02 Havoc Pennington <hp@redhat.com> + + * test/Makefile.am (all-local): add a rule to copy tests to + builddir, so we can have generated tests. Use this to remove the + silly hack for testing system.conf and session.conf. Will use this + shortly to generate .service files pointing to test binaries. + +2003-04-02 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-string.c (set_length): fix a bug - we allocated max of + current alloc and needed new length, not max of the doubled + allocation and needed new length. Also, when building tests, + don't do the double-allocation stuff, just realloc every time. + +2003-04-02 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_file_get_contents): include filenames + in error messages + (_dbus_string_get_dirname): new + (_dbus_sysdeps_test): new + (_dbus_directory_open): include dirnames in error messages + + * bus/config-parser.c: interpret <include> and <includedir> and + <servicedir> relative to config file location if the given + filename is not absolute. + + * dbus/dbus-string.c (_dbus_string_find_byte_backward): new + +2003-04-02 Havoc Pennington <hp@redhat.com> + + * bus/connection.c (bus_transaction_send_error_reply): set sender + service for the error, and unref the reply on success + + * bus/activation.c: convert to use BusTransaction so OOM can be + handled correctly + (bus_activation_service_created): set sender of the message + +2003-04-01 Havoc Pennington <hp@redhat.com> + + * bus/config-parser.c, bus/bus.c: implement <servicedir> and + <includedir> (at least mostly) + + * dbus/dbus-sysdeps.c (_dbus_change_identity): set the group ID + first, then the user ID + +2003-04-01 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-server.c (dbus_server_set_auth_mechanisms): new + function + + * dbus/dbus-auth.c (_dbus_auth_set_mechanisms): new + + * dbus/dbus-internals.c (_dbus_dup_string_array): new function + + * dbus/dbus-sysdeps.c (_dbus_listen_unix_socket): chmod the + socket 0777, and unlink any existing socket. + + * bus/bus.c (bus_context_new): change our UID/GID and fork if + the configuration file so specifies; set up auth mechanism + restrictions + + * bus/config-parser.c (bus_config_parser_content): add support + for <fork> option and fill in code for <auth> + + * bus/system.conf.in: add <fork/> to default configuration, + and limit auth mechanisms to EXTERNAL + + * doc/config-file.txt (Elements): add <fork> + + * dbus/dbus-sysdeps.c (_dbus_become_daemon): new function + (_dbus_change_identity): new function + +2003-03-31 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_connect_unix_socket) + (_dbus_listen_unix_socket): fix off-by-one error in null + termination spotted by Nalin + +2003-03-31 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-keyring.c (_dbus_keyring_new_homedir): allow setting + DBUS_TEST_HOMEDIR when tests are enabled, so we can test without + having a real home directory available. + +2003-03-31 Havoc Pennington <hp@redhat.com> + + * bus/Makefile.am (install-data-hook): create /var/run/dbus + + * bus/messagebus.in: add init script for Red Hat /etc/init.d + + * configure.in: add support for specifying a style of init script + to install + +2003-03-31 Havoc Pennington <hp@redhat.com> + + Fix some annoying DBusString API and fix all affected code. + + * dbus/dbus-string.c (_dbus_string_init): get rid of annoying + max_length argument + (_dbus_string_get_data): change to return string instead of using + an out param + (_dbus_string_get_const_data): ditto + (_dbus_string_get_data_len): ditto + (_dbus_string_get_const_data_len): ditto + +2003-03-31 Havoc Pennington <hp@redhat.com> + + * bus/main.c (main): fix up the command line arguments to be nicer + +2003-03-31 Havoc Pennington <hp@redhat.com> + + * dbus/Makefile.am (INCLUDES): use EXPANDED_LOCALSTATEDIR to + define DBUS_SYSTEM_BUS_PATH as we want to compile in the same + final location that lands in the config file + + * bus/config-loader-expat.c (bus_config_load): fix type of + XML_Parser variable + + * doc/TODO: remove TODO item for dbus_bus_get() + + * dbus/dbus-bus.c (bus_data_free): add missing lock/unlock + +2003-03-31 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-transport-unix.c (_dbus_transport_new_for_domain_socket) + (_dbus_transport_new_for_tcp_socket): these didn't need the "server" + argument since they are always client side + + * dbus/dbus-server.c (dbus_server_get_address): new function + + * bus/main.c (main): take the configuration file as an argument. + + * test/data/valid-config-files/debug-allow-all.conf: new file to + use with dispatch.c tests for example + + * bus/test-main.c (main): require test data dir + + * bus/bus.c (bus_context_new): change this to take a + configuration file name as argument + + * doc/config-file.txt (Elements): add <servicedir> + + * bus/system.conf, bus/session.conf: new files + + * dbus/dbus-bus.c (dbus_bus_get): look for system bus on + well-known socket if none set + + * configure.in: create system.conf and session.conf + +2003-03-30 Havoc Pennington <hp@pobox.com> + + * bus/config-parser.c: hacking + + * dbus/dbus-memory.c: don't use DBusList for the list of stuff + to shut down, since it could cause weirdness with the DBusList + lock + + * dbus/dbus-list.c (_dbus_list_test): add tests for the + link-oriented stack routines + (alloc_link): free the mempool if the first alloc from it fails + + * dbus/dbus-mempool.c (struct DBusMemBlock): fix alignment issue + + * dbus/dbus-string.c (UNICODE_VALID): sync new version of this + from GLib + (_dbus_string_skip_white): new + + * doc/config-file.txt (Elements): add <includedir> + +2003-03-28 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-string.c (_dbus_string_copy_data_len) + (_dbus_string_copy_data): new functions + +2003-03-28 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-bus.c: (bus_data_free), (dbus_bus_get): + * dbus/dbus-bus.h: + Add dbus_bus_get. + + * dbus/dbus-memory.c: + Fix a doc comment. + +2003-03-28 Havoc Pennington <hp@pobox.com> + + * bus/test.c (bus_test_flush_bus): remove the sleep from here, + I think it may have just been superstition. Not sure. + + * dbus/dbus-string.c (_dbus_string_base64_decode): catch some OOM + failures that were not being handled. + + * dbus/dbus-auth.c (process_auth): fix a memleak in OOM handling + + * dbus/dbus-memory.c: add ability to set number of mallocs in a + row that will fail on out-of-memory. + + * dbus/dbus-internals.c (_dbus_test_oom_handling): convenience + function for testing out-of-memory handling. + + * bus/config-loader-expat.c (memsuite): don't wrap the dbus + allocation functions, they do map exactly to the expat ones. + +2003-03-27 Havoc Pennington <hp@redhat.com> + + * bus/config-loader-libxml.c (bus_config_load): add another error + check + +2003-03-26 Anders Carlsson <andersca@codefactory.se> + + * doc/TODO: + Add note about automatic service activation. + + * doc/dbus-specification.sgml: + Rename the specification and clarify a few things. + +2003-03-26 Anders Carlsson <andersca@codefactory.se> + + * Doxyfile.in: + * dbus/dbus-address.c: + * dbus/dbus-dict.c: + * dbus/dbus-marshal.c: + * dbus/dbus-server-debug-pipe.c: + * dbus/dbus-transport-unix.c: + Fix documentation warnings. + +2003-03-26 Havoc Pennington <hp@pobox.com> + + * bus/test-main.c, dbus/dbus-test.c (main): check memleaks + after every test so it's quick and easy to see which leaked, and + so we test multiple dbus_shutdown() calls + + * configure.in: change configure.in XML stuff to also support + expat + + * config-loader-libxml.c: some hacking + + * config-loader-expat.c: some hacking + + * config-parser.c: some hacking, plus tests + +2003-03-25 Havoc Pennington <hp@redhat.com> + + * throughout - add more _DBUS_ASSERT_ERROR_IS_CLEAR + + * configure.in: add --with-xml option to specify XML library, + right now only libxml is supported. + + * bus/config-loader-libxml.c, config-parser.c: sync some minor + nonworking code between home and work, still just stubs + +2003-03-24 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_set_fd_nonblocking): move to this + file + + * dbus/dbus-errors.c (dbus_set_error, dbus_set_error_const): allow + NULL argument for "message" if the error is a well-known one, + fill in a generic message in this case. + + * dbus/dbus-errors.h (DBusResultCode): Kill DBusResultCode in + favor of DBusError + + * bus/test.c (bus_test_flush_bus): add + + * bus/policy.c (bus_policy_test): test code stub + +2003-03-24 Havoc Pennington <hp@pobox.com> + + * bus/connection.c (bus_connections_setup_connection): set up + the "can this user connect" function, but it always returns + TRUE until we have a config file parser so we can have a config + file that allows connections. + +2003-03-23 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-threads.c (dbus_mutex_new, dbus_condvar_new): with + DBUS_BUILD_TESTS, actually alloc/free a block of memory for + the mutex, so we can check for proper memory management + and OOM handling. + + * dbus/dbus-dataslot.c: remove the mutex from + DBusDataSlotAllocator and lock it manually when using it, + to simplify fitting it into the global slots framework. + + * dbus/dbus-threads.c (init_static_locks): rework how we're + handling global locks so they are easily shut down. + + * bus/policy.c (bus_policy_append_rule): fix + + * bus/test-main.c (main): check for memleaks + + * dbus/dbus-test.c (dbus_internal_do_not_use_run_tests): make + test suite check for memleaks + + * dbus/dbus-memory.c: add support in test mode for tracking + number of outstanding blocks + +2003-03-23 Havoc Pennington <hp@pobox.com> + + * bus/policy.c, bus/bus.c, bus/connection.c: implement allow/deny + policies code + + * dbus/dbus-hash.h: add ULONG hash keys + + * dbus/dbus-sysdeps.c (_dbus_get_groups): new + (_dbus_get_group_id): new function + +2003-03-20 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c (dbus_connection_set_unix_user_function): + new function + (dbus_connection_get_unix_user): new function + +2003-03-20 Havoc Pennington <hp@pobox.com> + + * bus/connection.c (bus_connection_send_oom_error): assert that + message has a sender + (connection_execute_transaction): ditto + (bus_connection_preallocate_oom_error): fix to set the sender, and + set recipient to the destination service, not the bus driver + + * bus/policy.c: hacking + + * dbus/dbus-message.c (dbus_message_service_is): new function + (dbus_message_sender_is): new + +2003-03-19 Havoc Pennington <hp@redhat.com> + + * bus/policy.c: start sketching code for policy restrictions on + what connections can do. + +2003-03-18 Havoc Pennington <hp@redhat.com> + + * doc/TODO: some notes on high-level todo items. Little nitpick + stuff is all in @todo, so no need to add it here. + + * doc/config-file.txt: some notes on how config file might look + +2003-03-18 Anders Carlsson <andersca@codefactory.se> + + * configure.in: 0.6 + + * NEWS: Update. + +2003-03-17 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-internals.h: add gcc attributes so that + our printf-style functions warn on bad arguments to + format + + * dbus/dbus-sysdeps.c (_dbus_connect_tcp_socket): fix printf + format bug + + * dbus/dbus-message.c (_dbus_message_loader_queue_messages): fix + printf format bug + +2003-03-17 Havoc Pennington <hp@redhat.com> + + * bus/test-main.c (main): make it print something as it runs + so make check doesn't look stuck + + * doc/negotiation.txt, doc/dbus-sasl-profile.txt: remove + from CVS, now obsolete + +2003-03-17 Anders Carlsson <andersca@codefactory.se> + + * bus/dispatch.c: (bus_dispatch): + Refetch the service name since it may have been reallocated + when dbus_message_set_sender was called. + + * dbus/dbus-sysdeps.c: (_dbus_accept): + Add address and address length variables and use them to stop + valgrind from complaining. + +2003-03-17 Havoc Pennington <hp@pobox.com> + + All tests pass, no memleaks, no valgrind complaints. + + * bus/test.c: refcount handler_slot + + * bus/connection.c (bus_connections_new): refcount + connection_data_slot + + * dbus/dbus-auth-script.c (_dbus_auth_script_run): delete unused + bytes so that auth scripts pass. + + * bus/dispatch.c: init message_handler_slot so it gets allocated + properly + + * bus/dispatch.c (message_handler_slot_ref): fix memleak + + * dbus/dbus-server-debug-pipe.c (_dbus_server_debug_pipe_new): + dealloc server_pipe_hash when no longer used for benefit of + leak checking + + * dbus/dbus-auth.c (process_command): memleak fix + + * bus/dispatch.c (check_hello_message): memleak fix + +2003-03-16 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-bus.c (ensure_bus_data): fix double-unref of the data slot + +2003-03-17 Anders Carlsson <andersca@codefactory.se> + + * bus/activation.c (bus_activation_activate_service): Append + the pending activation entry to the list of pending activations. + +2003-03-16 Havoc Pennington <hp@pobox.com> + + * bus/dispatch.c (bus_dispatch_test): remove double-unrefs of + connections + + * dbus/dbus-address.c (create_entry): fix OOM handling when + failing to alloc entry->method + +2003-03-16 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-watch.c (_dbus_watch_new): handle failure to malloc + the watch + + * dbus/dbus-server-debug-pipe.c (_dbus_transport_debug_pipe_new): + add some missing dbus_set_result + + * bus/dispatch.c (bus_dispatch_add_connection): handle failure to + alloc the DBusMessageHandler + + * dbus/dbus-transport.c (_dbus_transport_disconnect): don't ref + the transport here, since we call this from the finalizer; it + resulted in a double-finalize. + + * dbus/dbus-transport.c (_dbus_transport_disconnect): fix a bug + where we tried to use transport->connection that was NULL, + happened when transport was disconnected early on due to OOM + + * bus/*.c: adapt to handle OOM for watches/timeouts + + * dbus/dbus-transport-unix.c: port to handle OOM during + watch handling + + * dbus/dbus-auth.c (_dbus_auth_get_unused_bytes): return a + reference to unused bytes instead of a copy + + * dbus/dbus-server.c (dbus_server_handle_watch): return FALSE for + out of memory + + * dbus/dbus-connection.c (dbus_connection_handle_watch): return + FALSE on OOM + + * dbus/dbus-timeout.c (dbus_timeout_handle): return FALSE for out + of memory + +2003-03-16 Anders Carlsson <andersca@codefactory.se> + + * doc/dbus-specification.sgml: + Document reply message for ActivateService. + +2003-03-16 Anders Carlsson <andersca@codefactory.se> + + * bus/activation.c: (bus_pending_activation_entry_free), + (bus_pending_activation_free), (bus_activation_new), + (bus_activation_unref), (bus_activation_service_created), + (bus_activation_activate_service): + * bus/activation.h: + * bus/bus.c: (bus_context_new): + * bus/desktop-file.c: (new_section): + * bus/driver.c: (bus_driver_send_service_deleted), + (bus_driver_handle_activate_service): + * bus/services.c: (bus_registry_new), (bus_registry_ensure): + * bus/services.h: + * dbus/dbus-connection.c: + (dbus_connection_send_with_reply_and_block): + * dbus/dbus-message.c: (dbus_message_append_args_valist): + * dbus/dbus-protocol.h: + Make activation work better. Now pending activations will be queued + and the daemon won't try to activate services that are already registered. + +2003-03-16 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-bus.c (ensure_bus_data): handle failure to set + connection data + + * dbus/dbus-memory.c (_dbus_initialize_malloc_debug): support + DBUS_MALLOC_BACKTRACES to print trace when failing an alloc + +2003-03-16 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-string.c (_dbus_string_validate_utf8): oops, unbreak + this. always run the test suite before commit... + + * bus/*: adapt to DBusConnection API changes + + * glib/dbus-gmain.c: adapt to DBusConnection API changes, + requires renaming stuff to avoid dbus_connection_dispatch name + conflict. + + * dbus/dbus-transport.c (_dbus_transport_queue_messages): new + function + + * dbus/dbus-message.c (_dbus_message_loader_queue_messages): + separate from _dbus_message_loader_return_buffer() + + * dbus/dbus-connection.c (dbus_connection_get_n_messages): remove + this, because it's now always broken to use; the number of + messages in queue vs. the number still buffered by the message + loader is undefined/meaningless. Should use + dbus_connection_get_dispatch_state(). + (dbus_connection_dispatch): rename from + dbus_connection_dispatch_message + +2003-03-16 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-string.c (_dbus_string_validate_utf8): copy in a real + implementation + +2003-03-16 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-connection.c: + (dbus_connection_send_with_reply_and_block): + Decrease connection->n_incoming when removing an entry + from the list. + * dbus/dbus-dict.c: (dbus_dict_entry_free), + (dbus_dict_set_boolean_array), (dbus_dict_set_int32_array), + (dbus_dict_set_uint32_array), (dbus_dict_set_double_array), + (dbus_dict_set_byte_array), (dbus_dict_set_string_array), + (dbus_dict_get_boolean_array), (dbus_dict_get_double_array), + (dbus_dict_get_byte_array): + Handle NULL arrays and strings. Also add support for byte arrays. + + * dbus/dbus-marshal.c: (_dbus_marshal_byte_array), + (_dbus_marshal_dict), (_dbus_demarshal_byte_array), + (_dbus_demarshal_int32_array), (_dbus_demarshal_uint32_array), + (_dbus_demarshal_double_array), (_dbus_demarshal_string_array), + (_dbus_demarshal_dict), (demarshal_and_validate_len), + (_dbus_marshal_validate_arg), (_dbus_marshal_test): + * dbus/dbus-marshal.h: + Add support for marshalling and demarshalling empty arrays and strings. + + * dbus/dbus-message.c: (dbus_message_append_args_valist), + (dbus_message_append_string_array), + (dbus_message_iter_get_boolean), + (dbus_message_iter_get_boolean_array), + (dbus_message_iter_get_int32_array), + (dbus_message_iter_get_uint32_array), + (dbus_message_iter_get_double_array), + (dbus_message_iter_get_byte_array), + (dbus_message_iter_get_string_array), (dbus_message_iter_get_dict), + (check_message_handling): + Add support for getting empty arrays and dicts. + + * dbus/dbus-string.c: (_dbus_string_validate_utf8): + Don't do any validation at all for now, that's better than just checking + for ASCII. + + * test/data/valid-messages/emptiness.message: + New test message with lots of empty arrays. + +2003-03-16 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c + (_dbus_connection_queue_received_message_link): new function that + can't fail due to OOM + + * dbus/dbus-message.c (_dbus_message_loader_pop_message_link): + new function pops a message together with a list link + containing it. + + * dbus/dbus-transport-unix.c (queue_messages): use new link-based + message queuing functions to avoid needing to alloc memory + +2003-03-16 Havoc Pennington <hp@pobox.com> + + Oops - test code was only testing failure of around 30 of the + mallocs in the test path, but it turns out there are 500+ + mallocs. I believe this was due to misguided linking setup such + that there was one copy of dbus_malloc etc. in the daemon and one + in the shared lib, and only daemon mallocs were tested. In any + case, the test case now tests all 500+ mallocs, and doesn't pass + yet, though there are lots of fixes in this patch. + + * dbus/dbus-connection.c (dbus_connection_dispatch_message): fix + this so that it doesn't need to allocate memory, since it + has no way of indicating failure due to OOM (and would be + annoying if it did). + + * dbus/dbus-list.c (_dbus_list_pop_first_link): new function + + * bus/Makefile.am: rearrange to create two self-contained + libraries, to avoid having libraries with overlapping symbols. + that was resulting in weirdness, e.g. I'm pretty sure there + were two copies of global static variables. + + * dbus/dbus-internals.c: move the malloc debug stuff to + dbus-memory.c + + * dbus/dbus-list.c (free_link): free list mempool if it becomes + empty. + + * dbus/dbus-memory.c (_dbus_disable_mem_pools): new function + + * dbus/dbus-address.c (dbus_parse_address): free list nodes + on failure. + + * bus/dispatch.c (bus_dispatch_add_connection): free + message_handler_slot when no longer using it, so + memory leak checkers are happy for the test suite. + + * dbus/dbus-server-debug-pipe.c (debug_finalize): free server name + + * bus/bus.c (new_connection_callback): disconnect in here if + bus_connections_setup_connection fails. + + * bus/connection.c (bus_connections_unref): fix to free the + connections + (bus_connections_setup_connection): if this fails, don't + disconnect the connection, just be sure there are no side + effects. + + * dbus/dbus-string.c (undo_alignment): unbreak this + + * dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were + leaking + (_dbus_auth_new): fix the order in which we free strings + on OOM failure + + * bus/connection.c (bus_connection_disconnected): fix to + not send ServiceDeleted multiple times in case of memory + allocation failure + + * dbus/dbus-bus.c (dbus_bus_get_base_service): new function to + get the base service name + (dbus_bus_register_client): don't return base service name, + instead store it on the DBusConnection and have an accessor + function for it. + (dbus_bus_register_client): rename dbus_bus_register() + + * bus/dispatch.c (check_hello_message): verify that other + connections on the bus also got the correct results, not + just the one sending hello + +2003-03-15 Havoc Pennington <hp@pobox.com> + + Make it pass the Hello handling test including all OOM codepaths. + Now to do other messages... + + * bus/services.c (bus_service_remove_owner): fix crash when + removing owner from an empty list of owners + (bus_registry_ensure): don't leave service in the list of + a connection's owned services if we fail to put the service + in the hash table. + + * bus/connection.c (bus_connection_preallocate_oom_error): set + error flag on the OOM error. + + * dbus/dbus-connection.c (_dbus_connection_new_for_transport): + handle _dbus_transport_set_connection failure + + * dbus/dbus-transport-unix.c (_dbus_transport_new_for_fd): modify + to create watches up front and simply enable/disable them as + needed. + (unix_connection_set): this can now fail on OOM + + * dbus/dbus-timeout.c, dbus/dbus-watch.c: add concept + of enabling/disabling a watch or timeout. + + * bus/loop.c (bus_loop_iterate): don't touch disabled + watches/timeouts + + * glib/dbus-gmain.c: adapt to enable/disable watches and timeouts + +2003-03-15 Havoc Pennington <hp@pobox.com> + + * bus/dispatch.c (bus_dispatch_test): OK, now finally actually + write useful test code, after all that futzing around ;-) + + Test does not yet pass because we can't handle OOM in + _dbus_transport_messages_pending (basically, + dbus_connection_preallocate_send() does not prealloc the write + watch). To fix this, I think we need to add new stuff to + set_watch_functions, namely a SetEnabled function so we can alloc + the watch earlier, then enable it later. + + * dbus/Makefile.am (libdbus_convenience_la_SOURCES): move + dbus-memory.c to the convenience lib + + * bus/test.c: rename some static functions to keep them clearly + distinct from stuff in connection.c. Handle client disconnection. + +2003-03-14 Havoc Pennington <hp@pobox.com> + + * bus/dispatch.c (bus_dispatch_test): do test using debug-pipe + transport, tests more of the real codepath. Set up clients + with bus_setup_debug_client. + + * bus/test.c (bus_setup_debug_client): function to set up debug + "clients" on the main loop + + * dbus/dbus-transport.c (_dbus_transport_open): add debug-pipe + support + + * dbus/dbus-server.c (dbus_server_listen): add debug-pipe + server type + + * dbus/dbus-server-debug.c: support a debug server based on pipes + + * dbus/dbus-sysdeps.c (_dbus_full_duplex_pipe): new function + (_dbus_close): new function + + * configure.in: check for socketpair + +2003-03-14 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-memory.c: add a "detect buffer overwrites on free" + cheesy hack + + * dbus/dbus-transport-debug.c: rework this a good bit to be + less complicated. hopefully still works. + + * dbus/dbus-server-debug.c (handle_new_client): remove timeout + manually + + * glib/dbus-gmain.c (timeout_handler): don't remove timeout + after running it + + * dbus/dbus-message.c (dbus_message_copy): rename from + dbus_message_new_from_message, fix it up to copy + all the message fields, add test case + + * bus/dispatch.c (bus_dispatch_test): add some more test code, + not quite passing yet + +2003-03-14 Havoc Pennington <hp@pobox.com> + + * bus/loop.c (bus_loop_iterate): add this so we can "run loop + until no work remains" in test code. (the large diff here + is just code movement, no actual changes) + + * dbus/dbus-server-debug.c (DEFAULT_INTERVAL): change interval to + 1, no point waiting around for test code. + (_dbus_server_debug_accept_transport): unref the timeout + after adding it (right?) + + * dbus/dbus-transport-debug.c (DEFAULT_INTERVAL): ditto + +2003-03-13 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-timeout.c (_dbus_timeout_list_set_functions): handle + out of memory + + * dbus/dbus-watch.c (_dbus_watch_list_set_functions): handle out + of memory + + * dbus/dbus-connection.h: Make AddWatchFunction and + AddTimeoutFunction return a bool so they can fail on out-of-memory + + * bus/bus.c (bus_context_new): set up timeout handlers + + * bus/connection.c (bus_connections_setup_connection): set up + timeout handlers + + * glib/dbus-gmain.c: adapt to the fact that set_functions stuff + can fail + + * bus/bus.c (bus_context_new): adapt to changes + + * bus/connection.c: adapt to changes + + * test/watch.c: adapt to DBusWatch changes + + * bus/dispatch.c (bus_dispatch_test): started adding this but + didn't finish + +2003-03-14 Anders Carlsson <andersca@codefactory.se> + + * bus/dispatch.c (send_service_nonexistent_error): Fix typo. + +2003-03-13 Havoc Pennington <hp@pobox.com> + + * bus/test.c, bus/test.h, bus/Makefile.am, bus/test-main.c: + set up a test framework as for the library + +2003-03-12 Havoc Pennington <hp@pobox.com> + + Throughout: purge global variables, introduce BusActivation, + BusConnections, BusRegistry, etc. objects instead. + + * bus/bus.h, bus/bus.c: introduce BusContext as a global + message bus object + + * test/Makefile.am (TEST_BINARIES): disable bus-test for now, + going to redo this a bit differently I think + +2003-03-12 Havoc Pennington <hp@redhat.com> + + Mega-patch that gets the message bus daemon initially handling + out-of-memory. Work still needed. Also lots of random + moving stuff to DBusError instead of ResultCode. + + * dbus/dbus-list.c (_dbus_list_length_is_one): new function + + * dbus/dbus-connection.c + (dbus_connection_send_with_reply_and_block): use DBusError + + * dbus/dbus-bus.c: adapt to API changes, make it use DBusError not + DBusResultCode + + * dbus/dbus-connection.c (dbus_connection_send): drop the result + code here, as the only failure possible is OOM. + + * bus/connection.c (bus_connection_disconnect): + rename bus_connection_disconnected as it's a notification only + + * bus/driver.c (bus_driver_handle_acquire_service): don't free + "name" on get_args failure, should be done by get_args; + don't disconnect client for bad args, just return an error. + (bus_driver_handle_service_exists): ditto + + * bus/services.c (bus_services_list): NULL-terminate returned array + + * bus/driver.c (bus_driver_send_service_lost) + (bus_driver_send_service_acquired): send messages from driver to a + specific client to the client's unique name, not to the broadcast + service. + + * dbus/dbus-message.c (decode_header_data): reject messages that + contain no name field + (_dbus_message_get_client_serial): rename to + dbus_message_get_serial and make public + (_dbus_message_set_serial): rename from set_client_serial + (_dbus_message_set_reply_serial): make public + (_dbus_message_get_reply_serial): make public + + * bus/connection.c (bus_connection_foreach): allow stopping + iteration by returning FALSE from foreach function. + + * dbus/dbus-connection.c (dbus_connection_send_preallocated) + (dbus_connection_free_preallocated_send) + (dbus_connection_preallocate_send): new API for sending a message + without possibility of malloc failure. + (dbus_connection_send_message): rename to just + dbus_connection_send (and same for whole function family) + + * dbus/dbus-errors.c (dbus_error_free): make this reinit the error + + * dbus/dbus-sysdeps.c (_dbus_exit): new function + + * bus/activation.c: handle/return errors + + * dbus/dbus-errors.h: add more DBUS_ERROR #define + + * dbus/dbus-sysdeps.c (_dbus_directory_open) (_dbus_file_get_contents) + (_dbus_directory_get_next_file): use DBusError instead of DBusResultCode + (_dbus_result_from_errno): move to this file + +2003-03-10 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-marshal.c: + (_dbus_marshal_set_string): + Take a length argument so we can marshal the correct string + length. + + (_dbus_marshal_dict), (_dbus_demarshal_dict), + (_dbus_marshal_get_arg_end_pos), (_dbus_marshal_validate_arg), + (_dbus_marshal_test): + * dbus/dbus-marshal.h: + Add support for marshalling and demarshalling dicts. + + * dbus/dbus-message-builder.c: (_dbus_message_data_load): + Add support for TYPE DICT. + + * dbus/dbus-message.c: (set_string_field): + Adjust header padding. + + (dbus_message_append_args_valist), (dbus_message_append_dict), + (dbus_message_get_args_valist), (dbus_message_iter_get_arg_type), + (dbus_message_iter_get_dict), (_dbus_message_loader_return_buffer), + (check_message_handling), (check_have_valid_message): + * dbus/dbus-message.h: + Add functions for setting and getting dicts. + + * dbus/dbus-protocol.h: + Add DBUS_TYPE_DICT. + + * dbus/dbus.h: + Add dbus-dict.h + + * doc/dbus-specification.sgml: + Add information about how dicts are marshalled. + + * test/data/invalid-messages/dict-with-nil-value.message: + * test/data/invalid-messages/too-short-dict.message: + * test/data/valid-messages/dict-simple.message: + * test/data/valid-messages/dict.message: + Add sample messages containing dicts. + +2003-03-08 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-dict.h: Add DBUS_END_DECLS. + +2003-03-07 Anders Carlsson <andersca@codefactory.se> + + * dbus/Makefile.am: + * dbus/dbus-dict.c: (dbus_dict_entry_free), (dbus_dict_new), + (dbus_dict_get_keys), (insert_entry), (dbus_dict_set_boolean), + (dbus_dict_set_int32), (dbus_dict_set_uint32), + (dbus_dict_set_double), (dbus_dict_set_string), + (dbus_dict_set_boolean_array), (dbus_dict_set_int32_array), + (dbus_dict_set_uint32_array), (dbus_dict_set_double_array), + (dbus_dict_set_string_array), (_dbus_dict_test): + * dbus/dbus-dict.h: + Fix according to comments from Havoc. + +2003-03-06 Michael Meeks <michael@server.home> + + * configure.in: if we don't have kde-config, disable have_qt. + +2003-03-07 Anders Carlsson <andersca@codefactory.se> + + * dbus/Makefile.am: + Add dbus-dict.[ch] + + * dbus/dbus-dict.c: (dbus_dict_entry_free), (dbus_dict_new), + (dbus_dict_ref), (dbus_dict_unref), (dbus_dict_contains), + (dbus_dict_remove), (dbus_dict_get_value_type), + (dbus_dict_get_keys), (dbus_dict_put_boolean), + (dbus_dict_put_int32), (dbus_dict_put_uint32), + (dbus_dict_put_double), (dbus_dict_put_string), + (dbus_dict_put_boolean_array), (dbus_dict_put_int32_array), + (dbus_dict_put_uint32_array), (dbus_dict_put_double_array), + (dbus_dict_put_string_array), (dbus_dict_get_boolean), + (dbus_dict_get_int32), (dbus_dict_get_uint32), + (dbus_dict_get_double), (dbus_dict_get_string), + (dbus_dict_get_boolean_array), (dbus_dict_get_int32_array), + (dbus_dict_get_uint32_array), (dbus_dict_get_double_array), + (dbus_dict_get_string_array), (_dbus_dict_test): + * dbus/dbus-dict.h: + Add DBusDict implementation + + * dbus/dbus-test.c: (dbus_internal_do_not_use_run_tests): + * dbus/dbus-test.h: + Add _dbus_dict_test + +2003-03-04 Havoc Pennington <hp@pobox.com> + + * test/data/auth/*: adapt to changes + + * dbus/dbus-auth-script.c (_dbus_auth_script_run): add + USERID_BASE64 and change USERNAME_BASE64 to put in username not + userid + + * dbus/dbus-keyring.c (_dbus_keyring_validate_context): prevent + more stuff from being in a context name, to make the protocol + simpler to deal with + + * dbus/dbus-errors.c (dbus_error_has_name): new function + (dbus_error_is_set): new function + + * dbus/dbus-auth.c: replace DBUS_STUPID_TEST_MECH auth + with DBUS_COOKIE_SHA1, implement DBUS_COOKIE_SHA1 + + * dbus/dbus-connection.c (dbus_connection_flush): also read + messages during a flush operation + + * dbus/Makefile.am: remove dbus-md5 since it isn't currently used. + +2003-03-05 Anders Carlsson <andersca@codefactory.se> + + * configure.in: Check for gethostbyname on Solaris. + + * dbus/dbus-transport.c: (_dbus_transport_open): + Remove duplicate "tcp" entry. + + * doc/dbus-specification.sgml: + Clarify some things. + +2003-03-05 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-auth.c: (send_rejected), (process_test_subdir): + * dbus/dbus-keyring.c: (_dbus_keyring_new_homedir), + (_dbus_keyring_test): + * dbus/dbus-md5.c: (_dbus_md5_compute): + * dbus/dbus-sha.c: (_dbus_sha_compute): + Plug memory leaks. + +2003-03-05 Anders Carlsson <andersca@codefactory.se> + + * README: Add some things. + +2003-03-04 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-message.c (dbus_message_append_args_valist): Add a break; + after case DBUS_TYPE_BOOELAN. + +2003-03-02 Havoc Pennington <hp@pobox.com> + + * test/break-loader.c (randomly_set_extreme_ints): add test that + sets really huge and small integers + + * dbus/dbus-marshal.c (_dbus_marshal_validate_arg): add check + that length of boolean array fits in the string, and that + string has room for boolean value in single-bool case. + + * dbus/dbus-message-builder.c (_dbus_message_data_load): add + optional value to "ALIGN" command which is what to fill the + alignment with. + + * test/data/valid-messages/no-padding.message: add regression + test for the message padding problem + +2003-03-02 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c (decode_header_data): fix to always init + message_padding, from Benjamin Dauvergne + +2003-03-02 Havoc Pennington <hp@pobox.com> + + * configure.in: 0.5 + + * NEWS: Update. + +2003-03-01 Joe Shaw <joe@assbarn.com> + + * configure.in: Check for "struct cmsgcred" and try to access its + members for BSD-like unices. + + * dbus/dbus-sysdeps.c (read_credentials_byte): Fold this back into + _dbus_read_credentials_unix_socket(). + (_dbus_read_credentials_unix_socket): Use recvmsg() instead of + read() for reading the credential byte off the unix socket. Use + struct cmsgcred on systems that support it. + +2003-02-27 Alexander Larsson <alexl@redhat.com> + + * glib/Makefile.am: + * configure.in: + Make gthreads-2.0 dependency optional. Don't build thread test if + its not found. + +2003-02-27 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c + (dbus_connection_send_message_with_reply_and_block): fix doh! + doh! doh! bug that resulted in never removing a reply from the + queue, no wonder we called get_reply_serial so much ;-) + + * dbus/dbus-message.c (struct DBusMessage): cache reply serial + and client serial instead of demarshaling them every time + +2003-02-27 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-marshal.c (_dbus_demarshal_int32): rewrite to be much + more inlined, using dbus-string-private.h, speeds things up + substantially + + * dbus/dbus-string.c (_dbus_string_free): apply align offset + when freeing the string + (_dbus_string_steal_data): fix for align offset + (undo_alignment): new function + +2003-02-26 Havoc Pennington <hp@redhat.com> + + All kinds of audit fixes from Owen, plus initial attempt to + handle unaligned memory returned from malloc. + + * dbus/dbus-string.c (_dbus_string_init): clamp max length to + leave room for align_offset and nul byte + (fixup_alignment): function to track an align_offset and + ensure real->str is aligned + (DBUS_GENERIC_STRING_PREAMBLE): len must be less than allocated, + to allow a nul byte plus align offset + (_dbus_string_lock): fix overflow issue + (_dbus_string_init_const_len): add assertions on sanity of len, + assign allocated to be ALLOCATION_PADDING larger than len + (set_length): fixup the overflow handling + (_dbus_string_get_data_len): fix overflow in assertion + (open_gap): detect overflow in size of gap to be opened + (_dbus_string_lengthen): add overflow check + (_dbus_string_align_length): fix overflow with _DBUS_ALIGN_VALUE + (_dbus_string_append): add overflow check + (_dbus_string_append_unichar): overflow + (_dbus_string_delete): fix overflow in assertion + (_dbus_string_copy_len): overflow in assertion + (_dbus_string_replace_len): overflows in assertions + (_dbus_string_find): change to implement in terms of + _dbus_string_find_to + (_dbus_string_find_to): assorted fixage + (_dbus_string_equal_c_str): assert c_str != NULL, + fix logic so the function works + (_dbus_string_ends_with_c_str): fix overflow thingy + (_dbus_string_base64_encode): overflow fix + (_dbus_string_validate_ascii): overflow + (_dbus_string_validate_nul): overflow + +2003-02-26 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-marshal.c (_dbus_marshal_test): fix to work with DISABLE_ASSERTS + +2003-02-26 Alexander Larsson <alexl@redhat.com> + + * configure.in: + Set DBUS_GLIB_THREADS_LIBS for apps using gthread-2.0 + + * dbus/dbus-connection.c: + * dbus/dbus-connection.h: + Fix _dbus_connection_acquire_io_path and _dbus_connection_acquire_dispatch. + Add dbus_connection_set_wakeup_main_function and use it when queueing + incoming and outgoing messages. + + + * dbus/dbus-dataslot.c: + Threadsafe usage of DBusDataSlotAllocator + + * dbus/dbus-message.c: (dbus_message_get_args_iter): + dbus_new can fail. + + * dbus/dbus-server-unix.c: + Add todo comment + + * glib/dbus-gmain.c: + Implement the new wakeup functions for glib. + + * glib/Makefile.am: + * glib/test-thread-client.c: + * glib/test-thread-server.c: + * glib/test-thread.h: + Initial cut at some thread test code. Not really done yet. + +2003-02-26 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c + (dbus_connection_send_message_with_reply_and_block): fix crash + where we ref'd the outgoing message instead of the returned reply + + * dbus/dbus-transport-unix.c (do_authentication): check read watch + at the end of this function, so if we didn't need to read for + authentication, we reinstall it for receiving messages + + * dbus/dbus-message.c (dbus_message_new_reply): allow replies to + a NULL sender for peer-to-peer case + + * dbus/dbus-transport-unix.c (check_read_watch): handle + !authenticated case correctly + + * glib/dbus-gmain.c: add support for DBusServer + + * dbus/dbus-server.c: add data slot support + + * glib/dbus-gmain.c (dbus_connection_setup_with_g_main): check + return values and handle errors + + * dbus/dbus-dataslot.c: factor out the data slot stuff from + DBusConnection + + * Doxyfile.in (INPUT): add glib subdir + + * glib/dbus-gmain.c (dbus_connection_setup_with_g_main): rename + setup_with_g_main instead of hookup_with_g_main; write docs + +2003-02-24 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-marshal.c: (_dbus_marshal_validate_arg): + * dbus/dbus-message-builder.c: (_dbus_message_data_load): + * dbus/dbus-message.c: (dbus_message_append_boolean), + (dbus_message_append_boolean_array), + (dbus_message_get_args_valist), (_dbus_message_test): + * dbus/dbus-message.h: + * doc/dbus-specification.sgml: + Various fixes as pointed out by Havoc. + + * test/data/invalid-messages/bad-boolean-array.message: + * test/data/invalid-messages/bad-boolean.message: + Add invalid boolean value test cases. + +2003-02-24 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-internals.c: (_dbus_type_to_string): + * dbus/dbus-marshal.c: (_dbus_marshal_get_arg_end_pos), + (_dbus_marshal_validate_arg): + * dbus/dbus-message-builder.c: (_dbus_message_data_load): + * dbus/dbus-message.c: (dbus_message_append_args_valist), + (dbus_message_append_boolean), (dbus_message_append_boolean_array), + (dbus_message_get_args_valist), (dbus_message_iter_get_boolean), + (dbus_message_iter_get_int32), (dbus_message_iter_get_uint32), + (dbus_message_iter_get_double), + (dbus_message_iter_get_boolean_array), (message_iter_test): + * dbus/dbus-message.h: + * dbus/dbus-protocol.h: + * doc/dbus-specification.sgml: + * test/data/valid-messages/lots-of-arguments.message: + Add support for boolean and boolean array types. + +2003-02-23 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-keyring.c: finish most of this implementation and + simple unit test + + * dbus/dbus-errors.c (dbus_set_error_const, dbus_set_error): make + these barf if the error isn't cleared to NULL + + * dbus/dbus-sysdeps.c (_dbus_delete_file): set error on failure + (_dbus_create_directory): new function + + * dbus/dbus-errors.c (dbus_set_error): fix warning + + * dbus/dbus-string.c (_dbus_string_hex_encode): new function + (_dbus_string_hex_decode): new function + (test_hex_roundtrip): test code + + * dbus/dbus-sha.c (_dbus_sha_compute): use dbus_string_hex_encode + + * dbus/dbus-md5.c (_dbus_md5_compute): use dbus_string_hex_encode + + * dbus/dbus-sysdeps.c (_dbus_string_save_to_file): make this use + the save-to-temp/rename trick to atomically write the new file + (_dbus_string_parse_uint): new function + +2003-02-22 Havoc Pennington <hp@pobox.com> + + * test/Makefile.am (dist-hook): fix dist for test/data/sha-1 + +2003-02-22 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c (dbus_message_iter_get_string_array): + (dbus_message_iter_get_byte_array): Fix up doxygen warnings + + * dbus/dbus-sha.c: add implementation of SHA-1 algorithm + + * dbus/test/data/sha-1: add US government test suite for SHA-1 + +2003-02-21 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-marshal.c: (_dbus_demarshal_string_array): + Make string arrays NULL-terminated. + + * dbus/dbus-memory.c: (dbus_free_string_array): + * dbus/dbus-memory.h: + New function for freeing NULL-terminated string arrays. + + * dbus/dbus-message-builder.c: (append_quoted_string), + (_dbus_message_data_load): + Add support for array types. + + * dbus/dbus-message.c: (check_message_handling): + Add more types as test cases. + + * dbus/dbus-sysdeps.c: (_dbus_string_parse_int), + (_dbus_string_parse_double): + Add the start offset to the end offset. + + * test/data/valid-messages/lots-of-arguments.message: + New test message with lots of arguments. + +2003-02-21 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-message.c: (dbus_message_append_nil), + (dbus_message_append_int32), (dbus_message_append_uint32), + (dbus_message_append_double), (dbus_message_append_string), + (dbus_message_append_int32_array), + (dbus_message_append_uint32_array), + (dbus_message_append_double_array), + (dbus_message_append_byte_array), + (dbus_message_append_string_array): + Fix all out-of-memory handling in these functions. + +2003-02-21 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-message.c: (dbus_message_append_nil): + Fix a silly. + +2003-02-21 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-message.c: (dbus_message_append_args_valist), + (dbus_message_append_nil), (dbus_message_append_int32_array), + (dbus_message_append_uint32_array), + (dbus_message_append_double_array), + (dbus_message_append_byte_array), + (dbus_message_append_string_array), (dbus_message_get_args_valist), + (dbus_message_iter_get_int32_array), + (dbus_message_iter_get_uint32_array), + (dbus_message_iter_get_double_array), + (dbus_message_iter_get_byte_array), + (dbus_message_iter_get_string_array): + + * dbus/dbus-message.h: + Add functions for appending and getting arrays. + +2003-02-21 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-mempool.c (_dbus_mem_pool_new): Make the + element size at least 8 bytes, fixes mempool tests on + 64-bit machines. + +2003-02-20 Alexander Larsson <alexl@redhat.com> + + * dbus/dbus-transport-unix.c (unix_do_iteration): + Unlock the connection mutex during a blocking select call. + Add todo about how we need a way to wake up the select. + + * dbus/dbus-connection-internal.h: + * dbus/dbus-connection.c: + Add _dbus_connection_lock and _dbus_connection_unlock. + +2003-02-19 Havoc Pennington <hp@pobox.com> + + * Doxyfile.in (PREDEFINED): put DOXYGEN_SHOULD_SKIP_THIS in + Doxyfile.in, not Doxyfile + + * dbus/dbus-keyring.c: do some hacking on this + + * dbus/dbus-sysdeps.c (_dbus_delete_file): new + + * dbus/dbus-errors.c (dbus_set_error_const): do not call + dbus_error_init + (dbus_set_error): remove dbus_error_init, check for message == + NULL *before* we sprintf into it, and add @todo about including + system headers in this file + + * dbus/dbus-sysdeps.c (_dbus_create_file_exclusively): new + + * dbus/dbus-errors.h (DBUS_ERROR_FAILED): add + + * dbus/dbus-sysdeps.c (get_user_info): break this function out to + get various bits of user information based on either username + or user ID + (_dbus_homedir_from_username): new function + +2003-02-19 Anders Carlsson <andersca@codefactory.se> + + * configure.in: + Add check for nonposix getpwnam_r + + * dbus/dbus-mempool.c: (_dbus_mem_pool_new): + Align the pool element size to a sizeof (void *) boundary. + + * dbus/dbus-sysdeps.c: (_dbus_setenv), (_dbus_connect_unix_socket), + (_dbus_listen_unix_socket), (_dbus_credentials_from_username): + General Solaris fixes. + + * test/data/valid-messages/simplest-manual.message: + Explicitly state that we want little-endian packing. + +2003-02-19 Mikael Hallendal <micke@codefactory.se> + + * dbus/dbus-server.c (dbus_server_listen): Support tcp: addresses. + + * dbus/dbus-transport-unix.c (_dbus_transport_new_for_tcp_socket): + Added to create a transport connecting using a tcp/ip socket. + + * dbus/dbus-sysdeps.c (_dbus_connect_tcp_socket): Added to connect + to a tcp socket at given host and port. + (_dbus_listen_tcp_socket): added to listen on tcp socket for given + hostname and port. + + * dbus/dbus-server.c (dbus_server_listen): Support tcp: addresses. + + * dbus/dbus-server-unix.c (_dbus_server_new_for_tcp_socket): + Added to create a server listening on a TCP/IP socket. + +2003-02-19 Havoc Pennington <hp@pobox.com> + + Throughout: mop up all the Doxygen warnings and undocumented + stuff. + + * dbus/dbus-sysdeps.c (do_exec): do not use execvp, we don't want + to search any paths. + + * dbus/dbus-threads.c: move global mutex initializers to + dbus-internals.h, multiple prototypes was confusing doxygen + besides being kind of ugly + + * Doxyfile (PREDEFINED): have Doxygen define + DOXYGEN_SHOULD_SKIP_THIS so we can exclude things from + docs with #ifndef DOXYGEN_SHOULD_SKIP_THIS + (do not abuse the feature! it's for stuff like the autogenerated + macros in dbus-md5.c, not just for things you don't feel like + documenting...) + +2003-02-18 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-string.c (_dbus_string_zero): new function + + * dbus/dbus-md5.c: include MD5 implementation by L. Peter Deutsch, + wrap it in some dbus-friendly API + + * dbus/dbus-types.h: add 16-bit types + +2003-02-18 Joe Shaw <joe@assbarn.com> + + * dbus/dbus-auth.c (handle_server_data_stupid_test_mech): Just get + credentials from our currently running process. + (get_word): Fix a buglet where we were copying the entire length + instead of relative to our position. + + * dbus/dbus-hash.c (_dbus_hash_test): Don't try to allocate the + keys on the stack... it's 640k of data. + + * dbus/dbus-sysdeps.c (_dbus_read_credentials_unix_socket): Always + read the credentials byte off the socket, even if we don't have + SO_PEERCRED. + (_dbus_poll): Implement poll() using select() for systems which + don't have it. + + * glib/test-dbus-glib.c (main): Print out an error if no + parameters are given. + + * test/data/auth/fallback.auth-script: Added. Tests that a client + can fallback to a secondary auth mechanism if the first fails. + +2003-02-18 Havoc Pennington <hp@pobox.com> + + * AUTHORS: add Alex + +2003-02-17 Havoc Pennington <hp@pobox.com> + + * doc/dbus-specification.sgml: lots of cosmetic + cleanups/rearrangement, add assorted FIXME, change DBUS_ADDRESS + env variable to DBUS_BUS_ADDRESS, s/client/application/, + s/server/bus/ (except in authentication section). Add a section + "Message Bus Message Routing" + +2003-02-17 Anders Carlsson <andersca@codefactory.se.> + + Release 0.4 + + * NEWS: Update + +2003-02-17 Anders Carlsson <andersca@codefactory.se> + + * doc/dbus-specification.sgml: + Specification updates. + +2003-02-17 Anders Carlsson <andersca@codefactory.se> + + * bus/activation.c: (bus_activation_init), (child_setup), + (bus_activation_activate_service): + * bus/activation.h: + * bus/main.c: (main): + Set DBUS_ADDRESS environment variable. + + * dbus/dbus-errors.c: (dbus_set_error): + Don't use va_copy since that's a C99 feature. + + * dbus/dbus-sysdeps.c: (_dbus_setenv), (do_exec), + (_dbus_spawn_async): + * dbus/dbus-sysdeps.h: + Add child_setup_func to _dbus_spawn_async. + + * doc/dbus-specification.sgml: + Update specification. + + * test/spawn-test.c: (setup_func), (main): + Fix test. + +2003-02-17 Alexander Larsson <alexl@redhat.com> + + * dbus/dbus-connection.c (_dbus_connection_handler_destroyed_locked): + Added todo. + +2003-02-17 Anders Carlsson <andersca@codefactory.se> + + * doc/.cvsignore: + * doc/Makefile.am: + * doc/dbus-test-plan.sgml: + Add test plan document. + + * test/Makefile.am: + Fix distcheck. + +2003-02-17 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-message.c: (decode_header_data), + (_dbus_message_loader_return_buffer): + Set the header padding amount when loading a message. + +2003-02-16 Anders Carlsson <andersca@codefactory.se> + + * bus/dispatch.c: (send_one_message): + Only send broadcast messages to registered connections. + + * dbus/dbus-message.c: (dbus_message_name_is): + * dbus/dbus-message.h: + New convenience function. + + * dbus/dbus-transport-debug.c: (do_reading): + Only dispatch one message per run. + + * test/Makefile.am: + * test/bus-test.c: (new_connection_callback), (die), + (test_hello_client1_handler), (test_hello_client2_handler), + (test_hello_replies), (main): + + * test/bus-test-loop.[ch]: + Add these. + +2003-02-16 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c (dbus_connection_dispatch_message): fix + backward conditional + +2003-02-16 Alexander Larsson <alexl@redhat.com> + + * dbus/dbus-connection.c: + Implement sent_message_with_reply. (with_reply_and block is still + busted). + Made dispatch_message not lose message if OOM. + + * dbus/dbus-errors.h: + Add NoReply error (for reply timeouts). + +2003-02-16 Alexander Larsson <alexl@redhat.com> + + * dbus/dbus-hash.c (_dbus_hash_table_unref): + Actually free keys and values when destroying hashtable. + +2003-02-16 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-auth.c: (client_try_next_mechanism): + Plug a leak. + + * dbus/dbus-threads.c: (dbus_condvar_wait_timeout): + Return TRUE if there's no thread implementation around. + + * glib/dbus-gmain.c: (free_source), + (dbus_connection_hookup_with_g_main): + Make sure to remove the GSource when the connection is finalized. + +2003-02-16 Anders Carlsson <andersca@codefactory.se> + + * bus/dispatch.c: (bus_dispatch_message_handler): + * dbus/dbus-errors.h: + Return an error if someone tries to send a message to a service + that doesn't exist. + +2003-02-16 Anders Carlsson <andersca@codefactory.se> + + * bus/activation.c: (load_directory), (bus_activation_init), + (bus_activation_activate_service): + * bus/activation.h: + * bus/driver.c: + (bus_driver_handle_activate_service), (bus_driver_handle_message): + More work on the activation handling. + + * dbus/dbus-errors.h: + Add some error messages + + * dbus/dbus-message.c: (dbus_message_new_error_reply): + * dbus/dbus-message.h: + New function that creates an error message. + + * dbus/dbus-protocol.h: + Add ACTIVATE_SERVER message. + + * dbus/dbus-server-unix.c: (unix_handle_watch), + (_dbus_server_new_for_domain_socket): + Call _dbus_fd_set_close_on_exec. + + * dbus/dbus-sysdeps.c: (make_pipe), (do_exec), + (_dbus_spawn_async), (_dbus_disable_sigpipe), + (_dbus_fd_set_close_on_exec): + * dbus/dbus-sysdeps.h: + Add _dbus_fd_set_close_on exec function. Also add function that checks + that all open fds are set to close-on-exec and warns otherwise. + + * dbus/dbus-transport-unix.c: + (_dbus_transport_new_for_domain_socket): + Call _dbus_fd_set_close_on_exec. + +2003-02-16 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c (dbus_connection_set_change_sigpipe): + allow people to avoid setting SIGPIPE to SIG_IGN + (_dbus_connection_new_for_transport): disable SIGPIPE unless + we've been asked not to + +2003-02-15 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-list.c: (_dbus_list_append_link), + (_dbus_list_prepend_link): + * dbus/dbus-memory.c: (dbus_malloc), (dbus_malloc0), + (dbus_realloc): + Warning fixes. + +2003-02-15 Anders Carlsson <andersca@codefactory.se> + + * bus/Makefile.am: + * bus/activation.c: (bus_activation_entry_free), + (add_desktop_file_entry), (load_directory), (bus_activation_init): + * bus/activation.h: + * bus/main.c: (main): + Add simple activation support, doesn't work yet though. + +2003-02-15 Zack Rusin <zack@kde.org> + + * qt/dbus-qthread.cpp: small casting fix + +2003-02-15 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-errors.c: (dbus_set_error): + * dbus/dbus-errors.h: + Add a few errors and make dbus_set_error void. + + * dbus/dbus-sysdeps.c: + (_dbus_errno_to_string), (close_and_invalidate), (make_pipe), + (write_err_and_exit), (read_ints), (do_exec), (_dbus_spawn_async): + * dbus/dbus-sysdeps.h: + Add _dbus_spawn_async. + + * test/spawn-test.c: (main): + Test for _dbus_spawn_async. + +2003-02-15 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-internals.h: + Fix build without tests. + + * dbus/dbus-list.c: (alloc_link): + Fix a segfault when a malloc fails. + + * dbus/dbus-memory.c: (initialize_malloc_debug), (dbus_malloc), + (dbus_malloc0), (dbus_realloc): + Add support for malloc debugging. + +2003-02-15 Alexander Larsson <alexl@redhat.com> + + * dbus/dbus-threads.c: + * dbus/dbus-threads.h: + Add condvars. Remove static mutext from API. + Implement static mutexes by initializing them from threads_init. + + * glib/dbus-gthread.c: + * qt/dbus-qthread.cpp: + Update with the thread api changes. + + + * dbus/dbus-list.c: + * dbus/dbus-list.h: + Turn StaticMutex into normal mutex + init function. + Export new functions _dbus_list_alloc_link, _dbus_list_free_link, + _dbus_list_append_link, _dbus_list_prepend_link + + + * dbus/dbus-sysdeps.c: + * dbus/dbus-sysdeps.h: + New type dbus_atomic_t, and new functions _dbus_atomic_inc, + _dbus_atomic_dec. Only slow fallback implementation at the moment. + + * dbus/dbus-protocol.h: + Add DBUS_MESSAGE_LOCAL_DISCONNECT define + + * dbus/dbus-message.c: + Make ref/unref atomic. + Fix some docs. + + * dbus/dbus-connection-internal.h: + * dbus/dbus-connection.c: + * dbus/dbus-connection.h: + Make threadsafe. + Change _peek to _borrow,_return & _steal_borrowed. + Change disconnect callback to event. + Make dbus_connection_dispatch_messages reentrant. + + * dbus/dbus-transport.c: + Don't ref the connection on calls to the transport + implementation. + + * dbus/dbus-message-handler.c: + Make threadsafe. + + * glib/dbus-gmain.c: + Don't use peek_message anymore + + * test/Makefile.am: + * test/debug-thread.c: + * test/debug-thread.h: + Simple thread implementation that asserts() on deadlocks in + single-threaded code. + + * test/bus-test.c: + (main) Call debug_threads_init. + + * test/watch.c: + Use disconnect message instead of disconnect callback. + + * bus/connection.c: + * bus/connection.h: + Don't call dbus_connection_set_disconnect_function. Instead export + bus_connection_disconnect. + + * bus/dispatch.c: + Call bus_connection_disconnect when we get a disconnected message. + +2003-02-15 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c (dbus_message_new): fool around with the + docs + +2003-02-14 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-mempool.c: fail if the debug functions so indicate + + * dbus/dbus-memory.c: fail if the debug functions indicate we + should + + * dbus/dbus-internals.c (_dbus_set_fail_alloc_counter) + (_dbus_decrement_fail_alloc_counter): debug functions to + simulate memory allocation failures + +2003-02-14 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-errors.h (struct DBusError): add a word of padding + to DBusError + +2003-02-13 Anders Carlsson <andersca@codefactory.se> + + * bus/driver.c: (bus_driver_handle_hello): + * bus/driver.h: + * bus/services.c: (bus_service_lookup): + Reorder message sending so we get a more sane order. + + * test/bus-test.c: (message_handler): + Fix tyop. + +2003-02-13 Anders Carlsson <andersca@codefactory.se> + + * bus/driver.c: (bus_driver_send_service_deleted), + (bus_driver_send_service_created), (bus_driver_send_service_lost), + (bus_driver_send_service_acquired), (bus_driver_handle_hello), + (bus_driver_send_welcome_message), + (bus_driver_handle_list_services), + (bus_driver_handle_acquire_service), + (bus_driver_handle_service_exists): + * dbus/dbus-bus.c: (dbus_bus_register_client), + (dbus_bus_acquire_service), (dbus_bus_service_exists): + * dbus/dbus-errors.c: (dbus_result_to_string): + * dbus/dbus-errors.h: + * dbus/dbus-message.c: (dbus_message_append_args), + (dbus_message_append_args_valist), (dbus_message_get_args), + (dbus_message_get_args_valist), (dbus_message_get_args_iter), + (dbus_message_iter_get_arg_type), (dbus_message_iter_get_string), + (dbus_message_iter_get_byte_array), + (dbus_message_iter_get_string_array), (message_iter_test), + (check_message_handling), (_dbus_message_test): + * dbus/dbus-message.h: + * test/bus-test.c: (main): + Change fields to arguments in messages, so that they won't be + confused with header fields. + + * glib/test-dbus-glib.c: (main): + Remove append_fields from hello message. + +2003-02-13 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-errors.c: + * dbus/dbus-message.c: + * dbus/dbus-string.c: + Documentation fixes. + +2003-02-13 Anders Carlsson <andersca@codefactory.se> + + * glib/dbus-gmain.c: (timeout_handler), (add_timeout), + (remove_timeout): + Implement support for timeouts in dbus-glib. + +2003-02-13 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-message-builder.c: (_dbus_message_data_load): + * dbus/dbus-message.c: (process_test_subdir): + * test/break-loader.c: (find_breaks_based_on): + Plug some memory leaks. + +2003-02-13 Richard Hult <rhult@codefactory.se> + + * bus/main.c: Fix build. + + * dbus/dbus-errors.h: + * dbus/dbus-errors.c: Fix copyright for Anders. + +2003-02-13 Anders Carlsson <andersca@codefactory.se> + + * bus/Makefile.am: + Add utils.[ch] + + * bus/connection.c: (bus_connection_foreach): + Fix a warning. + + * bus/desktop-file.c: (grow_lines_in_section), (grow_sections), + (unescape_string), (new_section), (parse_section_start), + (parse_key_value), (report_error), (bus_desktop_file_load), + (bus_desktop_file_get_string): + * bus/desktop-file.h: + Use DBusError for error reporting. + + * bus/dispatch.c: (send_one_message), + (bus_dispatch_message_handler): + * bus/driver.c: (bus_driver_send_service_deleted), + (bus_driver_send_service_created), (bus_driver_send_service_lost), + (bus_driver_send_service_acquired), (bus_driver_handle_hello), + (bus_driver_send_welcome_message), + (bus_driver_handle_list_services), + (bus_driver_handle_acquire_service), + (bus_driver_handle_service_exists): + * bus/loop.c: (bus_loop_run): + * bus/main.c: + Use BUS_HANDLE_OOM instead of _DBUS_HANDLE_OOM. + + * bus/utils.c: (bus_wait_for_memory): + * bus/utils.h: + New files with general utility functions. + + * dbus/dbus-internals.h: + Remove _DBUS_HANDLE_OOM. + +2003-02-13 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-errors.c: (dbus_result_to_string), (dbus_error_init), + (dbus_error_free), (dbus_set_error_const), (dbus_set_error): + * dbus/dbus-errors.h: + Add DBusError structure. + +2003-02-13 Anders Carlsson <andersca@codefactory.se> + + * test/data/valid-messages/standard-acquire-service.message: + * test/data/valid-messages/standard-hello.message: + * test/data/valid-messages/standard-list-services.message: + * test/data/valid-messages/standard-service-exists.message: + Add some standard messages. + +2003-02-13 Anders Carlsson <andersca@codefactory.se> + + * bus/driver.c: (bus_driver_send_welcome_message), + (bus_driver_handle_list_services), + (bus_driver_handle_acquire_service), + (bus_driver_handle_service_exists), (bus_driver_handle_message): + Update for API changes in libdbus. + + * dbus/dbus-message.c: (dbus_message_new_reply): + * dbus/dbus-message.h: + Remove the name argument. The spec states that replies shouldn't + have a name. + +2003-02-13 Anders Carlsson <andersca@codefactory.se> + + * bus/desktop-file.c: (parse_section_start), (parse_key_value), + (report_error), (bus_desktop_file_load), (lookup_section), + (lookup_line), (bus_desktop_file_get_raw), + (bus_desktop_file_get_string): + * bus/desktop-file.h: + Some fixes, and new functions for getting a key value from a section. + +2003-02-13 Havoc Pennington <hp@pobox.com> + + * test/data/auth/fail-after-n-attempts.auth-script: new test + + * dbus/dbus-auth.c (send_rejected): shutdown_mech() when we + reject the client. + +2003-02-13 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-auth.c (handle_server_data_external_mech): args to + dbus_credentials_match were backward + + * dbus/dbus-auth-script.c (_dbus_auth_script_run): support + NO_CREDENTIALS and ROOT_CREDENTIALS + + * dbus/dbus-auth.c (_dbus_auth_do_work): move get_state() routine + into here. Never process more commands after we've reached an + end state; store further data as unused bytes. + + * test/data/auth/*: add more auth tests + + * dbus/dbus-auth-script.c (_dbus_auth_script_run): support EXPECT + command to match exact string and EXPECT_UNUSED to match unused + bytes + + * test/Makefile.am (dist-hook): fix to dist all the test stuff + +2003-02-12 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-string.c (_dbus_string_pop_line): fix to also strip + \r off of popped lines + + * dbus/dbus-auth.c (_dbus_auth_test): write code to run auth + scripts + + * dbus/dbus-auth-script.c (_dbus_auth_script_run): when doing a + SEND, append \r\n + +2003-02-12 Havoc Pennington <hp@pobox.com> + + * dbus/Makefile.am: remove break-loader from the build, since it + moved. + + * configure.in: add --enable-gcov to turn on coverage profiling + flags and disable optimization + +2003-02-10 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-auth-script.c, dbus/dbus-auth-script.h: sync + initial cut at test framework for DBusAuth from laptop. + Doesn't quite work yet but it compiles and I need to get + it off the 266mhz laptop. ;-) + + * dbus/dbus-server-debug.c (_dbus_server_debug_accept_transport): + fix a memleak in error case + +2003-02-12 Anders Carlsson <andersca@codefactory.se> + + * bus/Makefile.am: + * bus/desktop-file.c: + * bus/desktop-file.h: + Add a desktop file parser. + +2003-02-11 Zack Rusin <zack@kde.org> + + * qt/message.[h|cpp]: sample implementation + of the KDE wrapper for DBusMessage + +2003-02-09 Zack Rusin <zack@kde.org> + + * test/bus-test.c: make_it_compile + * doc/dbus-specification.sgml: minimal semantic fix + +2003-02-06 Anders Carlsson <andersca@codefactory.se> + + Release 0.3 + + * NEWS: Update + +2003-02-06 Anders Carlsson <andersca@codefactory.se> + + * dbus/Makefile.am: + * dbus/dbus-break-loader.c: + * test/Makefile.am: + * test/break-loader.c: + Move dbus-break-loader to test/ and rename it to break-loader. + +2003-02-02 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-keyring.c, dbus/dbus-keyring.h: template files + for code to manage cookies in your home directory + + * dbus/dbus-sysdeps.c (_dbus_generate_random_bytes): new function + + * dbus/dbus-auth.c (get_state): impose a maximum number of tries + to authenticate, then disconnect the client. + +2003-02-03 Alexander Larsson <alexl@redhat.com> + + * dbus/dbus-message.c (dbus_message_append_fields): + Correct docs. + +2003-02-02 Anders Carlsson <andersca@codefactory.se> + + * doc/dbus-specification.sgml: + Update address format section. + +2003-02-02 Anders Carlsson <andersca@codefactory.se> + + * test/Makefile.am: + * test/bus-test.c: (get_time), (add_timeout), (remove_timeout), + (message_handler), (new_connection_callback), (loop_quit), + (loop_run), (main): + Add bus test. + +2003-02-02 Anders Carlsson <andersca@codefactory.se> + + * bus/driver.c: (bus_driver_handle_service_exists): + Simplify the code a bit. + + * dbus/dbus-bus.c: (dbus_bus_service_exists): + Fix a silly. + +2003-02-02 Anders Carlsson <andersca@codefactory.se> + + * bus/Makefile.am: + Add libdbus-daemon.la and link to it. + +2003-02-01 James Willcox <jwillcox@gnome.org> + + * bus/driver.c: (bus_driver_handle_own_service): + Actually include the service reply code in the message. + +2003-02-02 Anders Carlsson <andersca@codefactory.se> + + * bus/driver.c: (bus_driver_handle_service_exists): + Don't unref the incoming message. + +2003-02-02 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus.h: Add dbus-address.h and dbus-bus.h + +2003-02-02 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-server.c: (dbus_server_listen): + * dbus/dbus-transport.c: (_dbus_transport_open): + ifdef out the calls to the debug transport and server. + +2003-02-02 Alexander Larsson <alexl@redhat.com> + + * dbus/dbus-watch.c (dbus_watch_get_flags): + Add note in the docs that ERROR or HANGUP won't be returned + and are assumed always on. + + * glib/dbus-gmain.c (add_watch): + Always add IO_ERR | IO_HUP + + * dbus/dbus-message.h: + Add semicolon after dbus_message_iter_get_string_array(). + Makes qt code build again + +2003-02-01 Anders Carlsson <andersca@codefactory.se> + + * bus/driver.c: (create_unique_client_name), + (bus_driver_handle_hello): + Don't take a name, just use a numeric id to identify + each client. + + * dbus/Makefile.am: + * dbus/dbus-bus.c: (dbus_bus_register_client), + (dbus_bus_acquire_service), (dbus_bus_service_exists): + * dbus/dbus-bus.h: + Add new convenience functions for communicating with the bus. + + * dbus/dbus-message.h: + + * dbus/dbus-protocol.h: + Fix a typo. + +2003-02-01 Alexander Larsson <alexl@redhat.com> + + * dbus/dbus-message.c (dbus_message_append_fields): + Add some more doc comments. + +2003-02-01 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-break-loader.c (randomly_modify_length): change + a 4-byte value in the message as if it were a length + + * dbus/dbus-sysdeps.c (_dbus_string_save_to_file): don't set + execute bit on saved files + +2003-02-01 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-break-loader.c (main): new program to find messages + that break the loader. + + * dbus/dbus-sysdeps.c (_dbus_string_append_uint): new function + * dbus/dbus-sysdeps.c (_dbus_string_save_to_file): new function + + * dbus/dbus-string.c (_dbus_string_set_byte): new + +2003-01-31 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c: refactor the test code to be more general, + in preparation for writing a "randomly permute test cases to + try to break the loader" program. + +2003-01-31 Havoc Pennington <hp@pobox.com> + + * doc/dbus-specification.sgml: work on the specification + + * dbus/dbus-message.c (_dbus_message_loader_return_buffer): check + the protocol version of the message. + + * dbus/dbus-protocol.h: drop special _REPLY names, the spec + no longer specifies that. + (DBUS_SERVICE_REPLY_SERVICE_EXISTS): fix flags (1/2/4/8 not + 1/2/3/4) + + * dbus/dbus-marshal.c (_dbus_marshal_get_arg_end_pos): add missing + "break" for DBUS_TYPE_NIL, remove @todo + +2003-01-31 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c (dbus_message_set_is_error_reply): rename + just set_is_error/get_is_error as this is a commonly-used + function, and write docs. + +2003-01-31 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-address.c: (dbus_address_entry_free): + Free key and value lists. + + * dbus/dbus-internals.c: (_dbus_type_to_string): + Add the types we didn't have. + + * dbus/dbus-marshal.c: (_dbus_marshal_get_arg_end_pos), + (_dbus_marshal_validate_arg): + Add NIL types. + + * dbus/dbus-message.c: (dbus_message_set_sender): + Remove todo about being able to set sender to NULL. + + (dbus_message_set_is_error_reply), + (dbus_message_get_is_error_reply): + * dbus/dbus-message.h: + New functions. + + * dbus/dbus-protocol.h: + Add error reply flag. + + * test/data/valid-messages/opposite-endian.message: + Add NIL type to test. + +2003-01-31 Havoc Pennington <hp@pobox.com> + + * doc/dbus-specification.sgml: fully specify the header. Add + flags and major protocol version, and change header/body len to + unsigned. + + * dbus/dbus-message-builder.c (append_saved_length): append length + as uint32 + + * dbus/dbus-message.c (dbus_message_create_header): change header + length and body length to unsigned. Add the new fields from the + spec + (_dbus_message_loader_return_buffer): unsigned header/body len + +2003-01-30 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-auth.c: rework to use only REJECTED, no + MECHANISMS + + * doc/dbus-sasl-profile.txt: drop MECHANISMS and just + use REJECTED, suggested by Mark McLoughlin + +2003-01-30 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-server.c (dbus_server_listen): @todo about how we need + a better way to report errors here. e.g. "unix address lacks + path" or something. also "no such file" when the path doesn't + exist, etc. + + * dbus/dbus-address.c (dbus_address_entries_free): add @todo about + leaking list nodes + (dbus_parse_address): add @todo about documenting address format, + and allowing , and ; to be escaped + +2003-01-30 Anders Carlsson <andersca@codefactory.se> + + * dbus/Makefile.am: + Add dbus-address.[ch] + + * dbus/dbus-address.c: (dbus_address_entry_free), + (dbus_address_entries_free), (create_entry), + (dbus_address_entry_get_method), (dbus_address_entry_get_value), + (dbus_parse_address), (_dbus_address_test): + * dbus/dbus-address.h: + New files for dealing with address parsing. + + * dbus/dbus-connection.c: + Document timeout functions. + + * dbus/dbus-message.c: + Document dbus_message_new_from_message. + + * dbus/dbus-server-debug.c: + Document. + + * dbus/dbus-server.c: (dbus_server_listen): + Parse address and use correct server implementation. + + * dbus/dbus-string.c: (_dbus_string_find_to), (_dbus_string_test): + * dbus/dbus-string.h: + New function with test. + + * dbus/dbus-test.c: (dbus_internal_symbol_do_not_use_run_tests): + * dbus/dbus-test.h: + Add address tests. + + * dbus/dbus-transport-debug.c: + Document. + + * dbus/dbus-transport.c: (_dbus_transport_open): + Parse address and use correct transport implementation. + +2003-01-30 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c: use message->byte_order instead of + DBUS_COMPILER_BYTE_ORDER throughout. + (dbus_message_create_header): pad header to align the + start of the body of the message to 8-byte boundary + + * dbus/dbus-marshal.h: make all the demarshalers take const + DBusString arguments. + + * dbus/dbus-message.c (_dbus_message_loader_return_buffer): + validate message args here, so we don't have to do slow validation + later, and so we catch bad messages as they are incoming. Also add + better checks on header_len and body_len. Also fill in + message->byte_order + + * dbus/dbus-string.c (_dbus_string_validate_utf8): new (not + implemented properly) + (_dbus_string_validate_nul): new function to check all-nul + + * dbus/dbus-marshal.c (_dbus_marshal_get_field_end_pos): rename + get_arg_end_pos and remove all validation + (_dbus_marshal_validate_arg): actually do validation here. + +2003-01-29 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c (check_message_handling): fix assertion + failure on set_client_serial + +2003-01-28 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-server-debug.c: Add doc section comments + + * dbus/dbus-transport-debug.c: add doc section comments + +2003-01-28 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-string.c (_dbus_string_base64_decode): append bytes in + the reverse order from how I had it + (_dbus_string_base64_encode): reverse encoding order. I was + basically byteswapping everything during encoding. + +2003-01-28 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-connection-internal.h: + * dbus/dbus-connection.c: (_dbus_connection_add_timeout), + (_dbus_connection_remove_timeout): + Add functions for adding and removing timeouts. + + * dbus/dbus-message.c: (dbus_message_new_from_message): + Add new function that takes a message and creates an exact + copy of it, but with the refcount set to 1. + (check_message_handling): + Fix build error. + + * dbus/dbus-server-protected.h: + * dbus/dbus-server.c: (_dbus_server_init_base), + (_dbus_server_finalize_base), (_dbus_server_add_timeout), + (dbus_server_set_timeout_functions): + (_dbus_server_remove_timeout): + New functions so that a server can add and remove timeouts. + + (dbus_server_listen): + Add commented out call to dbus_server_debug_new. + + * dbus/dbus-timeout.c: (_dbus_timeout_new): + Actually set the handler, doh. + + * dbus/dbus-transport.c: (_dbus_transport_open): + Add commented out call to dbus_transport_debug_client_new. + + * dbus/Makefile.am: + Add dbus-transport-debug.[ch] and dbus-server-debug.[ch] + +2003-01-28 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c (check_message_handling): function to check + on the loaded message, iterates over it etc. + +2003-01-28 Havoc Pennington <hp@pobox.com> + + * test/Makefile.am (dist-hook): fix make distdir + + * dbus/Makefile.am (TESTS_ENVIRONMENT): fix make check + +2003-01-27 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-mempool.c (time_for_size): replace printf with + _dbus_verbose + + * dbus/dbus-message-builder.c (_dbus_message_data_load): allow + empty lines; fix the SAVE_LENGTH stuff to be + START_LENGTH/END_LENGTH so it actually works; couple other + bugfixes + + * test/Makefile.am (dist-hook): add dist-hook for .message files + + * dbus/dbus-string.c (DBUS_STRING_COPY_PREAMBLE): source of a copy + can be constant or locked. + (_dbus_string_free): allow freeing a const string as + documented/intended + + * dbus/dbus-sysdeps.c (_dbus_concat_dir_and_file): utility + + * dbus/dbus-test-main.c (main): take an argument which is the + directory containing test data + + * dbus/dbus-message.c (_dbus_message_test): pass a test_data_dir + argument to this and load all the messages in test/data/ + checking that they can be loaded or not loaded as appropriate. + +2003-01-27 Anders Carlsson <andersca@codefactory.se> + + * bus/dispatch.c: (bus_dispatch_message_handler): + Dispatch messages sent to services. + + * bus/driver.c: (bus_driver_send_service_deleted), + (bus_driver_send_service_created), (bus_driver_send_service_lost), + (bus_driver_send_service_acquired): + Add helper functions for sending service related messages. + + (bus_driver_send_welcome_message): + Send HELLO_REPLY instead of WELCOME. + + (bus_driver_handle_list_services): + Send LIST_SERVICES_REPLY instead of SERVICES. + + (bus_driver_handle_own_service), + (bus_driver_handle_service_exists): + New message handlers. + + (bus_driver_handle_message): + Invoke new message handlers. + + (bus_driver_remove_connection): + Don't remove any services here since that's done automatically + by bus_service_remove_owner now. + + * bus/driver.h: + New function signatures. + + * bus/services.c: (bus_service_add_owner): + Send ServiceAcquired message if we're the only primary owner. + + (bus_service_remove_owner): + Send ServiceAcquired/ServiceLost messages. + + (bus_service_set_prohibit_replacement), + (bus_service_get_prohibit_replacement): + Functions for setting prohibit replacement. + + (bus_service_has_owner): + New function that checks if a connection is in the owner queue of + a certain service. + + * bus/services.h: + Add new function signatures. + + * dbus/dbus-list.c: (_dbus_list_test): + Add tests for _dbus_list_remove_last and traversing the list backwards. + + * dbus/dbus-list.h: + Fix a typo in _dbus_list_get_prev_link, if we're at the first element we can't + go any further, so return NULL then. + + * dbus/dbus-protocol.h: + Add new messages, service flags and service replies. + +2003-01-26 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message-builder.c: implement, completely untested. + + * test/data/*: add data to be used in testing. + ".message" files are our simple loadable text format. + ".message-raw" will be binary dumps of messages. + + * dbus/dbus-string.c (_dbus_string_starts_with_c_str): new + +2003-01-26 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-sysdeps.c (_dbus_file_get_contents): new function + + * dbus/dbus-errors.c (dbus_result_to_string): add + file errors + + * dbus/dbus-message-builder.c: new file, will contain code to load + up messages from files. Not implemented yet. + +2003-01-26 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.c (dbus_message_set_sender): support deleting + the sender by setting to NULL + +2003-01-26 Havoc Pennington <hp@pobox.com> + + The unit tests pass, but otherwise untested. If it breaks, the + tests should have been better. ;-) + + * bus/driver.c (bus_driver_handle_hello): return if we disconnect + the connection. + + * dbus/dbus-message.c: redo everything so we maintain + message->header as the only copy of the various fields. + This avoids the possibility of out-of-memory in some cases, + for example dbus_message_lock() can't run out of memory anymore, + and avoids extra copying. Figured I may as well go ahead and do + this since it was busted for dbus_message_lock to not return + failure on OOM, and dbus_message_write_header was totally + unchecked for OOM. Also fixed some random other bugs. + + * dbus/dbus-marshal.c (_dbus_marshal_get_field_end_pos): verify + that strings are nul-terminated. Also, end_pos can be equal + to string length just not greater than, I think. + (_dbus_marshal_set_int32): new function + (_dbus_marshal_set_uint32): new function + (_dbus_marshal_set_string): new function + + * dbus/dbus-connection.c (_dbus_connection_new_for_transport): fix + a warning, init timeout_list to NULL + (dbus_connection_send_message): don't use uninitialized variable + "serial" + + * dbus/dbus-string.c (_dbus_string_replace_len): new function + +2003-01-26 Anders Carlsson <andersca@codefactory.se> + + * bus/driver.c: (bus_driver_handle_hello), + (bus_driver_send_welcome_message): + Plug leaks + +2003-01-26 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-auth.c: (process_auth), (_dbus_auth_unref): + * dbus/dbus-connection.c: (_dbus_connection_new_for_transport), + (dbus_connection_unref): + * dbus/dbus-marshal.c: (_dbus_marshal_test): + * dbus/dbus-message.c: (dbus_message_unref), + Plug memory leaks. + + (dbus_message_get_fields): + Remove debugging printout. + + (_dbus_message_loader_return_buffer): + Don't store the header string. + + (_dbus_message_test): + Plug leaks. + +2003-01-26 Richard Hult <rhult@codefactory.se> + + * glib/dbus-gmain.c (dbus_connection_dispatch): Traverse a copy of + the file descriptor list, since it can change under us. + +2003-01-25 Anders Carlsson <andersca@codefactory.se> + + * glib/dbus-gmain.c: (dbus_connection_prepare), + (dbus_connection_check), (dbus_connection_dispatch), (add_watch), + (remove_watch), (dbus_connection_hookup_with_g_main): + Rewrite the glib handling to use its own GSource instead of a + GIOChannel so we can catch messages put in the queue while waiting + for a reply. + +2003-01-25 Anders Carlsson <andersca@codefactory.se> + + * bus/Makefile.am: + * bus/connection.c: (connection_disconnect_handler), + (connection_watch_callback), (bus_connection_setup): + * bus/dispatch.c: (send_one_message), + (bus_dispatch_broadcast_message), (bus_dispatch_message_handler), + (bus_dispatch_add_connection), (bus_dispatch_remove_connection): + * bus/dispatch.h: + * bus/driver.c: (bus_driver_send_service_deleted), + (bus_driver_send_service_created), (bus_driver_handle_hello), + (bus_driver_send_welcome_message), + (bus_driver_handle_list_services), (bus_driver_remove_connection), + (bus_driver_handle_message): + * bus/driver.h: + Refactor code, put the message dispatching in its own file. Use + _DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client + is disconnected. + +2003-01-25 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-internals.h: + Add _DBUS_HANDLE_OOM macro, it doesn't do anything currently. + + * dbus/dbus-message.c: (dbus_message_get_sender): + * dbus/dbus-message.h: + Implement dbus_message_get_sender. + + * dbus/dbus-protocol.h: + Add message and service defines. + +2003-01-25 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-connection.c: (dbus_connection_send_message): + * dbus/dbus-message-internal.h: + * dbus/dbus-message.c: (_dbus_message_get_client_serial), + (dbus_message_write_header): + Remove _dbus_messag_unlock and don't set the client serial on a + message if one already exists. + +2003-01-24 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-list.c (alloc_link): put a thread lock on the global + list_pool + + * bus/driver.c (bus_driver_handle_list_services): fix a leak + on OOM + +2003-01-25 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-list.c: (alloc_link), (free_link): + Use a memory pool for the links. + +2003-01-25 Anders Carlsson <andersca@codefactory.se> + + * bus/connection.c: (bus_connection_foreach): + * bus/connection.h: + Add new bus_connection_foreach function. + + * bus/driver.c: (send_one_message), (bus_driver_broadcast_message): + Add function that broadcasts a message to all clients. + + (bus_driver_send_service_created), (bus_driver_handle_hello), + (bus_driver_send_welcome_message), + (bus_driver_handle_list_services), (bus_driver_message_handler): + Implement functions that take care of listing services, and notifying + clients when new services are created. + + * bus/services.c: (bus_services_list): + * bus/services.h: + Add new function that returns an array of strings with the currently + registered services. + + * glib/dbus-glib.h: + * glib/dbus-gmain.c: + Update copyright year. + +2003-01-25 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-connection.c: (dbus_connection_send_message): + Unlock the message in case it was sent earlier. + + (dbus_connection_send_message_with_reply_and_block): + Remove the reply message from the list. + + * dbus/dbus-marshal.c: (_dbus_demarshal_string_array): + Set array_len and new_pos correctly. + + (_dbus_marshal_test): + Remove debug output. + + * dbus/dbus-message-internal.h: + * dbus/dbus-message.c: (_dbus_message_get_reply_serial): + New function that returns the reply serial. + + (_dbus_message_unlock): + New function that unlocks a message and resets its header. + + (dbus_message_append_string_array), + (dbus_message_get_fields_valist), + (dbus_message_iter_get_field_type), + (dbus_message_iter_get_string_array), + (dbus_message_get_fields), + (dbus_message_append_fields_valist): + Handle string arrays. + + (dbus_message_set_sender): + Make this function public since the bus daemon needs it. + + (decode_header_data): + Set the reply serial to -1 initially. + + * dbus/dbus-message.h: + Add dbus_message_set_sender. + +2003-01-24 Havoc Pennington <hp@pobox.com> + + * doc/dbus-specification.sgml: add some stuff + +2003-01-22 Havoc Pennington <hp@pobox.com> + + * doc/dbus-specification.sgml: Start to document the protocol. + +2003-01-22 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c + (dbus_connection_send_message_with_reply_and_block): add some @todo + + * bus/driver.c (bus_driver_add_connection): add a FIXME about memleak + +2003-01-21 Havoc Pennington <hp@pobox.com> + + (patch untested because can't compile) + + * bus/driver.c (create_unique_client_name): make this function + never recycle client names. Also, caller should initialize + the DBusString. + + * dbus/dbus-sysdeps.c (_dbus_get_current_time): new function + +2003-01-21 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-marshal.c: (_dbus_marshal_double), + (_dbus_marshal_int32), (_dbus_marshal_uint32), + (_dbus_marshal_int32_array), (_dbus_marshal_uint32_array), + (_dbus_marshal_double_array), (_dbus_marshal_string_array), + (_dbus_demarshal_int32_array), (_dbus_demarshal_uint32_array), + (_dbus_demarshal_double_array), (_dbus_demarshal_string_array), + (_dbus_marshal_get_field_end_pos), (_dbus_marshal_test): + * dbus/dbus-marshal.h: + * dbus/dbus-protocol.h: + Add support for marshalling and demarshalling integer, double + and string arrays. + +2003-01-21 Anders Carlsson <andersca@codefactory.se> + + * bus/Makefile.am: + Add driver.[ch] + + * bus/connection.c: (connection_disconnect_handler): + Remove the connection from the bus driver's list. + + (connection_watch_callback): Dispatch messages. + + (free_connection_data): Free connection name. + + (bus_connection_setup): Add connection to the bus driver's list. + (bus_connection_remove_owned_service): + (bus_connection_set_name), (bus_connection_get_name): + Add functions for setting and getting the connection's name. + + * bus/connection.h: + Add function headers. + + * bus/driver.c: (create_unique_client_name), + (bus_driver_handle_hello_message), + (bus_driver_send_welcome_message), (bus_driver_message_handler), + (bus_driver_add_connection), (bus_driver_remove_connection): + * bus/driver.h: + * bus/main.c: + * bus/services.c: (bus_service_free): + * bus/services.h: + New file that handles communication and registreation with the bus + itself. + +2003-01-21 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-connection.c: (dbus_connection_send_message): + Add a new client_serial parameter. + + (dbus_connection_send_message_with_reply): + Remove a @todo since we've implemented the blocking function. + + (dbus_connection_send_message_with_reply_and_block): + New function that sends a message and waits for a reply and + then returns the reply. + + * dbus/dbus-connection.h: + Add new functions. + + * dbus/dbus-errors.c: (dbus_result_to_string): + * dbus/dbus-errors.h: + Add new DBUS_RESULT. + + * dbus/dbus-message-internal.h: + * dbus/dbus-message.c: (_dbus_message_get_reply_serial), + (_dbus_message_set_sender), (dbus_message_write_header), + (dbus_message_new_reply), (decode_header_data), + (_dbus_message_loader_return_buffer), (_dbus_message_test): + * dbus/dbus-message.h: + Add new functions that set the reply serial and sender. + Also marshal and demarshal them correctly and add test. + + * dbus/dbus-protocol.h: + Add new DBUS_MESSAGE_TYPE_SENDER. + + * glib/dbus-glib.h: + * glib/dbus-gmain.c: (watch_callback), (free_callback_data), + (add_watch), (remove_watch), (add_timeout), (remove_timeout), + (dbus_connection_hookup_with_g_main): + * glib/test-dbus-glib.c: (main): + Rewrite to use GIOChannel and remove the GSource crack. + + * test/echo-client.c: (main): + * test/watch.c: (check_messages): + Update for changed APIs + +2003-01-19 Anders Carlsson <andersca@codefactory.se> + + * dbus/Makefile.am: Add dbus-timeout.[cħ] + + * dbus/dbus-connection.c: (_dbus_connection_new_for_transport): + Create a DBusTimeoutList. + (dbus_connection_set_timeout_functions): Add new function to + set timeout callbacks + + * dbus/dbus-connection.h: Add public DBusTimeout API. + + * dbus/dbus-message.c: (dbus_message_get_service): + * dbus/dbus-message.h: New function. + + * dbus/dbus-server.c: Fix small doc typo. + + * dbus/dbus-timeout.[ch]: New files for mainloop timeouts. + +2003-01-19 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-string.c (_dbus_string_move_len): Don't delete all + of the string, just as long as specified. + +2003-01-19 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c (dbus_connection_get_is_authenticated): + new function + + * dbus/dbus-server.c (dbus_server_set_max_connections) + (dbus_server_get_max_connections, dbus_server_get_n_connections): + keep track of current number of connections, and add API for + setting a max (but haven't implemented enforcing the max yet) + +2003-01-18 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-transport-unix.c (unix_do_iteration): only do the + reading/writing if read_watch != NULL or write_watch != NULL. + + * dbus/dbus-message.c (_dbus_message_loader_return_buffer): fix + the message loader code to actually load message->header and + message->body into the newly-created message. + + * dbus/dbus-transport-unix.c (check_write_watch): fix a mem leak + in OOM case + + * dbus/dbus-connection.c (dbus_connection_set_max_message_size) + (dbus_connection_get_max_message_size) + (dbus_connection_set_max_live_messages_size) + (dbus_connection_get_max_live_messages_size): implement some + resource limitation functions + + * dbus/dbus-resources.c: new file implementing some of the + resource limits stuff + + * dbus/dbus-message.c (dbus_message_iter_get_byte_array): add + missing docs, add @todo to handle OOM etc. + + * dbus/dbus-marshal.c (_dbus_demarshal_byte_array): add missing + docs + +2003-01-18 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-connection.c (dbus_connection_unref): disconnect the + connection if it hasn't been already. + + * dbus/dbus-connection.h: kill off the idea of an ErrorFunction, + replace with DisconnectFunction. + +2003-01-18 Havoc Pennington <hp@pobox.com> + + Building --disable-verbose-mode --disable-asserts --disable-tests + cuts the library from 112K to 45K or so + + * configure.in: check for varargs macro support, + add --enable-verbose-mode, --enable-asserts. + + * dbus/dbus-internals.h (_dbus_assert): support + DBUS_DISABLE_ASSERT + (_dbus_verbose): support DBUS_ENABLE_VERBOSE_MODE + +2003-01-18 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-test.c: include config.h so that tests actually run + + * dbus/dbus-string.c: add assertions that stuff is 8-byte aligned, + so the failure mode when that assumption fails will be plenty + obvious. + +2003-01-18 Havoc Pennington <hp@pobox.com> + + * configure.in: default --enable-tests to $USE_MAINTAINER_MODE + + * dbus/Makefile.am: fix it up so dubs-test-main.c is included in + the distribution + + * test/Makefile.am: don't use special variable "TESTS" for echo-* + since we don't want to use those in make check + +2003-01-15 Havoc Pennington <hp@redhat.com> + + Release 0.2 + + * NEWS: update + +2003-01-15 Havoc Pennington <hp@redhat.com> + + * test/Makefile.am: fix so that test source code ends up in the + distribution on make distcheck + +2003-01-15 Havoc Pennington <hp@redhat.com> + + Release 0.1. + + * NEWS: update + +2003-01-15 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-test.c (dbus_internal_symbol_do_not_use_run_tests): + fix build when --disable-tests + + * Makefile.am (EXTRA_DIST): put HACKING in here + + * HACKING: document procedure for making a tarball release. + +2003-01-14 Anders Carlsson <andersca@codefactory.se> + + * bus/connection.c: (connection_error_handler), + (bus_connection_setup): + * bus/main.c: (main): + Make sure that the DBusConnectionData struct is NULLed + out to prevent a segfault. + + * dbus/dbus-errors.c: (dbus_result_to_string): + * dbus/dbus-errors.h: + * dbus/dbus-message.c: (dbus_message_get_fields), + (dbus_message_get_fields_valist), (_dbus_message_test): + * dbus/dbus-message.h: + Make dbus_message_get_fields return a result code so we can + track invalid fields as well as oom. + +2003-01-11 Havoc Pennington <hp@pobox.com> + + * configure.in: change --enable-test/--enable-ansi action-if-given + to enable_foo=$enableval instead of enable_foo=yes + +2003-01-08 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-string.c (_dbus_string_align_length): new function + + * dbus/dbus-test-main.c: move main() for test app here + * dbus/dbus-test.c + (dbus_internal_symbol_do_not_use_run_tests): we have to export a + symbol to run tests, because dbus-test isn't in the main + library + + Code review nitpicks. + + * dbus/dbus-message.c (dbus_message_write_header): add newlines + for people with narrow emacs ;-). Assert client_serial was filled + in. Assert message->name != NULL. + (dbus_message_append_fields): have "first_field_type" arg separate + from va list, needed for C++ binding that also uses varargs IIRC + and helps with type safety + (dbus_message_new): add @todo about using DBusString to store + service/name internally + (dbus_message_new): don't leak ->service and ->name on OOM later + in the function + (dbus_message_unref): free the service name + (dbus_message_get_fields): same change to varargs + i.e. first_field_type + (_dbus_message_loader_return_buffer): assert that the message data + is aligned (if not it's a bug in our code). Put in verbose griping + about why we set corrupted = TRUE. + (decode_header_data): add FIXME that char* is evil. Was going to + add FIXME about evil locale-specific string.h strncmp, but just + switched to wacky string-as-uint32 optimization. Move check for + "no room for field name" above get_const_data_len() to avoid + assertion failure in get_const_data_len if we have trailing 2 + bytes or the like. Check for service and name fields being + provided twice. Don't leak service/name on error. Require field + names to be aligned to 4 bytes. + + * dbus/dbus-marshal.c: move byte swap stuff to header + (_dbus_pack_int32): uscore-prefix + (_dbus_unpack_int32): uscore-prefix + (_dbus_unpack_uint32): export + (_dbus_demarshal_string): add @todo complaining about use of + memcpy() + (_dbus_marshal_get_field_end_pos): add @todo about bad error + handling allowing corrupt data to go unchecked + +2003-01-08 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-transport-unix.c (unix_do_iteration): add read/write + to the select() as needed for authentication. (should be using + _dbus_poll() not select, but for another day) + + * dbus/dbus.h: include dbus/dbus-protocol.h + +2003-01-08 Anders Carlsson <andersca@codefactory.se> + + * dbus/Makefile.am (dbusinclude_HEADERS): Install + dbus-connection.h + +2003-01-08 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-internals.c: (_dbus_type_to_string): + New function that returns a string describing a type. + + * dbus/dbus-marshal.c: (_dbus_demarshal_byte_array): + * dbus/dbus-marshal.h: + * dbus/dbus-message.c: (dbus_message_get_fields_valist), + (dbus_message_iter_get_field_type), (dbus_message_iter_get_double), + (dbus_message_iter_get_byte_array): + * dbus/dbus-message.h: + Add new convenience functions for appending and getting message fields. + Also add demarshalling routines for byte arrays. + +2003-01-07 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-connection-internal.h: + * dbus/dbus-connection.c: (_dbus_connection_new_for_transport), + (_dbus_connection_get_next_client_serial), + (dbus_connection_send_message): + * dbus/dbus-internals.h: + * dbus/dbus-marshal.c: (unpack_uint32), (dbus_unpack_int32), + (dbus_pack_int32), (_dbus_marshal_double), (_dbus_marshal_int32), + (_dbus_marshal_uint32), (_dbus_demarshal_double), + (_dbus_demarshal_int32), (_dbus_demarshal_uint32), + (_dbus_demarshal_string), (_dbus_marshal_get_field_end_pos), + (_dbus_verbose_bytes), (_dbus_marshal_test): + * dbus/dbus-marshal.h: + * dbus/dbus-message-internal.h: + * dbus/dbus-message.c: (_dbus_message_set_client_serial), + (dbus_message_write_header), (_dbus_message_lock), + (dbus_message_new), (dbus_message_ref), (dbus_message_unref), + (dbus_message_get_name), (dbus_message_append_int32), + (dbus_message_append_uint32), (dbus_message_append_double), + (dbus_message_append_string), (dbus_message_append_byte_array), + (dbus_message_get_fields_iter), (dbus_message_iter_ref), + (dbus_message_iter_unref), (dbus_message_iter_has_next), + (dbus_message_iter_next), (dbus_message_iter_get_field_type), + (dbus_message_iter_get_string), (dbus_message_iter_get_int32), + (dbus_message_iter_get_uint32), (dbus_message_iter_get_double), + (decode_header_data), (_dbus_message_loader_return_buffer), + (message_iter_test), (_dbus_message_test): + * dbus/dbus-message.h: + * dbus/dbus-protocol.h: + * dbus/dbus-test.c: (main): + * dbus/dbus-test.h: + * glib/test-dbus-glib.c: (message_handler), (main): + * test/echo-client.c: (main): + * test/watch.c: (check_messages): + Make messages sendable and receivable for real. + +2003-01-07 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-marshal.c: (_dbus_marshal_double), + (_dbus_marshal_string), (_dbus_marshal_byte_array): + * dbus/dbus-message.c: (dbus_message_append_int32), + (dbus_message_append_uint32), (dbus_message_append_double), + (dbus_message_append_string), (dbus_message_append_byte_array): + Handle OOM restoration. + +2003-01-07 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-marshal.c: (_dbus_marshal_string), + (_dbus_demarshal_string), (_dbus_marshal_test): + * dbus/dbus-marshal.h: + * dbus/dbus-message.c: (dbus_message_get_name), + Document these functions. + + (dbus_message_append_int32), (dbus_message_append_uint32), + (dbus_message_append_double), (dbus_message_append_string), + (dbus_message_append_byte_array): + * dbus/dbus-message.h: + Add functions for adding message fields of different types. + + * dbus/dbus-protocol.h: + Add the different types. + +2003-01-05 Havoc Pennington <hp@pobox.com> + + * bus/connection.c: implement routines for handling connections, + first thing is keeping a list of owned services on each connection + and setting up watches etc. + + * bus/services.c: implement a mapping from service names to lists + of connections + + * dbus/dbus-hash.c: add DBUS_HASH_POINTER + + * dbus/dbus-threads.c (dbus_static_mutex_lock): add functions + to use static mutexes for global data + + * dbus/dbus-connection.c (dbus_connection_set_data): add new + collection of functions to set/get application-specific data + on the DBusConnection. + +2003-01-04 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-sysdeps.c (_dbus_sleep_milliseconds): new function + (_dbus_poll): new function + + * dbus/dbus-internals.h (_DBUS_STRUCT_OFFSET): new macro + copied from GLib + + * bus/loop.c: initial code for the daemon main loop + +2003-01-04 Havoc Pennington <hp@pobox.com> + + * test/watch.c (error_handler): make it safe if the error handler + is called multiple times (if we s/error handler/disconnect + handler/ we should just guarantee it's called only once) + + * dbus/dbus-transport.c (_dbus_transport_disconnect): call the + error handler on disconnect (it's quite possible we should + just change the error handler to a "disconnect handler," I'm + not sure we have any other meaningful errors) + + * configure.in: check for getpwnam_r + + * dbus/dbus-transport.c, dbus/dbus-transport-unix.c, + dbus/dbus-auth.c: add credentials support, add EXTERNAL auth + mechanism as in SASL spec, using socket credentials + + * dbus/dbus-sysdeps.c (_dbus_read_credentials_unix_socket): new function + (_dbus_send_credentials_unix_socket): new function + + * dbus/dbus-sysdeps.c (_dbus_accept_unix_socket): rename just + dbus_accept() + (_dbus_write): only check errno if <0 returned + (_dbus_write_two): ditto + +2003-01-02 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-marshal.c: (_dbus_marshal_utf8_string), + (_dbus_marshal_byte_array), (_dbus_demarshal_utf8_string), + (_dbus_marshal_test): + * dbus/dbus-marshal.h: + Add _dbus_marshal_byte_array and rename _dbus_marshal_string + to _dbus_marshal_utf8_string. Also fix some tests. + +2002-12-28 Harri Porten <porten@kde.org> + + * configure.in: added check for C++ compiler and a very cheesy + check for the Qt integration + + * Makefile.am (SUBDIRS): compile qt subdir if support is enabled + + * qt/Makefile.am: added + + * qt/.cvsignore: added + + * qt/dbus-qthread.cc, qt/dbus-qthread.cpp: renamed former to + latter, added #ifdef QT_THREAD_SUPPORT guard. + + * dbus/Makefile.am: added missing headers for make dist + +2002-12-28 Kristian Rietveld <kris@gtk.org> + + * dbus/Makefile.am: fixup export-symbols-regex. + +2002-12-27 Anders Carlsson <andersca@codefactory.se> + + * acinclude.m4: Add this file and put the + PKG_CHECK_MODULE macro in it. + +2002-12-27 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-marshal.c: (_dbus_marshal_string), + (_dbus_demarshal_double), (_dbus_demarshal_int32), + (_dbus_demarshal_uint32), (_dbus_demarshal_string), + (_dbus_marshal_test): + Make the demarshalling routines align the pos argument. + Add string marshalling tests and fix the obvious bugs + discovered. + +2002-12-26 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-auth.c: fixes fixes fixes + + * dbus/dbus-transport-unix.c: wire up support for + encoding/decoding data on the wire + + * dbus/dbus-auth.c (_dbus_auth_encode_data) + (_dbus_auth_decode_data): append to target string + instead of nuking it. + +2002-12-26 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-marshal.h (DBUS_COMPILER_BYTE_ORDER): #ifdef + WORDS_BIGENDIAN then compiler byte order is DBUS_BIG_ENDIAN, + doh + + * dbus/dbus-marshal.c: Add macros to do int swapping in-place and + avoid swap_bytes() overhead (ignoring possible assembly stuff for + now). Main point is because I wanted unpack_uint32 to implement + _dbus_verbose_bytes + (_dbus_verbose_bytes): new function + + * dbus/dbus-string.c (_dbus_string_validate_ascii): new function + + * dbus/dbus-message.c (_dbus_message_loader_get_is_corrupted): add + mechanism to handle a corrupt message stream + (_dbus_message_loader_new): fix preallocation to only prealloc, + not prelengthen + + * dbus/dbus-string.c (_dbus_string_skip_blank): fix this function + (_dbus_string_test): enhance tests for copy/move and fix the + functions + + * dbus/dbus-transport-unix.c: Hold references in more places to + avoid reentrancy problems + + * dbus/dbus-transport.c: ditto + + * dbus/dbus-connection.c (dbus_connection_dispatch_message): don't + leak reference count in no-message case + + * test/watch.c (do_mainloop): handle adding/removing watches + during iteration over the watches. Also, ref the connection/server + stored on a watch, so we don't try to mangle a destroyed one. + + * dbus/dbus-transport-unix.c (do_authentication): perform + authentication + + * dbus/dbus-auth.c (get_state): add a state + AUTHENTICATED_WITH_UNUSED_BYTES and return it if required + (_dbus_auth_get_unused_bytes): append the unused bytes + to the passed in string, rather than prepend + + * dbus/dbus-transport.c (_dbus_transport_init_base): create + the auth conversation DBusAuth + + * dbus/dbus-transport-unix.c (_dbus_transport_new_for_fd) + (_dbus_transport_new_for_domain_socket): when creating a + transport, pass in whether it's a client-side or server-side + transport so we know which DBusAuth to create + +2002-12-03 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-transport-unix.c (unix_finalize): finalize base + _after_ finalizing the derived members + (unix_connection_set): unref watch if we fail to add it + + * dbus/dbus-connection.c (dbus_connection_unref): delete the + transport first, so that the connection owned by the + transport will be valid as the transport finalizes. + + * dbus/dbus-transport-unix.c (unix_finalize): free the write_watch + if necessary, and remove watches from the connection. + + * dbus/dbus-watch.c (_dbus_watch_list_free): improve a comment + +2002-12-26 Anders Carlsson <andersca@codefactory.se> + + * dbus/dbus-marshal.c: (_dbus_marshal_string), + (_dbus_demarshal_double), (_dbus_demarshal_int32), + (_dbus_demarshal_uint32), (_dbus_demarshal_string), + (_dbus_marshal_test): + * dbus/dbus-marshal.h: + Add string marshal functions and have the demarshal functions + return the new position. + +2002-12-25 Havoc Pennington <hp@pobox.com> + + * doc/dbus-sasl-profile.txt: docs on the authentication protocol, + it is a simple protocol that just maps directly to SASL. + + * dbus/dbus-auth.h, dbus/dbus-auth.c: authentication protocol + initial implementation, not actually used yet. + + * dbus/dbus-string.c (_dbus_string_find): new function + (_dbus_string_equal): new function + (_dbus_string_base64_encode): new function + (_dbus_string_base64_decode): new function + +2002-12-25 Anders Carlsson <andersca@codefactory.se> + + * dbus/Makefile.am: + * dbus/dbus-marshal.c: (swap_bytes), (_dbus_marshal_double), + (_dbus_marshal_int32), (_dbus_marshal_uint32), + (_dbus_demarshal_double), (_dbus_demarshal_int32), + (_dbus_demarshal_uint32), (_dbus_marshal_test): + * dbus/dbus-marshal.h: + * dbus/dbus-protocol.h: + * dbus/dbus-test.c: (main): + * dbus/dbus-test.h: + Add un-optimized marshalling/demarshalling routines. + +2002-12-25 Harri Porten <porten@kde.org> + + * qt/dbus-qt.h: adjusted ctor and getter to KDE/Qt conventions + +2002-12-24 Zack Rusin <zack@kde.org> + + * qt/dbus-qthread.cc: adding - integrates QMutex into Dbus + * qt/dbus-qt.h: skeleton with two sample implemenatation of the + main loop stuff + +2002-12-24 Havoc Pennington <hp@pobox.com> + + * glib/dbus-gthread.c: fix include + + * glib/dbus-glib.h: rename DBusMessageHandler for now. + I think glib API needs to change, though, as you don't + want to use DBusMessageFunction, you want to use the + DBusMessageHandler object. Probably + dbus_connection_open_with_g_main_loop() + and dbus_connection_setup_g_main_loop() or something like that + (but think of better names...) that just create a connection + that has watch/timeout functions etc. already set up. + + * dbus/dbus-connection.c + (dbus_connection_send_message_with_reply): new function just to + show how the message handler helps us deal with replies. + + * dbus/dbus-list.c (_dbus_list_remove_last): new function + + * dbus/dbus-string.c (_dbus_string_test): free a string that + wasn't + + * dbus/dbus-hash.c: use memory pools for the hash entries + (rebuild_table): be more paranoid about overflow, and + shrink table when we can + (_dbus_hash_test): reduce number of sprintfs and write + valid C89. Add tests for case where we grow and then + shrink the hash table. + + * dbus/dbus-mempool.h, dbus/dbus-mempool.c: memory pools + + * dbus/dbus-connection.c (dbus_connection_register_handler) + (dbus_connection_unregister_handler): new functions + + * dbus/dbus-message.c (dbus_message_get_name): new + + * dbus/dbus-list.c: fix docs typo + + * dbus/dbus-message-handler.h, dbus/dbus-message-handler.c: + an object representing a handler for messages. + +2002-12-16 Anders Carlsson <andersca@codefactory.se> + + * glib/dbus-glib.h: + * glib/dbus-gthread.c: (dbus_gthread_init): + Don't use the gdbus prefix for public functions. + +2002-12-16 Anders Carlsson <andersca@codefactory.se> + + * Makefile.am: + * configure.in: + Add GLib checks and fixup .pc files + + * glib/Makefile.am: + * glib/dbus-glib.h: + * glib/dbus-gmain.c: (gdbus_connection_prepare), + (gdbus_connection_check), (gdbus_connection_dispatch), + (gdbus_add_connection_watch), (gdbus_remove_connection_watch), + (dbus_connection_gsource_new): + * glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free), + (dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init): + * glib/test-dbus-glib.c: (message_handler), (main): + Add GLib support. + +2002-12-15 Harri Porten <porten@kde.org> + + * autogen.sh: check for libtoolize before attempting to use it + + * dbus/dbus-transport-unix.c: include <sys/time.h> for timeval + struct. + + * .cvsignore: ignore more stamp files + + * dbus/dbus-watch.c (_dbus_watch_list_new): fixed doc error + + * test/Makefile.am: added -I$(top_srcdir) to be able to compile + without make install. + +2002-12-15 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-threads.c: add thread stubs that a higher library + layer can fill in. e.g. the GLib wrapper might fill them in with + GThread stuff. We still need to use this thread API to + thread-safe-ize the library. + +2002-12-12 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-transport-unix.c, dbus/dbus-server-unix.c: use the + below new interfaces and include fewer system headers. + + * dbus/dbus-sysdeps.c (_dbus_read): new function + (_dbus_write): new function + (_dbus_write_two): new function + (_dbus_connect_unix_socket): new function + (_dbus_listen_unix_socket): new function + + * dbus/dbus-message-internal.h: change interfaces to use + DBusString + +2002-12-11 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-types.h: add dbus_unichar + + * dbus/dbus-internals.c (_dbus_verbose): use _dbus_getenv + + * dbus/dbus-connection.c (dbus_connection_send_message): return + TRUE on success + + * dbus/dbus-transport.c: include dbus-watch.h + + * dbus/dbus-connection.c: include dbus-message-internal.h + + * HACKING: add file with coding guidelines stuff. + + * dbus/dbus-string.h, dbus/dbus-string.c: Encapsulate all string + handling here, for security purposes (as in vsftpd). Not actually + using this class yet. + + * dbus/dbus-sysdeps.h, dbus/dbus-sysdeps.c: Encapsulate all + system/libc usage here, as in vsftpd, for ease of auditing (and + should also simplify portability). Haven't actually moved all the + system/libc usage into here yet. + +2002-11-25 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-internals.c (_dbus_verbose): fix to not + always print the first verbose message. + +2002-11-24 Havoc Pennington <hp@pobox.com> + + * test/echo-client.c, test/echo-server.c: cheesy test + clients. + + * configure.in (AC_CHECK_FUNCS): check for writev + + * dbus/dbus-message.c (_dbus_message_get_network_data): new + function + + * dbus/dbus-list.c (_dbus_list_foreach): new function + + * dbus/dbus-internals.c (_dbus_verbose): new function + + * dbus/dbus-server.c, dbus/dbus-server.h: public object + representing a server that listens for connections. + + * dbus/.cvsignore: create + + * dbus/dbus-errors.h, dbus/dbus-errors.c: + public API for reporting errors + + * dbus/dbus-connection.h, dbus/dbus-connection.c: + public object representing a connection that + sends/receives messages. (Same object used for + both client and server.) + + * dbus/dbus-transport.h, dbus/dbus-transport.c: + Basic abstraction for different kinds of stream + that we might read/write messages from. + +2002-11-23 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-internals.h (_DBUS_INT_MAX): add _DBUS_INT_MIN + _DBUS_INT_MAX + + * dbus/dbus-test.c (main): add list test, and include + dbus-test.h as intended + + * dbus/dbus-hash.c (_dbus_hash_table_remove_string) + (_dbus_hash_table_remove_int): return value indicates + whether the entry existed to remove + + * dbus/dbus-list.c: add linked list utility class, + with docs and tests + + * dbus/dbus-hash.c: add TODO item about shrinking the hash bucket + array sometimes. + +2002-11-23 Havoc Pennington <hp@pobox.com> + + * Doxyfile.in (INCLUDE_FILE_PATTERNS): expand DBUS_BEGIN_DECLS/ + DBUS_END_DECLS to nothing, that should fix this once and for all + + * Doxyfile.in (JAVADOC_AUTOBRIEF): set to YES + + * dbus/dbus-message.c, dbus/dbus-hash.c: + add some missing @brief + +2002-11-23 Havoc Pennington <hp@pobox.com> + + * dbus/dbus-message.h: put semicolons after DEBUG_BEGIN_DECLS + to avoid confusing Doxygen + + * dbus/dbus-hash.c: @} not }@ + + * dbus/dbus-message.c (struct DBusMessage): split out + internals docs + +2002-11-23 Havoc Pennington <hp@pobox.com> + + * configure.in: pile on more warning flags if using gcc + + * Doxyfile.in (EXTRACT_STATIC): set to NO, so we don't have + to document static functions + + * configure.in: add summary to end of configure so it + looks nice and attractive + + * dbus/dbus-hash.c: finish implementation and write unit + tests and docs + + * configure.in: add --enable-tests to enable unit tests + + * dbus/dbus-test.c: test program to run unit tests + for all files in dbus/*, initially runs a test for + dbus-hash.c + + * dbus/dbus-internals.h: file to hold some internal utility stuff + +2002-11-22 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-hash.c: copy in Tcl hash table, not yet + "ported" away from Tcl + + * dbus/dbus-types.h: header for types such as dbus_bool_t + +2002-11-22 Havoc Pennington <hp@redhat.com> + + * dbus/dbus.h: fixups for doc warnings + + * Doxyfile.in (FILE_PATTERNS): we need to scan .h to pick up + macros + (QUIET): make it quiet so we can see warnings + + * dbus/dbus-memory.c: teach D-BUS to allocate and free memory + +2002-11-22 Havoc Pennington <hp@redhat.com> + + * Makefile.am: include "Doxyfile" target in all-local + + * configure.in: generate the Doxyfile + + * Doxyfile.in: move Doxyfile here, so we can use + configure to generate a Doxyfile with the right + version number etc. + +2002-11-22 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c: move inline docs into .c file + + * Doxyfile (OUTPUT_DIRECTORY): move output to doc/api + so all docs are under doc/ + (MAN_EXTENSION): generate man pages. Use extension + ".3dbus" which matches ".3qt" on my system, + I guess this is OK, I don't know really. + (FILE_PATTERNS): look for .c files not .h, makes sense + for plain C I think + +2002-11-22 Havoc Pennington <hp@pobox.com> + + * Makefile.am (SUBDIRS): rename subdir "server" to "bus" + because any app can be a server, and any app can be a client, + the bus is a special kind of server. + +Thu Nov 21 23:35:31 2002 Zack Rusin <zack@kde.org> + + * Doxyfile : adding. Still needs Makefile rules to be generated + automatically (just run "doxygen" in the toplevel dir for now to + generate docs) + + * dbus/dbus-message.h : Adding sample docs (javadoc since + resembles gtk-doc a little more) + + * dbus/dbus.h : Adding sample docs + +2002-11-21 Havoc Pennington <hp@redhat.com> + + * dbus/Makefile.am (INCLUDES): define DBUS_COMPILATION + so we can allow ourselves to include files directly, + instead of having to use dbus.h + + * dbus/dbus.h: fill in + + * dbus/dbus-message.h: sketch out a sample header file. + Include griping if you include it directly instead of + via dbus.h + + * dbus/dbus-macros.h: new file with macros for extern "C", + TRUE/FALSE, NULL, etc. + + * doc/file-boilerplate.c: put include guards in here + +2002-11-21 Havoc Pennington <hp@redhat.com> + + * doc/file-boilerplate.c: include both AFL and GPL boilerplate. + + * COPYING: include the GPL as well, and license code + under both AFL and GPL. + +2002-11-21 Havoc Pennington <hp@redhat.com> + + * acconfig.h: get rid of this + + * autogen.sh (run_configure): add --no-configure option + + * configure.in: remove AC_ARG_PROGRAM to make + autoconf complain less. add AC_PREREQ. + add AC_DEFINE third arg. + +2002-11-21 Anders Carlsson <andersca@codefactory.se> + + * doc/Makefile.am: + Fix references so we can distcheck. + +2002-11-21 Havoc Pennington <hp@redhat.com> + + * Initial module creation +
diff --git a/ChangeLog.pre-1-2 b/ChangeLog.pre-1-2 new file mode 100644 index 0000000..b220448 --- /dev/null +++ b/ChangeLog.pre-1-2
@@ -0,0 +1,2027 @@ +2008-04-04 John (J5) Palmieri <johnp@redhat.com> + + * Released 1.2.1 + +2008-04-03 John (J5) Palmieri <johnp@redhat.com> + + Patch from Sumit <sumitskj_20@yahoo.com>, comments added + + * dbus/dbus-transport.c(_dbus_transport_open): fix mem leak + +2008-04-03 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-connection.c (dbus_connection_send): add documentation + to describe when to call dbus_connection_flush and + dbus_connection_unref after a call to dbus_connection_send is made + Initial wording by Stanislav Brabec <sbrabec at suse.cz> + (fd.o bug#13558) + +2008-04-03 John (J5) Palmieri <johnp@redhat.com> + + Patch from Kimmo Hämäläinen <kimmo.hamalainen at nokia.com> + + * bus/expirelist.c + (do_expiration_with_current_time): calculate correct min wait time + and next interval + (bus_expire_list_add, bus_expire_list_add_link): if the timeout is + disabled when we add an item to the expire list, enable the timeout + (do_expiration_with_current_time): only set timeout if there are + items to expire + +2008-04-01 Timo Hoenig <thoenig@suse.de> + + Patch from Frederic Crozat <fcrozat@mandriva.com> + + * bus/dir-watch-inotify.c (bus_watch_directory): Only monitor + IN_CLOSE_WRITE, IN_DELETE, IN_MOVE_TO and IN_MOVE_FROM events. This + way, only atomic changes to configuration file are monitored. + * bus/dir-watch-inotify.c (_handle_inotify_watch): Fix typo in + _dbus_verbose function call + * bus/dir-watch-inotify.c (bus_drop_all_directory_watches): Use + _dbus_strerror instead of perror + +2008-03-04 Havoc Pennington <hp@redhat.com> + + * bus/connection.c, bus/expirelist.c: Make the BusExpireList + struct opaque, adding accessors for manipulating the list. In this + commit there should be no change in functionality or behavior. The + purpose of this change is to improve encapsulation prior to fixing + some bugs Kimmo Hämäläinen found where the timeout is not properly + updated, since we need to e.g. take some action whenever adding + and removing stuff from the expire list. + +2008-03-31 Colin Walters <walters@verbum.org> + + Patch from Owen Taylor <otaylor@redhat.com> + + * tools/dbus-launch-x11.c: Check for X11 events before + selecting (FDO bug #15293) + +2008-03-31 Colin Walters <walters@verbum.org> + + Patch from Owen Taylor <otaylor@redhat.com> + + * tools/dbus-launch-x11.c: Make sure we call XFlush() + on all code paths (FDO bug #15293) + +2008-03-27 Havoc Pennington <hp@redhat.com> + + * tools/dbus-send.c (append_dict): Do not provide a signature to + dbus_message_iter_open_container() when opening a dict entry. + +2008-03-26 Colin Walters <walters@verbum.org> + + Patch from Scott James Remnant <scott@netsplit.com> + + * dbus/dbus-bus.c: Set default exit_on_disconnect after registration with + the bus, not before. This ensures that programs which wish to set + exit_on_disconnect to FALSE will not be terminated if the bus exits + during registration. (FDO Bug #15112) + +2008-03-04 John (J5) Palmieri <johnp@redhat.com> + + * fix broken poll on Mac OSX - build patch by Benjamin Reed + * configure.in: check for OSX's deadlocking poll + * dbus/dbus-sysdeps-unix.c (_dbus_poll): if we have a broken poll + don't use poll + +2008-03-04 John (J5) Palmieri <johnp@redhat.com> + + * check if the linker supports a flag instead of just checking for GNU + ld + * configure.in: move AM_PROG_LIBTOOL to the top + (ld_supports_flag): new function for checking if the linker supports + a given flag + +2008-03-04 John (J5) Palmieri <johnp@redhat.com> + + * add a changelog for Benjamin Reed's git patch RANT: Change Logs are + handled by git and having an external changelog just screws up + merging. We should write down rules for doing git commit messages + and leave it at that. + * configure.in: Platform build fixes for Mac OS X + the Darwin linker does not understand the -z option; wrap it in + a check for $with_gnu_ld. + environ is only available at runtime, so you need to make a + reference to _NSGetEnviron instead for symbols to resolve properly. + +2008-03-04 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: add $THREAD_LIBS to DBUS_LAUNCHER_LIBS so we link + correctly + +2008-03-04 John (J5) Palmieri <johnp@redhat.com> + + * tools/dbus-launch.c: wrap X'ism in #ifdef so we can compile + without X + +2008-02-28 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-sysdeps-unix.c: define _AI_ADDRCONFIG as 0 if not + defined so that we can compile with an older glibc + +2008-02-26 John (J5) Palmieri <johnp@redhat.com> + + * Released 1.1.20 + +2008-02-26 John (J5) Palmieri <johnp@redhat.com> + + * CVE-2008-0595 - security policy of the type <allow send_interface= + "some.interface.WithMethods"/> work as an implicit allow for + messages sent without an interface bypassing the default deny rules + and potentially allowing restricted methods exported on the bus to be + executed by unauthorized users. This patch fixes the issue. + * bus/policy.c (bus_client_policy_check_can_send, + bus_client_policy_check_can_receive): skip messages without an + interface when evaluating an allow rule, and thus pass it to the + default deny rules + +2008-02-26 John (J5) Palmieri <johnp@redhat.com> + + * correctly unref connections without guids during shutdown + * dbus/dbus-connection.c (close_connection_on_shutdown): new method + split out from shared_connections_shutdown + (shared_connections_shutdown): shutdown all shared connections + without guids + (_dbus_connection_ref_unlocked): handle OOM when prepending no guid + connections to the shared_connections_no_guid list + * Patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + +2008-02-21 John (J5) Palmieri <johnp@redhat.com> + + * fix build against the latest gcc/glibc + * dbus/dbus-sysdeps-unix.c: define _GNU_SOURCE + * bus/selinux.c: include limits.h + * Patch by Matthias Clasen <mclasen at redhat.com> + +2008-02-21 John (J5) Palmieri <johnp@redhat.com> + + * fixes dbus-launch so the bus goes away when X does + (Red Hat Bug #430412) + * tools/dbus-launch.c (main): set xdisplay = NULL + * Patch by Matthias Clasen <mclasen at redhat.com> + +2008-01-17 John (J5) Palmieri <johnp@redhat.com> + + * Released 1.1.4 + +2008-01-17 Timo Hoenig <thoenig@suse.de> + * fix inotify support + * bus/dir-watch-inotify.c (_handle_inotify_watch): fix reading of the + inotify events. Also, use ssize_t not size_t for 'ret'. + * bus/dir-watch-inotify.c (bus_watch_directory): watch not only for + IN_MODIFY but also for IN_CREATE and IN_DELETE + * bus/dir-watch-inotify.c (bus_drop_all_directory_watches): drop the + inotify watches more elegantly by closing inotify:_fd, set inotify_fd to + -1 after dropping the watches + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: post-release version bump + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * Released 1.1.3 (1.2.0RC1) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * fix hacking to say git instead of cvs + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Sébastien Couret <10function at gmail dot com> + + * dbus/dbus-marshal-recursive.c (all_reader_classes[]): wrap in + #ifndef DBUS_DISABLE_ASSERT since it is only used in asserts which + are noop + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Magnus Henoch <henoch plus bfdo at dtek dot chalmers dot se> + + * dbus/dbus-auth.c (handle_server_data_external_mech): handle SASL + EXTERNAL's inital empty responce (FDO Bug #9945) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * bus/messagebus.in: add lsb headers (FDO Bug #11491) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Peter O'Gorman <pogma at thewrittenword dot com> + + * dbus/dbus-spawn.c (babysit_signal_handler): check write return value + so we don't hang (FDO Bug #11665) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Peter O'Gorman <pogma at thewrittenword dot com> + + * dbus/dbus-sysdeps.h: support for AIX poll implementation (FDO Bug + #11666) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * tests/name-test/run-test.sh: make more portable (FDO Bug #11667) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * dbus/dbus-connection.c (_dbus_connection_get_next_client_serial): + don't check for < 0 on an unsigned variable (FDO Bug #12924) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * bus/bus.c (setup_server): check failed allocation (FDO Bug #12920) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * dbus/dbus-spawn.c (_dbus_spawn_async_with_babysitter): the API + contract says sitter_p can be NULL, so let's check it (FDO Bug #12919) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * dbus/dbus-spawn.c (read_ints, read_pid): use correct ssize_t type + instead of size_t (FDO Bug #12862) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * dbus/dbus-errors.c (dbus_set_error): make sure to call va_end if we + hit an OOM error inside va_start (FDO Bug #12846) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * dbus/dbus-connection.c (dbus_connection_send_with_reply): + fix possible crash if pending_return is NULL (FDO Bug #12673) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * portions of patch submitted by Tim Mooney + <enchanter at users dot sourceforge dot net> + + * configure.in: never auto-select libxml (FDO Bug #12479) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patches by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * dbus/dbus-sysdeps-unix (_dbus_get_autolaunch_address): handle OOM + (FDO Bug #12945) + + * dbus/dbus-uuidgen.c (return_uuid): handle OOM (FDO Bug #12928) + + * dbus/dbus-misc.c (dbus_get_local_machine_id): handle OOM, fix return + value to return NULL not FALSE (FDO Bug #12946) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * bus/bus.c (bus_context_check_security_policy): rewrite selinux error + handling to not abort due to a NULL read and to set the error only if + it is not already set (Based off of FDO Bug #12430) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * dbus/dbus-internals.c (_dbus_read_uuid_file_without_creating, + _dbus_create_uuid_file_exclusively): add OOM handling (FDO Bug #12952) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * dbus/dbus-spawn.c (babysit, babysitter_iteration): add error + handling when polling (FDO Bug #12954) + +2008-01-15 John (J5) Palmieri <johnp@redhat.com> + + * patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * bus/config-parser.c (locate_attributes): remove dead code which + always evaluated to TRUE + + * dbus/dbus-shell.c (_dbus_shell_quote): remove unused code + +2008-01-14 John (J5) Palmieri <johnp@redhat.com> + + * patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * bus/connection.c (bus_connection_complete): plug a possible + BusClientPolicy leak (FDO Bug #13242) + +2008-01-14 John (J5) Palmieri <johnp@redhat.com> + + * patch by Frederic Crozat <fcrozat at mandriva dot com> (FDO Bz# + 13268) + + * add inotify support + + * bus/Makefile.am: add inotify module to the build + + * bus/dir-watch-inotify.c: inotify module based off the dnotify and + kqueue modules + + * configure.in: add checks and switch for inotify + also add a printout at the end of configure if inotify and kqueue + support is being built in (dnotify already had this) + +2008-01-14 John (J5) Palmieri <johnp@redhat.com> + + * patch by Frederic Crozat <fcrozat at mandriva dot com> + + * bus/dir-watch-dnotify.c (bus_watch_directory): watch for file + creates also + +2008-01-14 John (J5) Palmieri <johnp@redhat.com> + + * patch by Kimmo Hämäläinen <kimmo dot hamalainen at nokia dot com> + + * dbus/dbus-transport-socket.c(do_reading): return message + loader buffer in case of OOM (FDO Bug#12666) + +2008-01-14 John (J5) Palmieri <johnp@redhat.com> + + * configure.in: add warning to output when libxml is selected since + we don't have a libxml maintainer and expat works perfectly fine + for what we need an xml parser for + +2008-01-14 John (J5) Palmieri <johnp@redhat.com> + + * Patch by Andrea Luzzardi <scox at sig11 dot org>: creates a + _dbus_geteuid function to fix EXTERNAL authentication in setuid + applications + + * dbus/dbus-sysdeps-unix.c (_dbus_geteuid): used to get the effective + uid of the running program + (_dbus_credentials_add_from_current_process): use geteuid instead of + getuid + (_dbus_append_user_from_current_process): use geteuid instead of + getuid + + * dbus/dbus-sysdeps-util-unix.c (_dbus_change_to_daemon_user): use + geteuid instead of getuid + (_dbus_unix_user_is_at_console): use geteuid instead of getuid + + * dbus/dbus-sysdeps-win.c (_dbus_geteuid): add a windows equivilant + that returns DBUS_UID_UNSET + +2007-12-18 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c (_dbus_connection_block_pending_call): + fix location of curly braces + +2007-11-23 Sjoerd Simons <sjoerd@luon.net> + + * tools/dbus-launch.c: let both a normal dbus-launch and an + autolaunched bus save their parameters in X11 if possible. This makes + the autolaunch and non-autolaunch behaviour more similar. With the + exception that on a normal launch there will always be a new session + bus and not being able to save parameters is not fatal. This also + enables to launch programs directly with autolaunch (not very usefull + though). + +2007-10-31 Havoc Pennington <hp@redhat.com> + + * bus/selinux.c (log_audit_callback): rewrite to use + _dbus_string_copy_to_buffer_with_nul() + + * dbus/dbus-string.c (_dbus_string_copy_to_buffer): change to NOT + nul-terminate the buffer; fail an assertion if there is not enough + space in the target buffer. This fixes two bugs where + copy_to_buffer was used to copy the binary bytes in a UUID, where + nul termination did not make sense. Bug reported by David Castelow. + (_dbus_string_copy_to_buffer_with_nul): new function that always + nul-terminates the buffer, and fails an assertion if there is not + enough space in the buffer. + +2007-10-23 Havoc Pennington <hp@redhat.com> + + * bus/bus.c (bus_context_new): use the new name here + + * bus/selinux.c (bus_selinux_audit_init): rename from audit_init() + to avoid possible libc conflict, and declare it in .h file to + avoid a warning + +2007-10-19 Havoc Pennington <hp@redhat.com> + + * bus/bus.c (bus_context_new): put audit_init() in HAVE_SELINUX + +2007-10-19 Havoc Pennington <hp@redhat.com> + + * bus/bus.c (bus_context_new): put the audit_init() in here + instead, which I believe ends up being the same as where it was + before, though I'm not sure I understand why it goes here. + + * dbus/dbus-sysdeps-util-unix.c (_dbus_change_to_daemon_user): + remove audit_init() from here, this file can't depend on code in + bus/ directory + +2007-10-16 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * configure.in: *Actually* fix detection of i486 atomic ops - + my previous attempt at a fix would always enable them due to wrong + quoting. Patch from Colin Walters <walters@verbum.org> + +2007-10-11 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * configure.in: enable Autoconf's AC_C_INLINE to avoid compilation + failure with gcc -ansi + * dbus/dbus-macros.h, dbus/dbus-arch-deps.h.in: Use new macro + _DBUS_GNUC_EXTENSION (the same as G_GNUC_EXTENSION) to avoid -ansi + warnings about use of "long long". + * dbus/dbus-server-socket.c: remove unused variable when assertions + are disabled + * dbus/dbus-marshal-validate.c: avoid empty statements by removing + stray semicolons + * tools/dbus-launch.c: convert C++-style comment to C-style, add {} + for clarity + * .gitignore: ignore vi swapfiles + * dbus/dbus-errors.h, dbus/dbus-errors.c: Add DBUS_ERROR_INIT macro, + equivalent to calling dbus_error_init() on an uninitialized DBusError + * dbus/dbus-address.c, dbus/dbus-auth-script.c, dbus/dbus-auth-util.c, + dbus/dbus-connection.c, dbus/dbus-internals.c, dbus/dbus-keyring.c, + dbus/dbus-message-util.c, dbus/dbus-server.c, dbus/dbus-sha.c, + dbus/dbus-spawn-win.c, dbus/dbus-spawn.c, + dbus/dbus-sysdeps-util-win.c, dbus/dbus-transport-socket.c, + dbus/dbus-transport.c, dbus/dbus-userdb.c: use that macro instead of + calling dbus_error_init() where it's clearly equivalent + * configure.in, dbus/dbus-sysdeps.h, dbus/dbus-sysdeps-unix.c: Fix + detection of i486 atomic ops. Previously, the attempts to determine + support at compile-time on Darwin were causing the i486 atomic ops to + be used on *all* i386 or x86-64 GCC builds (AH_VERBATIM can't be + conditionalized like we were trying to). + +2007-10-10 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * dbus/dbus-errors.c, dbus/dbus-protocol.h: Add new error + org.freedesktop.DBus.Error.ObjectPathInUse + * dbus/dbus-object-tree.h, dbus/dbus-object-tree.c, + dbus/dbus-connection.c, dbus/dbus-connection.h: add new functions + dbus_connection_try_register_object_path and + dbus_connection_try_register_fallback, which raise ObjectPathInUse + rather than asserting, to make object path registration less painful + for bindings + * .gitignore: add various things that weren't in .cvsignore because + CVS implicitly ignored them; generally bring up to date + +2007-10-09 John (J5) Palmieri <johnp@redhat.com> + + * tools/run-with-tmp-session-bus.sh: Fix env exports for better + portability (#9280) + * tools/dbus-send.1: Document syntax for container types in dbus-send + man file (#9553) - patch from Jack Spaar <jspaar at + users.sourceforge.net> + + [Both OK for MIT/X11 relicensing -smcv] + +2007-10-09 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * doc/dbus-specification.xml: Specifically forbid empty structs (#7969) + * doc/dbus-specification.xml: Patches from Kristoffer Lundén to clarify + description of DBUS_COOKIE_SHA1 (#10184) and allowable contents of a + variant (#10185, amended as per Havoc's comments) + + [All of the above are OK for MIT/X11 licensing] + +2007-10-03 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-internals.h: fd.o bug #11678 Don't error out if compiler + does not support vararg macros. _dbus_verbose is the only function + that does this so make it a noop if vararg macros are not supported + * bus/selinux.c, dbus/dbus-sysdeps-util-unix.c: fd.o bug #12429 + Reverse check to setpcap and only init audit if we were root + (patch by Dan Walsh <dwalsh@redhat.com>, + https://bugs.freedesktop.org/show_bug.cgi?id=12429). Reverse + we_were_root check to setpcap if we were root. Also only init audit + if we were root. So error dbus message will not show up when policy + reload happens. dbus -session will no longer try to send audit + message, only system will. + * configure.in: fd.o bug #11872 improve linker test for --gc-sections. + Patch by Tim Mooney <enchanter at users.sourceforge.net> + * configure.in, dbus/dbus-sysdeps.c: fd.o bug #11872 fix clearenv for + systems that do not have it. Patch from Brian Cameron <brian.cameron + at sun.com> + * tools/dbus-launch.c: fd.o bug #12547 remove superfluous if. + Also convert tabs to spaces + * configure.in, bus/Makefile.am, dbus/Makefile.am: Correctly implement + -fPIC and -fPIE. For security reasons we want possition independent + code for libraries and possition independent executable for + executables. Before we were just enabling -fPIC. Now we correctly + enable -fPIC and -PIE for libdbus and the bus respectively. Proper + LD_FLAGS are set for each also. + +2007-09-20 Ryan Lortie <desrt@desrt.ca> + + Add argument path matching support. Bug #11066. + + * dbus/signals.c (struct DBusMatchRule, bus_match_rule_new, + bus_match_rule_set_arg, bus_match_rule_parse_arg_match, + match_rule_matches): Add support for parsing and matching on + arg0path='/some/path' type rules. + + * dbus/signals.h (bus_match_rule_set_arg): change to take const + DBusString instead of const char * for the string to match against. + + * dbus/dbus-bus.c: add a quick note to dbus_bus_add_match + documentation about the path matching. + + * doc/dbus-specification.xml: add a more detailed description of the + changes here. + +2007-09-19 Ryan Lortie <desrt@desrt.ca> + + Add support for compacting DBusStrings to release wasted memory. + + * dbus/dbus-string.[ch] (compact, _dbus_string_compact, + _dbus_string_lock): new compact function to free up allocated memory + that is no longer used. + + * dbus/dbus-message.c (load_message): call _dbus_string_compact on the + message loader buffer. + + * dbus/dbus-transport-socket.c (do_reading, do_writing): call + _dbus_string_compact on the incoming/outgoing "encoded" buffers. + + * dbus/dbus-string-util.c (_dbus_string_test): add a few tests for + string compacting. + +2007-09-13 Ryan Lortie <desrt@desrt.ca> + + * HACKING: add more explicit git branch/tag instructions + +2007-09-13 Ryan Lortie <desrt@desrt.ca> + + migrate from cvs to git (cvs2svn -> git-svnimport). + + * HACKING: update release/branch/tag instructions + * */.cvsignore: rename to .gitignore + + also, clean up tags and branch names to conform to HACKING + +2007-08-17 William Jon McCann <mccann@jhu.edu> + + * update-dbus-docs.sh: upload DTD to server + +2007-08-17 Havoc Pennington <hp@redhat.com> + + * tools/dbus-launch-x11.c (set_address_in_x11): fix from Michael + Lorenz to use long not int with XChangeProperty format 32 + + * dbus/dbus-sysdeps-util-unix.c + (_dbus_write_pid_to_file_and_pipe): factor this out, and use the + same code in _dbus_become_daemon (where the parent writes the pid + file and to the pid pipe) and in bus_context_new (where the daemon + writes its own pid file and to its own pid pipe) + + * bus/bus.c (bus_context_new): close the pid pipe after we print + to it. Also, don't write the pid to the pipe twice when we fork, + someone reported this bug a long time ago. + +2007-08-03 Havoc Pennington <hp@redhat.com> + + * configure.in: add major/minor/micro version number AC_SUBST + + * dbus/dbus-arch-deps.h.in (DBUS_MAJOR_VERSION, + DBUS_MINOR_VERSION, DBUS_MICRO_VERSION, DBUS_VERSION_STRING, + DBUS_VERSION): collection of macros to get version of library we + are compiled against. + + * dbus/dbus-misc.c (dbus_get_version): new function, to get + version of library we are linked against at runtime. + +2007-07-30 Havoc Pennington <hp@redhat.com> + + * bus/activation-helper.c (check_bus_name): don't use + _dbus_check_valid_bus_name() which is only around with + --enable-checks, instead use _dbus_validate_bus_name(). + Bug #11766 from Diego <diego@pemas.net> + +2007-07-27 Havoc Pennington <hp@redhat.com> + + * configure.in: post-release version bump + +2007-07-27 Havoc Pennington <hp@redhat.com> + + * release 1.1.2 + +2007-07-26 Havoc Pennington <hp@redhat.com> + + * bus/config-parser-trivial.c (check_return_values): disable a + test that hardcoded the bus user's name + + * bus/dispatch.c (bus_dispatch_test_conf): remove the "if + (!use_launcher)" around the tests, they were only failing because + we didn't pass through all the expected errors from the helper. + + * bus/activation-exit-codes.h + (BUS_SPAWN_EXIT_CODE_CHILD_SIGNALED): add a code for child segfaulting + (BUS_SPAWN_EXIT_CODE_GENERIC_FAILURE): make "1" be a generic + failure code, so if a third party launch helper were written it + could just always return 1 on failure. + +2007-07-24 Daniel P. Berrange <dan@berrange.com> + + * bus/dbus-daemon.1: Add docs on new syntax options for the bus + address strings + + * dbus/dbus-address.c: Allow * in addresses (for binding to all + addresses). + + * dbus/dbus-sysdeps.h: + * dbus/dbus-sysdeps-unix.c: Re-write to use getaddrinfo instead + of gethostbyname to enable protocol independant name lookup, + making IPv6 work + + * dbus/dbus-server-socket.h: + * dbus/dbus-server-socket.c: Add support for 'family' in the + address string to specify ipv4 vs ipv6. Use a port string to + allow for service resolution. Allow for binding to multiple + sockets at once in case of dual IPv4 & IPv6 stacks. + + * dbus/dbus-server-unix.c: Pass in an array of file descriptors + instead of a single one. + + * dbus/dbus-transport-socket.h: + * dbus/dbus-transport-socket.c: Add support for 'family' in the + address string to specify ipv4 vs ipv6. Use a port string to + allow for service resolution. + +2007-07-24 Havoc Pennington <hp@redhat.com> + + * configure.in: add AM_PROG_CC_C_O to allow per-target CPPFLAGS + + * bus/dispatch.c (bus_dispatch_test_conf): Fix up setting + TEST_LAUNCH_HELPER_CONFIG to include the full path, and enable + test shell_fail_service_auto_start when use_launcher==TRUE + + * bus/activation-helper-bin.c (convert_error_to_exit_code): pass + through the INVALID_ARGS error so the test suite works + + * bus/activation.c (handle_activation_exit_error): return + DBUS_ERROR_NO_MEMORY if we get BUS_SPAWN_EXIT_CODE_NO_MEMORY + + * dbus/dbus-spawn.c (_dbus_babysitter_get_child_exit_status): + return only the exit code of the child, not the entire thingy from + waitpid(), and make the return value indicate whether the child + exited normally (with a status code) + + * bus/bus.c (process_config_first_time_only): _dbus_strdup works + on NULL so no need to check + (process_config_every_time): move servicehelper init here, so we + reload it on HUP or config file change + + * bus/Makefile.am (install-data-hook): remove comment because + Emacs make mode seems to be grumpy about it + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/Makefile.am: + * bus/test-system.c: (die), (check_memleaks), (test_pre_hook), + (test_post_hook), (main): + Add back the test-system.c file - not sure now this got ignored in the + diff. I blame git. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * configure.in: + Use ustar to generate the tarball; this fixes the make distcheck + problem when the data files do not fit in the archive: + tar: dbus-1.1.2/test/data/valid-service-files/org.freedesktop.DBus. + TestSuiteShellEchoServiceFail.service.in: file name is too + long (max 99); not dumped + + We have to have the 'long' names as the service helper matches by + filename rather than by the name in the service file. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * configure.in: + * test/Makefile.am: + * test/data/invalid-service-files-system/org.freedesktop.DBus.TestS + uiteNoExec.service.in: + * test/data/invalid-service-files-system/org.freedesktop.DBus.TestS + uiteNoService.service.in: + * test/data/invalid-service-files-system/org.freedesktop.DBus.TestS + uiteNoUser.service.in: + * test/data/valid-config-files-system/debug-allow-all-fail.conf.in: + * test/data/valid-config-files-system/debug-allow-all-pass.conf.in: + * test/data/valid-config-files/debug-allow-all-sha1.conf.in: + * test/data/valid-config-files/debug-allow-all.conf.in: + * test/data/valid-service-files-system/org.freedesktop.DBus.TestSui + teEchoService.service.in: + * test/data/valid-service-files-system/org.freedesktop.DBus.TestSui + teSegfaultService.service.in: + * test/data/valid-service-files-system/org.freedesktop.DBus.TestSui + teShellEchoServiceFail.service.in: + * test/data/valid-service-files-system/org.freedesktop.DBus.TestSui + teShellEchoServiceSuccess.service.in: + * test/data/valid-service-files/debug-echo.service.in: + * test/data/valid-service-files/debug-segfault.service.in: + * test/data/valid-service-files/debug-shell-echo-fail.service.in: + * test/data/valid-service-files/debug-shell-echo-success.service.in: + * test/data/valid-service-files/org.freedesktop.DBus.TestSuiteEchoS + ervice.service.in: + * test/data/valid-service-files/org.freedesktop.DBus.TestSuiteSegfa + ultService.service.in: + * test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShell + EchoServiceFail.service.in: + * test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShell + EchoServiceSuccess.service.in: + Add the data files needed by the system activation unit checks. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/dispatch.c: (check_segfault_service_no_auto_start), + (check_launch_service_file_missing), + (check_launch_service_user_missing), + (check_launch_service_exec_missing), + (check_launch_service_service_missing), (bus_dispatch_test_conf), + (bus_dispatch_test_conf_fail), (bus_dispatch_test): + Add unit tests for system activation. Most are copied from the + session activation tests, but some didn't apply when using a laucher. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/activation.c: (bus_activation_activate_service): + If the bus uses a service-laucher, then use the setuid laucher. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * configure.in: + Add the needed library exports for the new laucher. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * configure.in: + Check for -Wl,--gc-sections so we can really reduce the size of the + setuid binary. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/activation.c: (handle_activation_exit_error), + (babysitter_watch_callback): + Map the child exit status integer to a proper dbus error. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/bus.c: (process_config_first_time_only), + (process_config_every_time), (bus_context_unref), + (bus_context_get_servicehelper): + * bus/bus.h: + Add the concept of a service-helper and allow it's value to be read. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/activation.c: (bus_activation_entry_unref), + (update_desktop_file_entry): + Add the concept of, and read the value of user from the desktop file. + The user string is not required unless we are using system activation. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/activation.c: + * bus/desktop-file.h: + Move the defines into the header file, as we use these in the lauch + helper as well as the desktop file parsing. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/.cvsignore: + Add the autogenerated binary files. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/Makefile.am: + * bus/test.h: + Add the build glue for the lauch helper, and also add the launch-helper + OOM checks into make check. I've probably broken the build, give me 2. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/test-launch-helper.c: (die), (check_memleaks), + (test_post_hook), (bus_activation_helper_oom_test), (main): + Add a test wrapper to allow OOM checks on the launch helper. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/activation-helper-bin.c: (convert_error_to_exit_code), + (main): + * bus/activation-helper.c: (desktop_file_for_name), + (clear_environment), (check_permissions), (check_service_name), + (get_parameters_for_service), (switch_user), + (exec_for_correct_user), (check_bus_name), (get_correct_parser), + (launch_bus_name), (check_dbus_user), (run_launch_helper): + * bus/activation-helper.h: + Add the initial launch-helper. This is split into a main section and a + binary loader that allows us to lauch the main section in another test + harness to do stuff like OOM testing. No build glue yet. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/Makefile.am: + * bus/config-parser.c: (bus_config_parser_unref), + (start_busconfig_child), (bus_config_parser_end_element), + (servicehelper_path), (bus_config_parser_content), + (bus_config_parser_finished), + (bus_config_parser_get_servicehelper), + (test_default_session_servicedirs), + (test_default_system_servicedirs), (bus_config_parser_test): + * bus/config-parser.h: + Make the config-parser code use the common config code. + Also add the session and systemdirs stuff, and make the config parser + aware of the servicehelper field. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/system.conf.in: + Add new servicehelper fields to the default system.conf file. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/config-parser-trivial.c: (service_dirs_find_dir), + (service_dirs_append_link_unique_or_free), (bus_config_parser_new), + (bus_config_parser_unref), (bus_config_parser_start_element), + (bus_config_parser_end_element), (bus_config_parser_content), + (bus_config_parser_finished), (bus_config_parser_get_user), + (bus_config_parser_get_type), (bus_config_parser_get_service_dirs), + (check_return_values), (do_load), (check_loader_oom_func), + (process_test_valid_subdir), (make_full_path), (check_file_valid), + (bus_config_parser_trivial_test): + * bus/config-parser-trivial.h: + Add a security sensitive stripped down config parser for the setuid + launcher. This file only reads what it needs, and doesn't try to do + anything remotely clever like including external files. + It is not intended to validate the config file; it is expected that + config-parser will do that before the setuid program tries to read it. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/config-parser-common.c: + (bus_config_parser_element_name_to_type), + (bus_config_parser_element_type_to_name): + * bus/config-parser-common.h: + We don't want to run the whole config parser with all it's deps in the + setuid program. We need to implement a stripped down config parser just + for the launcher, and to do so I need some common functions and + defines; add them here. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * dbus/dbus-sysdeps-unix.c: + (_dbus_get_standard_system_servicedirs): + * dbus/dbus-sysdeps-win.c: + Provide a way to get the standard system servicedirs, just like we do + for the session service dirs. These should be seporate, as there may + be a security issue starting up some session stuff as root. + The use-case for the same binary starting up per-system _and_ + per-session is also not valid. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/dbus-daemon.1.in: + Add standard_system_servicedirs and servicehelper into the man file + and explain what each does. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * doc/busconfig.dtd: + Add servicehelper into the dtd, it will soon be a valid part of the + config file. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * dbus/dbus-spawn.c: (read_data), + (_dbus_babysitter_get_child_exit_status): + * dbus/dbus-spawn.h: + Add a function so we can get access to the exit status of the launch + helper. + By providing the return code and not the error we can leave the + 'what does this mean?' to the bus launch code and not include it in the + dbus directory. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * bus/activation-exit-codes.h: + Add defines which specify the output codes of the launch helper. + We have to use exit codes as this is the only way we can return failure + type without going grotty things like redirecting possibly-nonsecure + stderr into the error. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * dbus/dbus-protocol.h: + Add new error names needed for the launch helper. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * dbus/dbus-sysdeps.c: (_dbus_clearenv): + * dbus/dbus-sysdeps.h: + Add a wrapper for clearenv. + +2007-07-24 Richard Hughes <richard@hughsie.com> + + * doc/system-activation.txt: + Add design document for the system activation parts. I'll shortly be + committing many patches that add system activation using a setuid + launcher into CVS, so expect things to be broken for a few hours. + +2007-07-19 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/modules/FindKDEWIN.cmake: fixed comment + * cmake/modules/FindKDEWIN32.cmake: removed obsolate cmake module + +2007-07-18 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c (dbus_message_get_cached) + (dbus_message_cache_or_finalize): don't mess with message from + message cache outside of the cache lock. Bug #9164 from Jonathan + Matthew. + +2007-07-13 Havoc Pennington <hp@redhat.com> + + * Add indent-tabs-mode: nil to all file headers. + +2007-07-12 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps-util.c (_dbus_sysdeps_test): invert the test + for parsing hex as double to be sure it fails to work + + * dbus/dbus-sysdeps.c (_dbus_string_parse_double): don't allow hex numbers. + +2007-07-10 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-connection.c (struct DBusConnection): Fix from Olivier + Hochreutiner to avoid trying to protect individual bits in a word + with different locks (make dispatch_acquired and io_path_acquired + dbus_bool_t rather than bitfields) + +2007-07-09 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c,dbus-sysdeps-win.h,dbus-sysdeps-win-util.c, + dbus-sysdeps-spawn-win.c: synced with windbus sources + +2007-07-07 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c + (_dbus_getsid): remove unused jump label + (_dbus_read_credentials_socket): _dbus_string_init could fail, + check initialisation + (_dbus_get_working_dir, _dbus_init_working_dir): remove unused + functions + +2007-07-04 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/modules/FindKDEWIN.cmake: search in <program files dir>\win32libs + for windows supplementary packages too + +2007-06-30 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/dbus/CMakeLists.txt: handle userdb as unix file + +2007-06-30 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c,dbus/dbus-sysdeps-win.h: removed obsolate + DBusUserInfo code + +2007-06-30 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c (_dbus_daemon_init): reduced compiler warnings + +2007-06-23 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-auth-script.c (_dbus_auth_script_run): added UNIX_ONLY and + WIN_ONLY commands for auth scripts + * test/data/auth/external-root.auth-script: limit execution to unix + +2007-06-21 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-tranport.c (auth_via_default_rules): made the verbose spam + cross-platform + +2007-06-21 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-watch.c (dbus_watch_get_fd): 1) its behavior should + not be the same as before, the ABI has never been declared stable + on Windows and 2) do not commit to cross-platform files without + posting the exact patch to the mailing list + + * dbus/dbus-sysdeps-util.c (_dbus_sysdeps_test): as I have pointed + out before, either 0xff needs to work on both platforms, or none + of the dbus code can rely on it working. That means the options + are 1) audit the code for anywhere that relies on 0xff working, if + none found ideally add a test that it *doesn't* work and make unix + reject it explicitly, but in any case this test would go away or + 2) make it work on Windows also, then we don't have to figure out + whether we rely on it. + + And in either case, post the exact patch to the mailing list and + don't just commit. + +2007-06-21 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/CMakeLists.txt: added VERSION_PATCH to be able to + distinguish win32 binary release from dbus versioning + +2007-06-21 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c: deleted local DBusCredentials structure + (_dbus_getsid): new function + (_dbus_read_credentials_socket): used correct function + (_dbus_append_user_from_current_process, + _dbus_credentials_add_from_current_process): added real + sid reading + (_dbus_credentials_parse_and_add_desired,_dbus_parse_uid): + deleted + +2007-06-21 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-util.c (_dbus_sysdeps_test): don't check + 0xff as floating point, this isn't supported on win32 math + implementation + +2007-06-21 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c (_dbus_homedir_from_username, + _dbus_homedir_from_current_process, _dbus_append_desired_identity): + removed obsolate functions + +2007-06-21 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c, dbus/dbus-sysdeps-util-win.c, + dbus/dbus-sysdeps-win.h: disabled uid/sid conversation stuff + implementation by Peter Kuemmel + +2007-06-21 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-watch.c (dbus_watch_get_fd): this function is + deprecated and its behavior should be as before until all + client code is migrated. + +2007-06-19 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-util-win.c, tools/dbus-launch-win.c: + msvc7.1 fixes by Jaroslaw Staniek tested with mingw + +2007-06-19 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c, dbus/dbus-sysdeps-spawn-win.c, + dbus/dbus-sysdeps-win.h: disabled DBusSocket implementation + by Peter Kuemmel + +2007-06-18 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus-win.patch: removed obsolate patches + +2007-06-18 Havoc Pennington <hp@redhat.com> + + * configure.in: bump version to 1.1.2 so CVS is higher than last + release (this is not the 1.1.2 release) + +2007-06-18 Havoc Pennington <hp@redhat.com> + + * Release 1.1.1 + +2007-06-18 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.xml: document org.freedesktop.DBus.GetId() + + * bus/driver.c (bus_driver_handle_get_id): implement org.freedesktop.DBus.GetId() + + * bus/bus.c (bus_context_new): generate a unique ID for each bus context + + * dbus/dbus-connection.c (dbus_connection_get_server_id): new function + + * dbus/dbus-bus.c (dbus_bus_get_id): new function + + * dbus/dbus-server.c (dbus_server_get_id): new function + +2007-06-18 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps-unix.c (_dbus_read_credentials_socket): clean + this up a little bit, to try and understand why telnet'ing to a + server and sending a non-nul byte didn't disconnect immediately; + now it seems that it does disconnect immediately as it should, + though I don't understand what has changed. + +2007-06-18 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-watch.c (dbus_watch_get_socket) + (dbus_watch_get_unix_fd): new API to match DBusConnection + (dbus_watch_get_fd): deprecate this + + Throughout: just s/dbus_watch_get_fd/dbus_watch_get_socket/g for + now since all the transports use sockets anyway + +2007-06-16 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-macros.h, dbus/dbus-message.c, + dbus/dbus-message.h: renamed DBUS_GNUC_DEPRECATED + to DBUS_DEPRECATED and extended to msvc compiler + +2007-06-15 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/CMakeLists.txt: use local include header first + + * dbus/dbus-sysdeps-win.c: mingw fix of DBusCredential struct + +2007-06-15 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/ConfigureChecks.cmake,cmake/config.h.cmake: + added check for HAVE_ERRNO_H + + * cmake/dbus/CMakeLists.txt: added missing files + + * dbus/dbus-transport-win.c/.h: new files + + * dbus/dbus-sysdeps-win.c,.h: added required _unix functions + to make dbus compilable on win32 + + * dbus/dbus-sysdeps-win-utils.c,.h: moved some functions to + dbus-sysdeps-win.c + + * dbus-win.patch: removed applied or obsolate patches + + Note: dbus-win32 is now compilable, no guarantee that it runs + without any problems + +2007-06-15 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps-unix.c (_dbus_append_session_config_file) + (_dbus_append_system_config_file): new functions + + * bus/main.c (main): use _dbus_append_system_config_file() and + _dbus_append_session_config_file() + + * dbus/Makefile.am (INCLUDES): move DBUS_SYSTEM_CONFIG_FILE and + DBUS_SESSION_CONFIG_FILE into this makefile + +2007-06-15 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps.c (_dbus_set_errno_to_zero) + (_dbus_get_is_errno_nonzero, _dbus_get_is_errno_eintr) + (_dbus_strerror_from_errno): family of functions to abstract + errno, though these are somewhat bogus (really we should make our + socket wrappers not use errno probably - the issue is that any + usage of errno that isn't socket-related probably is not + cross-platform, so should either be in a unix-only file that can + use errno directly, or is a bug - these general errno wrappers + hide issues of this nature in non-socket code, while + socket-specific API changes would not since sockets are allowed + cross-platform) + +2007-06-14 Havoc Pennington <hp@redhat.com> + + * bus/dispatch.c (check_get_connection_unix_process_id): mop up + getpid() (noticed by Peter Kümmel) and adapt the test to + expect a "pid unknown" error when running on Windows. + +2007-06-14 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps-unix.c (_dbus_credentials_parse_and_add_user): + delete this function since it was effectively the same as + _dbus_credentials_add_from_username() + +2007-06-14 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-auth.c: adapt to keyring changes + + * dbus/dbus-keyring.c: change to avoid using user ID and home + directory directly; instead use a + keyring-location-from-credentials function in dbus-sysdeps + + * fix to use _dbus_append_user_from_current_process() instead of + _dbus_username_from_current_process() or _dbus_append_desired_identity(). + +2007-06-14 Ralf Habacker <ralf.habacker@freenet.de> + + * reverted global rename of function _dbus_username_from_current_process. + It needs too much tests to verify that the change does not break anything. + I had overseen that the signatures are different and requires non + trivial changes. + This is one *major* disadvantage of emulating oop functionality with c. + You are responsible for cleaning every object on every function return point + which could be a nightmare if you are not working with dbus all the days. + +2007-06-14 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-auth.c (handle_client_initial_response_cookie_sha1_mech): + fixed usage of _dbus_append_desired_identity() + + * dbus/dbus-sysdeps.h (_dbus_username_from_current_process): removed prototype + +2007-06-14 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps.c: moved global lock system_users from dbus-userdb.c + +2007-06-14 Ralf Habacker <ralf.habacker@freenet.de> + + * global rename of function _dbus_username_from_current_process + to _dbus_append_desired_identity. + Approved by Havoc Pennington + +2007-06-14 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c: disabled DBusUserInfo related code + (_dbus_append_desired_identity, _dbus_windows_user_is_process_owner): + new win32 functions as counterpart of unix related + (_dbus_send_credentials_socket,_dbus_read_credentials_socket): + renamed from ..._unix_socket + (_dbus_send_credentials_unix_socket): removed obsolate function + + * dbus/dbus-sysdeps-win-util.c: disabled DBusGroupInfo related code + (_dbus_verify_daemon_user,_dbus_change_to_daemon_user): + new win32 functions as counterpart of unix related + +2007-06-14 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * doc/dbus-specification.xml: say the protocol version is 1 instead of + 0 (patch from Kristoffer Lundén, fd.o#10033) and remove the FIXME + about removing protocol version from messages (as per Havoc's comment + on that bug) + +2007-06-14 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c (_dbus_pid_for_log,_dbus_flush_caches): + new win32 functions as counterpart of unix related + +2007-06-14 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/modules/FindKDEWIN.cmake, + cmake/modules/FindKDEWIN_Packager.cmake, + cmake/modules/Win32Macros.cmake: new files from the + kdewin32 project + * cmake/CMakeLists.txt: cleaned support for kdewin installer and + win32 explorer wrapper + +2007-06-13 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c (dbus_message_iter_open_container): Fix + broken return_if_fail (kind of scary that test suite does not + cover this) + +2007-06-13 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-server-socket.c (_dbus_server_listen_socket): support + all_interfaces=true|false for tcp servers + + * dbus/dbus-sysdeps-unix.c (_dbus_listen_tcp_socket): support + inaddr_any flag + + * bus/selinux.c: fix some missing includes + + * dbus/dbus-server-socket.c (_dbus_server_listen_socket): allow + port to simply be omitted in addition to specifying 0 + +2007-06-13 Havoc Pennington <hp@redhat.com> + + * configure.ac, bus/selinux.c, dbus/dbus-sysdeps-unix-util.c: add + libaudit support, no clue what this means really but now we have + it. Patches from Fedora package. + + * bus/bus.c (bus_context_new): move selinux initialization after + changing to daemon user, patch from Fedora package + + * dbus/dbus-transport.c (auth_via_unix_user_function): fix a typo + +2007-06-12 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c (dbus_message_iter_open_container): improve + the checks/warnings for contained_signature a bit + +2007-06-12 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-marshal-recursive.c (write_or_verify_typecode): + improve the warning a bit if you write extra data into a message + +2007-06-12 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-auth.c (sha1_handle_second_client_response) + (handle_server_data_anonymous_mech): add the process ID from + socket credentials, if available, even if not using EXTERNAL + + * dbus/dbus-transport.c (auth_via_default_rules): support + allow_anonymous flag + + * dbus/dbus-connection.c (dbus_connection_get_is_anonymous) + (dbus_connection_set_allow_anonymous): new API for controlling + anonymous access + +2007-06-09 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-string.c (_dbus_string_pop_line): fix this not to + think an empty line is the end of the file. + Also, fix some whitespace. + + * dbus/dbus-string-util.c: add more tests for + _dbus_string_pop_line() revealing that it thinks an empty line is + the end of the file, which broke dbus-auth-script.c so + it didn't really run the scripts + + * dbus/dbus-auth.c: add ANONYMOUS mechanism + + * dbus/dbus-auth-script.c (_dbus_auth_script_run): fix to detect + an empty/no-op auth script; add commands to check that we have or + don't have the expected credentials + +2007-06-09 Havoc Pennington <hp@redhat.com> + + * bus/policy.c (bus_policy_create_client_policy): gracefully + continue if the connection has no unix user - just don't apply + any unix user dependent rules. + + * bus/config-parser.c: remove dbus-userdb.h usage + + * bus/bus.c: remove dbus-userdb.h usage + + * dbus/dbus-transport.c (_dbus_transport_get_is_authenticated): + support Windows user function; also, fix the logic for checking + auth as root in the default auth code (broken in the previous + commit) + + * dbus/dbus-connection.c + (dbus_connection_set_windows_user_function): new function + (dbus_connection_get_windows_user): new function + +2007-06-09 Havoc Pennington <hp@redhat.com> + + * bus/dispatch.c (check_get_connection_unix_process_id): adapt + since sysdeps-unix.h stuff isn't included anymore + + * bus/bus.c (bus_context_new): use more abstract functions to + change user, so they can be no-ops on Windows + + * dbus/dbus-credentials.c, dbus/dbus-credentials.h, + dbus/dbus-credentials-util.c: new files containing a fully opaque + DBusCredentials data type to replace the old not opaque one. + + * configure.in (DBUS_UNIX): define DBUS_UNIX to match DBUS_WIN on + windows + + * dbus/dbus-userdb.h: prohibit on Windows, next step is to clean + up the uses of it in bus/*.c and factor out the parts of + cookie auth that depend on it + +2007-06-07 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-message.c: improve some docs related to reading values + from a message iter + +2007-06-02 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake: added cygwin compile support + +2007-06-01 Ralf Habacker <ralf.habacker@freenet.de> + + * tools/dbus-launch-win.c: new file, replaces script wrapper on win32. + + * cmake/dbus-launch.bat.cmake: removed obsolate file + +2007-05-31 Ralf Habacker <ralf.habacker@freenet.de> + + * bus/main.c (main): uses _dbus_get_config_file_name() to detect + session.conf location on win32. + + * dbus-sysdeps-win.h (_dbus_get_config_file_name,_dbus_file_exists): + new prototyp, undefined interface after including windows.h because + it makes trouble when a paramater is named interface. + + * dbus-sysdeps-win.c (_dbus_get_install_root, + _dbus_get_config_file_name,_dbus_file_exists): new functions. + +2007-05-27 Ralf Habacker <ralf.habacker@freenet.de> + + * bus/policy.c,dbus/dbus-internals.c: fixed inconsistant line endings + as reported by Peter Kümmel. + +2007-05-25 John (J5) Palmieri <johnp@redhat.com> + + * Released 1.1.0 + +2007-05-25 John (J5) Palmieri <johnp@redhat.com> + + * Split NEWS and ChangeLog into a .pre-1-0 file as per HACKING + We forgot to do this during the 1.0 release and it makes sense + now as we get ready to release the first 1.1.0 development tarball + +2007-05-25 John (J5) Palmieri <johnp@redhat.com> + + * create directory test/data/valid-config-files/session.d so that + make check passes + +2007-05-25 John (J5) Palmieri <johnp@redhat.com> + + * INSTALL: remove dependancies for bindings since they no longer + are a part of core + +2007-05-25 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-server-win.c,dbus/dbus-server-win.h: new file + with empty function _dbus_server_listen_platform_specific(). + + * dbus/dbus-server.c (listen_funcs): uses + _dbus_server_listen_platform_specific on any platform. + +2007-05-25 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c (fill_win_user_info_homedir): not getting + user info from a domain controller isn't an error, the computer + may run in a non domain context. + +2007-05-25 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c (_dbus_full_duplex_pipe): fixed assertation. + +2007-05-24 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * bus/config-parser.c (test_service_dir_matches): fixed ordering for unix. + + * bus/config-parser.c (test_default_session_servicedirs): made allocation + of _progs platform independent. + +2007-05-23 Havoc Pennington <hp@redhat.com> + + * bus/Makefile.am (install-data-hook): create session.d + + * bus/session.conf.in: add session.d for the session bus, so + security policy can be extended + +2007-05-22 Ralf.Habacker <ralf.habacker@freenet.de> + + * cmake/CMakeLists.txt: fixed creating of TEST_..._BINARY to make + bus-test able to find the binaries. + +2007-05-21 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * acinclude.m4, configure.in: In recent autotools, ${datadir} is + defined in terms of ${datarootdir}, so EXPANDED_DATADIR needs to be + expanded recursively. Rather than fixing configure.in to do this, I + grabbed the AS_AC_EXPAND macro from autostars.sf.net, which seems to be + commonly used. + +2007-05-21 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * update-dbus-docs.sh: Assorted improvements: + - Default user if $FDUSER is not set is the ssh default + (set in ~/.ssh/config or based on the local username), not a + hard-coded "johnp" + - Temporary checkout directory is created securely (preventing symlink + attacks), if mktemp(1) is available + - Use make -C rather than cd && make && cd .. + +2007-05-21 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * HACKING: Point to correct mailing list + +2007-05-21 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * doc/dbus-specification.xml: explicitly specify that STRING cannot + contain embedded NULs. + +2007-05-20 Ralf.Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-internal.c: fix inline problem on win32. + +2007-05-20 Ralf.Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c (fill_win_user_info_homedir): not reaching + domain controller isn't an error, converted error message to verbose + message. + +2007-05-19 Ralf.Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-test.c (dbus_internal_do_not_use_run_tests): disabled + tests not running on wince. + +2007-05-19 Ralf.Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-internals.c (_dbus_verbose_init): win32 requires 'varname=' + to unset a environment variable. + +2007-05-19 Ralf.Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps.c (_dbus_setenv): win32 requires 'varname=' + to unset a environment variable. + +2007-05-19 Ralf.Habacker <ralf.habacker@freenet.de> + + * bus/policy.c (bus_policy_create_client_policy): + win32 temporary fix until the userdb stuff is ported completly. + +2007-05-19 Ralf.Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-server.c (listen_funcs): + _dbus_server_listen_platform_specific is empty on win32, + limited to unix only. + + * dbus/dbus-server.c (valid_addresses): limit unix + only addresses to unix. + +2007-05-18 Havoc Pennington <hp@redhat.com> + + * doc/dbus-specification.xml: add a GetAll to the Properties + interface. + +2007-05-17 Ralf.Habacker <ralf.habacker@freenet.de> + + * bus\config-parser.c (test_default_session_servicedirs): + win32 fix. + +2007-05-17 Ralf.Habacker <ralf.habacker@freenet.de> + + * configure.in: define constant DBUS_UNIX. + +2007-05-14 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c (_dbus_printf_string_upper_bound): + compile fix for MS Platform SDK 6 + patch from Michael Luschas <mluschas@gmail.com> + +2007-05-10 John (J5) Palmieri <johnp@redhat.com> + + * dbus-1.pc.in: add daemondir to pc file + patch from Brian Cameron <brian.cameron at sun.com> + +2007-05-04 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * doc/dbus-specification.xml: mention the reserved o.fd.DBus.Local + interface and the corresponding /o/fd/DBus/Local object path; + describe them as reserved and forbid using them in a sent message, + mentioning that in the reference implementation this will cause the + connection to be dropped. Patch approved by Havoc. + +2007-04-28 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/: don't install test applications and service files, + moved CMAKE_DEBUG_POSTFIX to top level CMakeLists.txt + +2007-04-27 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-sysdeps-unix.c (_dbus_open_socket): fix #10781 from + Tobias Nygren, checking pointer to fd vs. 0 rather than checking + the fd itself + +2007-04-26 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/: added debug postfixes to debug exe's for + easier debugging. + * dbus\dbus-sysdeps-win.c (_dbus_win_set_error_from_win_error): + print error code in case no string message is available. + +2007-04-06 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * dbus/dbus-message-util.c, dbus/dbus-message.c, + dbus/dbus-message.h: Add API to convert a DBusMessage to/from a + byte array. Patch from Dafydd Harries <dafydd.harries@collabora.co.uk>, + approved by Havoc Pennington. + +2007-04-03 Timo Hoenig <thoenig@suse.de> + + * dbus/dbus-address.c (dbus_parse_address): Do not accept zero- + length address. + * dbus/dbus-address.c (_dbus_address_test): Add test for zero- + length address. + +2007-03-25 Ralf.Habacker <ralf.habacker@freenet.de> + + * cmake/dbus/CMakeLists.txt: debug postfix also for mingw. + +2007-03-16 Ralf.Habacker <ralf.habacker@freenet.de> + + * cmake/modules/FindExpat.cmake: fix package detection on win32. + + * README.win: update install instructions. + +2007-03-16 Ralf.Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps.h (_dbus_split_paths_and_append): + new prototyp + (_DBUS_PATH_SEPARATOR): new macro. + + * dbus/dbus-sysdeps.c (_dbus_split_paths_and_append): merged + from dbus/dbus-sysdeps-unix.c and dbus/dbus-sysdeps-win.c. + +2007-03-15 Ralf.Habacker <ralf.habacker@freenet.de> + + * bus/config-parser.c, bus/policy.c, + bus/policy.h, bus/dbus-daemon.1.in, + bus/session.conf.in: added eavesdrop support + for replies - patch by olli.salli at collabora.co.uk + approved by Havoc Pennington. + +2007-03-15 Ralf.Habacker <ralf.habacker@freenet.de> + + * dbus\dbus-sysdeps-win-thread.c: renamed to + dbus-sysdeps-thread-win.c, it is a platform depending file + similar to dbus-sysdeps-pthread.c. + +2007-03-15 Ralf.Habacker <ralf.habacker@freenet.de> + + * cmake\doc\CMakeLists.txt: added prelimary xml doc + support, needs cmake Find script. + +2007-03-14 Ralf.Habacker <ralf.habacker@freenet.de> + + * cmake: add doxygen support + +2007-03-14 Ralf.Habacker <ralf.habacker@freenet.de> + + * cmake/config.h.cmake: WINCE fixes, defined DBUS_UNIX. + +2007-03-13 Ralf.Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-util-win.c (dbus_become_daemon): + win32 compile fix. + +2007-03-13 Ralf.Habacker <ralf.habacker@freenet.de> + + * dbus-win.patch: removed obsolate patches. + +2007-03-13 Ralf.Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c: added zero byte sending + and receiving after connection start up + +2007-03-11 Havoc Pennington <hp@redhat.com> + + * tools/dbus-launch.c (do_close_stderr): fix C89 problem and + formatting problem + + * Mostly fix the DBusPipe mess. + - put line break after function return types + - put space before parens + - do not pass structs around by value + - don't use dbus_strerror after calling supposedly cross-platform + api + - don't name pipe variables "fd" + - abstract special fd numbers like -1 and 1 + +2007-03-12 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.h, dbus/dbus-sysdeps-win.c, + dbus/dbus-sysdeps-util-win.c: renamed functions + _dbus_xxx_file() to _dbus_file_xxx() to reflect + struct name DBusFile. + +2007-03-12 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-util-unix.c (_dbus_become_daemon): + fix _dbus_pid_fd check. + +2007-03-10 Ralf Habacker <ralf.habacker@freenet.de> + + * tools/dbus-print-message.c (print_message): + added printing of the reply serial to method returns and + errors, so you can actually figure out the message/reply + pairs - patch by olli.salli at collabora.co.uk. + +2007-03-10 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus-win.patch: removed committed patches. + +2007-03-10 Ralf Habacker <ralf.habacker@freenet.de> + + * bus/bus.c, bus/bus.h, bus/main.c, bus/test.c, + dbus/dbus-sysdeps-unix.c, dbus/dbus-sysdeps-util-unix.c, + dbus/dbus-sysdeps-util-win.c, dbus/dbus-sysdeps-win.c, + dbus/dbus-sysdeps.h: renamed _dbus_xxx_pipe to _dbus_pipe_xxx, + completed _dbus_pipe support. + +2007-03-10 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps.h (_dbus_listen_tcp_socket): + changed type or port to pointer, because the port is given back. + + * dbus/dbus-server-socket.c (_dbus_server_new_for_tcp_socket): + implemented returning tcp port. Skipping port parameter + and non integer port values in config <listen> statement + needs more effort. + + * dbus/dbus-sysdeps-unix.c, dbus/dbus-sysdeps-win.c + (_dbus_listen_tcp_socket): return the real used tcp port. + + * bus/dbus-daemon.1.in: added <listen> tcp examples + +2007-03-09 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/config.h.cmake: win32 msvc bug fix + +2007-03-09 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/config.h.cmake: fixed DBUS_WINxx defines, + using _WINCE does not work. + +2007-03-08 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus-win.patch: removed _dbus_write_pipe() patch, it is now + committed. + +2007-03-08 Ralf Habacker <ralf.habacker@freenet.de> + + * bus/bus.c, dbus/dbus-sysdeps-unix.c, dbus/dbus-sysdeps.h: + rename pipe related write() function calls to _dbus_write_pipe(). + +2007-03-08 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus-win.patch: added bus/config-loader-libexpat.c patch, + uses DBUS_WIN for alls win32 related #ifdefs, + some minor cleanups + +2007-03-08 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus-win.patch: updated patch for bus/dispatch.c. + +2007-03-08 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus-win.patch: dbus-connection.c (dbus_connection_get_unix_user, + dbus_connection_get_unix_process_id): Let return them valid user id's, + otherwise bus-test fails. How to replace on win32 ?. + + * dbus/dbus-sysdeps-win.c (fill_win_user_info_homedir): + fix memory leak. + +2007-03-08 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win.c (_dbus_win_set_error_from_win_error): + use dbus friendly error name. + (fill_win_user_info_homedir): print user name in error case too. + +2007-03-08 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/ConfigureChecks.cmake: fixed socketpair check + +2007-03-08 Ralf Habacker <ralf.habacker@freenet.de> + + * bus/dispatch.c: disabled segfault test on win32 for now + +2007-03-08 Ralf Habacker <ralf.habacker@freenet.de> + + * configure.in, cmake/ConfigureChecks.cmake: added check + for setrlimit. + * test/test-segfault.c: only include setrlimit stuff only + when available. + +2007-03-07 Ralf Habacker <ralf.habacker@freenet.de> + + * test/test-segfault.c: unix compile fix. + * dbus-win.patch: removed obsolate patches. + +2007-03-07 Ralf Habacker <ralf.habacker@freenet.de> + + * bus/activation.c: removed obsolate include header. + * test/test-segfault.c: win32 compile fix, rlimit + isn't available on win32. + * dbus-win.patch: removed some more patches, they + are applied or obsolate + +2007-03-06 Ralf Habacker <ralf.habacker@freenet.de> + + * bus-win.patch: fixes unix listen problems, dbus-test + now runs. + +2007-03-06 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake/dbus/CMakeLists.txt,cmake/bus/CMakeLists.txt, + cmake/CMakeLists.txt: win32 compile fix + +2007-03-04 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus-win.patch, README.win: added available win32 + patches from windbus project (http://sf.net/projects/windbus) + +2007-03-04 Ralf Habacker <ralf.habacker@freenet.de> + + * bus/activation.c: (bus_activation_activate_service): + fixed call to _dbus_spawn_async_with_babysitter(). + +2007-03-04 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-spawn.c,dbus/dbus-spawn.h (_dbus_spawn_async_with_babysitter): + added environment pointer as function parameter, used on win32. + + * test/spawn-test.c: fixed call to above mentioned function. + +2007-03-04 Ralf Habacker <ralf.habacker@freenet.de> + + * configure.in,test/test-sleep-forever.c,test/test-names.c: + added configure check for unistd.h. + +2007-03-04 Ralf Habacker <ralf.habacker@freenet.de> + + * test/Makefile.am: fixed test data copy problem in + out of source build, when sources came from svn or cvs. + +2007-03-03 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/*-win.*,bus/*-win.*: added win32 platform related + files. These files are only added to the cmake build system. + The missing dbus-win.patch file will be added later. + +2007-03-03 Ralf Habacker <ralf.habacker@freenet.de> + + * cmake: new directory, contains cmake build support. + See http://www.cmake.org for more informations. + Currently only unix will be buildable because some + win32 required files are still missing. + +2007-03-03 Thiago Macieira <thiago@kde.org> + + * dbus/dbus-sysdeps-unix.c: capture the dbus-launch stderr + output and add it to the DBusError message we return. + + * tools/dbus-launch.1: + * tools/dbus-launch.c: Add option --close-stderr to, well, + close stderr before starting dbus-daemon. + +2007-01-31 Havoc Pennington <hp@redhat.com> + + * bus/dbus-daemon.1.in: write a section in the man page on running + a test daemon for debugging purposes + +2007-01-26 Havoc Pennington <hp@redhat.com> + + * bus/session.conf.in: override all the default limits with much + higher limits on the session bus, there is no reason the session + bus should have low limits + + * bus/config-parser.c (bus_config_parser_new): increase default + limits so they are less likely to be hit; in particular the max + replies per connection was way too low + +2006-01-25 Simon McVittie <simon.mcvittie@collabora.co.uk> + + * doc/dbus-tutorial.xml: Replace Python section of tutorial with + a pointer to the tutorial maintained as part of dbus-python + +2006-12-31 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-unix.c: unix compile fix, moved + atomic_exchange_and_add() from dbus/dbus-sysdeps.c + to here, it's used by _dbus_atomic_inc() and _dbus_atomic_dec(). + +2006-12-31 Ralf Habacker <ralf.habacker@freenet.de> + + * tools/dbus-monitor.c: gettimeofday() is not available + on windows so we have to provide our own. It's taken from + lgpl'd kdewin32 package. - Patches from Christian Ehrlicher + +2006-12-31 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-unix.c: moved _dbus_atomic_inc/dec() + from dbus/dbus-sysdeps.c, windows version of _dbus_atomic_inc/dec() + is in dbus-sysdeps-win.c (not in this patch). + + * dbus/dbus-sysdeps.h: DBusAtomic::value is long on windows to fit + with InterlockedInc/Decrement. + - Patches from Christian Ehrlicher + +2006-12-31 Ralf Habacker <ralf.habacker@freenet.de> + + * tools/dbus-send.c, tools/dbus-monitor.c: win32 compile fix. + +2006-12-31 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-marshal-recursive.c (type DBusTypeReaderClass): + fix mispaced const statement. - Patch from Peter Kümmel + +2006-12-19 Ray Strode <rstrode@redhat.com> + + * bus/bus.c (process_config_every_time): + don't overwrite existing bus context activation object + until after we've checked that the new activation is + valid. + + * bus/main.c + (signal_handler), (handle_reload_watch): + don't call exit() on failure, instead make do and keep + going. + (close_reload_pipe): new function to turn off + hangup-causes-config-reload behavior if an unexpected + error occurs + +2006-12-13 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-sysdeps-win-thread.c (_dbus_condvar_wait_win32): + correctness fix. - Patch from Christian Ehrlicher + +2006-12-13 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-internals.h: msvc also knows about __FUNCTION__, + we should also use it. - Patch from Christian Ehrlicher + +2006-12-13 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus-sysdeps-util.c: added win32 related tests + +2006-12-12 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-string.c (_dbus_string_pop_line), + bus/desktop-file.c (parse_section_start, + parse_comment_or_blank,parse_key_value,): uses + _dbus_string_find_eol() to support platform independent eol style. + +2006-12-12 Ralf Habacker <ralf.habacker@freenet.de> + + * dbus/dbus-string.[ch] (_dbus_string_find_eol): new function. + * dbus/dbus-string-util.c (_dbus_string_test): added testcases for + _dbus_string_find_eol(). + Approved by: Havoc Pennington. + +2006-12-12 Tim Dijkstra <tim@famdijkstra.org> + + * configure.in: Added switch to disable user_database caching. + + * dbus/dbus-userdb-util.c, dbus/dbus-userdb.c: Add ifdefs to + be able disable user_dabase caching. + +2006-12-12 Tim Dijkstra <tim@famdijkstra.org> + + * bus/bus.c, bus/bus.h: Remove DBusUserDatabase from the BusContext + struct. It is unnecessary we have a global one already. Also remove + bus_context_get_user_database function, it is no longer needed. + Flush the global database on reload. + + * dbus/dbus-userdb-util.c: Replace _dbus_user_database_get_groups + with _dbus_groups_from_uid. It no longer needs a DBusUserDatabase. + + * dbus/dbus-userdb.c, dbus/dbus-userdb.h: + Add _dbus_user_database_flush_system. + Make more functions DBUS_USERDB_INCLUDES_PRIVATE. + Small unrelated change in _dbus_is_a_number: change + _dbus_string_parse_int to _dbus_string_parse_uint. + + * bus/connection.c: Change call to _dbus_user_database_get_groups to + _dbus_groups_from_uid. + + * bus/policy.c, bus/policy.h: Change call to + _dbus_user_database_get_groups to _dbus_groups_from_uid. Remove + DBusUserDatabase from bus_policy_allow_user prototype, it no longer + needs it. + +2006-12-12 John (J5) Palmieri <johnp@redhat.com> + + * bus/signal.c: Fix match_rule_equal errata + (CVE-2006-6107 - Patch from Kimmo Hämäläinen + <kimmo.hamalainen@nokia.com>) + +2006-11-19 Thiago Macieira <thiago@kde.org> + + * dbus/dbus-sysdeps-pthread.c (_dbus_pthread_mutex_lock, + _dbus_pthread_condvar_wait, + _dbus_pthread_condvar_wait_timeout): set pmutex->holder to + pthread_self() after coming back from a conditional variable + wait as well as in one codepath where it was forgotten. + Approved by: Havoc Pennington. + +2006-11-17 Havoc Pennington <hp@redhat.com> + + * update-dbus-docs.sh: allow setting fd.org username via env + variable. Make it run autogen with --enable-xml-docs=yes + --enable-doxygen-docs=yes so configure will fail if the required + tools are missing. + +2006-11-17 Havoc Pennington <hp@redhat.com> + + * doc/dbus-faq.xml: minor FAQ tweaks + +2006-11-14 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-misc.c, dbus/dbus-misc.h: Move + dbus_get_local_machine_id() to its own file, no substantive + changes. There are a couple other things we might want to add that + are "misc" so moving out of dbus-connection.[hc] which is big + enough already. + +2006-11-14 Havoc Pennington <hp@redhat.com> + + * dbus/dbus-internals.c (_dbus_generate_uuid): The spec said the + UUID had the timestamp last, but the implementation had it first; + move it to last since I think it's a tiny bit nicer (easier to + compare at a glance, faster to sort, less code), and will not + cause any practical compatibility problems. Also, always convert + the timestamp to big endian. + + * doc/dbus-specification.xml: Clean up the docs on the UUID. + + * tools/dbus-uuidgen.1: more prominently say it is not suitable + as a replacement for regular uuidgen/RFC4122. + +2006-11-14 John (J5) Palmieri <johnp@redhat.com> + + * dbus/dbus-threads.h: fix DBUS_THREAD_FUNCTIONS_ALL_MASK to have + the correct value so we don't assert when initalizing recursive threads + + * test/name-test/test-thread-init.c: call dbus_threads_init_default + instead of _dbus_threads_init_debug since it is more of a real world + test +
diff --git a/CleanSpec.mk b/CleanSpec.mk new file mode 100644 index 0000000..b84e1b6 --- /dev/null +++ b/CleanSpec.mk
@@ -0,0 +1,49 @@ +# Copyright (C) 2007 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# If you don't need to do a full clean build but would like to touch +# a file or delete some intermediate files, add a clean step to the end +# of the list. These steps will only be run once, if they haven't been +# run before. +# +# E.g.: +# $(call add-clean-step, touch -c external/sqlite/sqlite3.h) +# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) +# +# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with +# files that are missing or have been moved. +# +# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. +# Use $(OUT_DIR) to refer to the "out" directory. +# +# If you need to re-do something that's already mentioned, just copy +# the command and add it to the bottom of the list. E.g., if a change +# that you made last week required touching a file and a change you +# made today requires touching the same file, just copy the old +# touch step and add it to the end of the list. +# +# ************************************************ +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST +# ************************************************ + +# For example: +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) +#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) +#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) + +# ************************************************ +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST +# ************************************************
diff --git a/Doxyfile.in b/Doxyfile.in new file mode 100644 index 0000000..f0a37ed --- /dev/null +++ b/Doxyfile.in
@@ -0,0 +1,180 @@ +# Doxyfile 0.1 + +#--------------------------------------------------------------------------- +# General configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = D-Bus +PROJECT_NUMBER = @VERSION@ +OUTPUT_DIRECTORY = doc/api +OUTPUT_LANGUAGE = English +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_STATIC = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ALWAYS_DETAILED_SEC = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +INTERNAL_DOCS = NO +STRIP_CODE_COMMENTS = YES +CASE_SENSE_NAMES = YES +SHORT_NAMES = NO +HIDE_SCOPE_NAMES = NO +VERBATIM_HEADERS = YES +SHOW_INCLUDE_FILES = YES +JAVADOC_AUTOBRIEF = YES +INHERIT_DOCS = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +DISTRIBUTE_GROUP_DOC = NO +TAB_SIZE = 8 +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +ALIASES = +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +OPTIMIZE_OUTPUT_FOR_C = YES +SHOW_USED_FILES = YES +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = YES +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_FORMAT = +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = @top_srcdir@/dbus +FILE_PATTERNS = *.c *.h +RECURSIVE = YES +#EXCLUDE = test + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. + +EXCLUDE_PATTERNS = Makefile.* ChangeLog CHANGES CHANGES.* README \ + README.* *.png AUTHORS DESIGN DESIGN.* *.desktop \ + DESKTOP* COMMENTS HOWTO magic NOTES TODO THANKS + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = NO +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = YES +MAN_OUTPUT = man +MAN_EXTENSION = .3dbus +MAN_LINKS = YES +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = YES +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = YES +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = "DBUS_BEGIN_DECLS=" \ + "DBUS_END_DECLS=" \ + "DOXYGEN_SHOULD_SKIP_THIS" \ + "DBUS_GNUC_DEPRECATED=" \ + "_DBUS_GNUC_PRINTF(from,to)=" +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::addtions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +PERL_PATH = +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +TEMPLATE_RELATIONS = YES +HIDE_UNDOC_RELATIONS = YES +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +GRAPHICAL_HIERARCHY = YES +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 640 +MAX_DOT_GRAPH_HEIGHT = 1024 +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::addtions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO
diff --git a/HACKING b/HACKING new file mode 100644 index 0000000..2fed9e6 --- /dev/null +++ b/HACKING
@@ -0,0 +1,356 @@ +The guidelines in this file are the ideals; it's better to send a +not-fully-following-guidelines patch than no patch at all, though. We +can always polish it up. + +Mailing list +=== + +The D-Bus mailing list is dbus@lists.freedesktop.org; discussion +of patches, etc. should go there. + +Security +=== + +If you find a security vulnerability that is not known to the public, +please report it privately to dbus-security@lists.freedesktop.org +or by reporting a freedesktop.org bug that is marked as +restricted to the "D-BUS security group". + +Most of D-Bus is security sensitive. Guidelines related to that: + + - avoid memcpy(), sprintf(), strlen(), snprintf, strlcat(), + strstr(), strtok(), or any of this stuff. Use DBusString. + If DBusString doesn't have the feature you need, add it + to DBusString. + + There are some exceptions, for example + if your strings are just used to index a hash table + and you don't do any parsing/modification of them, perhaps + DBusString is wasteful and wouldn't help much. But definitely + if you're doing any parsing, reallocation, etc. use DBusString. + + - do not include system headers outside of dbus-memory.c, + dbus-sysdeps.c, and other places where they are already + included. This gives us one place to audit all external + dependencies on features in libc, etc. + + - do not use libc features that are "complicated" + and may contain security holes. For example, you probably shouldn't + try to use regcomp() to compile an untrusted regular expression. + Regular expressions are just too complicated, and there are many + different libc's out there. + + - we need to design the message bus daemon (and any similar features) + to use limited privileges, run in a chroot jail, and so on. + +http://vsftpd.beasts.org/ has other good security suggestions. + +Coding Style +=== + + - The C library uses GNU coding conventions, with GLib-like + extensions (e.g. lining up function arguments). The + Qt wrapper uses KDE coding conventions. + + - Write docs for all non-static functions and structs and so on. try + "doxygen Doxyfile" prior to commit and be sure there are no + warnings printed. + + - All external interfaces (network protocols, file formats, etc.) + should have documented specifications sufficient to allow an + alternative implementation to be written. Our implementation should + be strict about specification compliance (should not for example + heuristically parse a file and accept not-well-formed + data). Avoiding heuristics is also important for security reasons; + if it looks funny, ignore it (or exit, or disconnect). + +Development +=== + +D-Bus uses Git as its version control system. The main repository is +hosted at git.freedesktop.org/dbus/dbus. To clone D-Bus, execute the +following command: + + git clone git://git.freedesktop.org/dbus/dbus +OR + git clone git.freedesktop.org:dbus/dbus + +The latter form is the one that allows pushing, but it also requires +an SSH account on the server. The former form allows anonymous +checkouts. + +D-Bus development happens in two branches in parallel: the current +stable branch, with an even minor number (like 1.0, 1.2 and 1.4), and +the next development branch, with the next odd number. + +The stable branch is named after the version number itself (dbus-1.2, +dbus-1.4), whereas the development branch is simply known as "master". + +When making a change to D-Bus, do the following: + + - check out the earliest branch of D-Bus that makes sense to have + your change in. If it's a bugfix, it's normally the current stable + branch; if it's a feature, it's normally the "master" branch. If + you have an important security fix, you may want to apply to older + branches too. + + - for large changes: + if you're developing a new, large feature, it's recommended + to create a new branch and do your development there. Publish + your branch at a suitable place and ask others to help you + develop and test it. Once your feature is considered finalised, + you may merge it into the "master" branch. + +- for small changes: + . make your change to the source code + . execute tests to guarantee that you're not introducing a + regression. For that, execute: make check + (if possible, add a new test to check the fix you're + introducing) + . commit your change using "git commit" + in the commit message, write a short sentence describing what + you did in the first line. Then write a longer description in + the next paragraph(s). + . repeat the previous steps if necessary to have multiple commits + + - extract your patches and send to the D-Bus mailing list for + review or post them to the D-Bus Bugzilla, attaching them to a bug + report. To extract the patches, execute: + git format-patch origin/master + + - once your code has been reviewed, you may push it to the Git + server: + git push origin my-branch:remote + OR + git push origin dbus-X.Y + OR + git push origin master + (consult the Git manual to know which command applies) + + - (Optional) if you've not worked on "master", merge your changes to + that branch. If you've worked on an earlier branch than the current + stable, merge your changes upwards towards the stable branch, then + from there into "master". + + . execute: git checkout master + . ensure that you have the latest "master" from the server, update + if you don't + . execute: git merge dbus-X.Y + . if you have any conflicts, resolve them, git add the conflicted + files and then git commit + . push the "master" branch to the server as well + + Executing this merge is recommended, but not necessary for all + changes. You should do this step if your bugfix is critical for the + development in "master", or if you suspect that conflicts will arise + (you're usually the best person to resolve conflicts introduced by + your own code), or if it has been too long since the last merge. + + +Making a release +=== + +To make a release of D-Bus, do the following: + + - check out a fresh copy from Git + + - verify that the libtool versioning/library soname is + changed if it needs to be, or not changed if not + + - update the file NEWS based on the git history + + - verify that the version number of dbus-specification.xml is + changed if it needs to be; if changes have been made, update the + release date in that file + + - update the AUTHORS file with "make update-authors" if necessary + + - the version number should have major.minor.micro, even + if micro is 0, i.e. "1.0.0" and "1.2.0" not "1.0"/"1.2"; the micro + version should be even for releases, and odd for intermediate snapshots + + - "make distcheck" (DO NOT just "make dist" - pass the check!) + + - if make distcheck fails, fix it. + + - once distcheck succeeds, "git commit -a". This is the version + of the tree that corresponds exactly to the released tarball. + + - tag the tree with "git tag -s -m 'Released X.Y.Z' dbus-X.Y.Z" + where X.Y.Z is the version of the release. If you can't sign + then simply created an unsigned annotated tag: + "git tag -a -m 'Released X.Y.Z' dbus-X.Y.Z". + + - bump the version number up in configure.ac (so the micro version is odd), + and commit it. Make sure you do this *after* tagging the previous + release! The idea is that git has a newer version number + than anything released. Similarly, bump the version number of + dbus-specification.xml and set the release date to "(not finalized)". + + - merge the branch you've released to the chronologically-later + branch (usually "master"). You'll probably have to fix a merge + conflict in configure.ac (the version number). + + - push your changes and the tag to the central repository with + git push origin master dbus-X.Y dbus-X.Y.Z + + - scp your tarball to freedesktop.org server and copy it to + dbus.freedesktop.org:/srv/dbus.freedesktop.org/www/releases/dbus/dbus-X.Y.Z.tar.gz. + This should be possible if you're in group "dbus" + + - Update the online documentation with `make -C doc maintainer-upload-docs`. + + - update the wiki page http://www.freedesktop.org/Software/dbus by + adding the new release under the Download heading. Then, cut the + link and changelog for the previous that was there. + + - update the wiki page + http://www.freedesktop.org/Software/DbusReleaseArchive pasting the + previous release. Note that bullet points for each of the changelog + items must be indented three more spaces to conform to the + formatting of the other releases there. + + - post to dbus@lists.freedesktop.org announcing the release. + + +Making a ".0" stable release +=== + +We create a branch for each stable release. The branch name should be +dbus-X.Y which is a branch that has releases versioned X.Y.Z; +changes on a stable branch should be limited to significant bug fixes. + +Because we won't make minor changes like keeping up with the latest +deprecations on a stable branch, stable branches should turn off the +gcc warning for deprecated declarations (e.g. see commit 4ebb275ab7). + +Be extra-careful not to merge master (or any branch based on master) into a +stable branch. + +To branch: + git branch dbus-X.Y +and upload the branch tag to the server: + git push origin dbus-X.Y + +To develop in this branch: + git checkout dbus-X.Y + +Environment variables +=== + +These are the environment variables that are used by the D-Bus client library + +DBUS_VERBOSE=1 +Turns on printing verbose messages. This only works if D-Bus has been +compiled with --enable-verbose-mode + +DBUS_MALLOC_FAIL_NTH=n +Can be set to a number, causing every nth call to dbus_alloc or +dbus_realloc to fail. This only works if D-Bus has been compiled with +--enable-tests. + +DBUS_MALLOC_FAIL_GREATER_THAN=n +Can be set to a number, causing every call to dbus_alloc or +dbus_realloc to fail if the number of bytes to be allocated is greater +than the specified number. This only works if D-Bus has been compiled with +--enable-tests. + +DBUS_TEST_MALLOC_FAILURES=n +Many of the D-Bus tests will run over and over, once for each malloc +involved in the test. Each run will fail a different malloc, plus some +number of mallocs following that malloc (because a fair number of bugs +only happen if two or more mallocs fail in a row, e.g. error recovery +that itself involves malloc). This env variable sets the number of +mallocs to fail. +Here's why you care: If set to 0, then the malloc checking is skipped, +which makes the test suite a heck of a lot faster. Just run with this +env variable unset before you commit. + +Tests +=== + +These are the test programs that are built if dbus is compiled using +--enable-tests. + +dbus/test-dbus +This is the main unit test program that tests all aspects of the D-Bus +client library. + +dbus/bus-test +This it the unit test program for the message bus. + +test/break-loader +A test that tries to break the message loader by passing it randomly +created invalid messages. + +test/name-test/* +This is a suite of programs which are run with a temporary session bus. +If your test involves multiple processes communicating, your best bet +is to add a test in here. + +"make check" runs all the deterministic test programs (i.e. not break-loader). + +"make lcov-check" is available if you configure with --enable-compiler-coverage +and gives a complete report on test suite coverage. + +Patches +=== + +Please file them at http://bugzilla.freedesktop.org under component +dbus, and also post to the mailing list for discussion. The commit +rules are: + + - for fixes that don't affect API or protocol, they can be committed + if any one qualified reviewer other than patch author + reviews and approves + + - for fixes that do affect API or protocol, two people + in the reviewer group have to review and approve the commit, and + posting to the list is definitely mandatory + + - if there's a live unresolved controversy about a change, + don't commit it while the argument is still raging. + + - at their discretion, members of the reviewer group may also commit + branches/patches under these conditions: + + - the branch does not add or change API, ABI or wire-protocol + + - the branch solves a known problem and is covered by the regression tests + + - there are no objections from the rest of the review group within + a week of the patches being attached to Bugzilla + + - the committer gets a positive review on Bugzilla from someone they + consider qualified to review the change (e.g. a colleague with D-Bus + experience; not necessarily a member of the reviewer group) + + - regardless of reviews, to commit a patch: + - make check must pass + - the test suite must be extended to cover the new code + as much as reasonably feasible (see Tests above) + - the patch has to follow the portability, security, and + style guidelines + - the patch should as much as reasonable do one thing, + not many unrelated changes + No reviewer should approve a patch without these attributes, and + failure on these points is grounds for reverting the patch. + +The reviewer group that can approve patches: + +Havoc Pennington <hp@pobox.net> +Michael Meeks <michael.meeks@novell.com> +Alexander Larsson <alexl@redhat.com> +Zack Rusin <zack@kde.org> +Joe Shaw <joe@assbarn.com> +Mikael Hallendal <micke@imendio.com> +Richard Hult <richard@imendio.com> +Owen Fraser-Green <owen@discobabe.net> +Olivier Andrieu <oliv__a@users.sourceforge.net> +Colin Walters <walters@verbum.org> +Thiago Macieira <thiago@kde.org> +John Palmieri <johnp@redhat.com> +Scott James Remnant <scott@netsplit.com> +Will Thompson <will.thompson@collabora.co.uk> +Simon McVittie <simon.mcvittie@collabora.co.uk> +David Zeuthen <davidz@redhat.com>
diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..f2f0122 --- /dev/null +++ b/INSTALL
@@ -0,0 +1,248 @@ + DBus Installation + ================= + +Quick start +=========== + +DBus could be build with GNU AutoTools or with cmake for its build system, +thus the basic install procedure can be summarized as: + +with autotools: + + ./configure --prefix=/usr + make + su make install + +The configure script will automatically determine whether to try and +build bindings for GLib, Qt, Qt3, Python and Mono based on what tools +are installed on the host system. The default build behaviour can be +overridden using the --enable-XXX/--disable-XXX arguments to configure. +A typical scenario in which it is desirable to override automatic +detection, is during packaging of binary builds, where a predictable +dependancy chain is required. For more details on GNU AutoTools +installation, consult the generic instructions later in this document + +with cmake: + mkdir dbus-build-dir + cd dbus-build-dir + cmake -G <makefile-generator-name> [-D<option>] <dbus-src-root>/cmake + make + make install + +cmake will automatically determine whether to build some features +based on what tools and/or libraries are installed on the host system. +The default build behaviour can be overridden using the +-DENABLE_<XXX> arguments to cmake. +A typical scenario in which it is desirable to override automatic +detection, is during packaging of binary builds, where a predictable +dependancy chain is required. For more details on cmake installation, +consult http://www.cmake.org/cmake/help/help.html. + +External software dependancies +============================== + +The only fundamental requirement to build DBus is an XML parser, +however, there are a number of other software packages which (if +present) will enhance functionality. + +Core library +------------ + + Requisite: + + - Gettext + - expat + + Optional: + + - libselinux (for SELinux integration) + - doxygen (for API documentation) + - xmlto or meinproc4 (for Spec & other XML documentation) + +==================================================================== + +The rest of this document contains the generic GNU AutoTools install +insructions.... + +Basic Installation +================== + + These are generic installation instructions. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, a file +`config.cache' that saves the results of its tests to speed up +reconfiguring, and a file `config.log' containing compiler output +(useful mainly for debugging `configure'). + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If at some point `config.cache' +contains results you don't want to keep, you may remove or edit it. + + The file `configure.in' is used to create `configure' by a program +called `autoconf'. You only need `configure.in' if you want to change +it or regenerate `configure' using a newer version of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. If you're + using `csh' on an old version of System V, you might need to type + `sh ./configure' instead to prevent `csh' from trying to execute + `configure' itself. + + Running `configure' takes awhile. While running, it prints some + messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. You can give `configure' +initial values for variables by setting them in the environment. Using +a Bourne-compatible shell, you can do that on the command line like +this: + CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure + +Or on systems that have the `env' program, you can do it like this: + env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you must use a version of `make' that +supports the `VPATH' variable, such as GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + If you have to use a `make' that does not supports the `VPATH' +variable, you have to compile the package for one architecture at a time +in the source code directory. After you have installed the package for +one architecture, use `make distclean' before reconfiguring for another +architecture. + +Installation Names +================== + + By default, `make install' will install the package's files in +`/usr/local/bin', `/usr/local/man', etc. You can specify an +installation prefix other than `/usr/local' by giving `configure' the +option `--prefix=PATH'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +give `configure' the option `--exec-prefix=PATH', the package will use +PATH as the prefix for installing programs and libraries. +Documentation and other data files will still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=PATH' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + + There may be some features `configure' can not figure out +automatically, but needs to determine by the type of host the package +will run on. Usually `configure' can figure that out, but if it prints +a message saying it can not guess the host type, give it the +`--host=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name with three fields: + CPU-COMPANY-SYSTEM + +See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the host type. + + If you are building compiler tools for cross-compiling, you can also +use the `--target=TYPE' option to select the type of system they will +produce code for and the `--build=TYPE' option to select the type of +system on which you are compiling the package. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Operation Controls +================== + + `configure' recognizes the following options to control how it +operates. + +`--cache-file=FILE' + Use and save the results of the tests in FILE instead of + `./config.cache'. Set FILE to `/dev/null' to disable caching, for + debugging `configure'. + +`--help' + Print a summary of the options to `configure', and exit. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`--version' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`configure' also accepts some other, not widely useful, options.
diff --git a/MODULE_LICENSE_AFL_AND_GPL b/MODULE_LICENSE_AFL_AND_GPL new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/MODULE_LICENSE_AFL_AND_GPL
diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..756ab8b --- /dev/null +++ b/Makefile.am
@@ -0,0 +1,36 @@ +SUBDIRS=dbus bus tools test doc + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = dbus-1.pc + +DISTCLEANFILES = \ + dbus-1.pc + +EXTRA_DIST = \ + autogen.sh \ + HACKING \ + dbus-1.pc.in \ + cleanup-man-pages.sh \ + ChangeLog.pre-1-0 \ + NEWS.pre-1-0 \ + ChangeLog.pre-1-2 \ + NEWS.pre-1-2 \ + README.valgrind \ + README.win \ + README.wince \ + README.cygwin \ + README.launchd \ + cmake + +all-local: Doxyfile + +update-authors: + git shortlog -s -e | cut -c 8- | sort > AUTHORS + +DISTCHECK_CONFIGURE_FLAGS = \ + --enable-xml-docs \ + --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) + +ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} + +include tools/lcov.am
diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..56b4ccc --- /dev/null +++ b/NEWS
@@ -0,0 +1,2085 @@ +D-Bus 1.10.12 (2016-10-10) +== + +The “not excessively inhospitable” release. + +Security fixes: + +• Do not treat ActivationFailure message received from root-owned systemd + name as a format string. In principle this is a security vulnerability, + but we do not believe it is exploitable in practice, because only + privileged processes can own the org.freedesktop.systemd1 bus name, and + systemd does not appear to send activation failures that contain "%". + + Please note that this probably *was* exploitable in dbus versions + older than 1.6.30, 1.8.16 and 1.9.10 due to a missing check which at + the time was only thought to be a denial of service vulnerability + (CVE-2015-0245). If you are still running one of those versions, + patch or upgrade immediately. + + (fd.o #98157, Simon McVittie) + +Other fixes: + +• Harden dbus-daemon against malicious or incorrect ActivationFailure + messages by rejecting them if they do not come from a privileged + process, or if systemd activation is not enabled + (fd.o #98157, Simon McVittie) + +• Avoid undefined behaviour when setting reply serial number without going + via union DBusBasicValue (fd.o #98035, Marc Mutz) + +• autogen.sh: fail cleanly if autoconf fails (Simon McVittie) + +D-Bus 1.10.10 (2016-08-15) +== + +The “tungsten door” release. + +Fixes: + +• On Linux, when dbus-daemon is run with reduced susceptibility to the + OOM killer (typically via systemd), do not let child processes inherit + that setting (fd.o #32851; Kimmo Hämäläinen, WaLyong Cho) + +• Output valid shell syntax in ~/.dbus/session-bus/ if the bus address + contains a semicolon (fd.o #94746, Thiago Macieira) + +• Fix memory leaks and thread safety in subprocess starting on Windows + (fd.o #95191, Ralf Habacker) + +• Do not require systemd to have a service file if using it for activation + (fd.o #93194; Simon McVittie; backport from 1.11.0) + +• Stop test-dbus-daemon incorrectly failing on platforms that cannot + discover the process ID of clients (fd.o #96653, Руслан Ижбулатов) + +• In tests that exercise correct handling of crashing D-Bus services, + suppress Windows crash handler (fd.o #95155; Yiyang Fei, Ralf Habacker) + +• Explicitly check for stdint.h (Ioan-Adrian Ratiu) + +• update-activation-environment: produce better diagnostics on error + (fd.o #96653, Simon McVittie) + +• Don't fail the build with an unused const variable warning under gcc 6 + (fd.o #97282; Thomas Zimmermann, Simon McVittie) + +• Merge dbus-1.10-ci branch, containing backports from 1.11.0 in build/test + code to support continuous integration (fd.o #93194, Simon McVittie) + + · Avoid -Wunused-label when compiling with libselinux but no libaudit + · In development builds, allow OOM tests to be disabled as documented + · Accept and ignore the --tap argument in all "embedded tests", and run + all automated tests with that argument for better diagnostics + · Fix the systemd activation test under CMake by installing the required + files + · In Automake, fix shell syntax for installcheck-local with no DESTDIR + · In Automake, don't try to run manual tests in installcheck + · In CMake, don't run manual-tcp test as an automated test + · Add travis-ci.org build machinery + +D-Bus 1.10.8 (2016-03-07) +== + +The “digestive biscuits” release. + +Fixes: + +• Enable "large file support" on systems where it exists: dbus-daemon + is not expected to open large files, but it might need to stat files + that happen to have large inode numbers (fd.o #93545, Hongxu Jia) + +• Eliminate padding inside DBusMessageIter on 64-bit platforms, + which might result in a pedantic C compiler not copying the entire contents + of a DBusMessageIter; statically assert that this is not an ABI change + in practice (fd.o #94136, Simon McVittie) + +• Document dbus-test-tool echo --sleep-ms=N instead of incorrect --sleep=N + (fd.o #94244, Dmitri Iouchtchenko) + +• Correctly report test failures in C tests from run-test.sh + (fd.o #93379; amit tewari, Simon McVittie) + +• When tests are enabled, run all the marshal-validate tests, not just + the even-numbered ones (fd.o #93908, Nick Lewycky) + +• Correct the expected error from one marshal-validate test, which was + previously not run due to the above bug (fd.o #93908, Simon McVittie) + +D-Bus 1.10.6 (2015-12-01) +== + +The “marzipan beetles” release. + +Fixes: + +• On Unix when running tests as root, don't assert that root and + the dbus-daemon user can still call UpdateActivationEnvironment; + assert that those privileged users can call BecomeMonitor instead + (fd.o #93036, Simon McVittie) + +• On Windows, fix a memory leak in the autolaunch transport (fd.o #92899, + Simon McVittie) + +• On Windows Autotools builds, don't run tests that rely on + dbus-run-session and other Unix-specifics (fd.o #92899, Simon McVittie) + +D-Bus 1.10.4 (2015-11-17) +== + +The “Frostburn Canyon” release. + +Enhancements: + +• GetConnectionCredentials, GetConnectionUnixUser and + GetConnectionUnixProcessID with argument "org.freedesktop.DBus" + will now return details of the dbus-daemon itself. This is required + to be able to call SetEnvironment on systemd. + (fd.o #92857, Jan Alexander Steffens) + +Fixes: + +• Make UpdateActivationEnvironment always fail with AccessDenied on the + system bus. Previously, it was possible to configure it so root could + call it, but the environment variables were not actually used, + because the launch helper would discard them. + (fd.o #92857, Jan Alexander Steffens) + +• On Unix with --systemd-activation on a user bus, make + UpdateActivationEnvironment pass on its arguments to systemd's + SetEnvironment method, solving inconsistency between the environments + used for traditional activation and systemd user-service activation. + (fd.o #92857, Jan Alexander Steffens) + +• On Windows, don't crash if <syslog/> or --syslog is used + (fd.o #92538, Ralf Habacker) + +• On Windows, fix a memory leak when setting a DBusError from a Windows + error (fd.o #92721, Ralf Habacker) + +• On Windows, don't go into infinite recursion if we abort the process + with backtraces enabled (fd.o #92721, Ralf Habacker) + +• Fix various failing tests, variously on Windows and cross-platform: + · don't test system.conf features (users, groups) that only make sense + on the system bus, which is not supported on Windows + · don't call _dbus_warn() when we skip a test, since it is fatal + · fix computation of expected <standard_session_servicedirs/> + · when running TAP tests, translate newlines to Unix format, fixing + cross-compiled tests under Wine on Linux + · don't stress-test refcounting under Wine, where it's really slow + · stop assuming that a message looped-back to the test will be received + immediately + · skip some system bus tests on Windows since they make no sense there + (fd.o #92538, fd.o #92721; Ralf Habacker, Simon McVittie) + +D-Bus 1.10.2 (2015-10-26) +== + +The “worst pies in London” release. + +Fixes: + +• Correct error handling for activation: if there are multiple attempts + to activate the same service and it fails immediately, the first attempt + would get the correct reply, but the rest would time out. We now send + the same error reply to each attempt. (fd.o #92200, Simon McVittie) + +• If BecomeMonitor is called with a syntactically invalid match rule, + don't crash with an assertion failure, fixing a regression in 1.9.10. + This was not exploitable as a denial of service, because the check + for a privileged user is done first. (fd.o #92298, Simon McVittie) + +• On Linux with --enable-user-session, add the bus address to the + environment of systemd services for better backwards compatibility + (fd.o #92612, Jan Alexander Steffens) + +• On Windows, fix the logic for replacing the installation prefix + in service files' Exec lines (fd.o #83539; Milan Crha, Simon McVittie) + +• On Windows, if installed in the conventional layout with ${prefix}/etc + and ${prefix}/share, use relative paths between bus configuration files + to allow the tree to be relocated (fd.o #92028, Simon McVittie) + +• Make more of the regression tests pass in Windows builds (fd.o #92538, + Simon McVittie) + +D-Bus 1.10.0 (2015-08-25) +== + +The “0x20” release. + +This is a new stable branch, recommended for use in OS distributions. + +Fixes since 1.9.20: + +• distribute test/tap-test.sh.in, even if the tarball was built without + tests enabled (fd.o #91684, Simon McVittie) +• work around a fd leak in libcap-ng < 0.7.7 (fd.o #91684, Simon McVittie) + +Summary of major changes since 1.8.0: + +• The basic setup for the well-known system and session buses is + now done in read-only files in ${datadir} (normally /usr/share). + See the NEWS entry for 1.9.18 for details. + +• AppArmor integration has been merged, with features similar to the + pre-existing SELinux integration. It is mostly compatible with the + patches previously shipped by Ubuntu, with one significant change: + Ubuntu's GetConnectionAppArmorSecurityContext method has been superseded + by GetConnectionCredentials and was not included. + +• The --enable-user-session configure option can be enabled + by OS integrators intending to use systemd to provide a session bus + per user (in effect, treating all concurrent graphical and non-graphical + login sessions as one large session). + +• The new listenable address mode "unix:runtime=yes" listens on + $XDG_RUNTIME_DIR/bus, the same AF_UNIX socket used by the systemd + user session. libdbus and "dbus-launch --autolaunch" will connect to + this address by default. GLib ≥ 2.45.3 and sd-bus ≥ 209 have a + matching default. + +• All executables are now dynamically linked to libdbus-1. + Previously, some executables, most notably dbus-daemon, were statically + linked to a specially-compiled variant of libdbus. This results in + various private functions in the _dbus namespace being exposed by the + shared library. These are not API, and must not be used outside + the dbus source tree. + +• On platforms with ELF symbol versioning, all public symbols + are versioned LIBDBUS_1_3. + +New bus APIs: + +• org.freedesktop.DBus.GetConnectionCredentials returns + LinuxSecurityLabel where supported +• org.freedesktop.DBus.Monitoring interface (privileged) + · BecomeMonitor method supersedes match rules with eavesdrop=true, + which are now deprecated +• org.freedesktop.DBus.Stats interface (semi-privileged) + · now enabled by default + · new GetAllMatchRules method +• org.freedesktop.DBus.Verbose interface (not normally compiled) + · toggles the effect of DBUS_VERBOSE + +New executables: + +• dbus-test-tool +• dbus-update-activation-environment + +New optional dependencies: + +• The systemd: pseudo-transport requires libsystemd or libsd-daemon +• Complete documentation requires Ducktype and yelp-tools +• Full test coverage requires GLib 2.36 and PyGI +• AppArmor integration requires libapparmor and optionally libaudit + +Dependencies removed: + +• dbus-glib + +D-Bus 1.9.20 (2015-08-06) +== + +The “Remember Tomorrow” release. + +This is a release-candidate for D-Bus 1.10.0. OS distribution vendors +should test it. + +Fixes: + +• Don't second-guess what the ABI of poll() is, allowing it to be used + on Integrity RTOS and other unusual platforms (fd.o #90314; + Rolland Dudemaine, Simon McVittie) + +• Don't duplicate audit subsystem integration if AppArmor and SELinux are + both enabled (fd.o #89225, Simon McVittie) + +• Log audit events for AppArmor/SELinux policy violations whenever + we have CAP_AUDIT_WRITE, even if not the system bus + (fd.o #83856, Laurent Bigonville) + +D-Bus 1.9.18 (2015-07-21) +== + +The “Pirate Elite” release. + +Configuration changes: + +• The basic setup for the well-known system and session buses is now done + in read-only files in ${datadir}, moving a step closer to systems + that can operate with an empty /etc directory. In increasing order + of precedence: + + · ${datadir}/dbus-1/s*.conf now perform the basic setup such as setting + the default message policies. + · ${sysconfdir}/dbus-1/s*.conf are now optional. By default + dbus still installs a trivial version of each, for documentation + purposes; putting configuration directives in these files is deprecated. + · ${datadir}/dbus-1/s*.d/ are now available for third-party software + to install "drop-in" configuration snippets (any packages + using those directories should explicitly depend on at least this + version of dbus). + · ${sysconfdir}/dbus-1/s*.d/ are also still available for sysadmins + or third-party software to install "drop-in" configuration snippets + · ${sysconfdir}/dbus-1/s*-local.conf are still available for sysadmins' + overrides + + ${datadir} is normally /usr/share, ${sysconfdir} is normally /etc, + and "s*" refers to either system or session as appropriate. + + (fd.o #89280, Dimitri John Ledkov) + +Fixes: + +• Fix a memory leak when GetConnectionCredentials() succeeds + (fd.o #91008, Jacek Bukarewicz) + +• Ensure that dbus-monitor does not reply to messages intended for others, + resulting in its own disconnection (fd.o #90952, Simon McVittie) + +D-Bus 1.9.16 (2015-05-14) +== + +The “titanium barns” release. + +Dependencies: + +• Automake 1.13 is now required when compiling from git or modifying + the build system. + +Security hardening: + +• On Unix platforms, change the default configuration for the session bus + to only allow EXTERNAL authentication (secure kernel-mediated + credentials-passing), as was already done for the system bus. + + This avoids falling back to DBUS_COOKIE_SHA1, which relies on strongly + unpredictable pseudo-random numbers. + + If you are using D-Bus over the (unencrypted!) tcp: or nonce-tcp: transport, + in conjunction with DBUS_COOKIE_SHA1 and a shared home directory using + NFS or similar, you will need to reconfigure the session bus to accept + DBUS_COOKIE_SHA1 by commenting out the <auth> element. This configuration + is not recommended. + + (fd.o #90414, Simon McVittie) + +• When asked for random numbers for DBUS_COOKIE_SHA1, the nonce-tcp: + transport, UUIDs or any other reason, fail if we cannot obtain entropy + (from /dev/urandom or CryptGenRandom()) or an out-of-memory condition + occurs, instead of silently falling back to low-entropy pseudorandom + numbers from rand(). (fd.o #90414; Simon McVittie, Ralf Habacker) + +Enhancements: + +• Add dbus_message_iter_get_element_count() + (fd.o #30350; Christian Dywan, Simon McVittie) + +• Introduce new internal DBusSocket and DBusPollable types so we can + stop treating the Windows SOCKET type as if it was int. DBusSocket + is specifically a socket, cross-platform. DBusPollable is whatever + _dbus_poll() can act on, i.e. a fd on Unix or a SOCKET on Windows. + (fd.o #89444; Ralf Habacker, Simon McVittie) + +• All regression tests now output TAP <https://testanything.org/> + (fd.o #89846, Simon McVittie) + +• Internal APIs consistently use signed values for timestamps + (fd.o #18494, Peter McCurdy) + +• Improve diagnostics when UpdateActivationEnvironment calls are rejected + (fd.o #88812, Simon McVittie) + +• Clean up a lot of compiler warnings + (fd.o #17289, fd.o #89284; Ralf Habacker, Simon McVittie) + +Fixes: + +• Add locking to DBusCounter's reference count and notify function + (fd.o #89297, Adrian Szyndela) + +• Ensure that DBusTransport's reference count is protected by the + corresponding DBusConnection's lock (fd.o #90312, Adrian Szyndela) + +• Correctly release DBusServer mutex before early-return if we run out + of memory while copying authentication mechanisms (fd.o #90021, + Ralf Habacker) + +• Make dbus-test-tool and dbus-update-activation-environment portable + to Windows (fd.o #90089, Ralf Habacker) + +• Correctly initialize all fields of DBusTypeReader (fd.o #90021; + Ralf Habacker, Simon McVittie) + +• Fix some missing \n in verbose (debug log) messages (fd.o #90004, + Ralf Habacker) + +• Clean up some memory and fd leaks in test code and tools + (fd.o #90021, Ralf Habacker) + +• Fix a NULL dereference if the dbus-daemon cannot read a configuration + directory for a reason that is not ENOENT (fd.o #90021, Ralf Habacker) + +• CMake generates a versioned shared library even if the revision is 0, + as it usually is on the development branch. (fd.o #89450, Ralf Habacker) + +D-Bus 1.9.14 (2015-03-02) +== + +The “don't stand in the poison cloud” release. + +Dependencies: + +• dbus-daemon and dbus-daemon-launch-helper now require libdbus. They + were previously linked to a static version of libdbus. + +• The tests no longer require dbus-glib in order to exercise the libdbus + shared library; they are always linked to libdbus now. + +Build-time configuration: + +• The new --enable-user-session option, off by default, can be enabled + by OS integrators intending to use systemd to provide a session bus + per user (in effect, treating all concurrent graphical and non-graphical + login sessions as one large session) + +Enhancements: + +• All executables are now linked dynamically to libdbus. + (fd.o #83115; Bertrand SIMONNET, Simon McVittie, Ralf Habacker) + +• On platforms that support them (GNU libc and possibly others), + libdbus now has versioned symbols for its public API. + All public symbols (visible in the header files) are currently + versioned as LIBDBUS_1_3; private symbols starting with _dbus or + dbus_internal have a version that changes with each release, and + must not be used by applications. (also fd.o #83115) + +• New listenable address mode "unix:runtime=yes" which listens on + a real filesystem (non-abstract) socket $XDG_RUNTIME_DIR/bus + (fd.o #61303; Colin Walters, Alexander Larsson, Simon McVittie) + +• Add optional systemd units for a per-user bus listening on + $XDG_RUNTIME_DIR/bus (fd.o #61301; Simon McVittie, Colin Walters) + +• On Unix platforms, both libdbus and "dbus-launch --autolaunch" + default to connecting to $XDG_RUNTIME_DIR/bus if it is a socket + (also fd.o #61301) + +• New dbus-update-activation-environment tool uploads environment + variables to "dbus-daemon --session" and optionally "systemd --user", + primarily as a way to keep the per-user bus compatible with + distributions' existing X11 login scripts (also fd.o #61301) + +• <includedir/> elements in dbus-daemon configuration are now silently + ignored if the directory does not exist. (fd.o #89280, Dimitri John Ledkov) + +• Add microsecond-resolution timestamps to the default output of + dbus-monitor and dbus-send (fd.o #88896; Ralf Habacker, Simon McVittie) + +Fixes: + +• Fix a race condition in the 'monitor' test introduced in 1.9.10 + (fd.o #89222, Simon McVittie) + +D-Bus 1.9.12 (2015-02-19) +== + +The “monster lasagna” release. + +Dependencies: + +• Ducktype and yelp-tools are now required to build complete documentation + (they are optional for normal builds). + +Enhancements: + +• D-Bus Specification version 0.26 + · GetConnectionCredentials can return LinuxSecurityLabel or WindowsSID + · document the BecomeMonitor method + +• On Linux, add LinuxSecurityLabel to GetConnectionCredentials + (fd.o #89041; Tyler Hicks, Simon McVittie) + +• On Linux, add support for AppArmor mediation of message sending and + receiving and name ownership (paralleling existing SELinux mediation + support), and eavesdropping (a new check, currently AppArmor-specific) + (fd.o #75113; John Johansen, Tyler Hicks, Simon McVittie) + +• In dbus-send and dbus-monitor, pretty-print \0-terminated bytestrings + that have printable ASCII contents; we previously only did this for + unterminated bytestrings (fd.o #89109, Simon McVittie) + +• Add a guide to designing good D-Bus APIs (fd.o #88994, Philip Withnall) + +• On Windows, add WindowsSID to GetConnectionCredentials + (fd.o #54445, Ralf Habacker) + +• Improve clarity of dbus-monitor --profile output and add more columns + (fd.o #89165, Ralf Habacker) + +• Add a man page for dbus-test-tool, and build it under CMake as well + as Autotools (fd.o#89086, Simon McVittie) + +• If dbus-daemon was compiled with --enable-verbose, add a D-Bus API + to control it at runtime, overriding the DBUS_VERBOSE environment variable + (fd.o #88896, Ralf Habacker) + +Fixes: + +• Reduce the number of file descriptors used in the fd-passing test, + avoiding failure under the default Linux fd limit, and automatically + skip it if the rlimit is too small (fd.o #88998, Simon McVittie) + +D-Bus 1.9.10 (2015-02-09) +== + +The “sad cyborgs” release. + +Security fixes merged from 1.8.16: + +• Do not allow non-uid-0 processes to send forged ActivationFailure + messages. On Linux systems with systemd activation, this would + allow a local denial of service: unprivileged processes could + flood the bus with these forged messages, winning the race with + the actual service activation and causing an error reply + to be sent back when service auto-activation was requested. + This does not prevent the real service from being started, + so the attack only works while the real service is not running. + (CVE-2015-0245, fd.o #88811; Simon McVittie) + +Enhancements: + +• The new Monitoring interface in the dbus-daemon lets dbus-monitor and + similar tools receive messages without altering the security properties + of the system bus, by calling the new BecomeMonitor method on a + private connection. This bypasses the normal <allow> and <deny> rules + entirely, so to preserve normal message-privacy assumptions, only root + is allowed to do this on the system bus. Restricted environments, + such as Linux with LSMs, should lock down access to the Monitoring + interface. (fd.o #46787, Simon McVittie) + +• dbus-monitor uses BecomeMonitor to capture more traffic, if the + dbus-daemon supports it and access permissions allow it. + It still supports the previous approach ("eavesdropping" match rules) + for compatibility with older bus daemons. (fd.o #46787, Simon) + +• dbus-monitor can now log the message stream as binary data for later + analysis, with either no extra framing beyond the normal D-Bus headers, + or libpcap-compatible framing treating each D-Bus message + as a captured packet. (fd.o #46787, Simon) + +Other fixes: + +• Fix some CMake build regressions (fd.o #88964, Ralf Habacker) + +• On Unix, forcibly terminate regression tests after 60 seconds to + prevent them from blocking continuous integration frameworks + (fd.o #46787, Simon) + +D-Bus 1.9.8 (2015-02-03) +== + +The “all the types of precipitation” release. + +Dependencies: + +• full test coverage now requires GLib 2.36 +• full test coverage now requires PyGI (PyGObject 3, + "import gi.repository.GObject") instead of the + obsolete PyGObject 2 ("import gobject") + +Enhancements: + +• add GLib-style "installed tests" (fd.o #88810, Simon McVittie) + +• better regression test coverage, including systemd activation + (fd.o #57952, #88810; Simon McVittie) + +Fixes: + +• fatal errors correctly make the dbus-daemon exit even if <syslog/> is + turned off (fd.o #88808, Simon McVittie) + +• TCP sockets on Windows no longer fail to listen approximately 1 time + in 256, caused by a logic error that should have always made it fail but + was mitigated by incorrect endianness for the port number + (fd.o #87999, Ralf Habacker) + +• fix some Windows build failures (fd.o #88009, #88010; Ralf Habacker) + +• on Windows, allow up to 8K connections to the dbus-daemon instead of the + previous 64, completing a previous fix which only worked under + Autotools (fd.o #71297, Ralf Habacker) + +• on Windows, if the IP family is unspecified only use IPv4, + to mitigate IPv6 not working correctly (fd.o #87999, Ralf Habacker) + +• fix some unlikely memory leaks on OOM (fd.o #88087, Simon McVittie) + +• lcov code coverage analysis works again (fd.o #88808, Simon McVittie) + +• fix an unused function error with --disable-embedded-tests (fd.o #87837, + Thiago Macieira) + +D-Bus 1.9.6 (2015-01-05) +== + +The “I do have a bread knife” release. + +Security hardening: + +• Do not allow calls to UpdateActivationEnvironment from uids other than + the uid of the dbus-daemon. If a system service installs unsafe + security policy rules that allow arbitrary method calls + (such as CVE-2014-8148) then this prevents memory consumption and + possible privilege escalation via UpdateActivationEnvironment. + + We believe that in practice, privilege escalation here is avoided + by dbus-daemon-launch-helper sanitizing its environment; but + it seems better to be safe. + +• Do not allow calls to UpdateActivationEnvironment or the Stats interface + on object paths other than /org/freedesktop/DBus. Some system services + install unsafe security policy rules that allow arbitrary method calls + to any destination, method and interface with a specified object path; + while less bad than allowing arbitrary method calls, these security + policies are still harmful, since dbus-daemon normally offers the + same API on all object paths and other system services might behave + similarly. + +Other fixes: + +• Add missing initialization so GetExtendedTcpTable doesn't crash on + Windows Vista SP0 (fd.o #77008, Илья А. Ткаченко) + +D-Bus 1.9.4 (2014-11-24) +== + +The “extra-sturdy caramel” release. + +Fixes: + +• Partially revert the CVE-2014-3639 patch by increasing the default + authentication timeout on the system bus from 5 seconds back to 30 + seconds, since this has been reported to cause boot regressions for + some users, mostly with parallel boot (systemd) on slower hardware. + + On fast systems where local users are considered particularly hostile, + administrators can return to the 5 second timeout (or any other value + in milliseconds) by saving this as /etc/dbus-1/system-local.conf: + + <busconfig> + <limit name="auth_timeout">5000</limit> + </busconfig> + + (fd.o #86431, Simon McVittie) + +• Add a message in syslog/the Journal when the auth_timeout is exceeded + (fd.o #86431, Simon McVittie) + +• Send back an AccessDenied error if the addressed recipient is not allowed + to receive a message (and in builds with assertions enabled, don't + assert under the same conditions). (fd.o #86194, Jacek Bukarewicz) + +D-Bus 1.9.2 (2014-11-10) +== + +The “structurally unsound flapjack” release. + +Security fixes: + +• Increase dbus-daemon's RLIMIT_NOFILE rlimit to 65536 + so that CVE-2014-3636 part A cannot exhaust the system bus' + file descriptors, completing the incomplete fix in 1.8.8. + (CVE-2014-7824, fd.o #85105; Simon McVittie, Alban Crequy) + +Enhancements: + +• D-Bus Specification version 0.25 + · new value 'const' for EmitsChangedSignal annotation + (fd.o #72958, Lennart Poettering) + · new ALLOW_INTERACTIVE_AUTHORIZATION flag, for PolicyKit and similar + (fd.o #83449; Lennart Poettering, Simon McVittie) + · annotate table of types with reserved/basic/container, and for + basic types, fixed/string-like + · clarify arbitrary limits by quoting them in mebibytes + +• New API: add accessors for the ALLOW_INTERACTIVE_AUTHORIZATION flag + (fd.o #83449, Simon McVittie) + +• Add dbus-test-tool, a D-Bus swiss army knife with multiple subcommands, + useful for debugging and performance testing: + · dbus-test-tool spam: send repeated messages + · dbus-test-tool echo: send an empty reply for all method calls + · dbus-test-tool black-hole: do not reply to method calls + (fd.o #34140; Alban Crequy, Simon McVittie, Will Thompson) + +• Add support for process ID in credentials-passing on NetBSD + (fd.o #69702, Patrick Welche) + +• Add an example script to find potentially undesired match rules + (fd.o #84598, Alban Crequy) + +• Document the central assumption that makes our use of credentials-passing + secure (fd.o #83499, Simon McVittie) + +• Replace the dbus-glib section of the tutorial with a GDBus recommendation, + and add some links to GDBus and QtDBus documentation (fd.o #25140, + Simon McVittie) + +Fixes: + +• Use a less confusing NoReply message when disconnected with a reply pending + (fd.o #76112, Simon McVittie) + +• Make the .pc file relocatable by letting pkg-config do all variable + expansion itself (fd.o #75858, Руслан Ижбулатов) + +• Fix a build failure on platforms with kqueue, which regressed in 1.9.0 + (fd.o #85563, Patrick Welche) + +• Consistently save errno after socket calls (fd.o #83625, Simon McVittie) + +• In dbus-spawn, when the grandchild process exits due to a failed exec(), + do not lose the exec() errno (fd.o #24821, Simon McVittie) + +• Do not fail the tests if a parent process has leaked non-close-on-exec + file descriptors to us (fd.o #73689, fd.o #83899; Simon McVittie) + +• Do not fail the tests on Unix platforms with incomplete + credentials-passing support, but do fail if we can't pass credentials + on a platform where it is known to work: Linux, FreeBSD, OpenBSD, NetBSD + (fd.o #69702, Simon McVittie) + +• Detect accept4, dirfd, inotify_init1, pipe2, and Unix fd passing + when building with cmake, and expand test coverage there + (fd.o #73689; Ralf Habacker, Simon McVittie) + +D-Bus 1.9.0 (2014-10-01) +== + +The “tiered cheeses” release. + +Requirements: + +• Support for the systemd: (LISTEN_FDS) pseudo-transport on Linux now + requires either the libsystemd or libsd-daemon shared library, dropping the + embedded convenience copy of sd-daemon (fd.o #71818, Simon) + +Build-time configuration changes: + +• The Stats interface is now enabled by default, and locked-down to + root-only on the system bus. Configure with --disable-stats + to disable it altogether on memory- or disk-constrained systems, + or see ${docdir}/examples/ to open it up to non-root users on the + system bus or restrict access on the session bus. + (fd.o #80759; Simon McVittie, Alban Crequy) + +• The CMake build system now builds the same shared library name as Autotools + on at least Linux and Windows: + - on Linux (and perhaps other Unix platforms), it previously built + libdbus-1.so, but now builds libdbus-1.so.3.* with development + symlink libdbus-1.so and SONAME/symlink libdbus-1.so.3 + - on Windows, it previously built either libdbus-1.dll (release) or + libdbus-1d.dll (debug), but now builds libdbus-1-3.dll, copied to + libdbus-1.dll for compatibility with older applications. + (fd.o #74117, Ralf Habacker) + +Enhancements: + +• D-Bus Specification version 0.24 + · document how to quote match rules (fd.o #24307, Simon McVittie) + · explicitly say that most message types never expect a reply + regardles of whether they have NO_REPLY_EXPECTED + (fd.o #75749, Simon McVittie) + +• on Unix platforms, disable Nagle's algorithm on TCP connections to improve + initial latency (fd.o #75544, Matt Hoosier) + +• use backtrace() if it is in -lexecinfo instead of libc, as on NetBSD + (fd.o #69702, Patrick Welche) + +• in dbus-monitor, print more information about file descriptors + (fd.o #80603, Alban Crequy) + +• do not install system bus configuration if built for Windows + (fd.o #83583; Ralf Habacker, Simon McVittie) + +• Add GetAllMatchRules to the Stats interface (fd.o #24307, Alban Crequy) + +• Add a regression test for file descriptor passing (fd.o #83622, + Simon McVittie) + +Fixes: + +• fix an incorrect error message if a Unix socket path is too long + (fd.o #73887, Antoine Jacoutot) + +• in an MSYS/Cygwin environment, pass Unix-style filenames to xmlto, + fixing documentation generation (fd.o #75860, Руслан Ижбулатов) + +• in Unix with X11, avoid giving dbus-launch a misleading argv[0] + in ps(1) (fd.o #69716, Chengwei Yang) + +• avoid calling poll() with timeout < -1, which is considered invalid + on FreeBSD and NetBSD (fd.o #78480, Jaap Boender) + +• be portable to BSD-derived platforms where O_CLOEXEC is unavailable in libc + (like Mac OS X 10.6), or available in libc but unsupported by the kernel + (fd.o #77032; rmvsxop, OBATA Akio, Patrick Welche) + +• Fix include path for test/internal/*.c with cmake (Ralf Habacker) + +• Documentation improvements + (fd.o #80795, #84313; Thomas Haller, Sebastian Rasmussen) + +• in dbus-monitor, do not leak file descriptors that we have monitored + (fd.o #80603, Alban Crequy) + +• Set the close-on-exec flag for the inotify file descriptor, even + if built with CMake or older libc (fd.o #73689, Simon McVittie) + +• Remove some LGPL code from the Windows dbus-daemon + (fd.o #57272, Ralf Habacker) + +D-Bus 1.8.8 (2014-09-16) +== + +The "smashy smashy egg man" release. + +Security fixes: + +• Do not accept an extra fd in the padding of a cmsg message, which + could lead to a 4-byte heap buffer overrun. + (CVE-2014-3635, fd.o #83622; Simon McVittie) + +• Reduce default for maximum Unix file descriptors passed per message + from 1024 to 16, preventing a uid with the default maximum number of + connections from exhausting the system bus' file descriptors under + Linux's default rlimit. Distributors or system administrators with a + more restrictive fd limit may wish to reduce these limits further. + + Additionally, on Linux this prevents a second denial of service + in which the dbus-daemon can be made to exceed the maximum number + of fds per sendmsg() and disconnect the process that would have + received them. + (CVE-2014-3636, fd.o #82820; Alban Crequy) + +• Disconnect connections that still have a fd pending unmarshalling after + a new configurable limit, pending_fd_timeout (defaulting to 150 seconds), + removing the possibility of creating an abusive connection that cannot be + disconnected by setting up a circular reference to a connection's + file descriptor. + (CVE-2014-3637, fd.o #80559; Alban Crequy) + +• Reduce default for maximum pending replies per connection from 8192 to 128, + mitigating an algorithmic complexity denial-of-service attack + (CVE-2014-3638, fd.o #81053; Alban Crequy) + +• Reduce default for authentication timeout on the system bus from + 30 seconds to 5 seconds, avoiding denial of service by using up + all unauthenticated connection slots; and when all unauthenticated + connection slots are used up, make new connection attempts block + instead of disconnecting them. + (CVE-2014-3639, fd.o #80919; Alban Crequy) + +Other fixes: + +• Check for libsystemd from systemd >= 209, falling back to + the older separate libraries if not found (Umut Tezduyar Lindskog, + Simon McVittie) + +• On Linux, use prctl() to disable core dumps from a test executable + that deliberately raises SIGSEGV to test dbus-daemon's handling + of that condition (fd.o #83772, Simon McVittie) + +• Fix compilation with --enable-stats (fd.o #81043, Gentoo #507232; + Alban Crequy) + +• Improve documentation for running tests on Windows (fd.o #41252, + Ralf Habacker) + +D-Bus 1.8.6 (2014-06-02) +== + +Security fixes: + +• On Linux ≥ 2.6.37-rc4, if sendmsg() fails with ETOOMANYREFS, silently drop + the message. This prevents an attack in which a malicious client can + make dbus-daemon disconnect a system service, which is a local + denial of service. + (fd.o #80163, CVE-2014-3532; Alban Crequy) + +• Track remaining Unix file descriptors correctly when more than one + message in quick succession contains fds. This prevents another attack + in which a malicious client can make dbus-daemon disconnect a system + service. + (fd.o #79694, fd.o #80469, CVE-2014-3533; Alejandro Martínez Suárez, + Simon McVittie, Alban Crequy) + +Other fixes: + +• When dbus-launch --exit-with-session starts a dbus-daemon but then cannot + attach to a session, kill the dbus-daemon as intended + (fd.o #74698, Роман Донченко) + +D-Bus 1.8.4 (2014-06-10) +== + +Security fix: + +• Alban Crequy at Collabora Ltd. discovered and fixed a denial-of-service + flaw in dbus-daemon, part of the reference implementation of D-Bus. + Additionally, in highly unusual environments the same flaw could lead to + a side channel between processes that should not be able to communicate. + (CVE-2014-3477, fd.o #78979) + +D-Bus 1.8.2 (2014-04-30) +== + +The “nobody wants red” release. + +Enhancements: + +• in the CMake build system, add some hints for Linux users cross-compiling + Windows D-Bus binaries to be able to run tests under Wine + (fd.o #41252, Ralf Habacker) + +• add Documentation key to dbus.service (fd.o #77447, Cameron Norman) + +Fixes: + +• in "dbus-uuidgen --ensure", try to copy systemd's /etc/machine-id + to /var/lib/dbus/machine-id instead of generating an entirely new ID + (fd.o #77941, Simon McVittie) + +• if dbus-launch receives an X error very quickly, do not kill + unrelated processes (fd.o #74698, Роман Донченко) + +• on Windows, allow up to 8K connections to the dbus-daemon, instead of the + previous 64 (fd.o #71297; Cristian Onet, Ralf Habacker) + +• cope with \r\n newlines in regression tests, since on Windows, + dbus-daemon.exe uses text mode (fd.o #75863, Руслан Ижбулатов) + +D-Bus 1.8.0 (2014-01-20) +== + +The “Wolverine distrusts my printer” release. + +This starts a new stable branch. The 1.6.x branch is now considered to be +outdated, and will only receive fixes for serious bugs such as security +flaws. The 1.4.x and 1.2.x branches no longer have upstream support and +are unlikely to get any more releases, but if distributors still need to +support them, please share security patches via upstream. + +Summary of changes since 1.6.x: + +• libdbus always behaves as if dbus_threads_init_default() had been called + (thread-safety by default) +• new dbus-run-session tool, replacing certain misuses of dbus-launch +• dbus-monitor can talk to outdated versions of dbus-daemon again +• new org.freedesktop.DBus.GetConnectionCredentials method +• GetConnectionUnixProcessID also works correctly on Windows, returning + the Windows process ID +• GetConnectionWindowsSID returns the correct SID on Windows +• expat is required, libxml2 can no longer be used as a substitute +• the userDB cache is required, and cannot be disabled +• a 64-bit integer type (either int, long, long long or _int64) is required +• better systemd-journald integration on Linux +• fixed long-standing fd and array leaks when failing to parse a message +• fixed referenced-but-never-freed parent nodes (effectively memory leaks) + when using certain object-path allocation patterns, notably in Avahi +• better defaults for Windows support +• better CMake support +• better portability to mingw32, FreeBSD, NetBSD, QNX and Hurd +• the source language for the man pages is now Docbook XML + +Enhancements since 1.7.10: + +• Enhance the CMake build system to check for GLib and compile/run + a subset of the regression tests (fd.o #41252, #73495; Ralf Habacker) + +Fixes since 1.7.10: + +• don't rely on va_copy(), use DBUS_VA_COPY() wrapper (fd.o #72840, + Ralf Habacker) + +• fix compilation of systemd journal support on older systemd versions where + sd-journal.h doesn't include syslog.h (fd.o #73455, Ralf Habacker) + +• fix compilation on older MSVC versions by including stdlib.h + (fd.o #73455, Ralf Habacker) + +• Allow <allow_anonymous/> to appear in an included configuration file + (fd.o #73475, Matt Hoosier) + +Test behaviour changes since 1.7.10: + +• If the tests crash with an assertion failure, they no longer default to + blocking for a debugger to be attached. Set DBUS_BLOCK_ON_ABORT in the + environment if you want the old behaviour. + +• To improve debuggability, the dbus-daemon and dbus-daemon-eavesdrop tests + can be run with an external dbus-daemon by setting + DBUS_TEST_DAEMON_ADDRESS in the environment. Test-cases that require + an unusually-configured dbus-daemon are skipped. + +D-Bus 1.7.10 (2014-01-06) +== + +The “weighted companion cube” release. + +This is a release candidate for D-Bus 1.8. + +D-Bus Specification 0.23: + +• don't require messages with no INTERFACE to be dispatched + (fd.o #68597, Simon McVittie) + +• document "tcp:bind=..." and "nonce-tcp:bind=..." (fd.o #72301, + Chengwei Yang) + +• define "listenable" and "connectable" addresses, and discuss + the difference (fd.o #61303, Simon McVittie) + +Enhancements: + +• support printing Unix file descriptors in dbus-send, dbus-monitor + (fd.o #70592, Robert Ancell) + +• don't install systemd units if --disable-systemd is given + (fd.o #71818, Chengwei Yang) + +Fixes: + +• don't leak memory on out-of-memory while listing activatable or + active services (fd.o #71526, Radoslaw Pajak) + +• fix undefined behaviour in a regression test (fd.o #69924, DreamNik) + +• escape Unix socket addresses correctly (fd.o #46013, Chengwei Yang) + +• on SELinux systems, don't assume that SECCLASS_DBUS, DBUS__ACQUIRE_SVC + and DBUS__SEND_MSG are numerically equal to their values in the + reference policy (fd.o #88719, osmond sun) + +• define PROCESS_QUERY_LIMITED_INFORMATION if missing from MinGW < 4 headers + (fd.o #71366, Matt Fischer) + +• define WIN32_LEAN_AND_MEAN to avoid conflicts between winsock.h and + winsock2.h (fd.o #71405, Matt Fischer) + +• do not return failure from _dbus_read_nonce() with no error set, + preventing a potential crash (fd.o #72298, Chengwei Yang) + +• on BSD systems, avoid some O(1)-per-process memory and fd leaks in kqueue, + preventing test failures (fd.o #69332, fd.o #72213; Chengwei Yang) + +• fix warning spam on Hurd by not trying to set SO_REUSEADDR on Unix sockets, + which doesn't do anything anyway on at least Linux and FreeBSD + (fd.o #69492, Simon McVittie) + +• fix use of TCP sockets on FreeBSD and Hurd by tolerating EINVAL from + sendmsg() with SCM_CREDS (retrying with plain send()), and looking + for credentials more correctly (fd.o #69492, Simon McVittie) + +• ensure that tests run with a temporary XDG_RUNTIME_DIR to avoid + getting mixed up in XDG/systemd "user sessions" (fd.o #61301, + Simon McVittie) + +• refresh cached policy rules for existing connections when bus + configuration changes (fd.o #39463, Chengwei Yang) + +D-Bus 1.7.8 (2013-11-01) +== + +The “extreme hills” release. + +Dependencies: + +• If systemd support is enabled, libsystemd-journal is now required. + +Enhancements: + +• When activating a non-systemd service under systemd, annotate its + stdout/stderr with its bus name in the Journal. Known limitation: + because the socket is opened before forking, the process will still be + logged as if it had dbus-daemon's process ID and user ID. + (fd.o #68559, Chengwei Yang) + +• Document more configuration elements in dbus-daemon(1) + (fd.o #69125, Chengwei Yang) + +Fixes: + +• Don't leak string arrays or fds if dbus_message_iter_get_args_valist() + unpacks them and then encounters an error (fd.o #21259, Chengwei Yang) + +• If compiled with libaudit, retain CAP_AUDIT_WRITE so we can write + disallowed method calls to the audit log, fixing a regression in 1.7.6 + (fd.o #49062, Colin Walters) + +• path_namespace='/' in match rules incorrectly matched nothing; it + now matches everything. (fd.o #70799, Simon McVittie) + +D-Bus 1.7.6 (2013-10-09) +== + +The “CSI Shrewsbury” release. + +Build-time configuration changes: + +• Directory change notification via dnotify on Linux is no longer + supported; it hadn't compiled successfully since 2010 in any case. + If you don't have inotify (Linux) or kqueue (*BSD), you will need + to send SIGHUP to the dbus-daemon when its configuration changes. + (fd.o #33001, Chengwei Yang) + +• Compiling with --disable-userdb-cache is no longer supported; + it didn't work since at least 2008, and would lead to an extremely + slow dbus-daemon even it worked. (fd.o #15589, #17133, #66947; + Chengwei Yang) + +• The DBUS_DISABLE_ASSERTS CMake option didn't actually disable most + assertions. It has been renamed to DBUS_DISABLE_ASSERT to be consistent + with the Autotools build system. (fd.o #66142, Chengwei Yang) + +• --with-valgrind=auto enables Valgrind instrumentation if and only if + valgrind headers are available. The default is still --with-valgrind=no. + (fd.o #56925, Simon McVittie) + +Dependencies: + +• Platforms with no 64-bit integer type are no longer supported. + (fd.o #65429, Simon McVittie) + +• GNU make is now (documented to be) required. (fd.o #48277, Simon McVittie) + +• Full test coverage no longer requires dbus-glib, although the tests do not + exercise the shared library (only a static copy) if dbus-glib is missing. + (fd.o #68852, Simon McVittie) + +Enhancements: + +• D-Bus Specification 0.22 + · Document GetAdtAuditSessionData() and + GetConnectionSELinuxSecurityContext() (fd.o #54445, Simon) + · Fix example .service file (fd.o #66481, Chengwei Yang) + · Don't claim D-Bus is "low-latency" (lower than what?), just + give factual statements about it supporting async use + (fd.o #65141, Justin Lee) + · Document the contents of .service files, and the fact that + system services' filenames are constrained + (fd.o #66608; Simon McVittie, Chengwei Yang) + +• Be thread-safe by default on all platforms, even if + dbus_threads_init_default() has not been called. For compatibility with + older libdbus, library users should continue to call + dbus_threads_init_default(): it is harmless to do so. + (fd.o #54972, Simon McVittie) + +• Add GetConnectionCredentials() method (fd.o #54445, Simon) + +• New API: dbus_setenv(), a simple wrapper around setenv(). + Note that this is not thread-safe. (fd.o #39196, Simon) + +• Add dbus-send --peer=ADDRESS (connect to a given peer-to-peer connection, + like --address=ADDRESS in previous versions) and dbus-send --bus=ADDRESS + (connect to a given bus, like dbus-monitor --address=ADDRESS). + dbus-send --address still exists for backwards compatibility, + but is no longer documented. (fd.o #48816, Andrey Mazo) + +• Windows-specific: + · "dbus-daemon --nofork" is allowed on Windows again. (fd.o #68852, + Simon McVittie) + +Fixes: + +• Avoid an infinite busy-loop if a signal interrupts waitpid() + (fd.o #68945, Simon McVittie) + +• Clean up memory for parent nodes when objects are unexported + (fd.o #60176, Thomas Fitzsimmons) + +• Make dbus_connection_set_route_peer_messages(x, FALSE) behave as + documented. Previously, it assumed its second parameter was TRUE. + (fd.o #69165, Chengwei Yang) + +• Escape addresses containing non-ASCII characters correctly + (fd.o #53499, Chengwei Yang) + +• Document <servicedir> search order correctly (fd.o #66994, Chengwei Yang) + +• Don't crash on "dbus-send --session / x.y.z" which regressed in 1.7.4. + (fd.o #65923, Chengwei Yang) + +• If malloc() returns NULL in _dbus_string_init() or similar, don't free + an invalid pointer if the string is later freed (fd.o #65959, Chengwei Yang) + +• If malloc() returns NULL in dbus_set_error(), don't va_end() a va_list + that was never va_start()ed (fd.o #66300, Chengwei Yang) + +• fix build failure with --enable-stats (fd.o #66004, Chengwei Yang) + +• fix a regression test on platforms with strict alignment (fd.o #67279, + Colin Walters) + +• Avoid calling function parameters "interface" since certain Windows headers + have a namespace-polluting macro of that name (fd.o #66493, Ivan Romanov) + +• Assorted Doxygen fixes (fd.o #65755, Chengwei Yang) + +• Various thread-safety improvements to static variables (fd.o #68610, + Simon McVittie) + +• Make "make -j check" work (fd.o #68852, Simon McVittie) + +• Fix a NULL pointer dereference on an unlikely error path + (fd.o #69327, Sviatoslav Chagaev) + +• Improve valgrind memory pool tracking (fd.o #69326, + Sviatoslav Chagaev) + +• Don't over-allocate memory in dbus-monitor (fd.o #69329, + Sviatoslav Chagaev) + +• dbus-monitor can monitor dbus-daemon < 1.5.6 again + (fd.o #66107, Chengwei Yang) + +• Unix-specific: + · If accept4() fails with EINVAL, as it can on older Linux kernels + with newer glibc, try accept() instead of going into a busy-loop. + (fd.o #69026, Chengwei Yang) + · If socket() or socketpair() fails with EINVAL or EPROTOTYPE, + for instance on Hurd or older Linux with a new glibc, try without + SOCK_CLOEXEC. (fd.o #69073; Pino Toscano, Chengwei Yang) + · Fix a file descriptor leak on an error code path. + (fd.o #69182, Sviatoslav Chagaev) + · dbus-run-session: clear some unwanted environment variables + (fd.o #39196, Simon) + · dbus-run-session: compile on FreeBSD (fd.o #66197, Chengwei Yang) + · Don't fail the autolaunch test if there is no DISPLAY (fd.o #40352, Simon) + · Use dbus-launch from the builddir for testing, not the installed copy + (fd.o #37849, Chengwei Yang) + · Fix compilation if writev() is unavailable (fd.o #69409, + Vasiliy Balyasnyy) + · Remove broken support for LOCAL_CREDS credentials passing, and + document where each credential-passing scheme is used (fd.o #60340, + Simon McVittie) + · Make autogen.sh work on *BSD by not assuming GNU coreutils functionality + (fd.o #35881, #69787; Chengwei Yang) + · dbus-monitor: be portable to NetBSD (fd.o #69842, Chengwei Yang) + · dbus-launch: stop using non-portable asprintf (fd.o #37849, Simon) + · Improve error reporting from the setuid activation helper (fd.o #66728, + Chengwei Yang) + +• Windows-specific: + · Remove unavailable command-line options from 'dbus-daemon --help' + (fd.o #42441, Ralf Habacker) + · Add support for looking up local TCPv4 clients' credentials on + Windows XP via the undocumented AllocateAndGetTcpExTableFromStack + function (fd.o #66060, Ralf Habacker) + · Fix insufficient dependency-tracking (fd.o #68505, Simon McVittie) + · Don't include wspiapi.h, fixing a compiler warning (fd.o #68852, + Simon McVittie) + +• Internal changes: + · add DBUS_ENABLE_ASSERT, DBUS_ENABLE_CHECKS for less confusing + conditionals (fd.o #66142, Chengwei Yang) + · improve verbose-mode output (fd.o #63047, Colin Walters) + · consolidate Autotools and CMake build (fd.o #64875, Ralf Habacker) + · fix various unused variables, unusual build configurations + etc. (fd.o #65712, #65990, #66005, #66257, #69165, #69410, #70218; + Chengwei Yang, Vasiliy Balyasnyy) + +D-Bus 1.7.4 (2013-06-13) +== + +The “but is your thread-safety thread-safe?” release. + +Security fixes: + +• CVE-2013-2168: Fix misuse of va_list that could be used as a denial + of service for system services. Vulnerability reported by Alexandru Cornea. + (Simon) + +Dependencies: + +• The Windows version of libdbus now contains a C++ source file, used + to provide global initialization when the library is loaded. + gcc (mingw*) users should ensure that g++ is also installed. + +• The libxml2-based configuration reader (which hasn't worked for 2.5 years, + and was never the recommended option) has been removed. Expat is now a + hard dependency. + +Enhancements: + +• It should now be safe to call dbus_threads_init_default() from any thread, + at any time. Authors of loadable modules and plugins that use libdbus + should consider doing so during initialization. + (fd.o #54972, Simon McVittie) + +• Improve dbus-send documentation and command-line parsing (fd.o #65424, + Chengwei Yang) + +Unix-specific: + · dbus-run-session: experimental new tool to start a temporary D-Bus + session, e.g. for regression tests or a text console, replacing + certain uses of dbus-launch which weren't really correct + (fd.o #39196, Simon) + +Other fixes: + +• In dbus-daemon, don't crash if a .service file starts with key=value + (fd.o #60853, Chengwei Yang) + +• Unix-specific: + · Fix a crash similar to CVE-2013-2168 the first time we try to use syslog + on a platform not defining LOG_PERROR, such as Solaris or QNX. + This regressed in 1.7.0. (Simon) + · Fix an assertion failure if we try to activate systemd services before + systemd connects to the bus (fd.o #50199, Chengwei Yang) + · Avoid compiler warnings for ignoring the return from write() + (Chengwei Yang) + +• Windows-specific: + · Under cmake, install runtime libraries (DLLs) into bin/ instead of lib/ + so that Windows finds them (fd.o #59733, Ralf Habacker) + +D-Bus 1.7.2 (2013-04-25) +== + +The “only partially opaque” release. + +Configuration changes: + +• On non-QNX Unix platforms, the default limit on fds per message in the + session bus configuration has reduced from 4096 to 1024. The default + limit used on the system bus was already 1024. On QNX, both limits are + reduced further, to 128. + +Enhancements: + +• D-Bus Specification 0.21 + · Following Unicode Corrigendum #9, the noncharacters U+nFFFE, U+nFFFF, + U+FDD0..U+FDEF are allowed in UTF-8 strings again. (fd.o #63072, + Simon McVittie) + +Fixes: + +• Diagnose incorrect use of dbus_connection_get_data() with negative slot + (i.e. before allocating the slot) rather than returning junk + (fd.o #63127, Dan Williams) + +• Fix a cmake build regression since 1.7.0 (fd.o #63682; Ralf Habacker, + Simon McVittie) + +• Unix-specific: + · On Linux, link successfully with glibc 2.17 (fd.o #63166, Simon McVittie) + · Under systemd, log to syslog only, not stderr, avoiding duplication + (fd.o #61399, #39987; Colin Walters, Dagobert Michelsen) + · Under systemd, remove unnecessary dependency on syslog.socket + (fd.o #63531, Cristian Rodríguez) + · Include alloca.h for alloca() if available, fixing compilation on + Solaris 10 (fd.o #63071, Dagobert Michelsen) + · Allow use of systemd-logind without the rest of systemd + (fd.o #62585, Martin Pitt) + · When built with CMake, link to librt and use the right path for + meinproc's XSLT stylesheets (fd.o #61637, Ralf Habacker) + · Reduce the default limit on number of fds per message to 128 under + QNX, working around an arbitrary OS limit (fd.o #61176, Matt Fischer) + +• Windows-specific: + · Do not claim that all bus clients have the dbus-daemon's credentials; + pick up local TCPv4 clients' credentials (process ID and security + identifier, i.e. user) using GetExtendedTcpTable() (fd.o #61787, + Ralf Habacker) + +D-Bus 1.7.0 (2013-02-22) +== + +The "Disingenuous Assertions" release. + +This is a new development release, starting the 1.7.x branch. D-Bus 1.6 +remains the recommended version for long-term-supported distributions +or the upcoming GNOME 3.8 release. + +Build-time configuration changes: + +• The --with-dbus-session-bus-default-address configure option is no longer + supported. Use the new --with-dbus-session-bus-connect-address and + --with-dbus-session-bus-listen-address options instead. On Windows, you + usually want them to have the same argument; on Unix, the defaults are + usually correct. + +• Similarly, the DBUS_SESSION_BUS_DEFAULT_ADDRESS CMake variable is no longer + supported; use the new DBUS_SESSION_BUS_LISTEN_ADDRESS and + DBUS_SESSION_BUS_CONNECT_ADDRESS variables instead. + +• cmake/cross-compile.sh has been removed. Instead, please use a + cross-toolchain file (-DCMAKE_TOOLCHAIN_FILE) as documented at + <http://www.vtk.org/Wiki/CMake_Cross_Compiling>; or use Autotools + as documented in "info automake Cross-Compilation", and set + PKG_CONFIG_PATH appropriately. + +Requirements: + +• Man pages now require xmlto (or either xmlto or meinproc, if using CMake). +• man2html is no longer used. + +Enhancements: + +• D-Bus Specification 0.20 + · actually say that /org/freedesktop/DBus is the object that + implements o.fd.DBus (fd.o #51865, Colin Walters) + · various reorganisation for better clarity (fd.o #38252, Simon McVittie) + · stop claiming that all basic types work just like INT32 (strings don't!) + +• The "source code" for the man pages is now Docbook XML, eliminating + the outdated duplicate copies used when building with CMake. + (fd.o #59805; Ralf Habacker, Simon McVittie) + +Fixes: + +• In the activation helper, when compiled for tests, do not reset the system + bus address, fixing the regression tests. (fd.o #52202, Simon) + +• Fix building with Valgrind 3.8, at the cost of causing harmless warnings + with Valgrind 3.6 on some compilers (fd.o #55932, Arun Raghavan) + +• Merge <servicehelper> from system-local.conf if necessary (fd.o #51560, + Krzysztof Konopko) + +• Under CMake, prefer xmlto over meinproc (fd.o #59733, Ralf Habacker) + +• Stop duplicating CMake's own logic to find libexpat + (fd.o #59733, Ralf Habacker) + +• Don't assume CMake host and build system are the same (fd.o #59733, + Ralf Habacker) + +• Avoid deprecation warnings for GLib 2.35 (fd.o #59971, Simon McVittie) + +• Unix-specific: + · Check for functions in libpthread correctly, fixing compilation on + (at least) OpenBSD (fd.o #47239, Simon) + · Don't leak temporary fds pointing to /dev/null (fd.o #56927, + Michel HERMIER) + · Update sd-daemon.[ch] from systemd (fd.o #60681) + · Add partial support for QNX (fd.o #60339, fd.o #61176; Matt Fischer) + +• Windows-specific: + · The default session bus listening and connecting address is now + "autolaunch:", which makes D-Bus on Windows interoperate with itself + and GDBus "out of the box". Use the configure options and cmake variables + described above if you require a different autolaunch scope. + (fd.o #38201, Simon McVittie) + · Avoid a CMake warning under Cygwin (fd.o #59401, Ralf Habacker) + +• Create session.d, system.d directories under CMake (fd.o #41319, + Ralf Habacker) + +D-Bus 1.6.8 (2012-09-28) +== + +The "Fix one thing, break another" release. + +• Follow up to CVE-2012-3524: The additional hardening + work to use __secure_getenv() as a followup to bug #52202 + broke certain configurations of gnome-keyring. Given + the difficulty of making this work without extensive + changes to gnome-keyring, use of __secure_getenv() is + deferred. + +D-Bus 1.6.6 (2012-09-28) +== + +The "Clear the environment in your setuid binaries, please" release. + +• CVE-2012-3524: Don't access environment variables (fd.o #52202) + Thanks to work and input from Colin Walters, Simon McVittie, + Geoffrey Thomas, and others. +• Unix-specific: + · Fix compilation on Solaris (fd.o #53286, Jonathan Perkin) + · Work around interdependent headers on OpenBSD by including sys/types.h + before each use of sys/socket.h (fd.o #54418, Brad Smith) + +D-Bus 1.6.4 (2012-07-18) +== + +• Detect that users are "at the console" correctly when configured with + a non-default path such as --enable-console-auth-dir=/run/console + (fd.o #51521, Dave Reisner) + +• Remove an incorrect assertion from DBusTransport (fd.o #51657, + Simon McVittie) + +• Make --enable-developer default to "no" (regression in 1.6.2; + fd.o #51657, Simon McVittie) + +• Windows-specific: + · Launch dbus-daemon correctly if its path contains a space + (fd.o #49450, Wolfgang Baron) + +D-Bus 1.6.2 (2012-06-27) +== + +The "Ice Cabbage" release. + +• Change how we create /var/lib/dbus so it works under Automake >= 1.11.4 + (fd.o #51406, Simon McVittie) + +• Don't return from dbus_pending_call_set_notify with a lock held on OOM + (fd.o #51032, Simon McVittie) + +• Disconnect "developer mode" (assertions, verbose mode etc.) from + Automake maintainer mode. D-Bus developers should now configure with + --enable-developer. Automake maintainer mode is now on by default; + distributions can disable it with --disable-maintainer-mode. + (fd.o #34671, Simon McVittie) + +• Automatically define DBUS_STATIC_BUILD in static-only Autotools builds, + fixing linking when targeting Windows (fd.o #33973; william, Simon McVittie) + +• Unix-specific: + · Check for libpthread under CMake on Unix (fd.o #47237, Simon McVittie) + +D-Bus 1.6.0 (2012-06-05) +== + +The “soul of this machine has improved” release. + +This version starts a new stable branch of D-Bus: only bug fixes will +be accepted into 1.6.x. Other changes will now go to the 1.7.x branch. + +Summary of changes since 1.4.x: + +• New requirements + · PTHREAD_MUTEX_RECURSIVE on Unix + · compiler support for 64-bit integers (int64_t or equivalent) + +• D-Bus Specification v0.19 + +• New dbus-daemon features + · <allow own_prefix="com.example.Service"/> rules allow the service to + own names like com.example.Service.Instance3 + · optional systemd integration when checking at_console policies + · --nopidfile option, mainly for use by systemd + · path_namespace and arg0namespace may appear in match rules + · eavesdropping is disabled unless the match rule contains eavesdrop=true + +• New public API + · functions to validate various string types (dbus_validate_path() etc.) + · dbus_type_is_valid() + · DBusBasicValue, a union of every basic type + +• Bug fixes + · removed an unsafe reimplementation of recursive mutexes + · dbus-daemon no longer busy-loops if it has far too many file descriptors + · dbus-daemon.exe --print-address works on Windows + · all the other bug fixes from 1.4.20 + +• Other major implementation changes + · on Linux, dbus-daemon uses epoll if supported, for better scalability + · dbus_threads_init() ignores its argument and behaves like + dbus_threads_init_default() instead + · removed the per-connection link cache, improving dbus-daemon performance + +• Developer features + · optional Valgrind instrumentation (--with-valgrind) + · optional Stats interface on the dbus-daemon (--enable-stats) + · optionally abort whenever malloc() fails (--enable-embedded-tests + and export DBUS_MALLOC_CANNOT_FAIL=1) + +Changes since 1.5.12: + +• Be more careful about monotonic time vs. real time, fixing DBUS_COOKIE_SHA1 + spec-compliance (fd.o #48580, David Zeuthen) + +• Don't use install(1) within the source/build trees, fixing the build as + non-root when using OpenBSD install(1) (fd.o #48217, Antoine Jacoutot) + +• Add missing commas in some tcp and nonce-tcp addresses, and remove + an unused duplicate copy of the nonce-tcp transport in Windows builds + (fd.o #45896, Simon McVittie) + +D-Bus 1.5.12 (2012-03-27) +== + +The “Big Book of Science” release. + +• Add public API to validate various string types: + dbus_validate_path(), dbus_validate_interface(), dbus_validate_member(), + dbus_validate_error_name(), dbus_validate_bus_name(), dbus_validate_utf8() + (fd.o #39549, Simon McVittie) + +• Turn DBusBasicValue into public API so bindings don't need to invent their + own "union of everything" type (fd.o #11191, Simon McVittie) + +• Enumerate data files included in the build rather than using find(1) + (fd.o #33840, Simon McVittie) + +• Add support for policy rules like <allow own_prefix="com.example.Service"/> + in dbus-daemon (fd.o #46273, Alban Crequy) + +• Windows-specific: + · make dbus-daemon.exe --print-address (and --print-pid) work again + on Win32, but not on WinCE (fd.o #46049, Simon McVittie) + · fix duplicate case value when compiling against mingw-w64 + (fd.o #47321, Andoni Morales Alastruey) + +D-Bus 1.5.10 (2012-02-21) +== + +The "fire in Delerium" release. + +On Unix platforms, PTHREAD_MUTEX_RECURSIVE (as specified in POSIX 2008 Base +and SUSv2) is now required. + +• D-Bus Specification 0.19: + · Formally define unique connection names and well-known bus names, + and document best practices for interface, bus, member and error names, + and object paths (fd.o #37095, Simon McVittie) + · Document the search path for session and system services on Unix, and + where they should be installed by build systems (fd.o #21620, fd.o #35306; + Simon McVittie) + · Document the systemd transport (fd.o #35232, Lennart Poettering) + +• Make dbus_threads_init() use the same built-in threading implementation + as dbus_threads_init_default(); the user-specified primitives that it + takes as a parameter are now ignored (fd.o #43744, Simon McVittie) + +• Allow all configured auth mechanisms, not just one (fd.o #45106, + Pavel Strashkin) + +• Improve cmake build system (Ralf Habacker): + · simplify XML parser dependencies (fd.o #41027) + · generate build timestamp (fd.o #41029) + · only create batch files on Windows + · fix option and cache syntax + · add help-options target + · share dbus-arch-deps.h.in with autotools rather than having our + own version (fd.o #41033) + +• Build tests successfully with older GLib, as found in e.g. Debian 6 + (fd.o #41219, Simon McVittie) + +• Avoid use of deprecated GThread API (fd.o #44413, Martin Pitt) + +• Build documentation correctly if man2html doesn't support filenames on + its command-line (fd.o #43875, Jack Nagel) + +• Improve test coverage. To get even more coverage, run the tests with + DBUS_TEST_SLOW=1 (fd.o #38285, #42811; Simon McVittie) + +• Reduce the size of the shared library by moving functionality only used + by dbus-daemon, tests etc. into their internal library and deleting + unused code (fd.o #34976, #39759; Simon McVittie) + +• Add dbus-daemon --nopidfile option, overriding the configuration, for + setups where the default configuration must include <pidfile/> to avoid + breaking traditional init, but the pid file is in fact unnecessary; use + it under systemd to improve startup time a bit (fd.o #45520, + Lennart Poettering) + +• Optionally (if configured --with-valgrind) add instrumentation to debug + libdbus and associated tools more meaningfully under Valgrind + (fd.o #37286, Simon McVittie) + +• Improve the dbus-send(1) man page (fd.o #14005, Simon McVittie) + +• Make dbus-protocol.h compatible with C++11 (fd.o #46147, Marc Mutz) + +• If tests are enabled and DBUS_MALLOC_CANNOT_FAIL is set in the environment, + abort on failure to malloc() (like GLib does), to turn runaway memory leaks + into a debuggable core-dump if a resource limit is applied (fd.o #41048, + Simon McVittie) + +• Don't crash if realloc() returns NULL in a debug build (fd.o #41048, + Simon McVittie) + +• Unix-specific: + · Replace our broken reimplementation of recursive mutexes, which has + been broken since 2006, with an ordinary pthreads recursive mutex + (fd.o #43744; Sigmund Augdal, Simon McVittie) + · Use epoll(7) for a more efficient main loop in Linux; equivalent patches + welcomed for other OSs' equivalents like kqueue, /dev/poll, or Solaris + event ports (fd.o #33337; Simon McVittie, Ralf Habacker) + · When running under systemd, use it instead of ConsoleKit to check + whether to apply at_console policies (fd.o #39609, Lennart Poettering) + · Avoid a highly unlikely fd leak (fd.o #29881, Simon McVittie) + · Don't close invalid fd -1 if getaddrinfo fails (fd.o #37258, eXeC001er) + · Don't touch ~/.dbus and ~/.dbus-keyrings when running 'make installcheck' + (fd.o #41218, Simon McVittie) + · Stop pretending we respect XDG_DATA_DIRS for system services: the launch + helper doesn't obey environment variables to avoid privilege escalation + attacks, so make the system bus follow the same rules + (fd.o #21620, Simon McVittie) + +• Windows-specific: + · Find the dbus-daemon executable next to the shared library (fd.o #41558; + Jesper Dam, Ralf Habacker) + · Remove the faulty implementation of _dbus_condvar_wake_all (fd.o #44609, + Simon McVittie) + +D-Bus 1.5.8 (2011-09-21) +== + +The "cross-metering" release. + +In addition to dead code removal and refactoring, this release contains all +of the bugfixes from 1.4.16. + +• Clean up dead code, and make more warnings fatal in development builds + (fd.o #39231, fd.o #41012; Simon McVittie) + +• If full test coverage is requested via --enable-tests, strictly require + Python, pygobject and dbus-python, which are required by some tests; if not, + and Python is missing, skip those tests rather than failing + (fd.o #37847, Simon McVittie) + +• When using cmake, provide the same version-info API in the installed headers + as for autotools (DBUS_VERSION, etc.) (fd.o #40905, Ralf Habacker) + +• Add a regression test for fd.o #38005 (fd.o #39836, Simon McVittie) + +• Make "NOCONFIGURE=1 ./autogen.sh" not run configure (Colin Walters) + +• Add _DBUS_STATIC_ASSERT and use it to check invariants (fd.o #39636, + Simon McVittie) + +• Fix duplicates in authors list (Ralf Habacker) + +• Fix broken links from dbus-tutorial.html if $(htmldir) != $(docdir) + (fd.o #39879, Chris Mayo) + +• Fix a small memory leak, and a failure to report errors, when updating + a service file entry for activation (fd.o #39230, Simon McVittie) + +• Unix-specific: + · Clean up (non-abstract) Unix sockets on bus daemon exit (fd.o #38656; + Brian Cameron, Simon McVittie) + · On systems that use libcap-ng but not systemd, drop supplemental groups + when switching to the daemon user (Red Hat #726953, Steve Grubb) + · Make the cmake build work again on GNU platforms (fd.o #29228, + Simon McVittie) + · Fix compilation on non-C99 systems that have inttypes.h but not stdint.h, + like Solaris (fd.o #40313, Dagobert Michelsen) + · Define CMSG_ALIGN, CMSG_LEN, CMSG_SPACE on Solaris < 10 + (fd.o #40235, Simon McVittie) + · Cope with Unixes that don't have LOG_PERROR, like Solaris 10 + (fd.o #39987, Simon McVittie) + · Cope with platforms whose vsnprintf violates both POSIX and C99, like + Tru64, IRIX and HP-UX (fd.o #11668, Simon McVittie) + +• Windows-specific: + · Fix compilation on MSVC, which doesn't understand "inline" with its + C99 meaning (fd.o #40000; Ralf Habacker, Simon McVittie) + · Fix misuse of GPid in test/dbus-daemon.c (fd.o #40003, Simon McVittie) + · Fix cross-compilation to Windows with Automake (fd.o #40003, Simon McVittie) + +D-Bus 1.5.6 (2011-07-29) +== + +The "weird, gravy-like aftertaste" release. + +In addition to new features and refactoring, this release contains all of the +bugfixes from 1.4.14. + +Potentially incompatible (Bustle and similar debugging tools will need +changes to work as intended): + +• Do not allow match rules to "eavesdrop" (receive messages intended for a + different recipient) by mistake: eavesdroppers must now opt-in to this + behaviour by putting "eavesdrop='true'" in the match rule, which will + not have any practical effect on buses where eavesdropping is not allowed + (fd.o #37890, Cosimo Alfarano) + +Other changes: + +• D-Bus Specification version 0.18 (fd.o #37890, fd.o #39450, fd.o #38252; + Cosimo Alfarano, Simon McVittie) + · add the "eavesdrop" keyword to match rules + · define eavesdropping, unicast messages and broadcast messages + · stop claiming that match rules are needed to match unicast messages to you + · promote the type system to be a top-level section + +• Use DBUS_ERROR_OBJECT_PATH_IN_USE if dbus_connection_try_register_object_path + or dbus_connection_try_register_fallback fails, not ...ADDRESS_IN_USE, + and simplify object-path registration (fd.o #38874, Jiří Klimeš) + +• Consistently use atomic operations on everything that is ever manipulated + via atomic ops, as was done for changes to DBusConnection's refcount in + 1.4.12 (fd.o #38005, Simon McVittie) + +• Fix a file descriptor leak when connecting to a TCP socket (fd.o #37258, + Simon McVittie) + +• Make "make check" in a clean tree work, by not running tests until + test data has been set up (fd.o #34405, Simon McVittie) + +• The dbus-daemon no longer busy-loops if it has a very large number of file + descriptors (fd.o #23194, Simon McVittie) + +• Refactor message flow through dispatching to avoid locking violations if + the bus daemon's message limit is hit; remove the per-connection link cache, + which was meant to improve performance, but now reduces it (fd.o #34393, + Simon McVittie) + +• Some cmake fixes (Ralf Habacker) + +• Remove dead code, mainly from DBusString (fd.o #38570, fd.o #39610; + Simon McVittie, Lennart Poettering) + +• Stop storing two extra byte order indicators in each D-Bus message + (fd.o #38287, Simon McVittie) + +• Add an optional Stats interface which can be used to get statistics from + a running dbus-daemon if enabled at configure time with --enable-stats + (fd.o #34040, Simon McVittie) + +• Fix various typos (fd.o #27227, fd.o #38284; Sascha Silbe, Simon McVittie) + +• Documentation (fd.o #36156, Simon McVittie): + · let xsltproc be overridden as usual: ./configure XSLTPROC=myxsltproc + · install more documentation automatically, including man2html output + · put dbus.devhelp in the right place (it must go in ${htmldir}) + +• Unix-specific: + · look for system services in /lib/dbus-1/system-services in addition to all + the other well-known locations; note that this should always be /lib, + even on platforms where shared libraries on the root FS would go in /lib64, + /lib/x86_64-linux-gnu or similar (fd.o #35229, Lennart Poettering) + · opt-in to fd passing on Solaris (fd.o #33465, Simon McVittie) + +• Windows-specific (Ralf Habacker): + · fix use of a mutex for autolaunch server detection + · don't crash on malloc failure in _dbus_printf_string_upper_bound + +D-Bus 1.5.4 (2011-06-10) +== + +Security (local denial of service): + +• Byte-swap foreign-endian messages correctly, preventing a long-standing + local DoS if foreign-endian messages are relayed through the dbus-daemon + (backporters: this is git commit c3223ba6c401ba81df1305851312a47c485e6cd7) + (CVE-2011-2200, fd.o #38120, Debian #629938; Simon McVittie) + +New things: + +• The constant to use for an infinite timeout now has a name, + DBUS_TIMEOUT_INFINITE. It is numerically equivalent to 0x7fffffff (INT32_MAX) + which can be used for source compatibility with older versions of libdbus. + +• If GLib and DBus-GLib are already installed, more tests will be built, + providing better coverage. The new tests can also be installed via + ./configure --enable-installed-tests + for system integration testing, if required. (fd.o #34570, Simon McVittie) + +Changes: + +• Consistently use atomic operations for the DBusConnection's refcount, + fixing potential threading problems (fd.o #38005, Simon McVittie) + +• Don't use -Wl,--gc-sections by default: in practice the size decrease is + small (300KiB on x86-64) and it frequently doesn't work in unusual + toolchains. To optimize for minimum installed size, you should benchmark + various possibilities for CFLAGS and LDFLAGS, and set the best flags for + your particular toolchain at configure time. (fd.o #33466, Simon McVittie) + +• Use #!/bin/sh for run-with-tmp-session-bus.sh, making it work on *BSD + (fd.o #35880, Timothy Redaelli) + +• Use ln -fs to set up dbus for systemd, which should fix reinstallation + when not using a DESTDIR (fd.o #37870, Simon McVittie) + +• Windows-specific changes: + · don't try to build dbus-daemon-launch-helper (fd.o #37838, Mark Brand) + +D-Bus 1.5.2 (2011-06-01) +== + +The "Boar Hunter" release. + +Notes for distributors: + + This version of D-Bus no longer uses -fPIE by default. Distributions wishing + to harden the dbus-daemon and dbus-launch-helper can re-enable this if their + toolchain supports it reliably, via something like: + + ./configure CFLAGS=-fPIE LDFLAGS="-pie -Wl,-z,relro" + + or by using distribution-specific wrappers such as Debian's hardening-wrapper. + +Changes: + + • D-Bus Specification v0.17 + · Reserve the extra characters used in signatures by GVariant + (fd.o #34529, Simon McVittie) + · Define the ObjectManager interface (fd.o #34869, David Zeuthen) + • Don't force -fPIE: distributions and libtool know better than we do whether + it's desirable (fd.o #16621, fd.o #27215; Simon McVittie) + • Allow --disable-gc-sections, in case your toolchain offers the + -ffunction-sections, -fdata-sections and -Wl,--gc-sections options + but they're broken, as seen on Solaris (fd.o #33466, Simon McVittie) + • Install dbus-daemon and dbus-daemon-launch-helper in a more normal way + (fd.o #14512; Simon McVittie, loosely based on a patch from Luca Barbato) + • Ensure that maintainers upload documentation with the right permissions + (fd.o #36130, Simon McVittie) + • Don't force users of libdbus to be linked against -lpthread, -lrt + (fd.o #32827, Simon McVittie) + • Log system-bus activation information to syslog (fd.o #35705, + Colin Walters) + • Log messages dropped due to quotas to syslog (fd.o #35358, + Simon McVittie) + • Make the nonce-tcp transport work on Unix (fd.o #34569, Simon McVittie) + • On Unix, if /var/lib/dbus/machine-id cannot be read, try /etc/machine-id + (fd.o #35228, Lennart Poettering) + • In the regression tests, don't report fds as "leaked" if they were open + on startup (fd.o #35173, Simon McVittie) + • Make dbus-monitor bail out if asked to monitor more than one bus, + rather than silently using the last one (fd.o #26548, Will Thompson) + • Clarify documentation (fd.o #35182, Simon McVittie) + • Clean up minor dead code and some incorrect error handling + (fd.o #33128, fd.o #29881; Simon McVittie) + • Check that compiler options are supported before using them (fd.o #19681, + Simon McVittie) + • Windows: + • Remove obsolete workaround for winioctl.h (fd.o #35083, Ralf Habacker) + +D-Bus 1.5.0 (2011-04-11) +== + +The "you never know when you need to tow something from your giant +flying shark" release. + + • D-Bus Specification v0.16 + · Add support for path_namespace and arg0namespace in match rules + (fd.o #24317, #34870; Will Thompson, David Zeuthen, Simon McVittie) + · Make argNpath support object paths, not just object-path-like strings, + and document it better (fd.o #31818, Will Thompson) + • Let the bus daemon implement more than one interface (fd.o #33757, + Simon McVittie) + • Optimize _dbus_string_replace_len to reduce waste (fd.o #21261, + Roberto Guido) + • Require user intervention to compile with missing 64-bit support + (fd.o #35114, Simon McVittie) + • Add dbus_type_is_valid as public API (fd.o #20496, Simon McVittie) + • Raise UnknownObject instead of UnknownMethod for calls to methods on + paths that are not part of the object tree, and UnknownInterface for calls + to unknown interfaces in the bus daemon (fd.o #34527, Lennart Poettering) + +D-Bus 1.4.8 (2011-04-08) +== + +The "It's like the beginning of a lobster" release. + + • Rename configure.in to configure.ac, and update it to modern conventions + (fd.o #32245; Javier Jardón, Simon McVittie) + • Correctly give XDG_DATA_HOME priority over XDG_DATA_DIRS (fd.o #34496, + Anders Kaseorg) + • Prevent X11 autolaunching if $DISPLAY is unset or empty, and add + --disable-x11-autolaunch configure option to prevent it altogether + in embedded environments (fd.o #19997, NB#219964; Simon McVittie) + • Install the documentation, and an index for Devhelp (fd.o #13495, + Debian #454142; Simon McVittie, Matthias Clasen) + • If checks are not disabled, check validity of string-like types and + booleans when sending them (fd.o #16338, NB#223152; Simon McVittie) + • Add UnknownObject, UnknownInterface, UnknownProperty and PropertyReadOnly + errors to dbus-shared.h (fd.o #34527, Lennart Poettering) + • Break up a huge conditional in config-parser so gcov can produce coverage + data (fd.o #10887, Simon McVittie) + • List which parts of the Desktop Entry specification are applicable to + .service files (fd.o #19159, Sven Herzberg) + • Don't suppress service activation if two services have the same Exec= + (fd.o #35750, Colin Walters) + • Windows: + · Avoid the name ELEMENT_TYPE due to namespace-pollution from winioctl.h + (Andre Heinecke) + · Include _dbus_path_is_absolute in libdbus on Windows, fixing compilation + (fd.o #32805, Mark Brand) + +D-Bus 1.4.6 (2010-02-17) +== + +The "1, 2, miss a few, 99, 100" release. + + • Remove unfinished changes intended to support GTest-based tests, + which were mistakenly included in 1.4.4 + +D-Bus 1.4.4 (2010-02-17) +== + + • Switch back to using even micro versions for stable releases; 1.4.1 + should have been called 1.4.2, so skip that version number + • Don't leave bad file descriptors being watched when spawning processes, + which could result in a busy-loop (fd.o #32992, NB#200248; possibly + also LP#656134, LP#680444, LP#713157) + • Check for MSG_NOSIGNAL correctly + • Fix failure to detect abstract socket support (fd.o #29895) + • Make _dbus_system_logv actually exit with DBUS_SYSTEM_LOG_FATAL + (fd.o #32262, NB#180486) + • Improve some error code paths (fd.o #29981, fd.o #32264, fd.o #32262, + fd.o #33128, fd.o #33277, fd.o #33126, NB#180486) + • Avoid possible symlink attacks in /tmp during compilation (fd.o #32854) + • Tidy up dead code (fd.o #25306, fd.o #33128, fd.o #34292, NB#180486) + • Improve gcc malloc annotations (fd.o #32710) + • If the system bus is launched via systemd, protect it from the OOM killer + • Documentation improvements (fd.o #11190) + • Avoid readdir_r, which is difficult to use correctly (fd.o #8284, + fd.o #15922, LP#241619) + • Cope with invalid files in session.d, system.d (fd.o #19186, + Debian #230231) + • Don't distribute generated files that embed our builddir (fd.o #30285, + fd.o #34292) + • Raise the system bus's fd limit to be sufficient for its configuration + (fd.o #33474, LP#381063) + • Fix syslog string processing + • Ignore -Waddress + • Remove broken gcov parsing code and --enable-gcov, and replace them + with lcov HTML reports and --enable-compiler-coverage (fd.o #10887) + • Windows: + · avoid live-lock in Windows CE due to unfair condition variables + • OpenBSD: + · support credentials-passing (fd.o #32542) + • Solaris: + · opt-in to thread safety (fd.o #33464) + +D-Bus 1.4.1 (20 December 2010) +== + + • Fix for CVE-2010-4352: sending messages with excessively-nested variants can + crash the bus. The existing restriction to 64-levels of nesting previously + only applied to the static type signature; now it also applies to dynamic + nesting using variants. Thanks to Rémi Denis-Courmont for discoving this + issue. + • OS X portability fixes, including launchd support. + • Windows autolaunch improvements. + • Various bug fixes. + +D-Bus 1.4.0 (6 Sep 2010) +== + - systemd hookup + +D-Bus 1.3.1 (23 June 2010) +== + - New standardized PropertiesChanged signal in the properties interface + - Various portability fixes, in particular to Windows platforms + - Support forking bus services, for compatibility + +D-Bus 1.3.0 (29 July 2009) +== + - ability for dbus-send to send to any bus (--address) + - file descriptor passing on Unix socket transports + - use of GCC atomic intrinsics for better processor support + (requires -march=i486 or above for x86 compilation) + - thread-safe FD_CLOEXEC setting on recent Linux kernels (2.6.24-27 and up) + and glibc (2.9 for pipe2 and 2.10 for accept4) + - feature negotiation in the bus daemon
diff --git a/NEWS.pre-1-0 b/NEWS.pre-1-0 new file mode 100644 index 0000000..7105bc5 --- /dev/null +++ b/NEWS.pre-1-0
@@ -0,0 +1,614 @@ +D-Bus 1.0.0 (08 November 2006) +== +- Documents updated with API/ABI garuntees +- Added missing patch FreeBSD need to run out of the box +- dbus-monitor now has a profile mode +- AUTHORS file updated with names from the ChangeLog + Thanks to everyone who helped get us here + +D-Bus 1.0 RC 3 (0.95) (02 November 2006) +== +- DBUS_API_SUBJECT_TO_CHANGE no longer needs to be defined when building apps +- ./configure checks now work when cross compiling +- dbus-uuidgen --ensure is now run in the init script so there is no need to + run it in a post script +- dbus-uuidgen now writes out to /var/lib/dbus to work with systems that do not + have a writable /etc. Packages should install and own the /var/lib/dbus + directory +- recursive locks are now used when dbus_threads_init_default is called +- standard_session_servicedirs tag added to the session.conf + under a normal build this specifies these service directories: + /usr/local/share/dbus-1/services + /usr/share/dbus-1/services + $HOME/.local/share/dbus-1/services +- fixed crash when a service directory is specified more than once +- fixed a crash in *BSD when watching config directories for changes +- fixed Irix build by using dirp->__dd_fd to get the file descriptor +- cleaned up the LOCAL_CREDS vs CMGCRED credential code so *BSD's don't + crash here anymore +- dbus_message_iter_get_array_len deprecated +- cleanup-man-pages.sh added so packagers can clean up Doxygen man page output + from 7 to 2 megs +- large documentation improvements +- numerous bug fixes + +D-Bus 1.0 RC 2 (0.94) (14 October 2006) +== +- dbus-uuidgen binary added for future remote machine identification + packagers should call dbus-uuidgen --ensure in their post +- GetMachineId peer method added to the bus API +- dbus_connection_set_route_peer_messages API added to let the bus send + peer messages directly to an app +- Autolaunch abilities added to dbus-launch with the --autolaunch flag + This feature allows libdbus to start a session bus if none can be found + This is an internal feature and should not be used by scripts + DBUS_SESSION_BUS_ADDRESS is still the correct way to specify a session bus +- dbus-launch now prints out a simple key value pairs instead of shell scripts + if one of the shell flags aren't used +- support DBUS_BLOCK_ON_ABORT env variable to cause blocking waiting for gdb +- weak ref are now held for shared connections so the right things happen + this fixes some pretty major bugs with the way connections were handled +- Some refactoring for Windows (doesn't effect Unix) +- Solaris build fixes +- MacOSX build fixes +- Cross compile build fixes. We now assume getpwnam_r is posix and va_lists + can be copied by value since we can't check this in a cross compile. If + this is not true for a particular target is up to the developer to patch. +- Bug fixing all around + +D-Bus 1.0 RC 1 (0.93) (14 September 2006) +== +- dbus_threads_init_default added for initalizing threads without the need for + bindings +- Filters are now properly removed +- dbus_connection_open now holds a hard ref to shared connections +- We now print out a warning and do nothing when someone tries to close a + shared connection +- The --introspect switch has been added to the bus for printing out + introspection data without actually running the bus +- LOCAL_CREDS socket credentials are now supported for systems which + support it such as NetBSD +- Generalize kqueue support so it works with NetBSD as well as FreeBSD +- Numerous bug fixes and memory leaks patched + +D-Bus 0.92 (18 August 2006) +== +- Proper thread locking added to pending calls +- Threading semantics changed from init early to init before the second thread + is started +- Correctly error out when an application tries to acquire or release the + org.freedesktop.DBus name instead of sending false result codes +- kqueue directory watching code can now be used to monitor config file changes + on FreeBSD +- --with-dbus-daemondir configure switch added so the daemon can be installed + separate from the user binaries +- Makefiles fixed for cygwin +- Various fixes for the ongoing Windows port +- Fixed docs and comments to use the D-Bus spelling instead of D-BUS +- Many memleaks and bugs fixed + +D-Bus 0.91 (24 July 2006) +== +- Remove some lingering bits left over from the bindings split +- Fix assertion causing D-Bus applications to crash when checks are enabled +- Fix a timeout bug which would block applications from being auto started + +D-Bus 0.90 (17 July 2006) +== +- API/ABI freeze for 1.0 +- Bindings are now split out into seperate packages +- ListActivatableNames added as a method on the bus +- Removed deprecated dbus_connection_disconnect (use dbus_connection_close) +- Shared connections are now unreffed on disconnect +- Fixed pending calls for threaded enviornments +- Pending calls get timed out on connection disconnect +- dbus_connection_send_with_reply returns TRUE and a NULL pending call + if you call it on a connection object which has been disconnected already + (it returns FALSE on Out of Memory errors only) +- dbus-monitor now correctly catches methods, not just signals +- dbus-monitor now prints object paths + +D-BUS 0.62 (12 June 2006) +== +- Doc fixes +- Added support for all data-types for the dbus tools +- Fixed eavesdropping on method calls (dbus-monitor) +- Fixed silent dropping of method calls with interface=NULL +- Fixed console ownership problems in Solaris +- Fixed installation of dbus-signature.h and #include it in dbus/dbus.h +- Flush the user database cache on config reload +- GLib bindings: + - Fix memory leaks + - Fix properties in DBusGProxy so that they can be given in any + order + - Added lots of assertions to ensure correct use + - Remove duplicated code + - Fix static string pointer uses in GPtrArray-based collections +- Python bindings: + - Remove reference to sys/cdefs.h +- Qt4 bindings: + - Code reorganized + - Added the dbusidl2cpp, dbuscpp2xml and dbus tools + - Added example programs (ping-pong, complex ping-pong, listnames, chat) + - Updated selftests + - Fixed compilation and .moc- and .ui-file processing and cleaning + - Made central classes derive from QObject + - Enhance error reporting + - Many bugfixes +- Mono bindings: + - Minor bugfixes + +D-BUS 0.61 (24 Febuary 2006) +== +- Documentation all around +- dbus-launch now produces correct sh and csh syntax +- Nested arrays now work correctly +- GLib bindings: + - Inheriting from DBusGProxy is now possible + - GPtrArrays can now be marshalled + - org.freedesktop.DBus.GLib.ClientCSymbol annotation added + - Openning connections to arbitrary addresses now supported +- Python bindings: + - sender_keyword and path_keyword keywords added to signal listener API + - Byte types now demarshal to unsigned char + - calling methods now do the correct thing +- Qt bindings: + - both Qt3 and Qt4 bindings can be built at the same time + - Use the standard org.freedesktop.DBus.Method.NoReply annotation + for the "async" calls instead of creating one for us. +- Mono bindings: + - 64bit arch fixes +- Massive bug fixing all around + +D-BUS 0.60 (30 November 2005) +== + +- major ABI/API changes - sonames changed +- RequestName queuing behavior has changed (refer to dbus-specification) + - DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT has been removed and + DBUS_NAME_FLAG_ALLOW_REPLACEMENT has been added to the flags +- signals emitted by the bus now show up in the introspect data +- auth EXTERNAL now supported on BSD varients +- ReleaseName method added to the bus to allow a service + to remove itself as owner of a bus name +- dbus_connection_read_write added for getting messages off the bus + in the absence of a mainloop +- Qt4 bindings added and the Qt3 bindings have been depricated +- python bindings: + - marshal using introspect data if available + - better exception handling and propigation + - private connections are now supported + - UTF-8 cleanups + - out_signature added to method decorators for specifying + how the return values should be marshaled + - sender_keyword added to method decorators for specifying + and argument to provide the unique name of the method caller + - async_callbacks added to method decorators + - multiple inheritance of classes now supported +- GLib bindings: + - respect NoReply annotations + - dbus_g_method_return_get_reply and dbus_g_method_return_send_reply + added to the lowlevel code for use when the dbus-glib marshalling + code is not adiquate +- numerous bug fixes all around + +D-BUS 0.50 (06 September 2005) +=== +This is a minor release from 0.36.2. The series number has changed +not because of any technical reasons but as an indication that we +are moving closer to 1.0. It is hoped that this will be the last +series to see major changes, most of which will be isolated to the +GLib and Python bindings, as we transition to concentrate more on +bug busting and code auditing. + +- D-Bus builds on the Cygwin platform +- Makefile cleanups +- Various bug fixes +- Optimization of the dbus object tree +- Memleaks and GIL crasher bugs have been fixed in the Python bindings + +D-BUS 0.36.2 (29 August 2005) +=== +- Security: Restrict other users from connecting to another users + session bus + +D-BUS 0.36.1 (24 August 2005) +=== +- Python Bindings: + - fixed to work with hal-device-manager + - For 64bit builds everything is installed to lib64/python2.4/ + since Python can't handle multilib + +D-BUS 0.36 (23 August 2005) +=== +- Maximum sized of cached messages have been reduced to 10K +- Match rules now allow matching on arguments inside the message +- introspect.xsl XSLT style sheet added for formatting introspection + data into XHTML for analysis +- Python bindings: + - now have working type objects for explicit + typecasting + - Variant type has been added + - Dictionaries, Variants and Arrays can all be passed the signiture or + type(s) of their children + - the optional timeout= keyword has been added when making method calls + - match on args has been implemented + - a .pth file has been added for dealing with libraries and python files + being in different directories such as in 64bit installs + - various bug fixes +- GLib bindings: + - deeply recursive types now supported + - many symbols are no longer exported as part of the public API + - various memleak and other bug fixes + +D-BUS 0.35.2 (17 July 2005) +=== +- Rename Unix Security Context to SELinux Security Context in API +- Fixed more dist errors that distcheck didn't pick up on +- Fixed various bugs in the python bindings that prevented them from working + +D-BUS 0.35.1 (16 July 2005) +=== +- Fixed dist error where python/dbus_bindings.pxd was being shipped + instead of dbus_bindings.pxd.in +- Use this instead of the 0.35 tarball + +D-BUS 0.35 (15 July 2005) +=== +- --with-dbus-user added to the configure scripts for configuring the + user the system bus runs on +- --with-console-auth-dir added to configure scripts for configuring the + directory to look in for console user locks +- service files for auto-starting D-Bus services now has the ability to pass + in command line arguments to the executable +- Huge auto-start bug squashed which caused some services not to start when + requested in rapid succession +- SE-Linux security contexts can now be appended to messages for inspection + by services that enforce their own security policies +- Colin says the GLib binding are ready for general consumption +- New GLib tutorial +- New GLib example code +- Python bindings are now version (0,42,0) +- Python bindings API has changed on the service side +- dbus.service has been split out as a seperate module +- dbus.service.Service is renamed to dbus.service.BusName +- dbus.service.Object has swapped the bus_name and object_path constructor + parameters to make it easier to do inheritance over the bus +- dbus.glib has been seperated out in order to lessen the dependency on glib + and to allow other mainloops to be integrated with the bindings including + a planned generic mainloop for non-gui apps. +- Python bindings now aquire the GIL when calling back into the python + interpreter. Fixes crashes when using threading and other random segfaults. +- New Python tutorial +- Numerous D-Bus bug fixes all around + +D-BUS 0.34 (15 June 2005) +=== +- dbus_connection_disconnect is deprecated in favor of dbus_connection_close +- The bus can now use D_NOTIFY (if available) to check when configuration files + have changed and reload them +- New dbus_message_has_path/member/interface API added +- The Ping message from the org.freedesktop.DBus.Peer interface is now handled +- Complete glib bindings overhaul (and are still under construction) +- Tutorial now has an updated GLib section +- GLib bindings can now send/receive hash tables, arrays and other complex types +- Python bindings overhaul (most public facing API's done) +- Python bindings have been split up into separate files +- Python added new type classes for hinting to the marshaler what type + to send over the wire +- Python bindings now have decorators for specifying exported methods and signals +- Numerous bug fixes + +D-BUS 0.33 (25 Apr 2005) +=== + +- downgrade requirement from GTK+-2.6 to 2.4 for building gtk components +- python binding API's have been overhalled to be more "pythonic" and cleaner +- python bindings now export dbus.version which is set to (0,40,0) +- python bindings now implement the org.freedesktop.DBus.Introspectable interface +- python binding match rules are now more flexable +- make check has been fixed +- many, many major bug fixes + +D-BUS 0.32 (29 Mar 2005) +=== + +- mono bindings now compiles correctly +- mono binding cleanups +- glib bindings generates wrappers for bus methods in dbus-glib-bindings.h +- glib binding cleanus +- users and groups can now be specified by UID and GID in config files +- numerous memory leak fixes +- various other fixes + +D-BUS 0.31 (07 Mar 2005) +=== + +- land the new message args API and recursive type system +- add docs and fixed Doxygen warnings throught source +- split out some functions not needed in libdbus to *-util.c source files +- take out type convienience functions +- libdbus now back below 150K +- booleans are now 32-bit instead of 8-bit +- specification updated +- grand renaming to strip out the use of "service" + just say "name" instead (or "bus name" when ambiguous) +- rename dbus-daemon-1 to dbus-daemon throughout +- rename activation to auto-start +- auto-start on by default now +- note that libdbus is the low-level API +- python bindings updated to the new API +- mono bindings updated to the new API +- add 16 bit types +- dictionaries are now ARRAYS of DICT_ENTRY +- dbus-glib-tool renamed to dbus-binding-tool +- massive rewrite of the glib bindings +- saner names for the dbus interface, object path and service defines +- new functions for handling type signitures +- bump sonames for libdbus and libdbus-glib +- various small fixes + +D-BUS 0.23 (11 Jan 2005) +=== + +- add setgroups() to drop supplementary groups +- updated SELinux support +- add an "at console" security policy +- fix a bug where org.freedesktop.DBus wasn't recognized as an existing + service. +- error out if --enable-mono is explicitly set and mono libs can't be found +- set the max_match_rules_per_connection limit from the config file. +- removed dbus_bug_get_with_g_main since it's been replaced by + dbus_g_bus_get +- fix fd leaks in socket code +- lots and lots of mono binding updates, including fixes to make it + compatible with Mono 1.1.3 +- added --nofork option to override config file setting at runtime +- added support for int64 and uint64 to the python bindings +- lots of python binding updates +- config file DTD updates +- use SerivceOwnerChanges signal instead of ServiceCreated and + ServiceDeleted +- fixes to the authentication code +- new init script for Slackware +- print out the pid even when --fork is passed +- increase preallocation sizes in DBusMessage to heavily reduce + reallocs +- lots of performance enhancements +- lots more small bug fixes + +D-BUS 0.22 +=== + +- add --reply-timeout to dbus-send +- fix a memleak +- fix Solaris/Forte build +- switch to AFL 2.1 rather than 2.0 to address patent termination clause + concerns +- add SELinux support +- mostly repair libxml backend for config parser, still doesn't + pass out of memory tests +- fix distcheck to include language bindings +- add GetConnectionUnixUser method on bus driver +- also for UnixProcessID +- lots of Python, Mono, other binding fixes +- change GLib bindings to not include dbus/dbus.h (fully encapsulate libdbus) +- pass paths as strings, not arrays of string +- add message signature header field +- cleanups to marshaling code +- clean up authentication code +- reload conf files on SIGHUP +- rename SERVICE/SENDER_SERVICE to DESTINATION/SENDER +- fix circular conf file inclusion +- allow empty arrays +- tons of other small bugfixes + +D-BUS 0.21 +=== + +- implement "auto activation" flag on messages, so the destination + service can be launched automatically +- fix a bug in custom type marshaling +- optimize case where multiple apps activate the same service + (avoid "thundering herd") +- add dynamic service file discovery/reloading +- fix a busy loop when blocking for a reply +- fix a 64-bit crash involving varargs +- fix a bus crash when processing an AcquireService +- allow appending TYPE_BYTE via append_args_valist +- fix dicts-inside-dicts +- enhancements to Python and Qt bindings + +D-BUS 0.20 +=== + +This release lands some very large API changes and numerous bugfixes. +The list of changes is too large to fully document here; please refer +to the documentation, and message-bus-list archives. + +D-BUS 0.13 +=== + +This is probably the last release before landing the large API changes +on the "dbus-object-names" branch. + +- fix system bus to always use filesystem socket; anyone + can create any abstract socket, which isn't secure + since if you can crash the system bus you'd be able + to replace it. +- add DTD for configuration file +- improve specification a bit + +D-BUS 0.12 +=== + +- fix "service messagebus status" on Red Hat +- fix demarshaling of DBUS_TYPE_NAMED +- fix "eval `dbus-launch --exit-with-session`" to exit properly +- fix build without --prefix +- useless fooling with Mono bindings +- useless fooling with gcj bindings +- fix srcdir != builddir +- fix various compiler warnings and other issues +- add get/set data to DBusMessage +- fix headers for C++ +- OS X build fixes +- abstract domain sockets support (Linux only) +- add dbus-cleanup-sockets utility for people + not using linux +- be consistent about defaulting to --session/--system + with command line tools +- merge in policies from included config files +- fix build on non-x86 +- docs updates +- lots of other bugfixes + +D-BUS 0.11 +=== + +- add --enable-docs to turn off/on the docbook stuff + (doesn't cover doxygen stuff yet) +- make people define DBUS_API_SUBJECT_TO_CHANGE + and read warning in README so they don't + expect the API to be frozen already +- rename .pc files to "dbus-1.pc" instead of + "dbus-1.0.pc" etc. - this will require changing + pkg-config invocations +- some docs cleanups +- add man pages for all executables +- allow send to/from bus driver in the default system.conf +- fix user lookup bug +- implement dbus-launch to launch the session message bus +- fix some thread deadlocks +- some performance profiling/optimization +- add dbus_bus_activate_service() function +- fix some minor bugs here and there +- install Red Hat initscript in the right place + +D-BUS 0.10 +=== + +- reversed order of args to dbus_message_new() +- renamed dbus_message_name_is() and some other + functions +- change DBusWatch to have dbus_watch_handle() + similar to dbus_timeout_handle(), drop + connection/server-specific handle routines +- change message serials to be unsigned +- implemented <allow>/<deny>/<limit> features for + config file; system bus now has a deny-all policy + by default. +- system.conf has <includedir>system.d</includedir> + so packages can install additions to the default + policy to <allow> the messages they need. e.g. + CUPS might install a cups.conf - see + test/data/valid-config-files/system.d/test.conf + for an example. +- add timeouts for authentication, activation +- add glib-style "checks" on public API, enable + those by default, disable assertions by default +- add GMainContext argument to GLib setup functions, + can be NULL for default context. Needed for threads. +- add 64-bit integer type +- validate type of standard message header fields +- consider messages in the org.freedesktop.Local + namespace to be invalid (to avoid fake disconnect + messages for example) +- fix assorted memory leaks and other bugs in + the SHA-1 auth mechanism +- cache user database information (groups user is + in, etc.) helps a lot with NIS +- always store uid_t, pid_t, gid_t in "ulong" + rather than "int" +- implement config file settings for which + users can connect +- SHA-1 unit test +- dbus-send, dbus-monitor command line utilities +- fixed lots of misc crashes and other bugs + +D-BUS 0.9 +=== + +- implemented a test case for service activation, + and fixed many bugs exposed by that +- implemented recursive argument marshaling/demarshaling + for messages, allowing multidimensional arrays +- fixed up integration of message dispatch with + main loop by adding a callback on change of + dispatch status +- add a pidfile feature to daemon +- some build fixes +- clean up unix domain sockets on exit +- add --print-address and the ability + to create a random server address + in a temporary directory + +D-BUS 0.8 +=== + +- fix dumb bug in 0.7 + +D-BUS 0.7 +=== + +- implement configuration file used to control bus characteristics +- implement daemon mode, changing user ID, and other system + bus features +- add init scripts for systemwide bus +- add "make check-coverage" target to check test coverage +- more test suite additions +- many, many bugfixes +- many API changes/fixes + +D-BUS 0.6 +=== +- Vastly improved bus daemon test suite +- Lots of misc. bugfixes and memory leak fixes +- Support for marshalling key/value data +- Activation improvements. + +D-BUS 0.5 +=== + +- Specification updates +- port to OS X and other BSD variants +- port to Solaris +- Partial work on cookie-based authentication +- Thread safety fixes +- Lots of misc. bugfixes +- Support for more array types +- Add data slots to DBusServer +- DBusString security audit fixes +- Fix for systems (or valgrind) with unaligned malloc blocks + +D-BUS 0.4 +=== + +- Preliminary activation support. +- Better authentication test suite +- Bus test program +- Specification updates +- Thread safety +- Bug fixes + +D-BUS 0.3 +=== + + - Preliminary limitations + - Message sending works + - Bus client + - Array marshalling/demarshalling + - Services + - Better OOM handling in the bus + - In-proc debug transport + - Transport/server address support + +D-BUS 0.2 +=== + + - Include test code in the tarball. + +D-BUS 0.1 +=== + + - Initial release.
diff --git a/NEWS.pre-1-2 b/NEWS.pre-1-2 new file mode 100644 index 0000000..d9898f8 --- /dev/null +++ b/NEWS.pre-1-2
@@ -0,0 +1,153 @@ +D-Bus 1.2.1 (04 April) +== +- Due to issues putting the re-licensing effort on hold indefinitely, it has + been decided to move to 1.2.x versioning scheme. Being that 1.1.20 is + considered to also be 1.2.0 and this being the second release in the 1.2.x + stable series we have versioned this release 1.2.1. This release contains a + number of bug fixes identified after 1.1.20. +- compiles under some older versions of glibc +- compiles without X support once again +- fix stuck server grab if dbus-launch is run in an existing D-Bus X session +- various Mac OSX build fixes added +- don't use the broken poll call on Mac OSX +- better checks for linker flag support should allow D-Bus to link under + various linkers +- exit_on_disconnect is set after the connection registers with a bus so we + don't exit if we get a disconnect during the handshake +- dicts now work correctly with dbus-send +- inotify backend is now less aggressive +- pending calls expire correctly +- memleak of uuid when the bus is autolaunched fixed + +D-Bus 1.1.20 - "Conisten Water" (27 Febuary) +== + +- This is the next generation supported STABLE release of D-Bus. For all + intents and purposes this is the 1.2.0 release WITHOUT the planned X11/MIT + license change due to a couple of license holders who have yet to respond. + For the most part this license change is being persued to simplify licensing + issues and fix a couple of licensing courner cases. When this happens D-Bus + will be released under the 1.2.0 version. + +- D-Bus 1.0.x effectively goes into security fix mode and will only be + updated for major issues. + +- Fixed CVE-2008-0595 - security policy of the type <allow send_interface= + "some.interface.WithMethods"/> work as an implicit allow for + messages sent without an interface bypassing the default deny rules and + potentially allowing restricted methods exported on the bus to be executed + by unauthorized users. + +- Fixes dbus-launch so the session bus goes away so does D-Bus + +- Builds against latest gcc/glibc changes + +- Correctly unref connections without guids during shutdown + +- About the name: Submitted by Greg K Nicholson, Conisten Water is a lake in + Cumbria, England where several water speed records have been broken. Between + 1956 and 1959 Sir Malcolm's son Donald Campbell set four successive records on the lake in Bluebird K7, a hydroplane. + (Wikipedia http://en.wikipedia.org/wiki/Coniston_Water#Waterspeed_record) + +D-Bus 1.1.4 - 1.2.0RC2 (17 January 2007) +== +- Fixes inotify support + +D-Bus 1.1.3 - 1.2.0RC1 (15 January 2007) +== + +- This release is intended to be Release Candidate 1 of major release + D-Bus 1.2.0. If nothing is found to be wrong with this release it + will become 1.2.0 within a week. If we need to make major changes + we will release an RC2 and start the process over again. + +- This is a development release, so API's may still change if problems + are found (though this is extreamly unlikely). + +- DTD for the introspection format is fixed and uploaded to the servers + +- Sources now reside in a git repository at + http://gitweb.freedesktop.org/?p=dbus/dbus.git;a=summary + +- Argument path matching of the type arg0path='/aa/bb/' is now supported + (see the specification for more information) + +- New error org.freedesktop.DBus.Error.ObjectPathInUse added + +- Autolaunched busses now save their parameters in X11 if possible making them + behave closer to busses launched through the normal mechanisms + +- inotify is now the default backend for watching configuration file changes + +- More support for the AIX platform has been added + +- Numerous bug fixes and performance enhancements + +D-Bus 1.1.2 (27 July 2007) +== + +- This release is intended to be a feature complete beta for stable + release 1.2.0, please test it. 1.2.0 will follow pretty soon if no + major problems are found. We'll do more betas if significant + changes are made. + +- This is a development release, so API's may still change if problems + are found (though we will try hard not to). + +- The system bus now supports starting services on demand. This uses a + setuid helper program because system bus daemon runs as a nobody + user, while services it launches may need to run as a different + user. + + ***Extra eyes auditing the setuid helper are encouraged and would be + timely right now, before 1.2.0*** + + A design doc is available in doc/system-activation.txt + +- The TCP address format has been enhanced, such that TCP may be + actually usable. The dbus-daemon man page describes the new + elements in the address format. 1.1.1 had added an all_interfaces + flag to the format, which has been removed in favor of a cleaner + approach. + +- Some thread-related bugs have been fixed, these are important fixes + if you are using multiple threads with libdbus, and not important + otherwise. + + +D-Bus 1.1.1 (18 June 2007) +== +- This is a development release, unless you need specific + functionality please use the stable releases as API's may change + (though we will try hard not to) +- The bus daemon now generates a globally-unique ID for itself, which is available + using the convenience function dbus_bus_get_id(). Use this as a unique ID + for a user's session, for example. +- dbus_server_get_id(), dbus_connection_get_server_id() now available to access + the unique ID of a particular address +- dbus_watch_get_fd() deprecated since it had unclear cross-platform semantics. + dbus_watch_get_unix_fd() and dbus_watch_get_socket() replace it. +- support ANONYMOUS mechanism for authentication, which allows a client to + authenticate as nobody in particular +- add API dbus_connection_set_allow_anonymous() which will allow the message + stream to begin if the client auths as anonymous (otherwise, the client + will be dropped unless they auth as a user). +- the ANONYMOUS support means you can now use D-Bus (without a bus daemon) as + a protocol for a network service provided to anonymous Internet or LAN + clients +- many internal changes to better support the Windows port, though the + port is still not complete in this release +- some improved documentation and return_if_fail checks +- some small bug fixes + +D-Bus 1.1.0 (25 May 2007) +== +- first release in the development series, unless you need specific + functionality please use the stable releases as API's may change + (though we will try hard not to) +- better eavesdropping support now picks up reply messages for debugging +- .pc file now lists the directory the daemon is installed into (daemondir) +- GetAll call added to the properties interface +- support for message serialization added for use with external transports like + TUBES!!! +- many bugs fixed
diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..a91ca1d --- /dev/null +++ b/NOTICE
@@ -0,0 +1,551 @@ +D-Bus is licensed to you under your choice of the Academic Free +License version 2.1, or the GNU General Public License version 2. +Both licenses are included here. Some of the standalone binaries are +under the GPL only; in particular, but not limited to, +tools/dbus-cleanup-sockets.c and test/decode-gcov.c. Each source code +file is marked with the proper copyright information - if you find a +file that isn't marked please bring it to our attention. + + +The Academic Free License +v. 2.1 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following notice immediately following the copyright notice for the Original Work: + +Licensed under the Academic Free License version 2.1 + +1) Grant of Copyright License. Licensor hereby grants You a +world-wide, royalty-free, non-exclusive, perpetual, sublicenseable +license to do the following: + +a) to reproduce the Original Work in copies; + +b) to prepare derivative works ("Derivative Works") based upon the Original Work; + +c) to distribute copies of the Original Work and Derivative Works to the public; + +d) to perform the Original Work publicly; and + +e) to display the Original Work publicly. + +2) Grant of Patent License. Licensor hereby grants You a world-wide, +royalty-free, non-exclusive, perpetual, sublicenseable license, under +patent claims owned or controlled by the Licensor that are embodied in +the Original Work as furnished by the Licensor, to make, use, sell and +offer for sale the Original Work and Derivative Works. + +3) Grant of Source Code License. The term "Source Code" means the +preferred form of the Original Work for making modifications to it and +all available documentation describing how to modify the Original +Work. Licensor hereby agrees to provide a machine-readable copy of the +Source Code of the Original Work along with each copy of the Original +Work that Licensor distributes. Licensor reserves the right to satisfy +this obligation by placing a machine-readable copy of the Source Code +in an information repository reasonably calculated to permit +inexpensive and convenient access by You for as long as Licensor +continues to distribute the Original Work, and by publishing the +address of that information repository in a notice immediately +following the copyright notice that applies to the Original Work. + +4) Exclusions From License Grant. Neither the names of Licensor, nor +the names of any contributors to the Original Work, nor any of their +trademarks or service marks, may be used to endorse or promote +products derived from this Original Work without express prior written +permission of the Licensor. Nothing in this License shall be deemed to +grant any rights to trademarks, copyrights, patents, trade secrets or +any other intellectual property of Licensor except as expressly stated +herein. No patent license is granted to make, use, sell or offer to +sell embodiments of any patent claims other than the licensed claims +defined in Section 2. No right is granted to the trademarks of +Licensor even if such marks are included in the Original Work. Nothing +in this License shall be interpreted to prohibit Licensor from +licensing under different terms from this License any Original Work +that Licensor otherwise would have a right to license. + +5) This section intentionally omitted. + +6) Attribution Rights. You must retain, in the Source Code of any +Derivative Works that You create, all copyright, patent or trademark +notices from the Source Code of the Original Work, as well as any +notices of licensing and any descriptive text identified therein as an +"Attribution Notice." You must cause the Source Code for any +Derivative Works that You create to carry a prominent Attribution +Notice reasonably calculated to inform recipients that You have +modified the Original Work. + +7) Warranty of Provenance and Disclaimer of Warranty. Licensor +warrants that the copyright in and to the Original Work and the patent +rights granted herein by Licensor are owned by the Licensor or are +sublicensed to You under the terms of this License with the permission +of the contributor(s) of those copyrights and patent rights. Except as +expressly stated in the immediately proceeding sentence, the Original +Work is provided under this License on an "AS IS" BASIS and WITHOUT +WARRANTY, either express or implied, including, without limitation, +the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL +WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential +part of this License. No license to Original Work is granted hereunder +except under this disclaimer. + +8) Limitation of Liability. Under no circumstances and under no legal +theory, whether in tort (including negligence), contract, or +otherwise, shall the Licensor be liable to any person for any direct, +indirect, special, incidental, or consequential damages of any +character arising as a result of this License or the use of the +Original Work including, without limitation, damages for loss of +goodwill, work stoppage, computer failure or malfunction, or any and +all other commercial damages or losses. This limitation of liability +shall not apply to liability for death or personal injury resulting +from Licensor's negligence to the extent applicable law prohibits such +limitation. Some jurisdictions do not allow the exclusion or +limitation of incidental or consequential damages, so this exclusion +and limitation may not apply to You. + +9) Acceptance and Termination. If You distribute copies of the +Original Work or a Derivative Work, You must make a reasonable effort +under the circumstances to obtain the express assent of recipients to +the terms of this License. Nothing else but this License (or another +written agreement between Licensor and You) grants You permission to +create Derivative Works based upon the Original Work or to exercise +any of the rights granted in Section 1 herein, and any attempt to do +so except under the terms of this License (or another written +agreement between Licensor and You) is expressly prohibited by +U.S. copyright law, the equivalent laws of other countries, and by +international treaty. Therefore, by exercising any of the rights +granted to You in Section 1 herein, You indicate Your acceptance of +this License and all of its terms and conditions. + +10) Termination for Patent Action. This License shall terminate +automatically and You may no longer exercise any of the rights granted +to You by this License as of the date You commence an action, +including a cross-claim or counterclaim, against Licensor or any +licensee alleging that the Original Work infringes a patent. This +termination provision shall not apply for an action alleging patent +infringement by combinations of the Original Work with other software +or hardware. + +11) Jurisdiction, Venue and Governing Law. Any action or suit relating +to this License may be brought only in the courts of a jurisdiction +wherein the Licensor resides or in which Licensor conducts its primary +business, and under the laws of that jurisdiction excluding its +conflict-of-law provisions. The application of the United Nations +Convention on Contracts for the International Sale of Goods is +expressly excluded. Any use of the Original Work outside the scope of +this License or after its termination shall be subject to the +requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 +et seq., the equivalent laws of other countries, and international +treaty. This section shall survive the termination of this License. + +12) Attorneys Fees. In any action to enforce the terms of this License +or seeking damages relating thereto, the prevailing party shall be +entitled to recover its costs and expenses, including, without +limitation, reasonable attorneys' fees and costs incurred in +connection with such action, including any appeal of such action. This +section shall survive the termination of this License. + +13) Miscellaneous. This License represents the complete agreement +concerning the subject matter hereof. If any provision of this License +is held to be unenforceable, such provision shall be reformed only to +the extent necessary to make it enforceable. + +14) Definition of "You" in This License. "You" throughout this +License, whether in upper or lower case, means an individual or a +legal entity exercising rights under, and complying with all of the +terms of, this License. For legal entities, "You" includes any entity +that controls, is controlled by, or is under common control with +you. For purposes of this definition, "control" means (i) the power, +direct or indirect, to cause the direction or management of such +entity, whether by contract or otherwise, or (ii) ownership of fifty +percent (50%) or more of the outstanding shares, or (iii) beneficial +ownership of such entity. + +15) Right to Use. You may use the Original Work in all ways not +otherwise restricted or conditioned by this License or by law, and +Licensor promises not to interfere with or be responsible for such +uses by You. + +This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights +reserved. Permission is hereby granted to copy and distribute this +license without modification. This license may not be modified without +the express written permission of its copyright owner. + + +-- +END OF ACADEMIC FREE LICENSE. The following is intended to describe the essential +differences between the Academic Free License (AFL) version 1.0 and other +open source licenses: + +The Academic Free License is similar to the BSD, MIT, UoI/NCSA and Apache +licenses in many respects but it is intended to solve a few problems with +those licenses. + +* The AFL is written so as to make it clear what software is being +licensed (by the inclusion of a statement following the copyright notice +in the software). This way, the license functions better than a template +license. The BSD, MIT and UoI/NCSA licenses apply to unidentified software. + +* The AFL contains a complete copyright grant to the software. The BSD +and Apache licenses are vague and incomplete in that respect. + +* The AFL contains a complete patent grant to the software. The BSD, MIT, +UoI/NCSA and Apache licenses rely on an implied patent license and contain +no explicit patent grant. + +* The AFL makes it clear that no trademark rights are granted to the +licensor's trademarks. The Apache license contains such a provision, but the +BSD, MIT and UoI/NCSA licenses do not. + +* The AFL includes the warranty by the licensor that it either owns the +copyright or that it is distributing the software under a license. None of +the other licenses contain that warranty. All other warranties are disclaimed, +as is the case for the other licenses. + +* The AFL is itself copyrighted (with the right granted to copy and distribute +without modification). This ensures that the owner of the copyright to the +license will control changes. The Apache license contains a copyright notice, +but the BSD, MIT and UoI/NCSA licenses do not. +-- +START OF GNU GENERAL PUBLIC LICENSE +-- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE 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. + + 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 +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This 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 Library General +Public License instead of this License.
diff --git a/README b/README new file mode 100644 index 0000000..0257e69 --- /dev/null +++ b/README
@@ -0,0 +1,184 @@ +Sections in this file describe: + - introduction and overview + - low-level vs. high-level API + - version numbers + - options to the configure script + - ABI stability policy + +Introduction +=== + +D-Bus is a simple system for interprocess communication and coordination. + +The "and coordination" part is important; D-Bus provides a bus daemon that does things like: + - notify applications when other apps exit + - start services on demand + - support single-instance applications + +See http://www.freedesktop.org/software/dbus/ for lots of documentation, +mailing lists, etc. + +See also the file HACKING for notes of interest to developers working on D-Bus. + +If you're considering D-Bus for use in a project, you should be aware +that D-Bus was designed for a couple of specific use cases, a "system +bus" and a "desktop session bus." These are documented in more detail +in the D-Bus specification and FAQ available on the web site. + +If your use-case isn't one of these, D-Bus may still be useful, but +only by accident; so you should evaluate carefully whether D-Bus makes +sense for your project. + +Security +== + +If you find a security vulnerability that is not known to the public, +please report it privately to dbus-security@lists.freedesktop.org +or by reporting a freedesktop.org bug that is marked as +restricted to the "D-BUS security group" (you might need to "Show +Advanced Fields" to have that option). + +On Unix systems, the system bus (dbus-daemon --system) is designed +to be a security boundary between users with different privileges. + +On Unix systems, the session bus (dbus-daemon --session) is designed +to be used by a single user, and only accessible by that user. + +We do not currently consider D-Bus on Windows to be security-supported, +and we do not recommend allowing untrusted users to access Windows +D-Bus via TCP. + +Note: low-level API vs. high-level binding APIs +=== + +A core concept of the D-Bus implementation is that "libdbus" is +intended to be a low-level API. Most programmers are intended to use +the bindings to GLib, Qt, Python, Mono, Java, or whatever. These +bindings have varying levels of completeness and are maintained as +separate projects from the main D-Bus package. The main D-Bus package +contains the low-level libdbus, the bus daemon, and a few command-line +tools such as dbus-launch. + +If you use the low-level API directly, you're signing up for some +pain. Think of the low-level API as analogous to Xlib or GDI, and the +high-level API as analogous to Qt/GTK+/HTML. + +Version numbers +=== + +D-Bus uses the common "Linux kernel" versioning system, where +even-numbered minor versions are stable and odd-numbered minor +versions are development snapshots. + +So for example, development snapshots: 1.1.1, 1.1.2, 1.1.3, 1.3.4 +Stable versions: 1.0, 1.0.1, 1.0.2, 1.2.1, 1.2.3 + +All pre-1.0 versions were development snapshots. + +Development snapshots make no ABI stability guarantees for new ABI +introduced since the last stable release. Development snapshots are +likely to have more bugs than stable releases, obviously. + +Configuration +=== + +dbus could be build by using autotools or cmake. + +When using autotools the configure step is initiated by running ./configure +with or without additional configuration flags. dbus requires GNU Make +(on BSD systems, this is typically called gmake) or a "make" implementation +with compatible extensions. + +When using cmake the configure step is initiated by running the cmake +program with or without additional configuration flags. + +Configuration flags +=== + +When using autotools, run "./configure --help" to see the possible +configuration options and environment variables. + +When using cmake, inspect README.cmake to see the possible +configuration options and environment variables. + +API/ABI Policy +=== + +Now that D-Bus has reached version 1.0, the objective is that all +applications dynamically linked to libdbus will continue working +indefinitely with the most recent system and session bus daemons. + + - The protocol will never be broken again; any message bus should + work with any client forever. However, extensions are possible + where the protocol is extensible. + + - If the library API is modified incompatibly, we will rename it + as in http://ometer.com/parallel.html - in other words, + it will always be possible to compile against and use the older + API, and apps will always get the API they expect. + +Interfaces can and probably will be _added_. This means both new +functions and types in libdbus, and new methods exported to +applications by the bus daemon. + +The above policy is intended to make D-Bus as API-stable as other +widely-used libraries (such as GTK+, Qt, Xlib, or your favorite +example). If you have questions or concerns they are very welcome on +the D-Bus mailing list. + +NOTE ABOUT DEVELOPMENT SNAPSHOTS AND VERSIONING + +Odd-numbered minor releases (1.1.x, 1.3.x, 2.1.x, etc. - +major.minor.micro) are devel snapshots for testing, and any new ABI +they introduce relative to the last stable version is subject to +change during the development cycle. + +Any ABI found in a stable release, however, is frozen. + +ABI will not be added in a stable series if we can help it. i.e. the +ABI of 1.2.0 and 1.2.5 you can expect to be the same, while the ABI of +1.4.x may add more stuff not found in 1.2.x. + +NOTE ABOUT STATIC LINKING + +We are not yet firmly freezing all runtime dependencies of the libdbus +library. For example, the library may read certain files as part of +its implementation, and these files may move around between versions. + +As a result, we don't yet recommend statically linking to +libdbus. Also, reimplementations of the protocol from scratch might +have to work to stay in sync with how libdbus behaves. + +To lock things down and declare static linking and reimplementation to +be safe, we'd like to see all the internal dependencies of libdbus +(for example, files read) well-documented in the specification, and +we'd like to have a high degree of confidence that these dependencies +are supportable over the long term and extensible where required. + +NOTE ABOUT HIGH-LEVEL BINDINGS + +Note that the high-level bindings are _separate projects_ from the +main D-Bus package, and have their own release cycles, levels of +maturity, and ABI stability policies. Please consult the documentation +for your binding. + +Bootstrapping D-Bus on new platforms +=== + +A full build of D-Bus, with all regression tests enabled and run, has some +dependencies which themselves depend on D-Bus, either for compilation or +for some of *their* regression tests: GLib, dbus-glib and dbus-python are +currently affected. + +To avoid circular dependencies, when bootstrapping D-Bus for the first time +on a new OS or CPU architecture, you can either cross-compile some of +those components, or choose the build order and options carefully: + +* build and install D-Bus without tests + - do not use the --enable-modular-tests=yes configure option + - do not use the --enable-tests=yes configure option +* build and install GLib, again without tests +* use those versions of libdbus and GLib to build and install dbus-glib +* ... and use those to install dbus-python +* rebuild libdbus; this time you can run all of the tests +* rebuild GLib; this time you can run all of the tests
diff --git a/README.cygwin b/README.cygwin new file mode 100755 index 0000000..904cbb4 --- /dev/null +++ b/README.cygwin
@@ -0,0 +1,6 @@ +The cygwin dbus port is included in master branch of +dbus git repository since 1.3.1. + +The cygwin port of dbus is maintained by: + +http://sourceware.org/cygwinports/
diff --git a/README.launchd b/README.launchd new file mode 100644 index 0000000..701e57d --- /dev/null +++ b/README.launchd
@@ -0,0 +1,61 @@ +Launchd[1,2] replaces init, inetd and cron on Mac OS X since 10.4 "Tiger". +dbus uses this service to provide a common session bus address for each user +and so deprecates the X11 enabled dbus-launcher. + +[1] http://developer.apple.com/MacOsX/launchd.html +[2] http://launchd.macosforge.org/ + + +Setup +=== + +Configure with --enable-launchd and --without-x (X11 should not harm but it's +simply not necessary any more) +After installation, to prevent a reboot, load the dbus session starter into +launchd by executing: +$ launchctl load /Library/LaunchAgents/org.freedesktop.dbus-session.plist + +You can change the launch agent dir via configure, but it's not recommended. +Make sure to execute the above line as the actual user for which you want to +use a session bus since launchd manages its agents on a per user basis. + + +How it works +=== + +Launchd allocates a socket and provides the unix path to it via the variable +DBUS_LAUNCHD_SESSION_BUS_SOCKET in launchd's environment. Every process +spawned by launchd (or dbus-daemon, if stared by launchd) can access it through +its own environment. Other processes can query launchd for it by executing: +$ launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET +However, this is normally done by the dbus client lib for you. + +If launchd start dbus-daemon with a config file containing a "launchd:env=FOO" +address, as the default session config does with env=DBUS_LAUNCHD_SESSION_BUS_SOCKET, +the daemon will get the file descriptor from launchd and start listening on it. +The environment variable is used to get the actual socket path which is passed +to every service spawned by dbus-daemon as a result from autolaunch messages. +Please note that it's not possible to start dbus-daemon manually when using a +"launchd:" address. Only child processes of launchd can access the above +mentioned file descriptor! + +To create custom buses just set up an other launch agent. As a quick start copy +/Library/LaunchAgents/org.freedesktop.dbus-session.plist, change the label +to i.e. "org.freedesktop.dbus-foo" and change the SecureSocketWithKey value, +i.e. to "DBUS_LAUNCHD_FOO_BUS_SOCKET". This environment variable has to be set +in the config file for your new bus in the <listen> element (see session.config). +Then edit your /Library/LaunchAgents/org.freedesktop.dbus-foo.plist to start +dbus-daemon with "--config-file=/opt/local/etc/dbus-1/foo.conf" instead of +"--session". Now load the new plist onto launchd as described in the setup +section of this document. +Executing "launchctl export" should now give you two sockets, one in +DBUS_LAUNCHD_SESSION_BUS_SOCKET and the new DBUS_LAUNCHD_FOO_BUS_SOCKET. +To connect to this new bus use "launchd:env=DBUS_LAUNCHD_FOO_BUS_SOCKET". + +Since Mac OS X 10.5 "Leopard" you can also configure launchd to start +dbus-daemon on demand as soon as some process connects to the socket. Since +it's broken on 10.4 this feature is disabled per default. Look at +/Library/LaunchAgents/org.freedesktop.dbus-session.plist to change it. + +On the client side, the envvar DBUS_SESSION_BUS_ADDRESS can be normally used +but if it's not set, launchd is queried for the session bus socket.
diff --git a/README.valgrind b/README.valgrind new file mode 100644 index 0000000..c13f530 --- /dev/null +++ b/README.valgrind
@@ -0,0 +1,24 @@ +Running D-Bus clients with Valgrind +==== + +When running programs using libdbus in Valgrind, some special care needs to be +taken so as to avoid incorrect detection of leaks in libdbus. To avoid these +false positives, do the following: + +* Grab a copy of the D-Bus source code + +* Run configure with the --enable-developer and --with-valgrind options + +* Run make + +* Either make sure your code calls dbus_shutdown() (at least while running in + Valgrind) or set DBUS_MESSAGE_CACHE=0 in your environment + +* Run Valgrind on your program with the /path/to/dbus/source/dbus/.libs in your + LD_LIBRARY_PATH + +Your Valgrind log should now be free of any (spurious) libdbus-related leaks. + +For the curious, the DBUS_MESSAGE_CACHE=0 is required because by +default, libdbus uses a recyclable pool of message structs. These help +performance a bit.
diff --git a/README.win b/README.win new file mode 100644 index 0000000..8a5b3c0 --- /dev/null +++ b/README.win
@@ -0,0 +1,114 @@ +----------------------------------------- +Windows port of the freedesktop.org D-Bus +----------------------------------------- + +Features and completeness +------------------------- +The windows port of dbus provides the dbus-1 library and mostly +applications which are already available on unix. These applications +are: dbus-daemon, dbus-launch, dbus-monitor and dbus-send. +DBus comes with a test suite which is used on unix to guarantate +production quality and this test suite runs mostly. There are some +test not running yet and there is help needed to get them running. + +Supported compilers +------------------- +On windows Microsoft Visual Studio 2010 (Express and professional variants) +and mingw-w64|32 are known to work. + +Building +-------- +DBus can be built on windows using automake or cmake. See the +file INSTALL for more information. + +windbus and dbus4win Ports +-------------------------- +The Windows ports from the windbus and dbus4win projects has been merged +into the freedesktop git master branch, as applicable. The spec has been +updated with windows specific stuff. + + +Tests +----- + - run complete test suite + make check + or + ctest [-V] + + - dbus library check + ctest [-V] -R test-dbus + + - bus daemon check + ctest [-V] -R test-bus + + - check available names + ctest [-V] -R test-names + + - check if dbus-daemon is accessable + bin\dbus-send.exe --session --type=method_call --print-reply --dest=org.freedesktop.DBus / org.freedesktop.DBus.ListNames method return sender=org.freedesktop.DBus -> dest=:1.4 array [ string "org.freedesktop.DBus"string ":1.4"] + + - start session dbus-daemon + either by running + bin\dbus-launch + or + start bin\dbus-daemon --session + + Before running these commands you may execute + set DBUS_VERBOSE=1 + for getting debug infos + + + - call function registerd in dbus + bin\dbus-send.exe --dest=org.freedesktop.DBus --print-reply --type=method_call / org.freedesktop.DBus.StartServiceByName string:org.freedesktop.DBus.TestSuiteEchoService uint32:455 method return sender=org.freedesktop.DBus -> dest=:1.8 uint32 2 + + note: When building with the Visual C++ IDE the *.exe files are in + the bin/Debug and bin/Release folder, not in the bin folder. + + +FAQ +--- + +- How far is WinDBus from being usable for production ? + + dbus comes with a test suite which is used on unix to guarantate + production quality and this test suite runs mostly. There are some + test not running and we need help to get them running. + In the pratice I and some other people are using dbus for at least more + than four years in conjunction with kde on windows without any problems. + +- On UNIX D-Bus uses UNIX sockets to communicate (correct me if I'm wrong). + What is used on Windows ? + + tcp sockets, there are some efforts to get named pipe running, but some + design problems of the win32 api, we are not able to solve without + bigger changes to the dbus code base let us stop this effort. + +- Do you have any clue if dbus-win32 can run in a Windows CE environment? + + dbus has been ported to wince, see README.wince for more information + +- Do you know if the C++ binding made by OpenWengo will be easily portable to Windows? + + The OpenWengo dbus-c++ binding has been ported to windows see in WinDBus svn + (http://sf.net/projects/windbus) + The related test applications are running well. + + +TODO +---- + +October 2010: + +- the code wrapped with DBUS_WIN_FIXME should be inspected if it required for windows + +- create a dbus setup installer + +- implement system bus and system bus service starter + see http://windbus.svn.sourceforge.net/viewvc/windbus/trunk/bus/bus-service-win.c + for a starting point + +- implement a real login session bus + The scope parameter of the autolaunch meta protocol could be extended to support user + specific session busses (like already done with the amarok bundled dbus which use a + shared memory area named "DBusDaemonAddressInfo:<username>". + Also the dbus installer should start a session bus on user login.
diff --git a/README.wince b/README.wince new file mode 100644 index 0000000..5790dcf --- /dev/null +++ b/README.wince
@@ -0,0 +1,81 @@ +DBus Daemon for Windows CE/Windows Mobile 6.5 +============================================= + +Bugs in upstream for any window version: +* MoveFileExA < 0 result check bug +* double dbus_free somewhere I forgot where (check in -ugly) +* alignment issue +* CreateProcess process information handle leak +* _dbus_getsid NULL vs INVALID_HANDLE_VALUE +* win_account_to_sid + +Customisation +============= + +1) At installation, the following registry value should be set to the +installation directory of the dbus installation (the directory +containing the bin, etc, share folders): + +HKLM\Software\freedesktop\DBus\Install Directory + +2) Instead of environment variable DBUS_VERBOSE, use +HKLM\Software\freedesktop\DBus\Verbose + +2) The keyring directory is MYDOCUMENTS\dbus-keyrings, not +HOMEPATH\.dbus-keyrings. + + +Compilation +=========== + +./configure --host=arm-mingw32ce CPPFLAGS=-I/path/to/expat/include LDFLAGS=-L/path/to/expat/lib + +A recent version of libtool is required, with this change: + +2010-02-28 Pierre Ossman <ossman@ossman.lkpg.cendio.se> (tiny change) + Ralf Wildenhues <Ralf.Wildenhues@gmx.de> + + Fix deplibs check fallback for 64-bit Windows and Windows CE. + * libltdl/m4/libtool.m4 (_LT_CHECK_MAGIC_METHOD): Accept file formats + 'pe-arm-wince' and 'pe-x86-64'. Add note about consistency with ... + * libltdl/config/ltmain.m4sh (func_win32_libid): ... the respective + pattern here; sync pattern from the former. + * tests/deplibs-mingw.at (deplibs without file command): New + file, new test. + * Makefile.am (TESTSUITE_AT): Update. + * NEWS: Update. + + +MB vs WCHAR +=========== + +Windows CE only supports the Unicode interface, while DBus Daemon uses +the Multi-Byte interface on Windows by default. The glue code does +not support multibyte in all cases. In particular, the _mbsrchr +function is not correctly implemented. It could be correctly +implemented, or dbus daemon could use the wchar interface more +consistently on all Windows targets. For now, the Windows CE port +will only work for filesystems without some weird characters in file +names. Is this a serious limitation? + + +Known Issues +============ + +Autolaunch is broken so far. + +Environment variables are faked. Some are punted to the registry, but +in any case they can not be used reliably for IPC. + +The test suite is not ported yet. + +dbus-pipe.c: + * Uses libc file descriptors. Needed for --print-address and + --print-pid which probably don't work yet. + +dbus-sysdeps-win.c: + * Backtraces have been disabled. + * _dbus_fd_set_close_on_exec Not supported, maybe we should disable + the warning. + * SearchPathA: Uses HKLM\\Software\\freedesktop\\DBus\\Install Directory + to locate binaries.
diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..6de735f --- /dev/null +++ b/autogen.sh
@@ -0,0 +1,108 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +ORIGDIR=`pwd` +cd $srcdir + +PROJECT=dbus +TEST_TYPE=-f +FILE=dbus-1.pc.in + +DIE=0 + +if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then + echo "Activating pre-commit hook." + cp .git/hooks/pre-commit.sample .git/hooks/pre-commit + chmod +x .git/hooks/pre-commit +fi + +(autoconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have autoconf installed to compile $PROJECT." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" + DIE=1 +} + +# If the user hasn't explicitly chosen an Automake version, use 1.11. This is +# the earliest version that gives us silent rules. +if test -z "$AUTOMAKE"; then + AUTOMAKE=automake-1.11 + ACLOCAL=aclocal-1.11 +fi + +($AUTOMAKE --version) < /dev/null > /dev/null 2>&1 || { + AUTOMAKE=automake + ACLOCAL=aclocal +} + +($AUTOMAKE --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have automake installed to compile $PROJECT." + echo "Get ftp://ftp.cygnus.com/pub/home/tromey/automake-1.2d.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 +} + +LIBTOOLIZE=`which libtoolize` +if ! test -f "$LIBTOOLIZE"; then + LIBTOOLIZE=`which glibtoolize` +fi + +($LIBTOOLIZE --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have libtoolize installed to compile $PROJECT." + echo "Install the libtool package from ftp.gnu.org or a mirror." + DIE=1 +} + +if test "$DIE" -eq 1; then + exit 1 +fi + +test $TEST_TYPE $FILE || { + echo "You must run this script in the top-level $PROJECT directory" + exit 1 +} + +if test -z "$*"; then + echo "I am going to run ./configure with no arguments - if you wish " + echo "to pass any to it, please specify them on the $0 command line." +fi + +$LIBTOOLIZE --copy --force + +$ACLOCAL -I m4 $ACLOCAL_FLAGS + +## optionally feature autoheader +(autoheader --version) < /dev/null > /dev/null 2>&1 && autoheader + +$AUTOMAKE -a $am_opt +if ! autoconf; then + echo "autoconf failed - version 2.5x is probably required" >&2 + exit 1 +fi + +cd $ORIGDIR + +if test x"$NOCONFIGURE" = x; then + run_configure=true + for arg in $*; do + case $arg in + --no-configure) + run_configure=false + ;; + *) + ;; + esac + done +else + run_configure=false +fi + +if $run_configure; then + $srcdir/configure --enable-developer --config-cache "$@" +fi
diff --git a/build-aux/tap-driver.sh b/build-aux/tap-driver.sh new file mode 100755 index 0000000..4254e2b --- /dev/null +++ b/build-aux/tap-driver.sh
@@ -0,0 +1,651 @@ +#! /bin/sh +# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# +# 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 2, 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 <http://www.gnu.org/licenses/>. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# This file is maintained in Automake, please report +# bugs to <bug-automake@gnu.org> or send patches to +# <automake-patches@gnu.org>. + +scriptversion=2013-12-23.17; # UTC + +# Make unconditional expansion of undefined variables an error. This +# helps a lot in preventing typo-related bugs. +set -u + +me=tap-driver.sh + +fatal () +{ + echo "$me: fatal: $*" >&2 + exit 1 +} + +usage_error () +{ + echo "$me: $*" >&2 + print_usage >&2 + exit 2 +} + +print_usage () +{ + cat <<END +Usage: + tap-driver.sh --test-name=NAME --log-file=PATH --trs-file=PATH + [--expect-failure={yes|no}] [--color-tests={yes|no}] + [--enable-hard-errors={yes|no}] [--ignore-exit] + [--diagnostic-string=STRING] [--merge|--no-merge] + [--comments|--no-comments] [--] TEST-COMMAND +The '--test-name', '-log-file' and '--trs-file' options are mandatory. +END +} + +# TODO: better error handling in option parsing (in particular, ensure +# TODO: $log_file, $trs_file and $test_name are defined). +test_name= # Used for reporting. +log_file= # Where to save the result and output of the test script. +trs_file= # Where to save the metadata of the test run. +expect_failure=0 +color_tests=0 +merge=0 +ignore_exit=0 +comments=0 +diag_string='#' +while test $# -gt 0; do + case $1 in + --help) print_usage; exit $?;; + --version) echo "$me $scriptversion"; exit $?;; + --test-name) test_name=$2; shift;; + --log-file) log_file=$2; shift;; + --trs-file) trs_file=$2; shift;; + --color-tests) color_tests=$2; shift;; + --expect-failure) expect_failure=$2; shift;; + --enable-hard-errors) shift;; # No-op. + --merge) merge=1;; + --no-merge) merge=0;; + --ignore-exit) ignore_exit=1;; + --comments) comments=1;; + --no-comments) comments=0;; + --diagnostic-string) diag_string=$2; shift;; + --) shift; break;; + -*) usage_error "invalid option: '$1'";; + esac + shift +done + +test $# -gt 0 || usage_error "missing test command" + +case $expect_failure in + yes) expect_failure=1;; + *) expect_failure=0;; +esac + +if test $color_tests = yes; then + init_colors=' + color_map["red"]="[0;31m" # Red. + color_map["grn"]="[0;32m" # Green. + color_map["lgn"]="[1;32m" # Light green. + color_map["blu"]="[1;34m" # Blue. + color_map["mgn"]="[0;35m" # Magenta. + color_map["std"]="[m" # No color. + color_for_result["ERROR"] = "mgn" + color_for_result["PASS"] = "grn" + color_for_result["XPASS"] = "red" + color_for_result["FAIL"] = "red" + color_for_result["XFAIL"] = "lgn" + color_for_result["SKIP"] = "blu"' +else + init_colors='' +fi + +# :; is there to work around a bug in bash 3.2 (and earlier) which +# does not always set '$?' properly on redirection failure. +# See the Autoconf manual for more details. +:;{ + ( + # Ignore common signals (in this subshell only!), to avoid potential + # problems with Korn shells. Some Korn shells are known to propagate + # to themselves signals that have killed a child process they were + # waiting for; this is done at least for SIGINT (and usually only for + # it, in truth). Without the `trap' below, such a behaviour could + # cause a premature exit in the current subshell, e.g., in case the + # test command it runs gets terminated by a SIGINT. Thus, the awk + # script we are piping into would never seen the exit status it + # expects on its last input line (which is displayed below by the + # last `echo $?' statement), and would thus die reporting an internal + # error. + # For more information, see the Autoconf manual and the threads: + # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html> + # <http://mail.opensolaris.org/pipermail/ksh93-integration-discuss/2009-February/004121.html> + trap : 1 3 2 13 15 + if test $merge -gt 0; then + exec 2>&1 + else + exec 2>&3 + fi + "$@" + echo $? + ) | LC_ALL=C ${AM_TAP_AWK-awk} \ + -v me="$me" \ + -v test_script_name="$test_name" \ + -v log_file="$log_file" \ + -v trs_file="$trs_file" \ + -v expect_failure="$expect_failure" \ + -v merge="$merge" \ + -v ignore_exit="$ignore_exit" \ + -v comments="$comments" \ + -v diag_string="$diag_string" \ +' +# TODO: the usages of "cat >&3" below could be optimized when using +# GNU awk, and/on on systems that supports /dev/fd/. + +# Implementation note: in what follows, `result_obj` will be an +# associative array that (partly) simulates a TAP result object +# from the `TAP::Parser` perl module. + +## ----------- ## +## FUNCTIONS ## +## ----------- ## + +function fatal(msg) +{ + print me ": " msg | "cat >&2" + exit 1 +} + +function abort(where) +{ + fatal("internal error " where) +} + +# Convert a boolean to a "yes"/"no" string. +function yn(bool) +{ + return bool ? "yes" : "no"; +} + +function add_test_result(result) +{ + if (!test_results_index) + test_results_index = 0 + test_results_list[test_results_index] = result + test_results_index += 1 + test_results_seen[result] = 1; +} + +# Whether the test script should be re-run by "make recheck". +function must_recheck() +{ + for (k in test_results_seen) + if (k != "XFAIL" && k != "PASS" && k != "SKIP") + return 1 + return 0 +} + +# Whether the content of the log file associated to this test should +# be copied into the "global" test-suite.log. +function copy_in_global_log() +{ + for (k in test_results_seen) + if (k != "PASS") + return 1 + return 0 +} + +function get_global_test_result() +{ + if ("ERROR" in test_results_seen) + return "ERROR" + if ("FAIL" in test_results_seen || "XPASS" in test_results_seen) + return "FAIL" + all_skipped = 1 + for (k in test_results_seen) + if (k != "SKIP") + all_skipped = 0 + if (all_skipped) + return "SKIP" + return "PASS"; +} + +function stringify_result_obj(result_obj) +{ + if (result_obj["is_unplanned"] || result_obj["number"] != testno) + return "ERROR" + + if (plan_seen == LATE_PLAN) + return "ERROR" + + if (result_obj["directive"] == "TODO") + return result_obj["is_ok"] ? "XPASS" : "XFAIL" + + if (result_obj["directive"] == "SKIP") + return result_obj["is_ok"] ? "SKIP" : COOKED_FAIL; + + if (length(result_obj["directive"])) + abort("in function stringify_result_obj()") + + return result_obj["is_ok"] ? COOKED_PASS : COOKED_FAIL +} + +function decorate_result(result) +{ + color_name = color_for_result[result] + if (color_name) + return color_map[color_name] "" result "" color_map["std"] + # If we are not using colorized output, or if we do not know how + # to colorize the given result, we should return it unchanged. + return result +} + +function report(result, details) +{ + if (result ~ /^(X?(PASS|FAIL)|SKIP|ERROR)/) + { + msg = ": " test_script_name + add_test_result(result) + } + else if (result == "#") + { + msg = " " test_script_name ":" + } + else + { + abort("in function report()") + } + if (length(details)) + msg = msg " " details + # Output on console might be colorized. + print decorate_result(result) msg + # Log the result in the log file too, to help debugging (this is + # especially true when said result is a TAP error or "Bail out!"). + print result msg | "cat >&3"; +} + +function testsuite_error(error_message) +{ + report("ERROR", "- " error_message) +} + +function handle_tap_result() +{ + details = result_obj["number"]; + if (length(result_obj["description"])) + details = details " " result_obj["description"] + + if (plan_seen == LATE_PLAN) + { + details = details " # AFTER LATE PLAN"; + } + else if (result_obj["is_unplanned"]) + { + details = details " # UNPLANNED"; + } + else if (result_obj["number"] != testno) + { + details = sprintf("%s # OUT-OF-ORDER (expecting %d)", + details, testno); + } + else if (result_obj["directive"]) + { + details = details " # " result_obj["directive"]; + if (length(result_obj["explanation"])) + details = details " " result_obj["explanation"] + } + + report(stringify_result_obj(result_obj), details) +} + +# `skip_reason` should be empty whenever planned > 0. +function handle_tap_plan(planned, skip_reason) +{ + planned += 0 # Avoid getting confused if, say, `planned` is "00" + if (length(skip_reason) && planned > 0) + abort("in function handle_tap_plan()") + if (plan_seen) + { + # Error, only one plan per stream is acceptable. + testsuite_error("multiple test plans") + return; + } + planned_tests = planned + # The TAP plan can come before or after *all* the TAP results; we speak + # respectively of an "early" or a "late" plan. If we see the plan line + # after at least one TAP result has been seen, assume we have a late + # plan; in this case, any further test result seen after the plan will + # be flagged as an error. + plan_seen = (testno >= 1 ? LATE_PLAN : EARLY_PLAN) + # If testno > 0, we have an error ("too many tests run") that will be + # automatically dealt with later, so do not worry about it here. If + # $plan_seen is true, we have an error due to a repeated plan, and that + # has already been dealt with above. Otherwise, we have a valid "plan + # with SKIP" specification, and should report it as a particular kind + # of SKIP result. + if (planned == 0 && testno == 0) + { + if (length(skip_reason)) + skip_reason = "- " skip_reason; + report("SKIP", skip_reason); + } +} + +function extract_tap_comment(line) +{ + if (index(line, diag_string) == 1) + { + # Strip leading `diag_string` from `line`. + line = substr(line, length(diag_string) + 1) + # And strip any leading and trailing whitespace left. + sub("^[ \t]*", "", line) + sub("[ \t]*$", "", line) + # Return what is left (if any). + return line; + } + return ""; +} + +# When this function is called, we know that line is a TAP result line, +# so that it matches the (perl) RE "^(not )?ok\b". +function setup_result_obj(line) +{ + # Get the result, and remove it from the line. + result_obj["is_ok"] = (substr(line, 1, 2) == "ok" ? 1 : 0) + sub("^(not )?ok[ \t]*", "", line) + + # If the result has an explicit number, get it and strip it; otherwise, + # automatically assing the next progresive number to it. + if (line ~ /^[0-9]+$/ || line ~ /^[0-9]+[^a-zA-Z0-9_]/) + { + match(line, "^[0-9]+") + # The final `+ 0` is to normalize numbers with leading zeros. + result_obj["number"] = substr(line, 1, RLENGTH) + 0 + line = substr(line, RLENGTH + 1) + } + else + { + result_obj["number"] = testno + } + + if (plan_seen == LATE_PLAN) + # No further test results are acceptable after a "late" TAP plan + # has been seen. + result_obj["is_unplanned"] = 1 + else if (plan_seen && testno > planned_tests) + result_obj["is_unplanned"] = 1 + else + result_obj["is_unplanned"] = 0 + + # Strip trailing and leading whitespace. + sub("^[ \t]*", "", line) + sub("[ \t]*$", "", line) + + # This will have to be corrected if we have a "TODO"/"SKIP" directive. + result_obj["description"] = line + result_obj["directive"] = "" + result_obj["explanation"] = "" + + if (index(line, "#") == 0) + return # No possible directive, nothing more to do. + + # Directives are case-insensitive. + rx = "[ \t]*#[ \t]*([tT][oO][dD][oO]|[sS][kK][iI][pP])[ \t]*" + + # See whether we have the directive, and if yes, where. + pos = match(line, rx "$") + if (!pos) + pos = match(line, rx "[^a-zA-Z0-9_]") + + # If there was no TAP directive, we have nothing more to do. + if (!pos) + return + + # Let`s now see if the TAP directive has been escaped. For example: + # escaped: ok \# SKIP + # not escaped: ok \\# SKIP + # escaped: ok \\\\\# SKIP + # not escaped: ok \ # SKIP + if (substr(line, pos, 1) == "#") + { + bslash_count = 0 + for (i = pos; i > 1 && substr(line, i - 1, 1) == "\\"; i--) + bslash_count += 1 + if (bslash_count % 2) + return # Directive was escaped. + } + + # Strip the directive and its explanation (if any) from the test + # description. + result_obj["description"] = substr(line, 1, pos - 1) + # Now remove the test description from the line, that has been dealt + # with already. + line = substr(line, pos) + # Strip the directive, and save its value (normalized to upper case). + sub("^[ \t]*#[ \t]*", "", line) + result_obj["directive"] = toupper(substr(line, 1, 4)) + line = substr(line, 5) + # Now get the explanation for the directive (if any), with leading + # and trailing whitespace removed. + sub("^[ \t]*", "", line) + sub("[ \t]*$", "", line) + result_obj["explanation"] = line +} + +function get_test_exit_message(status) +{ + if (status == 0) + return "" + if (status !~ /^[1-9][0-9]*$/) + abort("getting exit status") + if (status < 127) + exit_details = "" + else if (status == 127) + exit_details = " (command not found?)" + else if (status >= 128 && status <= 255) + exit_details = sprintf(" (terminated by signal %d?)", status - 128) + else if (status > 256 && status <= 384) + # We used to report an "abnormal termination" here, but some Korn + # shells, when a child process die due to signal number n, can leave + # in $? an exit status of 256+n instead of the more standard 128+n. + # Apparently, both behaviours are allowed by POSIX (2008), so be + # prepared to handle them both. See also Austing Group report ID + # 0000051 <http://www.austingroupbugs.net/view.php?id=51> + exit_details = sprintf(" (terminated by signal %d?)", status - 256) + else + # Never seen in practice. + exit_details = " (abnormal termination)" + return sprintf("exited with status %d%s", status, exit_details) +} + +function write_test_results() +{ + print ":global-test-result: " get_global_test_result() > trs_file + print ":recheck: " yn(must_recheck()) > trs_file + print ":copy-in-global-log: " yn(copy_in_global_log()) > trs_file + for (i = 0; i < test_results_index; i += 1) + print ":test-result: " test_results_list[i] > trs_file + close(trs_file); +} + +BEGIN { + +## ------- ## +## SETUP ## +## ------- ## + +'"$init_colors"' + +# Properly initialized once the TAP plan is seen. +planned_tests = 0 + +COOKED_PASS = expect_failure ? "XPASS": "PASS"; +COOKED_FAIL = expect_failure ? "XFAIL": "FAIL"; + +# Enumeration-like constants to remember which kind of plan (if any) +# has been seen. It is important that NO_PLAN evaluates "false" as +# a boolean. +NO_PLAN = 0 +EARLY_PLAN = 1 +LATE_PLAN = 2 + +testno = 0 # Number of test results seen so far. +bailed_out = 0 # Whether a "Bail out!" directive has been seen. + +# Whether the TAP plan has been seen or not, and if yes, which kind +# it is ("early" is seen before any test result, "late" otherwise). +plan_seen = NO_PLAN + +## --------- ## +## PARSING ## +## --------- ## + +is_first_read = 1 + +while (1) + { + # Involutions required so that we are able to read the exit status + # from the last input line. + st = getline + if (st < 0) # I/O error. + fatal("I/O error while reading from input stream") + else if (st == 0) # End-of-input + { + if (is_first_read) + abort("in input loop: only one input line") + break + } + if (is_first_read) + { + is_first_read = 0 + nextline = $0 + continue + } + else + { + curline = nextline + nextline = $0 + $0 = curline + } + # Copy any input line verbatim into the log file. + print | "cat >&3" + # Parsing of TAP input should stop after a "Bail out!" directive. + if (bailed_out) + continue + + # TAP test result. + if ($0 ~ /^(not )?ok$/ || $0 ~ /^(not )?ok[^a-zA-Z0-9_]/) + { + testno += 1 + setup_result_obj($0) + handle_tap_result() + } + # TAP plan (normal or "SKIP" without explanation). + else if ($0 ~ /^1\.\.[0-9]+[ \t]*$/) + { + # The next two lines will put the number of planned tests in $0. + sub("^1\\.\\.", "") + sub("[^0-9]*$", "") + handle_tap_plan($0, "") + continue + } + # TAP "SKIP" plan, with an explanation. + else if ($0 ~ /^1\.\.0+[ \t]*#/) + { + # The next lines will put the skip explanation in $0, stripping + # any leading and trailing whitespace. This is a little more + # tricky in truth, since we want to also strip a potential leading + # "SKIP" string from the message. + sub("^[^#]*#[ \t]*(SKIP[: \t][ \t]*)?", "") + sub("[ \t]*$", ""); + handle_tap_plan(0, $0) + } + # "Bail out!" magic. + # Older versions of prove and TAP::Harness (e.g., 3.17) did not + # recognize a "Bail out!" directive when preceded by leading + # whitespace, but more modern versions (e.g., 3.23) do. So we + # emulate the latter, "more modern" behaviour. + else if ($0 ~ /^[ \t]*Bail out!/) + { + bailed_out = 1 + # Get the bailout message (if any), with leading and trailing + # whitespace stripped. The message remains stored in `$0`. + sub("^[ \t]*Bail out![ \t]*", ""); + sub("[ \t]*$", ""); + # Format the error message for the + bailout_message = "Bail out!" + if (length($0)) + bailout_message = bailout_message " " $0 + testsuite_error(bailout_message) + } + # Maybe we have too look for dianogtic comments too. + else if (comments != 0) + { + comment = extract_tap_comment($0); + if (length(comment)) + report("#", comment); + } + } + +## -------- ## +## FINISH ## +## -------- ## + +# A "Bail out!" directive should cause us to ignore any following TAP +# error, as well as a non-zero exit status from the TAP producer. +if (!bailed_out) + { + if (!plan_seen) + { + testsuite_error("missing test plan") + } + else if (planned_tests != testno) + { + bad_amount = testno > planned_tests ? "many" : "few" + testsuite_error(sprintf("too %s tests run (expected %d, got %d)", + bad_amount, planned_tests, testno)) + } + if (!ignore_exit) + { + # Fetch exit status from the last line. + exit_message = get_test_exit_message(nextline) + if (exit_message) + testsuite_error(exit_message) + } + } + +write_test_results() + +exit 0 + +} # End of "BEGIN" block. +' + +# TODO: document that we consume the file descriptor 3 :-( +} 3>"$log_file" + +test $? -eq 0 || fatal "I/O or internal error" + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End:
diff --git a/bus/.gitignore b/bus/.gitignore new file mode 100644 index 0000000..861dc1f --- /dev/null +++ b/bus/.gitignore
@@ -0,0 +1,26 @@ +.deps +.libs +Makefile +Makefile.in +*.lo +*.la +dbus-daemon +dbus-daemon-activation-helper +dbus-daemon-activation-helper-test +dbus-daemon-launch-helper +dbus-daemon-launch-helper-test +*.bb +*.bbg +*.da +*.gcov +bus-test +rc.messagebus +messagebus +messagebus-config +session.conf +system.conf +bus-test-launch-helper +bus-test-system +dbus.service +dbus.socket +org.freedesktop.dbus-session.plist
diff --git a/bus/Android.mk b/bus/Android.mk new file mode 100644 index 0000000..248746a --- /dev/null +++ b/bus/Android.mk
@@ -0,0 +1,55 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_C_INCLUDES:= $(LOCAL_PATH)/.. + +LOCAL_CFLAGS:= \ + -O3 \ + -DDBUS_ANDROID_LOG \ + -DDBUS_COMPILATION \ + -DDBUS_DAEMON_NAME=\"dbus-daemon\" \ + -DDBUS_SYSTEM_CONFIG_FILE=\"/etc/dbus-1/system.conf\" \ + -DDBUS_SESSION_CONFIG_FILE=\"/etc/dbus-1/session.conf\" \ + -Wno-address \ + -Wno-empty-body \ + -Wno-pointer-sign \ + -Wno-sign-compare \ + -Wno-unused-parameter + +LOCAL_SRC_FILES:= \ + activation.c \ + activation-helper.c \ + apparmor.c \ + audit.c \ + bus.c \ + config-loader-expat.c \ + config-parser.c \ + config-parser-common.c \ + connection.c \ + desktop-file.c \ + dir-watch-inotify.c \ + dispatch.c \ + driver.c \ + expirelist.c \ + main.c \ + policy.c \ + selinux.c \ + services.c \ + signals.c \ + stats.c \ + utils.c + +ifeq ($(BUILD_EUREKA),true) +LOCAL_C_INCLUDES += external/expat/lib +LOCAL_STATIC_LIBRARIES := libexpat_static +LOCAL_SHARED_LIBRARIES := \ + libdbus +else +LOCAL_SHARED_LIBRARIES := \ + libexpat \ + libdbus +endif + +LOCAL_MODULE:=dbus-daemon + +include $(BUILD_EXECUTABLE)
diff --git a/bus/Makefile.am b/bus/Makefile.am new file mode 100644 index 0000000..33af09b --- /dev/null +++ b/bus/Makefile.am
@@ -0,0 +1,334 @@ +dbusdatadir=$(datadir)/dbus-1 +legacydbusdatadir=$(sysconfdir)/dbus-1 +dbus_daemon_execdir = $(DBUS_DAEMONDIR) + +DBUS_BUS_LIBS = \ + $(XML_LIBS) \ + $(SELINUX_LIBS) \ + $(APPARMOR_LIBS) \ + $(THREAD_LIBS) \ + $(ADT_LIBS) \ + $(NETWORK_libs) \ + $(NULL) + +DBUS_LAUNCHER_LIBS = \ + $(XML_LIBS) \ + $(THREAD_LIBS) \ + $(NETWORK_libs) \ + $(NULL) + +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + $(DBUS_STATIC_BUILD_CPPFLAGS) \ + $(XML_CFLAGS) \ + $(APPARMOR_CFLAGS) \ + -DDBUS_SYSTEM_CONFIG_FILE=\""$(dbusdatadir)/system.conf"\" \ + -DDBUS_COMPILATION \ + $(NULL) + +# if assertions are enabled, improve backtraces +AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ + +EFENCE= + +CONFIG_IN_FILES= \ + session.conf.in \ + system.conf.in \ + legacy-config/session.conf.in \ + legacy-config/system.conf.in \ + org.freedesktop.dbus-session.plist.in \ + example-system-enable-stats.conf.in \ + example-session-disable-stats.conf.in \ + $(NULL) + +dbusdata_DATA = session.conf +legacydbusdata_DATA = legacy-config/session.conf + +if DBUS_UNIX +dbusdata_DATA += system.conf +legacydbusdata_DATA += legacy-config/system.conf +endif + +examplesdir = ${docdir}/examples +examples_DATA = \ + example-system-enable-stats.conf \ + example-session-disable-stats.conf \ + $(NULL) + +if DBUS_ENABLE_LAUNCHD +agentdir=$(LAUNCHD_AGENT_DIR) +agent_DATA=org.freedesktop.dbus-session.plist +endif + +XML_SOURCES=config-loader-expat.c + +if DBUS_BUS_ENABLE_KQUEUE +DIR_WATCH_SOURCE=dir-watch-kqueue.c +else +if DBUS_BUS_ENABLE_INOTIFY +DIR_WATCH_SOURCE=dir-watch-inotify.c +else +DIR_WATCH_SOURCE=dir-watch-default.c +endif +endif + +BUS_SOURCES= \ + activation.c \ + activation.h \ + activation-exit-codes.h \ + apparmor.c \ + apparmor.h \ + audit.c \ + audit.h \ + bus.c \ + bus.h \ + config-parser.c \ + config-parser.h \ + config-parser-common.c \ + config-parser-common.h \ + connection.c \ + connection.h \ + desktop-file.c \ + desktop-file.h \ + $(DIR_WATCH_SOURCE) \ + dir-watch.h \ + dispatch.c \ + dispatch.h \ + driver.c \ + driver.h \ + expirelist.c \ + expirelist.h \ + policy.c \ + policy.h \ + selinux.h \ + selinux.c \ + services.c \ + services.h \ + signals.c \ + signals.h \ + stats.c \ + stats.h \ + test.c \ + test.h \ + utils.c \ + utils.h \ + $(XML_SOURCES) + +dbus_daemon_SOURCES= \ + $(BUS_SOURCES) \ + main.c + +dbus_daemon_LDADD= \ + $(top_builddir)/dbus/libdbus-1.la \ + $(top_builddir)/dbus/libdbus-internal.la \ + $(EFENCE) \ + $(DBUS_BUS_LIBS) + +LAUNCH_HELPER_SOURCES= \ + $(XML_SOURCES) \ + config-parser-common.c \ + config-parser-common.h \ + config-parser-trivial.c \ + config-parser-trivial.h \ + desktop-file.c \ + desktop-file.h \ + utils.c \ + utils.h \ + activation-exit-codes.h \ + activation-helper.h \ + activation-helper.c + +## This is the installed launch helper with the setuid checks +dbus_daemon_launch_helper_SOURCES= \ + activation-helper-bin.c \ + $(LAUNCH_HELPER_SOURCES) + +dbus_daemon_launch_helper_LDADD= \ + $(top_builddir)/dbus/libdbus-1.la \ + $(top_builddir)/dbus/libdbus-internal.la \ + $(DBUS_LAUNCHER_LIBS) + +## we build another binary so we can do the launch testing without root privs. +## DO NOT INSTALL THIS FILE +dbus_daemon_launch_helper_test_SOURCES= \ + activation-helper-bin.c \ + $(LAUNCH_HELPER_SOURCES) + +dbus_daemon_launch_helper_test_LDADD= \ + $(top_builddir)/dbus/libdbus-1.la \ + $(top_builddir)/dbus/libdbus-internal.la \ + $(DBUS_LAUNCHER_LIBS) + +dbus_daemon_launch_helper_test_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -DACTIVATION_LAUNCHER_TEST + +## we build yet another binary so we can do the OOM tests +## DO NOT INSTALL THIS FILE +test_bus_launch_helper_SOURCES= \ + test-launch-helper.c \ + $(LAUNCH_HELPER_SOURCES) + +test_bus_launch_helper_LDADD= \ + $(top_builddir)/dbus/libdbus-1.la \ + $(top_builddir)/dbus/libdbus-internal.la \ + $(DBUS_LAUNCHER_LIBS) + $(NULL) + +test_bus_launch_helper_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -DACTIVATION_LAUNCHER_TEST \ + -DACTIVATION_LAUNCHER_DO_OOM + +noinst_PROGRAMS = +dbus_daemon_exec_PROGRAMS = dbus-daemon +if DBUS_UNIX +libexec_PROGRAMS = dbus-daemon-launch-helper +endif DBUS_UNIX + +## Note that TESTS has special meaning (stuff to use in make check). +## We don't actually want to run any of these tests until test/ has been +## compiled, so we don't put them in TESTS here; we run them in test/ +## instead. + +if DBUS_ENABLE_EMBEDDED_TESTS +## we use noinst_PROGRAMS not check_PROGRAMS so that we build +## even when not doing "make check" + +# run as a test by test/Makefile.am +noinst_PROGRAMS += test-bus + +if DBUS_UNIX +# run as a test by test/Makefile.am +noinst_PROGRAMS += test-bus-launch-helper test-bus-system +# this is used by the tests but is not,itself, a test +noinst_PROGRAMS += dbus-daemon-launch-helper-test +endif DBUS_UNIX + +endif DBUS_ENABLE_EMBEDDED_TESTS + +test_bus_system_SOURCES= \ + $(XML_SOURCES) \ + config-parser-common.c \ + config-parser-common.h \ + config-parser-trivial.c \ + config-parser-trivial.h \ + utils.c \ + utils.h \ + test-system.c + +test_bus_system_LDADD = \ + $(top_builddir)/dbus/libdbus-1.la \ + $(top_builddir)/dbus/libdbus-internal.la \ + $(DBUS_BUS_LIBS) \ + $(NULL) + +test_bus_SOURCES= \ + $(BUS_SOURCES) \ + test-main.c + +test_bus_LDADD = \ + $(top_builddir)/dbus/libdbus-1.la \ + $(top_builddir)/dbus/libdbus-internal.la \ + $(DBUS_BUS_LIBS) \ + $(NULL) + +## mop up the gcov files +clean-local: + /bin/rm *.bb *.bbg *.da *.gcov || true + +install-data-hook: + $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/session.d + $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/services +if DBUS_UNIX + $(mkinstalldirs) $(DESTDIR)$(localstatedir)/run/dbus + $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/system.d + $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/system-services +endif +if HAVE_SYSTEMD +# Install dbus.socket as default implementation of a D-Bus stack. +# Deliberately not using $(LN_S) here: ln -fs is not universally portable, +# but neither is systemd, so it's OK to assume here that ln complies with SUS. + $(mkinstalldirs) $(DESTDIR)$(systemdsystemunitdir)/dbus.target.wants + ln -fs ../dbus.socket $(DESTDIR)$(systemdsystemunitdir)/dbus.target.wants/dbus.socket +# Unconditionally enable D-Bus on systemd installations + $(mkinstalldirs) $(DESTDIR)$(systemdsystemunitdir)/sockets.target.wants + ln -fs ../dbus.socket $(DESTDIR)$(systemdsystemunitdir)/sockets.target.wants/dbus.socket + $(mkinstalldirs) $(DESTDIR)$(systemdsystemunitdir)/multi-user.target.wants + ln -fs ../dbus.service $(DESTDIR)$(systemdsystemunitdir)/multi-user.target.wants/dbus.service +endif +if DBUS_ENABLE_USER_SESSION + $(mkinstalldirs) $(DESTDIR)$(systemduserunitdir)/sockets.target.wants + ln -fs ../dbus.socket $(DESTDIR)$(systemduserunitdir)/sockets.target.wants/dbus.socket +endif + +if DBUS_UNIX +install-exec-hook: + if test `id -u` -eq 0; then \ + chown root:$(DBUS_USER) $(DESTDIR)$(libexecdir)/dbus-daemon-launch-helper$(EXEEXT); \ + chmod 4750 $(DESTDIR)$(libexecdir)/dbus-daemon-launch-helper$(EXEEXT); \ + else \ + echo "Not installing $(DESTDIR)$(libexecdir)/dbus-daemon-launch-helper binary setuid!"; \ + echo "You'll need to manually set permissions to root:$(DBUS_USER) and permissions 4750"; \ + fi +endif + +#### Init scripts fun +SCRIPT_IN_FILES=messagebus.in \ + messagebus-config.in \ + rc.messagebus.in + +## Red Hat start +if DBUS_INIT_SCRIPTS_RED_HAT + +initddir=$(sysconfdir)/rc.d/init.d + +initd_SCRIPTS= \ + messagebus + +endif + ## Red Hat end + +## Slackware start +if DBUS_INIT_SCRIPTS_SLACKWARE + +initddir=$(sysconfdir)/rc.d/ + +initd_SCRIPTS= \ + rc.messagebus + +endif +## Slackware end + +## Cygwin start +if DBUS_INIT_SCRIPTS_CYGWIN + +bin_SCRIPTS= \ + messagebus-config + +endif +## Cygwin end + +if HAVE_SYSTEMD +SCRIPT_IN_FILES += \ + dbus.service.in \ + dbus.socket.in \ + systemd-user/dbus.service.in \ + systemd-user/dbus.socket.in \ + $(NULL) + +systemdsystemunit_DATA = \ + dbus.service \ + dbus.socket +endif + +if DBUS_ENABLE_USER_SESSION +systemduserunit_DATA = \ + systemd-user/dbus.service \ + systemd-user/dbus.socket \ + $(NULL) +endif + +#### Extra dist + +EXTRA_DIST=$(CONFIG_IN_FILES) $(SCRIPT_IN_FILES)
diff --git a/bus/NOTICE b/bus/NOTICE new file mode 100644 index 0000000..a91ca1d --- /dev/null +++ b/bus/NOTICE
@@ -0,0 +1,551 @@ +D-Bus is licensed to you under your choice of the Academic Free +License version 2.1, or the GNU General Public License version 2. +Both licenses are included here. Some of the standalone binaries are +under the GPL only; in particular, but not limited to, +tools/dbus-cleanup-sockets.c and test/decode-gcov.c. Each source code +file is marked with the proper copyright information - if you find a +file that isn't marked please bring it to our attention. + + +The Academic Free License +v. 2.1 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following notice immediately following the copyright notice for the Original Work: + +Licensed under the Academic Free License version 2.1 + +1) Grant of Copyright License. Licensor hereby grants You a +world-wide, royalty-free, non-exclusive, perpetual, sublicenseable +license to do the following: + +a) to reproduce the Original Work in copies; + +b) to prepare derivative works ("Derivative Works") based upon the Original Work; + +c) to distribute copies of the Original Work and Derivative Works to the public; + +d) to perform the Original Work publicly; and + +e) to display the Original Work publicly. + +2) Grant of Patent License. Licensor hereby grants You a world-wide, +royalty-free, non-exclusive, perpetual, sublicenseable license, under +patent claims owned or controlled by the Licensor that are embodied in +the Original Work as furnished by the Licensor, to make, use, sell and +offer for sale the Original Work and Derivative Works. + +3) Grant of Source Code License. The term "Source Code" means the +preferred form of the Original Work for making modifications to it and +all available documentation describing how to modify the Original +Work. Licensor hereby agrees to provide a machine-readable copy of the +Source Code of the Original Work along with each copy of the Original +Work that Licensor distributes. Licensor reserves the right to satisfy +this obligation by placing a machine-readable copy of the Source Code +in an information repository reasonably calculated to permit +inexpensive and convenient access by You for as long as Licensor +continues to distribute the Original Work, and by publishing the +address of that information repository in a notice immediately +following the copyright notice that applies to the Original Work. + +4) Exclusions From License Grant. Neither the names of Licensor, nor +the names of any contributors to the Original Work, nor any of their +trademarks or service marks, may be used to endorse or promote +products derived from this Original Work without express prior written +permission of the Licensor. Nothing in this License shall be deemed to +grant any rights to trademarks, copyrights, patents, trade secrets or +any other intellectual property of Licensor except as expressly stated +herein. No patent license is granted to make, use, sell or offer to +sell embodiments of any patent claims other than the licensed claims +defined in Section 2. No right is granted to the trademarks of +Licensor even if such marks are included in the Original Work. Nothing +in this License shall be interpreted to prohibit Licensor from +licensing under different terms from this License any Original Work +that Licensor otherwise would have a right to license. + +5) This section intentionally omitted. + +6) Attribution Rights. You must retain, in the Source Code of any +Derivative Works that You create, all copyright, patent or trademark +notices from the Source Code of the Original Work, as well as any +notices of licensing and any descriptive text identified therein as an +"Attribution Notice." You must cause the Source Code for any +Derivative Works that You create to carry a prominent Attribution +Notice reasonably calculated to inform recipients that You have +modified the Original Work. + +7) Warranty of Provenance and Disclaimer of Warranty. Licensor +warrants that the copyright in and to the Original Work and the patent +rights granted herein by Licensor are owned by the Licensor or are +sublicensed to You under the terms of this License with the permission +of the contributor(s) of those copyrights and patent rights. Except as +expressly stated in the immediately proceeding sentence, the Original +Work is provided under this License on an "AS IS" BASIS and WITHOUT +WARRANTY, either express or implied, including, without limitation, +the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL +WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential +part of this License. No license to Original Work is granted hereunder +except under this disclaimer. + +8) Limitation of Liability. Under no circumstances and under no legal +theory, whether in tort (including negligence), contract, or +otherwise, shall the Licensor be liable to any person for any direct, +indirect, special, incidental, or consequential damages of any +character arising as a result of this License or the use of the +Original Work including, without limitation, damages for loss of +goodwill, work stoppage, computer failure or malfunction, or any and +all other commercial damages or losses. This limitation of liability +shall not apply to liability for death or personal injury resulting +from Licensor's negligence to the extent applicable law prohibits such +limitation. Some jurisdictions do not allow the exclusion or +limitation of incidental or consequential damages, so this exclusion +and limitation may not apply to You. + +9) Acceptance and Termination. If You distribute copies of the +Original Work or a Derivative Work, You must make a reasonable effort +under the circumstances to obtain the express assent of recipients to +the terms of this License. Nothing else but this License (or another +written agreement between Licensor and You) grants You permission to +create Derivative Works based upon the Original Work or to exercise +any of the rights granted in Section 1 herein, and any attempt to do +so except under the terms of this License (or another written +agreement between Licensor and You) is expressly prohibited by +U.S. copyright law, the equivalent laws of other countries, and by +international treaty. Therefore, by exercising any of the rights +granted to You in Section 1 herein, You indicate Your acceptance of +this License and all of its terms and conditions. + +10) Termination for Patent Action. This License shall terminate +automatically and You may no longer exercise any of the rights granted +to You by this License as of the date You commence an action, +including a cross-claim or counterclaim, against Licensor or any +licensee alleging that the Original Work infringes a patent. This +termination provision shall not apply for an action alleging patent +infringement by combinations of the Original Work with other software +or hardware. + +11) Jurisdiction, Venue and Governing Law. Any action or suit relating +to this License may be brought only in the courts of a jurisdiction +wherein the Licensor resides or in which Licensor conducts its primary +business, and under the laws of that jurisdiction excluding its +conflict-of-law provisions. The application of the United Nations +Convention on Contracts for the International Sale of Goods is +expressly excluded. Any use of the Original Work outside the scope of +this License or after its termination shall be subject to the +requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 +et seq., the equivalent laws of other countries, and international +treaty. This section shall survive the termination of this License. + +12) Attorneys Fees. In any action to enforce the terms of this License +or seeking damages relating thereto, the prevailing party shall be +entitled to recover its costs and expenses, including, without +limitation, reasonable attorneys' fees and costs incurred in +connection with such action, including any appeal of such action. This +section shall survive the termination of this License. + +13) Miscellaneous. This License represents the complete agreement +concerning the subject matter hereof. If any provision of this License +is held to be unenforceable, such provision shall be reformed only to +the extent necessary to make it enforceable. + +14) Definition of "You" in This License. "You" throughout this +License, whether in upper or lower case, means an individual or a +legal entity exercising rights under, and complying with all of the +terms of, this License. For legal entities, "You" includes any entity +that controls, is controlled by, or is under common control with +you. For purposes of this definition, "control" means (i) the power, +direct or indirect, to cause the direction or management of such +entity, whether by contract or otherwise, or (ii) ownership of fifty +percent (50%) or more of the outstanding shares, or (iii) beneficial +ownership of such entity. + +15) Right to Use. You may use the Original Work in all ways not +otherwise restricted or conditioned by this License or by law, and +Licensor promises not to interfere with or be responsible for such +uses by You. + +This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights +reserved. Permission is hereby granted to copy and distribute this +license without modification. This license may not be modified without +the express written permission of its copyright owner. + + +-- +END OF ACADEMIC FREE LICENSE. The following is intended to describe the essential +differences between the Academic Free License (AFL) version 1.0 and other +open source licenses: + +The Academic Free License is similar to the BSD, MIT, UoI/NCSA and Apache +licenses in many respects but it is intended to solve a few problems with +those licenses. + +* The AFL is written so as to make it clear what software is being +licensed (by the inclusion of a statement following the copyright notice +in the software). This way, the license functions better than a template +license. The BSD, MIT and UoI/NCSA licenses apply to unidentified software. + +* The AFL contains a complete copyright grant to the software. The BSD +and Apache licenses are vague and incomplete in that respect. + +* The AFL contains a complete patent grant to the software. The BSD, MIT, +UoI/NCSA and Apache licenses rely on an implied patent license and contain +no explicit patent grant. + +* The AFL makes it clear that no trademark rights are granted to the +licensor's trademarks. The Apache license contains such a provision, but the +BSD, MIT and UoI/NCSA licenses do not. + +* The AFL includes the warranty by the licensor that it either owns the +copyright or that it is distributing the software under a license. None of +the other licenses contain that warranty. All other warranties are disclaimed, +as is the case for the other licenses. + +* The AFL is itself copyrighted (with the right granted to copy and distribute +without modification). This ensures that the owner of the copyright to the +license will control changes. The Apache license contains a copyright notice, +but the BSD, MIT and UoI/NCSA licenses do not. +-- +START OF GNU GENERAL PUBLIC LICENSE +-- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE 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. + + 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 +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This 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 Library General +Public License instead of this License.
diff --git a/bus/activation-exit-codes.h b/bus/activation-exit-codes.h new file mode 100644 index 0000000..bbb98dc --- /dev/null +++ b/bus/activation-exit-codes.h
@@ -0,0 +1,45 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* activation-exit-codes.h Return values for the launch helper which is set + * in the helper and read in dbus-spawn. + * + * Copyright (C) 2007 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_ACTIVATION_EXIT_CODES_H +#define BUS_ACTIVATION_EXIT_CODES_H + +/** Return codes from the launch helper - not public API. However, + * presumably if some third party did write their own launch helper, + * they would have to rely on these, or at least always return + * 1 for GENERIC_FAILURE. + */ +#define BUS_SPAWN_EXIT_CODE_GENERIC_FAILURE 1 +#define BUS_SPAWN_EXIT_CODE_NO_MEMORY 2 +#define BUS_SPAWN_EXIT_CODE_CONFIG_INVALID 3 +#define BUS_SPAWN_EXIT_CODE_SETUP_FAILED 4 +#define BUS_SPAWN_EXIT_CODE_NAME_INVALID 5 +#define BUS_SPAWN_EXIT_CODE_SERVICE_NOT_FOUND 6 +#define BUS_SPAWN_EXIT_CODE_PERMISSIONS_INVALID 7 +#define BUS_SPAWN_EXIT_CODE_FILE_INVALID 8 +#define BUS_SPAWN_EXIT_CODE_EXEC_FAILED 9 +#define BUS_SPAWN_EXIT_CODE_INVALID_ARGS 10 +#define BUS_SPAWN_EXIT_CODE_CHILD_SIGNALED 11 + +#endif /* BUS_ACTIVATION_EXIT_CODES_H */
diff --git a/bus/activation-helper-bin.c b/bus/activation-helper-bin.c new file mode 100644 index 0000000..f5f16d2 --- /dev/null +++ b/bus/activation-helper-bin.c
@@ -0,0 +1,103 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* activation-helper-bin.c Setuid helper for launching programs as a custom + * user. This file is security sensitive. + * + * Copyright (C) 2007 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> + +#include "utils.h" +#include "activation-helper.h" +#include "activation-exit-codes.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static int +convert_error_to_exit_code (DBusError *error) +{ + if (dbus_error_has_name (error, DBUS_ERROR_NO_MEMORY)) + return BUS_SPAWN_EXIT_CODE_NO_MEMORY; + + if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_CONFIG_INVALID)) + return BUS_SPAWN_EXIT_CODE_CONFIG_INVALID; + + if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_SETUP_FAILED)) + return BUS_SPAWN_EXIT_CODE_SETUP_FAILED; + + if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_SERVICE_INVALID)) + return BUS_SPAWN_EXIT_CODE_NAME_INVALID; + + if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND)) + return BUS_SPAWN_EXIT_CODE_SERVICE_NOT_FOUND; + + if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID)) + return BUS_SPAWN_EXIT_CODE_PERMISSIONS_INVALID; + + if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_FILE_INVALID)) + return BUS_SPAWN_EXIT_CODE_FILE_INVALID; + + if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_EXEC_FAILED)) + return BUS_SPAWN_EXIT_CODE_EXEC_FAILED; + + if (dbus_error_has_name (error, DBUS_ERROR_INVALID_ARGS)) + return BUS_SPAWN_EXIT_CODE_INVALID_ARGS; + + if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_CHILD_SIGNALED)) + return BUS_SPAWN_EXIT_CODE_CHILD_SIGNALED; + + /* should we assert? */ + fprintf(stderr, "%s: %s\n", error->name, error->message); + + return BUS_SPAWN_EXIT_CODE_GENERIC_FAILURE; +} + +int +main (int argc, char **argv) +{ + DBusError error; + int retval; + + /* default is all okay */ + retval = 0; + + /* have we used a help option or not specified the correct arguments? */ + if (argc != 2 || + strcmp (argv[1], "--help") == 0 || + strcmp (argv[1], "-h") == 0 || + strcmp (argv[1], "-?") == 0) + { + fprintf (stderr, "dbus-daemon-activation-helper service.to.activate\n"); + exit (0); + } + + dbus_error_init (&error); + if (!run_launch_helper (argv[1], &error)) + { + /* convert error to an exit code */ + retval = convert_error_to_exit_code (&error); + dbus_error_free (&error); + } + + return retval; +} +
diff --git a/bus/activation-helper.c b/bus/activation-helper.c new file mode 100644 index 0000000..394f393 --- /dev/null +++ b/bus/activation-helper.c
@@ -0,0 +1,549 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* activation-helper.c Setuid helper for launching programs as a custom + * user. This file is security sensitive. + * + * Copyright (C) 2007 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> + +#include "bus.h" +#include "driver.h" +#include "utils.h" +#include "desktop-file.h" +#include "config-parser-trivial.h" +#include "activation-helper.h" +#include "activation-exit-codes.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <pwd.h> +#include <grp.h> + +#include <dbus/dbus-misc.h> +#include <dbus/dbus-shell.h> +#include <dbus/dbus-marshal-validate.h> + +static BusDesktopFile * +desktop_file_for_name (BusConfigParser *parser, + const char *name, + DBusError *error) +{ + BusDesktopFile *desktop_file; + DBusList **service_dirs; + DBusList *link; + DBusError tmp_error; + DBusString full_path; + DBusString filename; + const char *dir; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + desktop_file = NULL; + + if (!_dbus_string_init (&filename)) + { + BUS_SET_OOM (error); + goto out_all; + } + + if (!_dbus_string_init (&full_path)) + { + BUS_SET_OOM (error); + goto out_filename; + } + + if (!_dbus_string_append (&filename, name) || + !_dbus_string_append (&filename, ".service")) + { + BUS_SET_OOM (error); + goto out; + } + + service_dirs = bus_config_parser_get_service_dirs (parser); + for (link = _dbus_list_get_first_link (service_dirs); + link != NULL; + link = _dbus_list_get_next_link (service_dirs, link)) + { + dir = link->data; + _dbus_verbose ("Looking at '%s'\n", dir); + + dbus_error_init (&tmp_error); + + /* clear the path from last time */ + _dbus_string_set_length (&full_path, 0); + + /* build the full path */ + if (!_dbus_string_append (&full_path, dir) || + !_dbus_concat_dir_and_file (&full_path, &filename)) + { + BUS_SET_OOM (error); + goto out; + } + + _dbus_verbose ("Trying to load file '%s'\n", _dbus_string_get_data (&full_path)); + desktop_file = bus_desktop_file_load (&full_path, &tmp_error); + if (desktop_file == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (&tmp_error); + _dbus_verbose ("Could not load %s: %s: %s\n", + _dbus_string_get_const_data (&full_path), + tmp_error.name, tmp_error.message); + + /* we may have failed if the file is not found; this is not fatal */ + if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) + { + dbus_move_error (&tmp_error, error); + /* we only bail out on OOM */ + goto out; + } + dbus_error_free (&tmp_error); + } + + /* did we find the desktop file we want? */ + if (desktop_file != NULL) + break; + } + + /* Didn't find desktop file; set error */ + if (desktop_file == NULL) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND, + "The name %s was not provided by any .service files", + name); + } + +out: + _dbus_string_free (&full_path); +out_filename: + _dbus_string_free (&filename); +out_all: + return desktop_file; +} + +/* Clears the environment, except for DBUS_STARTER_x, + * which we hardcode to the system bus. + */ +static dbus_bool_t +clear_environment (DBusError *error) +{ +#ifndef ACTIVATION_LAUNCHER_TEST + /* totally clear the environment */ + if (!_dbus_clearenv ()) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED, + "could not clear environment\n"); + return FALSE; + } + + /* Ensure the bus is set to system */ + dbus_setenv ("DBUS_STARTER_ADDRESS", DBUS_SYSTEM_BUS_DEFAULT_ADDRESS); + dbus_setenv ("DBUS_STARTER_BUS_TYPE", "system"); +#endif + + return TRUE; +} + +static dbus_bool_t +check_permissions (const char *dbus_user, DBusError *error) +{ +#ifndef ACTIVATION_LAUNCHER_TEST + uid_t uid, euid; + struct passwd *pw; + + pw = NULL; + uid = 0; + euid = 0; + + /* bail out unless the dbus user is invoking the helper */ + pw = getpwnam(dbus_user); + if (!pw) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID, + "cannot find user '%s'", dbus_user); + return FALSE; + } + uid = getuid(); + if (pw->pw_uid != uid) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID, + "not invoked from user '%s'", dbus_user); + return FALSE; + } + + /* bail out unless we are setuid to user root */ + euid = geteuid(); + if (euid != 0) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID, + "not setuid root"); + return FALSE; + } +#endif + + return TRUE; +} + +static dbus_bool_t +check_service_name (BusDesktopFile *desktop_file, + const char *service_name, + DBusError *error) +{ + char *name_tmp; + dbus_bool_t retval; + + retval = FALSE; + + /* try to get Name */ + if (!bus_desktop_file_get_string (desktop_file, + DBUS_SERVICE_SECTION, + DBUS_SERVICE_NAME, + &name_tmp, + error)) + goto failed; + + /* verify that the name is the same as the file service name */ + if (strcmp (service_name, name_tmp) != 0) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_FILE_INVALID, + "Service '%s' does not match expected value", name_tmp); + goto failed_free; + } + + retval = TRUE; + +failed_free: + /* we don't return the name, so free it here */ + dbus_free (name_tmp); +failed: + return retval; +} + +static dbus_bool_t +get_parameters_for_service (BusDesktopFile *desktop_file, + const char *service_name, + char **exec, + char **user, + DBusError *error) +{ + char *exec_tmp; + char *user_tmp; + + exec_tmp = NULL; + user_tmp = NULL; + + /* check the name of the service */ + if (!check_service_name (desktop_file, service_name, error)) + goto failed; + + /* get the complete path of the executable */ + if (!bus_desktop_file_get_string (desktop_file, + DBUS_SERVICE_SECTION, + DBUS_SERVICE_EXEC, + &exec_tmp, + error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + /* get the user that should run this service - user is compulsary for system activation */ + if (!bus_desktop_file_get_string (desktop_file, + DBUS_SERVICE_SECTION, + DBUS_SERVICE_USER, + &user_tmp, + error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + /* only assign if all the checks passed */ + *exec = exec_tmp; + *user = user_tmp; + return TRUE; + +failed: + dbus_free (exec_tmp); + dbus_free (user_tmp); + return FALSE; +} + +static dbus_bool_t +switch_user (char *user, DBusError *error) +{ +#ifndef ACTIVATION_LAUNCHER_TEST + struct passwd *pw; + + /* find user */ + pw = getpwnam (user); + if (!pw) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED, + "cannot find user '%s'\n", user); + return FALSE; + } + + /* initialize the group access list */ + if (initgroups (user, pw->pw_gid)) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED, + "could not initialize groups"); + return FALSE; + } + + /* change to the primary group for the user */ + if (setgid (pw->pw_gid)) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED, + "cannot setgid group %i", pw->pw_gid); + return FALSE; + } + + /* change to the user specified */ + if (setuid (pw->pw_uid) < 0) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED, + "cannot setuid user %i", pw->pw_uid); + return FALSE; + } +#endif + return TRUE; +} + +static dbus_bool_t +exec_for_correct_user (char *exec, char *user, DBusError *error) +{ + char **argv; + int argc; + dbus_bool_t retval; + + argc = 0; + retval = TRUE; + argv = NULL; + + if (!switch_user (user, error)) + return FALSE; + + /* convert command into arguments */ + if (!_dbus_shell_parse_argv (exec, &argc, &argv, error)) + return FALSE; + +#ifndef ACTIVATION_LAUNCHER_DO_OOM + /* replace with new binary, with no environment */ + if (execv (argv[0], argv) < 0) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED, + "Failed to exec: %s", argv[0]); + retval = FALSE; + } +#endif + + dbus_free_string_array (argv); + return retval; +} + +static dbus_bool_t +check_bus_name (const char *bus_name, + DBusError *error) +{ + DBusString str; + + _dbus_string_init_const (&str, bus_name); + if (!_dbus_validate_bus_name (&str, 0, _dbus_string_get_length (&str))) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_INVALID, + "bus name '%s' is not a valid bus name\n", + bus_name); + return FALSE; + } + + return TRUE; +} + +static dbus_bool_t +get_correct_parser (BusConfigParser **parser, DBusError *error) +{ + DBusString config_file; + dbus_bool_t retval; +#ifdef ACTIVATION_LAUNCHER_TEST + const char *test_config_file; +#endif + + retval = FALSE; + +#ifdef ACTIVATION_LAUNCHER_TEST + test_config_file = NULL; + + /* there is no _way_ we should be setuid if this define is set. + * but we should be doubly paranoid and check... */ + if (getuid() != geteuid()) + _dbus_assert_not_reached ("dbus-daemon-launch-helper-test binary is setuid!"); + + /* this is not a security hole. The environment variable is only passed in the + * dbus-daemon-lauch-helper-test NON-SETUID launcher */ + test_config_file = _dbus_getenv ("TEST_LAUNCH_HELPER_CONFIG"); + if (test_config_file == NULL) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED, + "the TEST_LAUNCH_HELPER_CONFIG env variable is not set"); + goto out; + } +#endif + + /* we _only_ use the predefined system config file */ + if (!_dbus_string_init (&config_file)) + { + BUS_SET_OOM (error); + goto out; + } +#ifndef ACTIVATION_LAUNCHER_TEST + if (!_dbus_string_append (&config_file, DBUS_SYSTEM_CONFIG_FILE)) + { + BUS_SET_OOM (error); + goto out_free_config; + } +#else + if (!_dbus_string_append (&config_file, test_config_file)) + { + BUS_SET_OOM (error); + goto out_free_config; + } +#endif + + /* where are we pointing.... */ + _dbus_verbose ("dbus-daemon-activation-helper: using config file: %s\n", + _dbus_string_get_const_data (&config_file)); + + /* get the dbus user */ + *parser = bus_config_load (&config_file, TRUE, NULL, error); + if (*parser == NULL) + { + goto out_free_config; + } + + /* woot */ + retval = TRUE; + +out_free_config: + _dbus_string_free (&config_file); +out: + return retval; +} + +static dbus_bool_t +launch_bus_name (const char *bus_name, BusConfigParser *parser, DBusError *error) +{ + BusDesktopFile *desktop_file; + char *exec, *user; + dbus_bool_t retval; + + exec = NULL; + user = NULL; + retval = FALSE; + + /* get the correct service file for the name we are trying to activate */ + desktop_file = desktop_file_for_name (parser, bus_name, error); + if (desktop_file == NULL) + return FALSE; + + /* get exec and user for service name */ + if (!get_parameters_for_service (desktop_file, bus_name, &exec, &user, error)) + goto finish; + + _dbus_verbose ("dbus-daemon-activation-helper: Name='%s'\n", bus_name); + _dbus_verbose ("dbus-daemon-activation-helper: Exec='%s'\n", exec); + _dbus_verbose ("dbus-daemon-activation-helper: User='%s'\n", user); + + /* actually execute */ + if (!exec_for_correct_user (exec, user, error)) + goto finish; + + retval = TRUE; + +finish: + dbus_free (exec); + dbus_free (user); + bus_desktop_file_free (desktop_file); + return retval; +} + +static dbus_bool_t +check_dbus_user (BusConfigParser *parser, DBusError *error) +{ + const char *dbus_user; + + dbus_user = bus_config_parser_get_user (parser); + if (dbus_user == NULL) + { + dbus_set_error (error, DBUS_ERROR_SPAWN_CONFIG_INVALID, + "could not get user from config file\n"); + return FALSE; + } + + /* check to see if permissions are correct */ + if (!check_permissions (dbus_user, error)) + return FALSE; + + return TRUE; +} + +dbus_bool_t +run_launch_helper (const char *bus_name, + DBusError *error) +{ + BusConfigParser *parser; + dbus_bool_t retval; + + parser = NULL; + retval = FALSE; + + /* clear the environment, apart from a few select settings */ + if (!clear_environment (error)) + goto error; + + /* check to see if we have a valid bus name */ + if (!check_bus_name (bus_name, error)) + goto error; + + /* get the correct parser, either the test or default parser */ + if (!get_correct_parser (&parser, error)) + goto error; + + /* check we are being invoked by the correct dbus user */ + if (!check_dbus_user (parser, error)) + goto error_free_parser; + + /* launch the bus with the service defined user */ + if (!launch_bus_name (bus_name, parser, error)) + goto error_free_parser; + + /* woohoo! */ + retval = TRUE; + +error_free_parser: + bus_config_parser_unref (parser); +error: + return retval; +} +
diff --git a/bus/activation-helper.h b/bus/activation-helper.h new file mode 100644 index 0000000..361a4c6 --- /dev/null +++ b/bus/activation-helper.h
@@ -0,0 +1,31 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* activation-helper.h The actual activation helper split from the main + * function for testing. + * + * Copyright (C) 2007 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_ACTIVATION_HELPER_H +#define BUS_ACTIVATION_HELPER_H + +dbus_bool_t run_launch_helper (const char *bus_name, DBusError *error); + + +#endif /* BUS_ACTIVATION_HELPER_H */
diff --git a/bus/activation.c b/bus/activation.c new file mode 100644 index 0000000..1211329 --- /dev/null +++ b/bus/activation.c
@@ -0,0 +1,2661 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* activation.c Activation of services + * + * Copyright (C) 2003 CodeFactory AB + * Copyright (C) 2003 Red Hat, Inc. + * Copyright (C) 2004 Imendio HB + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "activation.h" +#include "activation-exit-codes.h" +#include "desktop-file.h" +#include "dispatch.h" +#include "services.h" +#include "test.h" +#include "utils.h" +#include <dbus/dbus-internals.h> +#include <dbus/dbus-hash.h> +#include <dbus/dbus-list.h> +#include <dbus/dbus-shell.h> +#include <dbus/dbus-spawn.h> +#include <dbus/dbus-timeout.h> +#include <dbus/dbus-sysdeps.h> +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif + +struct BusActivation +{ + int refcount; + DBusHashTable *entries; + DBusHashTable *pending_activations; + char *server_address; + BusContext *context; + int n_pending_activations; /**< This is in fact the number of BusPendingActivationEntry, + * i.e. number of pending activation requests, not pending + * activations per se + */ + DBusHashTable *directories; + DBusHashTable *environment; +}; + +typedef struct +{ + int refcount; + char *dir_c; + DBusHashTable *entries; +} BusServiceDirectory; + +typedef struct +{ + int refcount; + char *name; + char *exec; + char *user; + char *systemd_service; + unsigned long mtime; + BusServiceDirectory *s_dir; + char *filename; +} BusActivationEntry; + +typedef struct BusPendingActivationEntry BusPendingActivationEntry; + +struct BusPendingActivationEntry +{ + /* Normally a method call, but if connection is NULL, this is a signal + * instead. + */ + DBusMessage *activation_message; + /* NULL if this activation entry is for the dbus-daemon itself, + * waiting for systemd to start. In this case, auto_activation is always + * TRUE. + */ + DBusConnection *connection; + + dbus_bool_t auto_activation; +}; + +typedef struct +{ + int refcount; + BusActivation *activation; + char *service_name; + char *exec; + char *systemd_service; + DBusList *entries; + int n_entries; + DBusBabysitter *babysitter; + DBusTimeout *timeout; + unsigned int timeout_added : 1; +} BusPendingActivation; + +#if 0 +static BusServiceDirectory * +bus_service_directory_ref (BusServiceDirectory *dir) +{ + _dbus_assert (dir->refcount); + + dir->refcount++; + + return dir; +} +#endif + +static void +bus_service_directory_unref (BusServiceDirectory *dir) +{ + if (dir == NULL) + return; + + _dbus_assert (dir->refcount > 0); + dir->refcount--; + + if (dir->refcount > 0) + return; + + if (dir->entries) + _dbus_hash_table_unref (dir->entries); + + dbus_free (dir->dir_c); + dbus_free (dir); +} + +static void +bus_pending_activation_entry_free (BusPendingActivationEntry *entry) +{ + if (entry->activation_message) + dbus_message_unref (entry->activation_message); + + if (entry->connection) + dbus_connection_unref (entry->connection); + + dbus_free (entry); +} + +static BusPendingActivation * +bus_pending_activation_ref (BusPendingActivation *pending_activation) +{ + _dbus_assert (pending_activation->refcount > 0); + pending_activation->refcount += 1; + + return pending_activation; +} + +static void +bus_pending_activation_unref (BusPendingActivation *pending_activation) +{ + DBusList *link; + + if (pending_activation == NULL) /* hash table requires this */ + return; + + _dbus_assert (pending_activation->refcount > 0); + pending_activation->refcount -= 1; + + if (pending_activation->refcount > 0) + return; + + if (pending_activation->timeout_added) + { + _dbus_loop_remove_timeout (bus_context_get_loop (pending_activation->activation->context), + pending_activation->timeout); + pending_activation->timeout_added = FALSE; + } + + if (pending_activation->timeout) + _dbus_timeout_unref (pending_activation->timeout); + + if (pending_activation->babysitter) + { + if (!_dbus_babysitter_set_watch_functions (pending_activation->babysitter, + NULL, NULL, NULL, + pending_activation->babysitter, + NULL)) + _dbus_assert_not_reached ("setting watch functions to NULL failed"); + + _dbus_babysitter_unref (pending_activation->babysitter); + } + + dbus_free (pending_activation->service_name); + dbus_free (pending_activation->exec); + dbus_free (pending_activation->systemd_service); + + link = _dbus_list_get_first_link (&pending_activation->entries); + + while (link != NULL) + { + BusPendingActivationEntry *entry = link->data; + + bus_pending_activation_entry_free (entry); + + link = _dbus_list_get_next_link (&pending_activation->entries, link); + } + _dbus_list_clear (&pending_activation->entries); + + pending_activation->activation->n_pending_activations -= + pending_activation->n_entries; + + _dbus_assert (pending_activation->activation->n_pending_activations >= 0); + + dbus_free (pending_activation); +} + +static BusActivationEntry * +bus_activation_entry_ref (BusActivationEntry *entry) +{ + _dbus_assert (entry->refcount > 0); + entry->refcount++; + + return entry; +} + +static void +bus_activation_entry_unref (BusActivationEntry *entry) +{ + if (entry == NULL) /* hash table requires this */ + return; + + _dbus_assert (entry->refcount > 0); + entry->refcount--; + + if (entry->refcount > 0) + return; + + dbus_free (entry->name); + dbus_free (entry->exec); + dbus_free (entry->user); + dbus_free (entry->filename); + dbus_free (entry->systemd_service); + + dbus_free (entry); +} + +static dbus_bool_t +update_desktop_file_entry (BusActivation *activation, + BusServiceDirectory *s_dir, + DBusString *filename, + BusDesktopFile *desktop_file, + DBusError *error) +{ + char *name, *exec, *user, *exec_tmp, *systemd_service; + BusActivationEntry *entry; + DBusStat stat_buf; + DBusString file_path; + DBusError tmp_error; + dbus_bool_t retval; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + retval = FALSE; + name = NULL; + exec = NULL; + user = NULL; + exec_tmp = NULL; + entry = NULL; + systemd_service = NULL; + + dbus_error_init (&tmp_error); + + if (!_dbus_string_init (&file_path)) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!_dbus_string_append (&file_path, s_dir->dir_c) || + !_dbus_concat_dir_and_file (&file_path, filename)) + { + BUS_SET_OOM (error); + goto out; + } + + if (!_dbus_stat (&file_path, &stat_buf, NULL)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Can't stat the service file\n"); + goto out; + } + + if (!bus_desktop_file_get_string (desktop_file, + DBUS_SERVICE_SECTION, + DBUS_SERVICE_NAME, + &name, + error)) + goto out; + + if (!bus_desktop_file_get_string (desktop_file, + DBUS_SERVICE_SECTION, + DBUS_SERVICE_EXEC, + &exec_tmp, + error)) + goto out; + + exec = _dbus_strdup (_dbus_replace_install_prefix (exec_tmp)); + dbus_free (exec_tmp); + exec_tmp = NULL; + + /* user is not _required_ unless we are using system activation */ + if (!bus_desktop_file_get_string (desktop_file, + DBUS_SERVICE_SECTION, + DBUS_SERVICE_USER, + &user, &tmp_error)) + { + _DBUS_ASSERT_ERROR_IS_SET (&tmp_error); + /* if we got OOM, then exit */ + if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) + { + dbus_move_error (&tmp_error, error); + goto out; + } + else + { + /* if we have error because we didn't find anything then continue */ + dbus_error_free (&tmp_error); + dbus_free (user); + user = NULL; + } + } + _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error); + + /* systemd service is never required */ + if (!bus_desktop_file_get_string (desktop_file, + DBUS_SERVICE_SECTION, + DBUS_SERVICE_SYSTEMD_SERVICE, + &systemd_service, &tmp_error)) + { + _DBUS_ASSERT_ERROR_IS_SET (&tmp_error); + /* if we got OOM, then exit */ + if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) + { + dbus_move_error (&tmp_error, error); + goto out; + } + else + { + /* if we have error because we didn't find anything then continue */ + dbus_error_free (&tmp_error); + dbus_free (systemd_service); + systemd_service = NULL; + } + } + + _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error); + + entry = _dbus_hash_table_lookup_string (s_dir->entries, + _dbus_string_get_const_data (filename)); + + if (entry == NULL) /* New file */ + { + /* FIXME we need a better-defined algorithm for which service file to + * pick than "whichever one is first in the directory listing" + */ + if (_dbus_hash_table_lookup_string (activation->entries, name)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Service %s already exists in activation entry list\n", name); + goto out; + } + + entry = dbus_new0 (BusActivationEntry, 1); + if (entry == NULL) + { + BUS_SET_OOM (error); + goto out; + } + + entry->name = name; + entry->exec = exec; + entry->user = user; + entry->systemd_service = systemd_service; + entry->refcount = 1; + + /* ownership has been transferred to entry, do not free separately */ + name = NULL; + exec = NULL; + user = NULL; + systemd_service = NULL; + + entry->s_dir = s_dir; + entry->filename = _dbus_strdup (_dbus_string_get_const_data (filename)); + if (!entry->filename) + { + BUS_SET_OOM (error); + goto out; + } + + if (!_dbus_hash_table_insert_string (activation->entries, entry->name, bus_activation_entry_ref (entry))) + { + BUS_SET_OOM (error); + goto out; + } + + if (!_dbus_hash_table_insert_string (s_dir->entries, entry->filename, bus_activation_entry_ref (entry))) + { + /* Revert the insertion in the entries table */ + _dbus_hash_table_remove_string (activation->entries, entry->name); + BUS_SET_OOM (error); + goto out; + } + + _dbus_verbose ("Added \"%s\" to list of services\n", entry->name); + } + else /* Just update the entry */ + { + bus_activation_entry_ref (entry); + _dbus_hash_table_remove_string (activation->entries, entry->name); + + if (_dbus_hash_table_lookup_string (activation->entries, name)) + { + _dbus_verbose ("The new service name \"%s\" of service file \"%s\" is already in cache, ignoring\n", + name, _dbus_string_get_const_data (&file_path)); + dbus_set_error (error, DBUS_ERROR_FAILED, + "The new service name \"%s\" of service file \"%s\" is already in cache, ignoring\n", + name, _dbus_string_get_const_data (&file_path)); + goto out; + } + + /* ownership has been transferred to entry, do not free separately */ + dbus_free (entry->name); + entry->name = name; + name = NULL; + + dbus_free (entry->exec); + entry->exec = exec; + exec = NULL; + + dbus_free (entry->user); + entry->user = user; + user = NULL; + + dbus_free (entry->systemd_service); + entry->systemd_service = systemd_service; + systemd_service = NULL; + + if (!_dbus_hash_table_insert_string (activation->entries, + entry->name, bus_activation_entry_ref(entry))) + { + BUS_SET_OOM (error); + /* Also remove path to entries hash since we want this in sync with + * the entries hash table */ + _dbus_hash_table_remove_string (entry->s_dir->entries, + entry->filename); + goto out; + } + } + + entry->mtime = stat_buf.mtime; + retval = TRUE; + +out: + /* if these have been transferred into entry, the variables will be NULL */ + dbus_free (name); + dbus_free (exec); + dbus_free (user); + dbus_free (systemd_service); + _dbus_string_free (&file_path); + + if (entry) + bus_activation_entry_unref (entry); + + return retval; +} + +static dbus_bool_t +check_service_file (BusActivation *activation, + BusActivationEntry *entry, + BusActivationEntry **updated_entry, + DBusError *error) +{ + DBusStat stat_buf; + dbus_bool_t retval; + BusActivationEntry *tmp_entry; + DBusString file_path; + DBusString filename; + + retval = TRUE; + tmp_entry = entry; + + _dbus_string_init_const (&filename, entry->filename); + + if (!_dbus_string_init (&file_path)) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!_dbus_string_append (&file_path, entry->s_dir->dir_c) || + !_dbus_concat_dir_and_file (&file_path, &filename)) + { + BUS_SET_OOM (error); + retval = FALSE; + goto out; + } + + if (!_dbus_stat (&file_path, &stat_buf, NULL)) + { + _dbus_verbose ("****** Can't stat file \"%s\", removing from cache\n", + _dbus_string_get_const_data (&file_path)); + + _dbus_hash_table_remove_string (activation->entries, entry->name); + _dbus_hash_table_remove_string (entry->s_dir->entries, entry->filename); + + tmp_entry = NULL; + retval = TRUE; + goto out; + } + else + { + if (stat_buf.mtime > entry->mtime) + { + BusDesktopFile *desktop_file; + DBusError tmp_error; + + dbus_error_init (&tmp_error); + + desktop_file = bus_desktop_file_load (&file_path, &tmp_error); + if (desktop_file == NULL) + { + _dbus_verbose ("Could not load %s: %s\n", + _dbus_string_get_const_data (&file_path), + tmp_error.message); + if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) + { + dbus_move_error (&tmp_error, error); + retval = FALSE; + goto out; + } + dbus_error_free (&tmp_error); + retval = TRUE; + goto out; + } + + /* @todo We can return OOM or a DBUS_ERROR_FAILED error + * Handle these both better + */ + if (!update_desktop_file_entry (activation, entry->s_dir, &filename, desktop_file, &tmp_error)) + { + bus_desktop_file_free (desktop_file); + if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) + { + dbus_move_error (&tmp_error, error); + retval = FALSE; + goto out; + } + dbus_error_free (&tmp_error); + retval = TRUE; + goto out; + } + + bus_desktop_file_free (desktop_file); + retval = TRUE; + } + } + +out: + _dbus_string_free (&file_path); + + if (updated_entry != NULL) + *updated_entry = tmp_entry; + return retval; +} + + +/* warning: this doesn't fully "undo" itself on failure, i.e. doesn't strip + * hash entries it already added. + */ +static dbus_bool_t +update_directory (BusActivation *activation, + BusServiceDirectory *s_dir, + DBusError *error) +{ + DBusDirIter *iter; + DBusString dir, filename; + BusDesktopFile *desktop_file; + DBusError tmp_error; + dbus_bool_t retval; + BusActivationEntry *entry; + DBusString full_path; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + iter = NULL; + desktop_file = NULL; + + _dbus_string_init_const (&dir, s_dir->dir_c); + + if (!_dbus_string_init (&filename)) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!_dbus_string_init (&full_path)) + { + BUS_SET_OOM (error); + _dbus_string_free (&filename); + return FALSE; + } + + retval = FALSE; + + /* from this point it's safe to "goto out" */ + + iter = _dbus_directory_open (&dir, error); + if (iter == NULL) + { + _dbus_verbose ("Failed to open directory %s: %s\n", + s_dir->dir_c, + error ? error->message : "unknown"); + goto out; + } + + /* Now read the files */ + dbus_error_init (&tmp_error); + while (_dbus_directory_get_next_file (iter, &filename, &tmp_error)) + { + _dbus_assert (!dbus_error_is_set (&tmp_error)); + + _dbus_string_set_length (&full_path, 0); + + if (!_dbus_string_ends_with_c_str (&filename, ".service")) + { + _dbus_verbose ("Skipping non-.service file '%s'\n", + _dbus_string_get_const_data (&filename)); + continue; + } + + entry = _dbus_hash_table_lookup_string (s_dir->entries, _dbus_string_get_const_data (&filename)); + if (entry) /* Already has this service file in the cache */ + { + if (!check_service_file (activation, entry, NULL, error)) + goto out; + + continue; + } + + if (!_dbus_string_append (&full_path, s_dir->dir_c) || + !_dbus_concat_dir_and_file (&full_path, &filename)) + { + BUS_SET_OOM (error); + goto out; + } + + /* New file */ + desktop_file = bus_desktop_file_load (&full_path, &tmp_error); + if (desktop_file == NULL) + { + _dbus_verbose ("Could not load %s: %s\n", + _dbus_string_get_const_data (&full_path), + tmp_error.message); + + if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) + { + dbus_move_error (&tmp_error, error); + goto out; + } + + dbus_error_free (&tmp_error); + continue; + } + + /* @todo We can return OOM or a DBUS_ERROR_FAILED error + * Handle these both better + */ + if (!update_desktop_file_entry (activation, s_dir, &filename, desktop_file, &tmp_error)) + { + bus_desktop_file_free (desktop_file); + desktop_file = NULL; + + _dbus_verbose ("Could not add %s to activation entry list: %s\n", + _dbus_string_get_const_data (&full_path), tmp_error.message); + + if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) + { + dbus_move_error (&tmp_error, error); + goto out; + } + + dbus_error_free (&tmp_error); + continue; + } + else + { + bus_desktop_file_free (desktop_file); + desktop_file = NULL; + continue; + } + } + + if (dbus_error_is_set (&tmp_error)) + { + dbus_move_error (&tmp_error, error); + goto out; + } + + retval = TRUE; + + out: + if (!retval) + _DBUS_ASSERT_ERROR_IS_SET (error); + else + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (iter != NULL) + _dbus_directory_close (iter); + _dbus_string_free (&filename); + _dbus_string_free (&full_path); + + return retval; +} + +static dbus_bool_t +populate_environment (BusActivation *activation) +{ + DBusString key; + DBusString value; + int i; + char **environment; + dbus_bool_t retval = FALSE; + + environment = _dbus_get_environment (); + + if (environment == NULL) + return FALSE; + + if (!_dbus_string_init (&key)) + { + dbus_free_string_array (environment); + return FALSE; + } + + if (!_dbus_string_init (&value)) + { + _dbus_string_free (&key); + dbus_free_string_array (environment); + return FALSE; + } + + for (i = 0; environment[i] != NULL; i++) + { + if (!_dbus_string_append (&key, environment[i])) + break; + + if (_dbus_string_split_on_byte (&key, '=', &value)) + { + char *hash_key, *hash_value; + + if (!_dbus_string_steal_data (&key, &hash_key)) + break; + + if (!_dbus_string_steal_data (&value, &hash_value)) + break; + + if (!_dbus_hash_table_insert_string (activation->environment, + hash_key, hash_value)) + break; + } + _dbus_string_set_length (&key, 0); + _dbus_string_set_length (&value, 0); + } + + if (environment[i] != NULL) + goto out; + + retval = TRUE; +out: + + _dbus_string_free (&key); + _dbus_string_free (&value); + dbus_free_string_array (environment); + + return retval; +} + +dbus_bool_t +bus_activation_reload (BusActivation *activation, + const DBusString *address, + DBusList **directories, + DBusError *error) +{ + DBusList *link; + char *dir; + + if (activation->server_address != NULL) + dbus_free (activation->server_address); + if (!_dbus_string_copy_data (address, &activation->server_address)) + { + BUS_SET_OOM (error); + goto failed; + } + + if (activation->entries != NULL) + _dbus_hash_table_unref (activation->entries); + activation->entries = _dbus_hash_table_new (DBUS_HASH_STRING, NULL, + (DBusFreeFunction)bus_activation_entry_unref); + if (activation->entries == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + + if (activation->directories != NULL) + _dbus_hash_table_unref (activation->directories); + activation->directories = _dbus_hash_table_new (DBUS_HASH_STRING, NULL, + (DBusFreeFunction)bus_service_directory_unref); + + if (activation->directories == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + + link = _dbus_list_get_first_link (directories); + while (link != NULL) + { + BusServiceDirectory *s_dir; + + dir = _dbus_strdup ((const char *) link->data); + if (!dir) + { + BUS_SET_OOM (error); + goto failed; + } + + s_dir = dbus_new0 (BusServiceDirectory, 1); + if (!s_dir) + { + dbus_free (dir); + BUS_SET_OOM (error); + goto failed; + } + + s_dir->refcount = 1; + s_dir->dir_c = dir; + + s_dir->entries = _dbus_hash_table_new (DBUS_HASH_STRING, NULL, + (DBusFreeFunction)bus_activation_entry_unref); + + if (!s_dir->entries) + { + bus_service_directory_unref (s_dir); + BUS_SET_OOM (error); + goto failed; + } + + if (!_dbus_hash_table_insert_string (activation->directories, s_dir->dir_c, s_dir)) + { + bus_service_directory_unref (s_dir); + BUS_SET_OOM (error); + goto failed; + } + + /* only fail on OOM, it is ok if we can't read the directory */ + if (!update_directory (activation, s_dir, error)) + { + if (dbus_error_has_name (error, DBUS_ERROR_NO_MEMORY)) + goto failed; + else + dbus_error_free (error); + } + + link = _dbus_list_get_next_link (directories, link); + } + + return TRUE; + failed: + return FALSE; +} + +BusActivation* +bus_activation_new (BusContext *context, + const DBusString *address, + DBusList **directories, + DBusError *error) +{ + BusActivation *activation; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + activation = dbus_new0 (BusActivation, 1); + if (activation == NULL) + { + BUS_SET_OOM (error); + return NULL; + } + + activation->refcount = 1; + activation->context = context; + activation->n_pending_activations = 0; + + if (!bus_activation_reload (activation, address, directories, error)) + goto failed; + + /* Initialize this hash table once, we don't want to lose pending + * activations on reload. */ + activation->pending_activations = _dbus_hash_table_new (DBUS_HASH_STRING, NULL, + (DBusFreeFunction)bus_pending_activation_unref); + + if (activation->pending_activations == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + + activation->environment = _dbus_hash_table_new (DBUS_HASH_STRING, + (DBusFreeFunction) dbus_free, + (DBusFreeFunction) dbus_free); + + if (activation->environment == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + + if (!populate_environment (activation)) + { + BUS_SET_OOM (error); + goto failed; + } + + return activation; + + failed: + bus_activation_unref (activation); + return NULL; +} + +BusActivation * +bus_activation_ref (BusActivation *activation) +{ + _dbus_assert (activation->refcount > 0); + + activation->refcount += 1; + + return activation; +} + +void +bus_activation_unref (BusActivation *activation) +{ + _dbus_assert (activation->refcount > 0); + + activation->refcount -= 1; + + if (activation->refcount > 0) + return; + + dbus_free (activation->server_address); + if (activation->entries) + _dbus_hash_table_unref (activation->entries); + if (activation->pending_activations) + _dbus_hash_table_unref (activation->pending_activations); + if (activation->directories) + _dbus_hash_table_unref (activation->directories); + if (activation->environment) + _dbus_hash_table_unref (activation->environment); + + dbus_free (activation); +} + +static dbus_bool_t +add_bus_environment (BusActivation *activation, + DBusError *error) +{ + const char *type; + + if (!bus_activation_set_environment_variable (activation, + "DBUS_STARTER_ADDRESS", + activation->server_address, + error)) + return FALSE; + + type = bus_context_get_type (activation->context); + if (type != NULL) + { + if (!bus_activation_set_environment_variable (activation, + "DBUS_STARTER_BUS_TYPE", type, + error)) + return FALSE; + + if (strcmp (type, "session") == 0) + { + if (!bus_activation_set_environment_variable (activation, + "DBUS_SESSION_BUS_ADDRESS", + activation->server_address, + error)) + return FALSE; + } + else if (strcmp (type, "system") == 0) + { + if (!bus_activation_set_environment_variable (activation, + "DBUS_SYSTEM_BUS_ADDRESS", + activation->server_address, + error)) + return FALSE; + } + } + + return TRUE; +} + +typedef struct +{ + BusPendingActivation *pending_activation; + DBusPreallocatedHash *hash_entry; +} RestorePendingData; + +static void +restore_pending (void *data) +{ + RestorePendingData *d = data; + + _dbus_assert (d->pending_activation != NULL); + _dbus_assert (d->hash_entry != NULL); + + _dbus_verbose ("Restoring pending activation for service %s, has timeout = %d\n", + d->pending_activation->service_name, + d->pending_activation->timeout_added); + + _dbus_hash_table_insert_string_preallocated (d->pending_activation->activation->pending_activations, + d->hash_entry, + d->pending_activation->service_name, d->pending_activation); + + bus_pending_activation_ref (d->pending_activation); + + d->hash_entry = NULL; +} + +static void +free_restore_pending_data (void *data) +{ + RestorePendingData *d = data; + + if (d->hash_entry) + _dbus_hash_table_free_preallocated_entry (d->pending_activation->activation->pending_activations, + d->hash_entry); + + bus_pending_activation_unref (d->pending_activation); + + dbus_free (d); +} + +static dbus_bool_t +add_restore_pending_to_transaction (BusTransaction *transaction, + BusPendingActivation *pending_activation) +{ + RestorePendingData *d; + + d = dbus_new (RestorePendingData, 1); + if (d == NULL) + return FALSE; + + d->pending_activation = pending_activation; + d->hash_entry = _dbus_hash_table_preallocate_entry (d->pending_activation->activation->pending_activations); + + bus_pending_activation_ref (d->pending_activation); + + if (d->hash_entry == NULL || + !bus_transaction_add_cancel_hook (transaction, restore_pending, d, + free_restore_pending_data)) + { + free_restore_pending_data (d); + return FALSE; + } + + _dbus_verbose ("Saved pending activation to be restored if the transaction fails\n"); + + return TRUE; +} + +dbus_bool_t +bus_activation_service_created (BusActivation *activation, + const char *service_name, + BusTransaction *transaction, + DBusError *error) +{ + BusPendingActivation *pending_activation; + DBusMessage *message; + DBusList *link; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + /* Check if it's a pending activation */ + pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations, service_name); + + if (!pending_activation) + return TRUE; + + bus_context_log (activation->context, + DBUS_SYSTEM_LOG_INFO, "Successfully activated service '%s'", + service_name); + + link = _dbus_list_get_first_link (&pending_activation->entries); + while (link != NULL) + { + BusPendingActivationEntry *entry = link->data; + DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link); + + /* entry->connection is NULL for activating systemd */ + if (entry->connection && dbus_connection_get_is_connected (entry->connection)) + { + /* Only send activation replies to regular activation requests. */ + if (!entry->auto_activation) + { + dbus_uint32_t result; + + message = dbus_message_new_method_return (entry->activation_message); + if (!message) + { + BUS_SET_OOM (error); + goto error; + } + + result = DBUS_START_REPLY_SUCCESS; + + if (!dbus_message_append_args (message, + DBUS_TYPE_UINT32, &result, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + BUS_SET_OOM (error); + goto error; + } + + if (!bus_transaction_send_from_driver (transaction, entry->connection, message)) + { + dbus_message_unref (message); + BUS_SET_OOM (error); + goto error; + } + + dbus_message_unref (message); + } + } + + link = next; + } + + return TRUE; + + error: + return FALSE; +} + +dbus_bool_t +bus_activation_send_pending_auto_activation_messages (BusActivation *activation, + BusService *service, + BusTransaction *transaction) +{ + BusPendingActivation *pending_activation; + DBusList *link; + + /* Check if it's a pending activation */ + pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations, + bus_service_get_name (service)); + + if (!pending_activation) + return TRUE; + + link = _dbus_list_get_first_link (&pending_activation->entries); + while (link != NULL) + { + BusPendingActivationEntry *entry = link->data; + DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link); + + if (entry->auto_activation && (entry->connection == NULL || dbus_connection_get_is_connected (entry->connection))) + { + DBusConnection *addressed_recipient; + DBusError error; + + dbus_error_init (&error); + + addressed_recipient = bus_service_get_primary_owners_connection (service); + + /* Resume dispatching where we left off in bus_dispatch() */ + if (!bus_dispatch_matches (transaction, + entry->connection, + addressed_recipient, + entry->activation_message, &error)) + { + /* If permission is denied, we just want to return the error + * to the original method invoker; in particular, we don't + * want to make the RequestName call fail with that error + * (see fd.o #78979, CVE-2014-3477). */ + if (!bus_transaction_send_error_reply (transaction, entry->connection, + &error, entry->activation_message)) + { + bus_connection_send_oom_error (entry->connection, + entry->activation_message); + } + + link = next; + continue; + } + } + + link = next; + } + + if (!add_restore_pending_to_transaction (transaction, pending_activation)) + { + _dbus_verbose ("Could not add cancel hook to transaction to revert removing pending activation\n"); + goto error; + } + + _dbus_hash_table_remove_string (activation->pending_activations, bus_service_get_name (service)); + + return TRUE; + + error: + return FALSE; +} + +/** + * FIXME @todo the error messages here would ideally be preallocated + * so we don't need to allocate memory to send them. + * Using the usual tactic, prealloc an OOM message, then + * if we can't alloc the real error send the OOM error instead. + */ +static dbus_bool_t +try_send_activation_failure (BusPendingActivation *pending_activation, + const DBusError *how) +{ + BusActivation *activation; + DBusList *link; + BusTransaction *transaction; + + activation = pending_activation->activation; + + transaction = bus_transaction_new (activation->context); + if (transaction == NULL) + return FALSE; + + link = _dbus_list_get_first_link (&pending_activation->entries); + while (link != NULL) + { + BusPendingActivationEntry *entry = link->data; + DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link); + + if (entry->connection && dbus_connection_get_is_connected (entry->connection)) + { + if (!bus_transaction_send_error_reply (transaction, + entry->connection, + how, + entry->activation_message)) + goto error; + } + + link = next; + } + + bus_transaction_execute_and_free (transaction); + + return TRUE; + + error: + if (transaction) + bus_transaction_cancel_and_free (transaction); + return FALSE; +} + +/** + * Free the pending activation and send an error message to all the + * connections that were waiting for it. + */ +static void +pending_activation_failed (BusPendingActivation *pending_activation, + const DBusError *how) +{ + /* FIXME use preallocated OOM messages instead of bus_wait_for_memory() */ + while (!try_send_activation_failure (pending_activation, how)) + _dbus_wait_for_memory (); + + /* Destroy this pending activation */ + _dbus_hash_table_remove_string (pending_activation->activation->pending_activations, + pending_activation->service_name); +} + +/** + * Depending on the exit code of the helper, set the error accordingly + */ +static void +handle_servicehelper_exit_error (int exit_code, + DBusError *error) +{ + switch (exit_code) + { + case BUS_SPAWN_EXIT_CODE_CONFIG_INVALID: + dbus_set_error (error, DBUS_ERROR_SPAWN_CONFIG_INVALID, + "Invalid configuration (missing or empty <user>?)"); + break; + case BUS_SPAWN_EXIT_CODE_NO_MEMORY: + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, + "Launcher could not run (out of memory)"); + break; + case BUS_SPAWN_EXIT_CODE_SETUP_FAILED: + dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED, + "Failed to setup environment correctly"); + break; + case BUS_SPAWN_EXIT_CODE_NAME_INVALID: + dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_INVALID, + "Bus name is not valid or missing"); + break; + case BUS_SPAWN_EXIT_CODE_SERVICE_NOT_FOUND: + dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND, + "Bus name not found in system service directory"); + break; + case BUS_SPAWN_EXIT_CODE_PERMISSIONS_INVALID: + dbus_set_error (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID, + "The permission of the setuid helper is not correct"); + break; + case BUS_SPAWN_EXIT_CODE_FILE_INVALID: + dbus_set_error (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID, + "The service file is incorrect or does not have all required attributes"); + break; + case BUS_SPAWN_EXIT_CODE_EXEC_FAILED: + dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED, + "Cannot launch daemon, file not found or permissions invalid"); + break; + case BUS_SPAWN_EXIT_CODE_INVALID_ARGS: + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "Invalid arguments to command line"); + break; + case BUS_SPAWN_EXIT_CODE_CHILD_SIGNALED: + dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_SIGNALED, + "Launched child was signaled, it probably crashed"); + break; + case BUS_SPAWN_EXIT_CODE_GENERIC_FAILURE: + default: + dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_EXITED, + "Launch helper exited with unknown return code %i", exit_code); + break; + } +} + +static void +pending_activation_finished_cb (DBusBabysitter *babysitter, + void *data) +{ + BusPendingActivation *pending_activation = data; + dbus_bool_t uses_servicehelper; + + _dbus_assert (babysitter == pending_activation->babysitter); + _dbus_babysitter_ref (babysitter); + + /* There are two major cases here; are we the system bus or the session? Here this + * is distinguished by whether or not we use a setuid helper launcher. With the launch helper, + * some process exit codes are meaningful, processed by handle_servicehelper_exit_error. + * + * In both cases though, just ignore when a process exits with status 0; it's possible for + * a program to (misguidedly) "daemonize", and that appears to us as an exit. This closes a race + * condition between this code and the child process claiming the bus name. + */ + uses_servicehelper = bus_context_get_servicehelper (pending_activation->activation->context) != NULL; + + /* strictly speaking this is redundant with the check in dbus-spawn now */ + if (_dbus_babysitter_get_child_exited (babysitter)) + { + DBusError error; + DBusHashIter iter; + dbus_bool_t activation_failed; + int exit_code = 0; + + dbus_error_init (&error); + + _dbus_babysitter_set_child_exit_error (babysitter, &error); + + /* Explicitly check for SPAWN_CHILD_EXITED to avoid overwriting an + * exec error */ + if (dbus_error_has_name (&error, DBUS_ERROR_SPAWN_CHILD_EXITED) + && _dbus_babysitter_get_child_exit_status (babysitter, &exit_code)) + { + activation_failed = exit_code != 0; + + dbus_error_free(&error); + + if (activation_failed) + { + if (uses_servicehelper) + handle_servicehelper_exit_error (exit_code, &error); + else + _dbus_babysitter_set_child_exit_error (babysitter, &error); + } + } + else + { + activation_failed = TRUE; + } + + if (activation_failed) + { + bus_context_log (pending_activation->activation->context, + DBUS_SYSTEM_LOG_INFO, "Activated service '%s' failed: %s", + pending_activation->service_name, + error.message); + + /* Destroy all pending activations with the same exec */ + _dbus_hash_iter_init (pending_activation->activation->pending_activations, + &iter); + while (_dbus_hash_iter_next (&iter)) + { + BusPendingActivation *p = _dbus_hash_iter_get_value (&iter); + + if (p != pending_activation && p->exec != NULL && + strcmp (p->exec, pending_activation->exec) == 0) + pending_activation_failed (p, &error); + } + + /* Destroys the pending activation */ + pending_activation_failed (pending_activation, &error); + + dbus_error_free (&error); + } + } + + _dbus_babysitter_unref (babysitter); +} + +static dbus_bool_t +add_babysitter_watch (DBusWatch *watch, + void *data) +{ + BusPendingActivation *pending_activation = data; + + return _dbus_loop_add_watch ( + bus_context_get_loop (pending_activation->activation->context), + watch); +} + +static void +remove_babysitter_watch (DBusWatch *watch, + void *data) +{ + BusPendingActivation *pending_activation = data; + + _dbus_loop_remove_watch (bus_context_get_loop (pending_activation->activation->context), + watch); +} + +static void +toggle_babysitter_watch (DBusWatch *watch, + void *data) +{ + BusPendingActivation *pending_activation = data; + + _dbus_loop_toggle_watch (bus_context_get_loop (pending_activation->activation->context), + watch); +} + +static dbus_bool_t +pending_activation_timed_out (void *data) +{ + BusPendingActivation *pending_activation = data; + DBusError error; + + /* Kill the spawned process, since it sucks + * (not sure this is what we want to do, but + * may as well try it for now) + */ + if (pending_activation->babysitter) + _dbus_babysitter_kill_child (pending_activation->babysitter); + + dbus_error_init (&error); + + bus_context_log_and_set_error (pending_activation->activation->context, + DBUS_SYSTEM_LOG_INFO, &error, DBUS_ERROR_TIMED_OUT, + "Failed to activate service '%s': timed out", + pending_activation->service_name); + + pending_activation_failed (pending_activation, &error); + + dbus_error_free (&error); + + return TRUE; +} + +static void +cancel_pending (void *data) +{ + BusPendingActivation *pending_activation = data; + + _dbus_verbose ("Canceling pending activation of %s\n", + pending_activation->service_name); + + if (pending_activation->babysitter) + _dbus_babysitter_kill_child (pending_activation->babysitter); + + _dbus_hash_table_remove_string (pending_activation->activation->pending_activations, + pending_activation->service_name); +} + +static void +free_pending_cancel_data (void *data) +{ + BusPendingActivation *pending_activation = data; + + bus_pending_activation_unref (pending_activation); +} + +static dbus_bool_t +add_cancel_pending_to_transaction (BusTransaction *transaction, + BusPendingActivation *pending_activation) +{ + if (!bus_transaction_add_cancel_hook (transaction, cancel_pending, + pending_activation, + free_pending_cancel_data)) + return FALSE; + + bus_pending_activation_ref (pending_activation); + + _dbus_verbose ("Saved pending activation to be canceled if the transaction fails\n"); + + return TRUE; +} + +static dbus_bool_t +update_service_cache (BusActivation *activation, DBusError *error) +{ + DBusHashIter iter; + + _dbus_hash_iter_init (activation->directories, &iter); + while (_dbus_hash_iter_next (&iter)) + { + DBusError tmp_error; + BusServiceDirectory *s_dir; + + s_dir = _dbus_hash_iter_get_value (&iter); + + dbus_error_init (&tmp_error); + if (!update_directory (activation, s_dir, &tmp_error)) + { + if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY)) + { + dbus_move_error (&tmp_error, error); + return FALSE; + } + + dbus_error_free (&tmp_error); + continue; + } + } + + return TRUE; +} + +static BusActivationEntry * +activation_find_entry (BusActivation *activation, + const char *service_name, + DBusError *error) +{ + BusActivationEntry *entry; + + entry = _dbus_hash_table_lookup_string (activation->entries, service_name); + if (!entry) + { + if (!update_service_cache (activation, error)) + return NULL; + + entry = _dbus_hash_table_lookup_string (activation->entries, + service_name); + } + else + { + BusActivationEntry *updated_entry; + + if (!check_service_file (activation, entry, &updated_entry, error)) + return NULL; + + entry = updated_entry; + } + + if (!entry) + { + dbus_set_error (error, DBUS_ERROR_SERVICE_UNKNOWN, + "The name %s was not provided by any .service files", + service_name); + return NULL; + } + + return entry; +} + +static char ** +bus_activation_get_environment (BusActivation *activation) +{ + char **environment; + int i, length; + DBusString entry; + DBusHashIter iter; + + length = _dbus_hash_table_get_n_entries (activation->environment); + + environment = dbus_new0 (char *, length + 1); + + if (environment == NULL) + return NULL; + + i = 0; + _dbus_hash_iter_init (activation->environment, &iter); + + if (!_dbus_string_init (&entry)) + { + dbus_free_string_array (environment); + return NULL; + } + + while (_dbus_hash_iter_next (&iter)) + { + const char *key, *value; + + key = (const char *) _dbus_hash_iter_get_string_key (&iter); + value = (const char *) _dbus_hash_iter_get_value (&iter); + + if (!_dbus_string_append_printf (&entry, "%s=%s", key, value)) + break; + + if (!_dbus_string_steal_data (&entry, environment + i)) + break; + i++; + } + + _dbus_string_free (&entry); + + if (i != length) + { + dbus_free_string_array (environment); + environment = NULL; + } + + return environment; +} + +dbus_bool_t +bus_activation_set_environment_variable (BusActivation *activation, + const char *key, + const char *value, + DBusError *error) +{ + char *hash_key; + char *hash_value; + dbus_bool_t retval; + + retval = FALSE; + hash_key = NULL; + hash_value = NULL; + hash_key = _dbus_strdup (key); + + if (hash_key == NULL) + goto out; + + hash_value = _dbus_strdup (value); + + if (hash_value == NULL) + goto out; + + if (!_dbus_hash_table_insert_string (activation->environment, + hash_key, hash_value)) + goto out; + + retval = TRUE; +out: + if (retval == FALSE) + { + dbus_free (hash_key); + dbus_free (hash_value); + BUS_SET_OOM (error); + } + + return retval; +} + +static void +child_setup (void *user_data) +{ +#ifdef DBUS_UNIX + BusActivation *activation = user_data; + DBusRLimit *initial_fd_limit; + DBusError error; + + dbus_error_init (&error); + initial_fd_limit = bus_context_get_initial_fd_limit (activation->context); + + if (initial_fd_limit != NULL && + !_dbus_rlimit_restore_fd_limit (initial_fd_limit, &error)) + { + /* unfortunately we don't actually know the service name here */ + bus_context_log (activation->context, + DBUS_SYSTEM_LOG_WARNING, + "Failed to reset fd limit before activating " + "service: %s: %s", + error.name, error.message); + } +#endif +} + + +dbus_bool_t +bus_activation_activate_service (BusActivation *activation, + DBusConnection *connection, + BusTransaction *transaction, + dbus_bool_t auto_activation, + DBusMessage *activation_message, + const char *service_name, + DBusError *error) +{ + DBusError tmp_error; + BusActivationEntry *entry; + BusPendingActivation *pending_activation; + BusPendingActivationEntry *pending_activation_entry; + DBusMessage *message; + DBusString service_str; + const char *servicehelper; + char **argv; + char **envp = NULL; + int argc; + dbus_bool_t retval; + dbus_bool_t was_pending_activation; + DBusString command; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (activation->n_pending_activations >= + bus_context_get_max_pending_activations (activation->context)) + { + dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED, + "The maximum number of pending activations has been reached, activation of %s failed", + service_name); + return FALSE; + } + + if (bus_context_get_systemd_activation (activation->context) && + strcmp (service_name, "org.freedesktop.systemd1") == 0) + { + /* if we're doing systemd activation, we assume systemd will connect + * eventually, and it does not need a .service file */ + entry = NULL; + } + else + { + entry = activation_find_entry (activation, service_name, error); + if (!entry) + return FALSE; + } + + /* Bypass the registry lookup if we're auto-activating, bus_dispatch would not + * call us if the service is already active. + */ + if (!auto_activation) + { + /* Check if the service is active */ + _dbus_string_init_const (&service_str, service_name); + if (bus_registry_lookup (bus_context_get_registry (activation->context), &service_str) != NULL) + { + dbus_uint32_t result; + + _dbus_verbose ("Service \"%s\" is already active\n", service_name); + + message = dbus_message_new_method_return (activation_message); + + if (!message) + { + _dbus_verbose ("No memory to create reply to activate message\n"); + BUS_SET_OOM (error); + return FALSE; + } + + result = DBUS_START_REPLY_ALREADY_RUNNING; + + if (!dbus_message_append_args (message, + DBUS_TYPE_UINT32, &result, + DBUS_TYPE_INVALID)) + { + _dbus_verbose ("No memory to set args of reply to activate message\n"); + BUS_SET_OOM (error); + dbus_message_unref (message); + return FALSE; + } + + retval = bus_transaction_send_from_driver (transaction, connection, message); + dbus_message_unref (message); + if (!retval) + { + _dbus_verbose ("Failed to send reply\n"); + BUS_SET_OOM (error); + } + + return retval; + } + } + + pending_activation_entry = dbus_new0 (BusPendingActivationEntry, 1); + if (!pending_activation_entry) + { + _dbus_verbose ("Failed to create pending activation entry\n"); + BUS_SET_OOM (error); + return FALSE; + } + + pending_activation_entry->auto_activation = auto_activation; + + pending_activation_entry->activation_message = activation_message; + dbus_message_ref (activation_message); + pending_activation_entry->connection = connection; + if (connection) + dbus_connection_ref (connection); + + /* Check if the service is being activated */ + pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations, service_name); + was_pending_activation = (pending_activation != NULL); + if (was_pending_activation) + { + if (!_dbus_list_append (&pending_activation->entries, pending_activation_entry)) + { + _dbus_verbose ("Failed to append a new entry to pending activation\n"); + + BUS_SET_OOM (error); + bus_pending_activation_entry_free (pending_activation_entry); + return FALSE; + } + + pending_activation->n_entries += 1; + pending_activation->activation->n_pending_activations += 1; + } + else + { + pending_activation = dbus_new0 (BusPendingActivation, 1); + if (!pending_activation) + { + _dbus_verbose ("Failed to create pending activation\n"); + + BUS_SET_OOM (error); + bus_pending_activation_entry_free (pending_activation_entry); + return FALSE; + } + + pending_activation->activation = activation; + pending_activation->refcount = 1; + + pending_activation->service_name = _dbus_strdup (service_name); + if (!pending_activation->service_name) + { + _dbus_verbose ("Failed to copy service name for pending activation\n"); + + BUS_SET_OOM (error); + bus_pending_activation_unref (pending_activation); + bus_pending_activation_entry_free (pending_activation_entry); + return FALSE; + } + + if (entry != NULL) + { + pending_activation->exec = _dbus_strdup (entry->exec); + if (!pending_activation->exec) + { + _dbus_verbose ("Failed to copy service exec for pending activation\n"); + BUS_SET_OOM (error); + bus_pending_activation_unref (pending_activation); + bus_pending_activation_entry_free (pending_activation_entry); + return FALSE; + } + } + + if (entry != NULL && entry->systemd_service != NULL) + { + pending_activation->systemd_service = _dbus_strdup (entry->systemd_service); + if (!pending_activation->systemd_service) + { + _dbus_verbose ("Failed to copy systemd service for pending activation\n"); + BUS_SET_OOM (error); + bus_pending_activation_unref (pending_activation); + bus_pending_activation_entry_free (pending_activation_entry); + return FALSE; + } + } + + pending_activation->timeout = + _dbus_timeout_new (bus_context_get_activation_timeout (activation->context), + pending_activation_timed_out, + pending_activation, + NULL); + if (!pending_activation->timeout) + { + _dbus_verbose ("Failed to create timeout for pending activation\n"); + + BUS_SET_OOM (error); + bus_pending_activation_unref (pending_activation); + bus_pending_activation_entry_free (pending_activation_entry); + return FALSE; + } + + if (!_dbus_loop_add_timeout (bus_context_get_loop (activation->context), + pending_activation->timeout)) + { + _dbus_verbose ("Failed to add timeout for pending activation\n"); + + BUS_SET_OOM (error); + bus_pending_activation_unref (pending_activation); + bus_pending_activation_entry_free (pending_activation_entry); + return FALSE; + } + + pending_activation->timeout_added = TRUE; + + if (!_dbus_list_append (&pending_activation->entries, pending_activation_entry)) + { + _dbus_verbose ("Failed to add entry to just-created pending activation\n"); + + BUS_SET_OOM (error); + bus_pending_activation_unref (pending_activation); + bus_pending_activation_entry_free (pending_activation_entry); + return FALSE; + } + + pending_activation->n_entries += 1; + pending_activation->activation->n_pending_activations += 1; + + if (!_dbus_hash_table_insert_string (activation->pending_activations, + pending_activation->service_name, + pending_activation)) + { + _dbus_verbose ("Failed to put pending activation in hash table\n"); + + BUS_SET_OOM (error); + bus_pending_activation_unref (pending_activation); + return FALSE; + } + } + + if (!add_cancel_pending_to_transaction (transaction, pending_activation)) + { + _dbus_verbose ("Failed to add pending activation cancel hook to transaction\n"); + BUS_SET_OOM (error); + goto cancel_pending_activation; + } + + if (was_pending_activation) + return TRUE; + + if (bus_context_get_systemd_activation (activation->context)) + { + if (strcmp (service_name, "org.freedesktop.systemd1") == 0) + /* systemd itself is missing apparently. That can happen + only during early startup. Let's just wait until systemd + connects to us and do nothing. */ + return TRUE; + + if (entry->systemd_service) + { + BusTransaction *activation_transaction; + DBusString service_string; + BusService *service; + BusRegistry *registry; + + /* OK, we have a systemd service configured for this entry, + hence let's enqueue an activation request message. This + is implemented as a directed signal, not a method call, + for three reasons: 1) we don't expect a response on + success, where we just expect a name appearing on the + bus; 2) at this time the systemd service might not yet + have connected, so we wouldn't know the message serial at + this point to set up a pending call; 3) it is ugly if the + bus suddenly becomes the caller of a remote method. */ + + message = dbus_message_new_signal (DBUS_PATH_DBUS, + "org.freedesktop.systemd1.Activator", + "ActivationRequest"); + if (!message) + { + _dbus_verbose ("No memory to create activation message\n"); + BUS_SET_OOM (error); + goto cancel_pending_activation; + } + + if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS) || + !dbus_message_set_destination (message, "org.freedesktop.systemd1") || + !dbus_message_append_args (message, + DBUS_TYPE_STRING, &entry->systemd_service, + DBUS_TYPE_INVALID)) + { + _dbus_verbose ("No memory to set args of activation message\n"); + dbus_message_unref (message); + BUS_SET_OOM (error); + goto cancel_pending_activation; + } + + /* Create our transaction */ + activation_transaction = bus_transaction_new (activation->context); + if (activation_transaction == NULL) + { + _dbus_verbose ("No memory to create activation transaction\n"); + dbus_message_unref (message); + BUS_SET_OOM (error); + goto cancel_pending_activation; + } + + /* Check whether systemd is already connected */ + registry = bus_connection_get_registry (connection); + _dbus_string_init_const (&service_string, "org.freedesktop.systemd1"); + service = bus_registry_lookup (registry, &service_string); + + /* Following the general principle of "log early and often", + * we capture that we *want* to send the activation message, even if + * systemd is not actually there to receive it yet */ + if (!bus_transaction_capture (activation_transaction, + NULL, message)) + { + dbus_message_unref (message); + BUS_SET_OOM (error); + goto cancel_pending_activation; + } + + if (service != NULL) + { + bus_context_log (activation->context, + DBUS_SYSTEM_LOG_INFO, "Activating via systemd: service name='%s' unit='%s'", + service_name, + entry->systemd_service); + /* Wonderful, systemd is connected, let's just send the msg */ + retval = bus_dispatch_matches (activation_transaction, NULL, bus_service_get_primary_owners_connection (service), + message, error); + } + else + { + bus_context_log (activation->context, + DBUS_SYSTEM_LOG_INFO, "Activating systemd to hand-off: service name='%s' unit='%s'", + service_name, + entry->systemd_service); + /* systemd is not around, let's "activate" it. */ + retval = bus_activation_activate_service (activation, NULL, activation_transaction, TRUE, + message, "org.freedesktop.systemd1", error); + } + + dbus_message_unref (message); + + if (!retval) + { + bus_context_log (activation->context, + DBUS_SYSTEM_LOG_INFO, "Failed to activate via systemd: service name='%s' unit='%s'", + service_name, + entry->systemd_service); + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_verbose ("failed to send activation message: %s\n", error->name); + bus_transaction_cancel_and_free (activation_transaction); + goto cancel_pending_activation; + } + + bus_transaction_execute_and_free (activation_transaction); + return TRUE; + } + + /* OK, we have no configured systemd service, hence let's + proceed with traditional activation. */ + } + + /* If entry was NULL, it would be because we were doing systemd activation + * and activating systemd itself; but we already handled that case with + * an early-return */ + _dbus_assert (entry != NULL); + + /* use command as system and session different */ + if (!_dbus_string_init (&command)) + { + BUS_SET_OOM (error); + goto cancel_pending_activation; + } + + /* does the bus use a helper? */ + servicehelper = bus_context_get_servicehelper (activation->context); + if (servicehelper != NULL) + { + if (entry->user == NULL) + { + _dbus_string_free (&command); + dbus_set_error (error, DBUS_ERROR_SPAWN_FILE_INVALID, + "Cannot do system-bus activation with no user\n"); + goto cancel_pending_activation; + } + + /* join the helper path and the service name */ + if (!_dbus_string_append (&command, servicehelper)) + { + _dbus_string_free (&command); + BUS_SET_OOM (error); + goto cancel_pending_activation; + } + if (!_dbus_string_append (&command, " ")) + { + _dbus_string_free (&command); + BUS_SET_OOM (error); + goto cancel_pending_activation; + } + if (!_dbus_string_append (&command, service_name)) + { + _dbus_string_free (&command); + BUS_SET_OOM (error); + goto cancel_pending_activation; + } + } + else + { + /* the bus does not use a helper, so we can append arguments with the exec line */ + if (!_dbus_string_append (&command, entry->exec)) + { + _dbus_string_free (&command); + BUS_SET_OOM (error); + goto cancel_pending_activation; + } + } + + /* convert command into arguments */ + if (!_dbus_shell_parse_argv (_dbus_string_get_const_data (&command), &argc, &argv, error)) + { + _dbus_verbose ("Failed to parse command line: %s\n", entry->exec); + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_string_free (&command); + goto cancel_pending_activation; + } + _dbus_string_free (&command); + + if (!add_bus_environment (activation, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_free_string_array (argv); + goto cancel_pending_activation; + } + + envp = bus_activation_get_environment (activation); + + if (envp == NULL) + { + BUS_SET_OOM (error); + dbus_free_string_array (argv); + goto cancel_pending_activation; + } + + _dbus_verbose ("Spawning %s ...\n", argv[0]); + if (servicehelper != NULL) + bus_context_log (activation->context, + DBUS_SYSTEM_LOG_INFO, "Activating service name='%s' (using servicehelper)", + service_name); + else + bus_context_log (activation->context, + DBUS_SYSTEM_LOG_INFO, "Activating service name='%s'", + service_name); + + dbus_error_init (&tmp_error); + + if (!_dbus_spawn_async_with_babysitter (&pending_activation->babysitter, + service_name, + argv, + envp, + child_setup, + activation, + &tmp_error)) + { + _dbus_verbose ("Failed to spawn child\n"); + bus_context_log (activation->context, + DBUS_SYSTEM_LOG_INFO, "Failed to activate service %s: %s", + service_name, + tmp_error.message); + _DBUS_ASSERT_ERROR_IS_SET (&tmp_error); + dbus_move_error (&tmp_error, error); + dbus_free_string_array (argv); + dbus_free_string_array (envp); + goto cancel_pending_activation; + } + + dbus_free_string_array (argv); + envp = NULL; + + _dbus_assert (pending_activation->babysitter != NULL); + + _dbus_babysitter_set_result_function (pending_activation->babysitter, + pending_activation_finished_cb, + pending_activation); + + if (!_dbus_babysitter_set_watch_functions (pending_activation->babysitter, + add_babysitter_watch, + remove_babysitter_watch, + toggle_babysitter_watch, + pending_activation, + NULL)) + { + BUS_SET_OOM (error); + _dbus_verbose ("Failed to set babysitter watch functions\n"); + goto cancel_pending_activation; + } + + return TRUE; + +cancel_pending_activation: + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_hash_table_remove_string (activation->pending_activations, + pending_activation->service_name); + return FALSE; +} + +dbus_bool_t +bus_activation_list_services (BusActivation *activation, + char ***listp, + int *array_len) +{ + int i, j, len; + char **retval; + DBusHashIter iter; + + len = _dbus_hash_table_get_n_entries (activation->entries); + retval = dbus_new (char *, len + 1); + + if (retval == NULL) + return FALSE; + + _dbus_hash_iter_init (activation->entries, &iter); + i = 0; + while (_dbus_hash_iter_next (&iter)) + { + BusActivationEntry *entry = _dbus_hash_iter_get_value (&iter); + + retval[i] = _dbus_strdup (entry->name); + if (retval[i] == NULL) + goto error; + + i++; + } + + retval[i] = NULL; + + if (array_len) + *array_len = len; + + *listp = retval; + return TRUE; + + error: + for (j = 0; j < i; j++) + dbus_free (retval[j]); + dbus_free (retval); + + return FALSE; +} + +dbus_bool_t +dbus_activation_systemd_failure (BusActivation *activation, + DBusMessage *message) +{ + DBusError error; + const char *code, *str, *unit = NULL; + + dbus_error_init(&error); + + /* This is called whenever the systemd activator sent us a + response. We'll invalidate all pending activations that match the + unit name. */ + + if (dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &unit, + DBUS_TYPE_STRING, &code, + DBUS_TYPE_STRING, &str, + DBUS_TYPE_INVALID)) + dbus_set_error (&error, code, "%s", str); + + + if (unit) + { + DBusHashIter iter; + + bus_context_log (activation->context, + DBUS_SYSTEM_LOG_INFO, "Activation via systemd failed for unit '%s': %s", + unit, + str); + + _dbus_hash_iter_init (activation->pending_activations, + &iter); + + while (_dbus_hash_iter_next (&iter)) + { + BusPendingActivation *p = _dbus_hash_iter_get_value (&iter); + + if (p->systemd_service && strcmp (p->systemd_service, unit) == 0) + pending_activation_failed(p, &error); + } + } + + dbus_error_free(&error); + + return TRUE; +} + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + +#include <stdio.h> + +#define SERVICE_NAME_1 "MyService1" +#define SERVICE_NAME_2 "MyService2" +#define SERVICE_NAME_3 "MyService3" + +#define SERVICE_FILE_1 "service-1.service" +#define SERVICE_FILE_2 "service-2.service" +#define SERVICE_FILE_3 "service-3.service" + +static dbus_bool_t +test_create_service_file (DBusString *dir, + const char *filename, + const char *name, + const char *exec) +{ + DBusString file_name, full_path; + FILE *file; + dbus_bool_t ret_val; + + ret_val = TRUE; + _dbus_string_init_const (&file_name, filename); + + if (!_dbus_string_init (&full_path)) + return FALSE; + + if (!_dbus_string_append (&full_path, _dbus_string_get_const_data (dir)) || + !_dbus_concat_dir_and_file (&full_path, &file_name)) + { + ret_val = FALSE; + goto out; + } + + file = fopen (_dbus_string_get_const_data (&full_path), "w"); + if (!file) + { + ret_val = FALSE; + goto out; + } + + fprintf (file, "[D-BUS Service]\nName=%s\nExec=%s\n", name, exec); + fclose (file); + +out: + _dbus_string_free (&full_path); + return ret_val; +} + +static dbus_bool_t +test_remove_service_file (DBusString *dir, const char *filename) +{ + DBusString file_name, full_path; + dbus_bool_t ret_val; + + ret_val = TRUE; + + _dbus_string_init_const (&file_name, filename); + + if (!_dbus_string_init (&full_path)) + return FALSE; + + if (!_dbus_string_append (&full_path, _dbus_string_get_const_data (dir)) || + !_dbus_concat_dir_and_file (&full_path, &file_name)) + { + ret_val = FALSE; + goto out; + } + + if (!_dbus_delete_file (&full_path, NULL)) + { + ret_val = FALSE; + goto out; + } + +out: + _dbus_string_free (&full_path); + return ret_val; +} + +static dbus_bool_t +test_remove_directory (DBusString *dir) +{ + DBusDirIter *iter; + DBusString filename, full_path; + dbus_bool_t ret_val; + + ret_val = TRUE; + + if (!_dbus_string_init (&filename)) + return FALSE; + + if (!_dbus_string_init (&full_path)) + { + _dbus_string_free (&filename); + return FALSE; + } + + iter = _dbus_directory_open (dir, NULL); + if (iter == NULL) + { + ret_val = FALSE; + goto out; + } + + while (_dbus_directory_get_next_file (iter, &filename, NULL)) + { + if (!test_remove_service_file (dir, _dbus_string_get_const_data (&filename))) + { + ret_val = FALSE; + _dbus_directory_close (iter); + goto out; + } + } + _dbus_directory_close (iter); + + if (!_dbus_delete_directory (dir, NULL)) + { + ret_val = FALSE; + goto out; + } + +out: + _dbus_string_free (&filename); + _dbus_string_free (&full_path); + + return ret_val; +} + +static dbus_bool_t +init_service_reload_test (DBusString *dir) +{ + DBusStat stat_buf; + + if (!_dbus_stat (dir, &stat_buf, NULL)) + { + if (!_dbus_create_directory (dir, NULL)) + return FALSE; + } + else + { + if (!test_remove_directory (dir)) + return FALSE; + + if (!_dbus_create_directory (dir, NULL)) + return FALSE; + } + + /* Create one initial file */ + if (!test_create_service_file (dir, SERVICE_FILE_1, SERVICE_NAME_1, "exec-1")) + return FALSE; + + return TRUE; +} + +static dbus_bool_t +cleanup_service_reload_test (DBusString *dir) +{ + if (!test_remove_directory (dir)) + return FALSE; + + return TRUE; +} + +typedef struct +{ + BusActivation *activation; + const char *service_name; + dbus_bool_t expecting_find; +} CheckData; + +static dbus_bool_t +check_func (void *data) +{ + CheckData *d; + BusActivationEntry *entry; + DBusError error; + dbus_bool_t ret_val; + + ret_val = TRUE; + d = data; + + dbus_error_init (&error); + + entry = activation_find_entry (d->activation, d->service_name, &error); + if (entry == NULL) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + ret_val = TRUE; + } + else + { + if (d->expecting_find) + ret_val = FALSE; + } + + dbus_error_free (&error); + } + else + { + if (!d->expecting_find) + ret_val = FALSE; + } + + return ret_val; +} + +static dbus_bool_t +do_test (const char *description, dbus_bool_t oom_test, CheckData *data) +{ + dbus_bool_t err; + + if (oom_test) + err = !_dbus_test_oom_handling (description, check_func, data); + else + err = !check_func (data); + + if (err) + _dbus_assert_not_reached ("Test failed"); + + return TRUE; +} + +static dbus_bool_t +do_service_reload_test (DBusString *dir, dbus_bool_t oom_test) +{ + BusActivation *activation; + DBusString address; + DBusList *directories; + CheckData d; + + directories = NULL; + _dbus_string_init_const (&address, ""); + + if (!_dbus_list_append (&directories, _dbus_string_get_data (dir))) + return FALSE; + + activation = bus_activation_new (NULL, &address, &directories, NULL); + if (!activation) + return FALSE; + + d.activation = activation; + + /* Check for existing service file */ + d.expecting_find = TRUE; + d.service_name = SERVICE_NAME_1; + + if (!do_test ("Existing service file", oom_test, &d)) + return FALSE; + + /* Check for non-existing service file */ + d.expecting_find = FALSE; + d.service_name = SERVICE_NAME_3; + + if (!do_test ("Nonexisting service file", oom_test, &d)) + return FALSE; + + /* Check for added service file */ + if (!test_create_service_file (dir, SERVICE_FILE_2, SERVICE_NAME_2, "exec-2")) + return FALSE; + + d.expecting_find = TRUE; + d.service_name = SERVICE_NAME_2; + + if (!do_test ("Added service file", oom_test, &d)) + return FALSE; + + /* Check for removed service file */ + if (!test_remove_service_file (dir, SERVICE_FILE_2)) + return FALSE; + + d.expecting_find = FALSE; + d.service_name = SERVICE_FILE_2; + + if (!do_test ("Removed service file", oom_test, &d)) + return FALSE; + + /* Check for updated service file */ + + _dbus_sleep_milliseconds (1000); /* Sleep a second to make sure the mtime is updated */ + + if (!test_create_service_file (dir, SERVICE_FILE_1, SERVICE_NAME_3, "exec-3")) + return FALSE; + + d.expecting_find = TRUE; + d.service_name = SERVICE_NAME_3; + + if (!do_test ("Updated service file, part 1", oom_test, &d)) + return FALSE; + + d.expecting_find = FALSE; + d.service_name = SERVICE_NAME_1; + + if (!do_test ("Updated service file, part 2", oom_test, &d)) + return FALSE; + + bus_activation_unref (activation); + _dbus_list_clear (&directories); + + return TRUE; +} + +dbus_bool_t +bus_activation_service_reload_test (const DBusString *test_data_dir) +{ + DBusString directory; + const char *tmp; + dbus_bool_t ret = FALSE; + + if (!_dbus_string_init (&directory)) + return FALSE; + + tmp = _dbus_get_tmpdir (); + + if (tmp == NULL) + goto out; + + if (!_dbus_string_append (&directory, tmp)) + goto out; + + if (!_dbus_string_append (&directory, "/dbus-reload-test-") || + !_dbus_generate_random_ascii (&directory, 6, NULL)) + goto out; + + /* Do normal tests */ + if (!init_service_reload_test (&directory)) + _dbus_assert_not_reached ("could not initiate service reload test"); + + if (!do_service_reload_test (&directory, FALSE)) + { + /* Do nothing? */ + } + + /* Do OOM tests */ + if (!init_service_reload_test (&directory)) + _dbus_assert_not_reached ("could not initiate service reload test"); + + if (!do_service_reload_test (&directory, TRUE)) + { + /* Do nothing? */ + } + + /* Cleanup test directory */ + if (!cleanup_service_reload_test (&directory)) + goto out; + + ret = TRUE; + +out: + _dbus_string_free (&directory); + return ret; +} + +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/bus/activation.h b/bus/activation.h new file mode 100644 index 0000000..fc5d426 --- /dev/null +++ b/bus/activation.h
@@ -0,0 +1,68 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* activation.h Activation of services + * + * Copyright (C) 2003 CodeFactory AB + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_ACTIVATION_H +#define BUS_ACTIVATION_H + +#include <dbus/dbus.h> +#include <dbus/dbus-list.h> +#include "bus.h" + +BusActivation* bus_activation_new (BusContext *context, + const DBusString *address, + DBusList **directories, + DBusError *error); +dbus_bool_t bus_activation_reload (BusActivation *activation, + const DBusString *address, + DBusList **directories, + DBusError *error); +BusActivation* bus_activation_ref (BusActivation *activation); +void bus_activation_unref (BusActivation *activation); + +dbus_bool_t bus_activation_set_environment_variable (BusActivation *activation, + const char *key, + const char *value, + DBusError *error); +dbus_bool_t bus_activation_activate_service (BusActivation *activation, + DBusConnection *connection, + BusTransaction *transaction, + dbus_bool_t auto_activation, + DBusMessage *activation_message, + const char *service_name, + DBusError *error); +dbus_bool_t bus_activation_service_created (BusActivation *activation, + const char *service_name, + BusTransaction *transaction, + DBusError *error); +dbus_bool_t bus_activation_list_services (BusActivation *registry, + char ***listp, + int *array_len); +dbus_bool_t dbus_activation_systemd_failure (BusActivation *activation, + DBusMessage *message); + +dbus_bool_t bus_activation_send_pending_auto_activation_messages (BusActivation *activation, + BusService *service, + BusTransaction *transaction); + + +#endif /* BUS_ACTIVATION_H */
diff --git a/bus/apparmor.c b/bus/apparmor.c new file mode 100644 index 0000000..3ba84d8 --- /dev/null +++ b/bus/apparmor.c
@@ -0,0 +1,1101 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * apparmor.c AppArmor security checks for D-Bus + * + * Based on selinux.c + * + * Copyright © 2014-2015 Canonical, Ltd. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "apparmor.h" + +#ifdef HAVE_APPARMOR + +#include <dbus/dbus-internals.h> +#include <dbus/dbus-string.h> +#include <errno.h> +#include <fcntl.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/apparmor.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <syslog.h> +#include <unistd.h> + +#ifdef HAVE_LIBAUDIT +#include <libaudit.h> +#endif /* HAVE_LIBAUDIT */ + +#include "audit.h" +#include "connection.h" +#include "utils.h" + +/* Store the value telling us if AppArmor D-Bus mediation is enabled. */ +static dbus_bool_t apparmor_enabled = FALSE; + +typedef enum { + APPARMOR_DISABLED, + APPARMOR_ENABLED, + APPARMOR_REQUIRED +} AppArmorConfigMode; + +/* Store the value of the AppArmor mediation mode in the bus configuration */ +static AppArmorConfigMode apparmor_config_mode = APPARMOR_ENABLED; + +/* The AppArmor context, consisting of a label and a mode. */ +struct BusAppArmorConfinement +{ + int refcount; /* Reference count */ + + char *label; /* AppArmor confinement label */ + const char *mode; /* AppArmor confinement mode (freed by freeing *label) */ +}; + +static BusAppArmorConfinement *bus_con = NULL; + +/** + * Callers of this function give up ownership of the *label and *mode + * pointers. + * + * Additionally, the responsibility of freeing *label and *mode becomes the + * responsibility of the bus_apparmor_confinement_unref() function. However, it + * does not free *mode because libapparmor's aa_getcon(), and libapparmor's + * other related functions, allocate a single buffer for *label and *mode and + * then separate the two char arrays with a NUL char. See the aa_getcon(2) man + * page for more details. + */ +static BusAppArmorConfinement* +bus_apparmor_confinement_new (char *label, + const char *mode) +{ + BusAppArmorConfinement *confinement; + + confinement = dbus_new0 (BusAppArmorConfinement, 1); + if (confinement != NULL) + { + confinement->refcount = 1; + confinement->label = label; + confinement->mode = mode; + } + + return confinement; +} + +/* + * Return TRUE on successful check, FALSE on OOM. + * Set *is_supported to whether AA has D-Bus features. + */ +static dbus_bool_t +_bus_apparmor_detect_aa_dbus_support (dbus_bool_t *is_supported) +{ + int mask_file; + DBusString aa_dbus; + char *aa_securityfs = NULL; + dbus_bool_t retval = FALSE; + + *is_supported = FALSE; + + if (!_dbus_string_init (&aa_dbus)) + return FALSE; + + if (aa_find_mountpoint (&aa_securityfs) != 0) + goto out; + + /* + * John Johansen has confirmed that the mainline kernel will not have + * the apparmorfs/features/dbus/mask file until the mainline kernel + * has AppArmor getpeersec support. + */ + if (!_dbus_string_append (&aa_dbus, aa_securityfs) || + !_dbus_string_append (&aa_dbus, "/features/dbus/mask")) + goto out; + + /* We need to open() the flag file, not just stat() it, because AppArmor + * does not mediate stat() in the apparmorfs. If you have a + * dbus-daemon inside an LXC container, with insufficiently broad + * AppArmor privileges to do its own AppArmor mediation, the desired + * result is that it behaves as if AppArmor was not present; but a stat() + * here would succeed, and result in it trying and failing to do full + * mediation. https://bugs.launchpad.net/ubuntu/+source/dbus/+bug/1238267 */ + mask_file = open (_dbus_string_get_const_data (&aa_dbus), + O_RDONLY | O_CLOEXEC); + if (mask_file != -1) + { + *is_supported = TRUE; + close (mask_file); + } + + retval = TRUE; + +out: + free (aa_securityfs); + _dbus_string_free (&aa_dbus); + + return retval; +} + +static dbus_bool_t +modestr_is_complain (const char *mode) +{ + if (mode && strcmp (mode, "complain") == 0) + return TRUE; + return FALSE; +} + +static void +log_message (dbus_bool_t allow, const char *op, DBusString *data) +{ + const char *mstr; +#ifdef HAVE_LIBAUDIT + int audit_fd; +#endif + + if (allow) + mstr = "ALLOWED"; + else + mstr = "DENIED"; + +#ifdef HAVE_LIBAUDIT + audit_fd = bus_audit_get_fd (); + + if (audit_fd >= 0) + { + DBusString avc; + + if (!_dbus_string_init (&avc)) + goto syslog; + + if (!_dbus_string_append_printf (&avc, + "apparmor=\"%s\" operation=\"dbus_%s\" %s\n", + mstr, op, _dbus_string_get_const_data (data))) + { + _dbus_string_free (&avc); + goto syslog; + } + + /* FIXME: need to change this to show real user */ + audit_log_user_avc_message (audit_fd, AUDIT_USER_AVC, + _dbus_string_get_const_data (&avc), + NULL, NULL, NULL, getuid ()); + _dbus_string_free (&avc); + return; + } + +syslog: +#endif /* HAVE_LIBAUDIT */ + + syslog (LOG_USER | LOG_NOTICE, "apparmor=\"%s\" operation=\"dbus_%s\" %s\n", + mstr, op, _dbus_string_get_const_data (data)); +} + +static dbus_bool_t +_dbus_append_pair_uint (DBusString *auxdata, const char *name, + unsigned long value) +{ + return _dbus_string_append (auxdata, " ") && + _dbus_string_append (auxdata, name) && + _dbus_string_append (auxdata, "=") && + _dbus_string_append_uint (auxdata, value); +} + +static dbus_bool_t +_dbus_append_pair_str (DBusString *auxdata, const char *name, const char *value) +{ + return _dbus_string_append (auxdata, " ") && + _dbus_string_append (auxdata, name) && + _dbus_string_append (auxdata, "=\"") && + _dbus_string_append (auxdata, value) && + _dbus_string_append (auxdata, "\""); +} + +static dbus_bool_t +_dbus_append_mask (DBusString *auxdata, uint32_t mask) +{ + const char *mask_str; + + /* Only one permission bit can be set */ + if (mask == AA_DBUS_SEND) + mask_str = "send"; + else if (mask == AA_DBUS_RECEIVE) + mask_str = "receive"; + else if (mask == AA_DBUS_BIND) + mask_str = "bind"; + else + return FALSE; + + return _dbus_append_pair_str (auxdata, "mask", mask_str); +} + +static dbus_bool_t +is_unconfined (const char *con, const char *mode) +{ + /* treat con == NULL as confined as it is going to result in a denial */ + if ((!mode && con && strcmp (con, "unconfined") == 0) || + strcmp (mode, "unconfined") == 0) + { + return TRUE; + } + + return FALSE; +} + +static dbus_bool_t +query_append (DBusString *query, const char *buffer) +{ + if (!_dbus_string_append_byte (query, '\0')) + return FALSE; + + if (buffer && !_dbus_string_append (query, buffer)) + return FALSE; + + return TRUE; +} + +static dbus_bool_t +build_common_query (DBusString *query, const char *con, const char *bustype) +{ + /** + * libapparmor's aa_query_label() function scribbles over the first + * AA_QUERY_CMD_LABEL_SIZE bytes of the query string with a private value. + */ + return _dbus_string_insert_bytes (query, 0, AA_QUERY_CMD_LABEL_SIZE, 0) && + _dbus_string_append (query, con) && + _dbus_string_append_byte (query, '\0') && + _dbus_string_append_byte (query, AA_CLASS_DBUS) && + _dbus_string_append (query, bustype ? bustype : ""); +} + +static dbus_bool_t +build_service_query (DBusString *query, + const char *con, + const char *bustype, + const char *name) +{ + return build_common_query (query, con, bustype) && + query_append (query, name); +} + +static dbus_bool_t +build_message_query (DBusString *query, + const char *src_con, + const char *bustype, + const char *name, + const char *dst_con, + const char *path, + const char *interface, + const char *member) +{ + return build_common_query (query, src_con, bustype) && + query_append (query, name) && + query_append (query, dst_con) && + query_append (query, path) && + query_append (query, interface) && + query_append (query, member); +} + +static dbus_bool_t +build_eavesdrop_query (DBusString *query, const char *con, const char *bustype) +{ + return build_common_query (query, con, bustype); +} + +static void +set_error_from_query_errno (DBusError *error, int error_number) +{ + dbus_set_error (error, _dbus_error_from_errno (error_number), + "Failed to query AppArmor policy: %s", + _dbus_strerror (error_number)); +} + +static void +set_error_from_denied_message (DBusError *error, + DBusConnection *sender, + DBusConnection *proposed_recipient, + dbus_bool_t requested_reply, + const char *msgtype, + const char *path, + const char *interface, + const char *member, + const char *error_name, + const char *destination) +{ + const char *proposed_recipient_loginfo; + const char *unset = "(unset)"; + + proposed_recipient_loginfo = proposed_recipient ? + bus_connection_get_loginfo (proposed_recipient) : + "bus"; + + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "An AppArmor policy prevents this sender from sending this " + "message to this recipient; type=\"%s\", " + "sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" " + "error name=\"%s\" requested_reply=\"%d\" " + "destination=\"%s\" (%s)", + msgtype, + bus_connection_get_name (sender), + bus_connection_get_loginfo (sender), + interface ? interface : unset, + member ? member : unset, + error_name ? error_name : unset, + requested_reply, + destination, + proposed_recipient_loginfo); +} +#endif /* HAVE_APPARMOR */ + +/** + * Do early initialization; determine whether AppArmor is enabled. + * Return TRUE on successful check (whether AppArmor is actually + * enabled or not) or FALSE on OOM. + */ +dbus_bool_t +bus_apparmor_pre_init (void) +{ +#ifdef HAVE_APPARMOR + apparmor_enabled = FALSE; + + if (!aa_is_enabled ()) + return TRUE; + + if (!_bus_apparmor_detect_aa_dbus_support (&apparmor_enabled)) + return FALSE; +#endif + + return TRUE; +} + +dbus_bool_t +bus_apparmor_set_mode_from_config (const char *mode, DBusError *error) +{ +#ifdef HAVE_APPARMOR + if (mode != NULL) + { + if (strcmp (mode, "disabled") == 0) + apparmor_config_mode = APPARMOR_DISABLED; + else if (strcmp (mode, "enabled") == 0) + apparmor_config_mode = APPARMOR_ENABLED; + else if (strcmp (mode, "required") == 0) + apparmor_config_mode = APPARMOR_REQUIRED; + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Mode attribute on <apparmor> must have value " + "\"required\", \"enabled\" or \"disabled\", " + "not \"%s\"", mode); + return FALSE; + } + } + + return TRUE; +#else + if (mode == NULL || strcmp (mode, "disabled") == 0 || + strcmp (mode, "enabled") == 0) + return TRUE; + + dbus_set_error (error, DBUS_ERROR_FAILED, + "Mode attribute on <apparmor> must have value \"enabled\" or " + "\"disabled\" but cannot be \"%s\" when D-Bus is built " + "without AppArmor support", mode); + return FALSE; +#endif +} + +/** + * Verify that the config mode is compatible with the kernel's AppArmor + * support. If AppArmor mediation will be enabled, determine the bus + * confinement label. + */ +dbus_bool_t +bus_apparmor_full_init (DBusError *error) +{ +#ifdef HAVE_APPARMOR + char *label, *mode; + + if (apparmor_enabled) + { + if (apparmor_config_mode == APPARMOR_DISABLED) + { + apparmor_enabled = FALSE; + return TRUE; + } + + if (bus_con == NULL) + { + if (aa_getcon (&label, &mode) == -1) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Error getting AppArmor context of bus: %s", + _dbus_strerror (errno)); + return FALSE; + } + + bus_con = bus_apparmor_confinement_new (label, mode); + if (bus_con == NULL) + { + BUS_SET_OOM (error); + free (label); + return FALSE; + } + } + } + else + { + if (apparmor_config_mode == APPARMOR_REQUIRED) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "AppArmor mediation required but not present"); + return FALSE; + } + else if (apparmor_config_mode == APPARMOR_ENABLED) + { + return TRUE; + } + } +#endif + + return TRUE; +} + +void +bus_apparmor_shutdown (void) +{ +#ifdef HAVE_APPARMOR + if (!apparmor_enabled) + return; + + _dbus_verbose ("AppArmor shutdown\n"); + + bus_apparmor_confinement_unref (bus_con); + bus_con = NULL; +#endif /* HAVE_APPARMOR */ +} + +dbus_bool_t +bus_apparmor_enabled (void) +{ +#ifdef HAVE_APPARMOR + return apparmor_enabled; +#else + return FALSE; +#endif +} + +void +bus_apparmor_confinement_unref (BusAppArmorConfinement *confinement) +{ +#ifdef HAVE_APPARMOR + if (!apparmor_enabled) + return; + + _dbus_assert (confinement != NULL); + _dbus_assert (confinement->refcount > 0); + + confinement->refcount -= 1; + + if (confinement->refcount == 0) + { + /** + * Do not free confinement->mode, as libapparmor does a single malloc for + * both confinement->label and confinement->mode. + */ + free (confinement->label); + dbus_free (confinement); + } +#endif +} + +void +bus_apparmor_confinement_ref (BusAppArmorConfinement *confinement) +{ +#ifdef HAVE_APPARMOR + if (!apparmor_enabled) + return; + + _dbus_assert (confinement != NULL); + _dbus_assert (confinement->refcount > 0); + + confinement->refcount += 1; +#endif /* HAVE_APPARMOR */ +} + +BusAppArmorConfinement* +bus_apparmor_init_connection_confinement (DBusConnection *connection, + DBusError *error) +{ +#ifdef HAVE_APPARMOR + BusAppArmorConfinement *confinement; + char *label, *mode; + int fd; + + if (!apparmor_enabled) + return NULL; + + _dbus_assert (connection != NULL); + + if (!dbus_connection_get_socket (connection, &fd)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Failed to get socket file descriptor of connection"); + return NULL; + } + + if (aa_getpeercon (fd, &label, &mode) == -1) + { + if (errno == ENOMEM) + BUS_SET_OOM (error); + else + dbus_set_error (error, _dbus_error_from_errno (errno), + "Failed to get AppArmor confinement information of socket peer: %s", + _dbus_strerror (errno)); + return NULL; + } + + confinement = bus_apparmor_confinement_new (label, mode); + if (confinement == NULL) + { + BUS_SET_OOM (error); + free (label); + return NULL; + } + + return confinement; +#else + return NULL; +#endif /* HAVE_APPARMOR */ +} + +/** + * Returns true if the given connection can acquire a service, + * using the tasks security context + * + * @param connection connection that wants to own the service + * @param bustype name of the bus + * @param service_name the name of the service to acquire + * @param error the reason for failure when FALSE is returned + * @returns TRUE if acquire is permitted + */ +dbus_bool_t +bus_apparmor_allows_acquire_service (DBusConnection *connection, + const char *bustype, + const char *service_name, + DBusError *error) +{ + +#ifdef HAVE_APPARMOR + BusAppArmorConfinement *con = NULL; + DBusString qstr, auxdata; + dbus_bool_t free_auxdata = FALSE; + dbus_bool_t allow = FALSE, audit = TRUE; + unsigned long pid; + int res, serrno = 0; + + if (!apparmor_enabled) + return TRUE; + + _dbus_assert (connection != NULL); + + con = bus_connection_dup_apparmor_confinement (connection); + + if (is_unconfined (con->label, con->mode)) + { + allow = TRUE; + audit = FALSE; + goto out; + } + + if (!_dbus_string_init (&qstr)) + goto oom; + + if (!build_service_query (&qstr, con->label, bustype, service_name)) + { + _dbus_string_free (&qstr); + goto oom; + } + + res = aa_query_label (AA_DBUS_BIND, + _dbus_string_get_data (&qstr), + _dbus_string_get_length (&qstr), + &allow, &audit); + _dbus_string_free (&qstr); + if (res == -1) + { + serrno = errno; + set_error_from_query_errno (error, serrno); + goto audit; + } + + /* Don't fail operations on profiles in complain mode */ + if (modestr_is_complain (con->mode)) + allow = TRUE; + + if (!allow) + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "Connection \"%s\" is not allowed to own the service " + "\"%s\" due to AppArmor policy", + bus_connection_is_active (connection) ? + bus_connection_get_name (connection) : "(inactive)", + service_name); + + if (!audit) + goto out; + + audit: + if (!_dbus_string_init (&auxdata)) + goto oom; + free_auxdata = TRUE; + + if (!_dbus_append_pair_str (&auxdata, "bus", bustype ? bustype : "unknown")) + goto oom; + + if (!_dbus_append_pair_str (&auxdata, "name", service_name)) + goto oom; + + if (serrno && !_dbus_append_pair_str (&auxdata, "info", strerror (serrno))) + goto oom; + + if (!_dbus_append_mask (&auxdata, AA_DBUS_BIND)) + goto oom; + + if (connection && dbus_connection_get_unix_process_id (connection, &pid) && + !_dbus_append_pair_uint (&auxdata, "pid", pid)) + goto oom; + + if (con->label && !_dbus_append_pair_str (&auxdata, "label", con->label)) + goto oom; + + log_message (allow, "bind", &auxdata); + + out: + if (con != NULL) + bus_apparmor_confinement_unref (con); + if (free_auxdata) + _dbus_string_free (&auxdata); + return allow; + + oom: + if (error != NULL && !dbus_error_is_set (error)) + BUS_SET_OOM (error); + allow = FALSE; + goto out; + +#else + return TRUE; +#endif /* HAVE_APPARMOR */ +} + +/** + * Check if Apparmor security controls allow the message to be sent to a + * particular connection based on the security context of the sender and + * that of the receiver. The destination connection need not be the + * addressed recipient, it could be an "eavesdropper" + * + * @param sender the sender of the message. + * @param proposed_recipient the connection the message is to be sent to. + * @param requested_reply TRUE if the message is a reply requested by + * proposed_recipient + * @param bustype name of the bus + * @param msgtype message type (DBUS_MESSAGE_TYPE_METHOD_CALL, etc.) + * @param path object path the message should be sent to + * @param interface the type of the object instance + * @param member the member of the object + * @param error_name the name of the error if the message type is error + * @param destination name that the message should be sent to + * @param source name that the message should be sent from + * @param error the reason for failure when FALSE is returned + * @returns TRUE if the message is permitted + */ +dbus_bool_t +bus_apparmor_allows_send (DBusConnection *sender, + DBusConnection *proposed_recipient, + dbus_bool_t requested_reply, + const char *bustype, + int msgtype, + const char *path, + const char *interface, + const char *member, + const char *error_name, + const char *destination, + const char *source, + DBusError *error) +{ +#ifdef HAVE_APPARMOR + BusAppArmorConfinement *src_con = NULL, *dst_con = NULL; + DBusString qstr, auxdata; + dbus_bool_t src_allow = FALSE, dst_allow = FALSE; + dbus_bool_t src_audit = TRUE, dst_audit = TRUE; + dbus_bool_t free_auxdata = FALSE; + unsigned long pid; + int len, res, src_errno = 0, dst_errno = 0; + uint32_t src_perm = AA_DBUS_SEND, dst_perm = AA_DBUS_RECEIVE; + const char *msgtypestr = dbus_message_type_to_string(msgtype); + + if (!apparmor_enabled) + return TRUE; + + _dbus_assert (sender != NULL); + + src_con = bus_connection_dup_apparmor_confinement (sender); + + if (proposed_recipient) + { + dst_con = bus_connection_dup_apparmor_confinement (proposed_recipient); + } + else + { + dst_con = bus_con; + bus_apparmor_confinement_ref (dst_con); + } + + /* map reply messages to initial send and receive permission. That is + * permission to receive a message from X grants permission to reply to X. + * And permission to send a message to Y grants permission to receive a reply + * from Y. Note that this only applies to requested replies. Unrequested + * replies still require a policy query. + */ + if (requested_reply) + { + /* ignore requested reply messages and let dbus reply mapping handle them + * as the send was already allowed + */ + src_allow = TRUE; + dst_allow = TRUE; + goto out; + } + + if (is_unconfined (src_con->label, src_con->mode)) + { + src_allow = TRUE; + src_audit = FALSE; + } + else + { + if (!_dbus_string_init (&qstr)) + goto oom; + + if (!build_message_query (&qstr, src_con->label, bustype, destination, + dst_con->label, path, interface, member)) + { + _dbus_string_free (&qstr); + goto oom; + } + + res = aa_query_label (src_perm, + _dbus_string_get_data (&qstr), + _dbus_string_get_length (&qstr), + &src_allow, &src_audit); + _dbus_string_free (&qstr); + if (res == -1) + { + src_errno = errno; + set_error_from_query_errno (error, src_errno); + goto audit; + } + } + + if (is_unconfined (dst_con->label, dst_con->mode)) + { + dst_allow = TRUE; + dst_audit = FALSE; + } + else + { + if (!_dbus_string_init (&qstr)) + goto oom; + + if (!build_message_query (&qstr, dst_con->label, bustype, source, + src_con->label, path, interface, member)) + { + _dbus_string_free (&qstr); + goto oom; + } + + res = aa_query_label (dst_perm, + _dbus_string_get_data (&qstr), + _dbus_string_get_length (&qstr), + &dst_allow, &dst_audit); + _dbus_string_free (&qstr); + if (res == -1) + { + dst_errno = errno; + set_error_from_query_errno (error, dst_errno); + goto audit; + } + } + + /* Don't fail operations on profiles in complain mode */ + if (modestr_is_complain (src_con->mode)) + src_allow = TRUE; + if (modestr_is_complain (dst_con->mode)) + dst_allow = TRUE; + + if (!src_allow || !dst_allow) + set_error_from_denied_message (error, + sender, + proposed_recipient, + requested_reply, + msgtypestr, + path, + interface, + member, + error_name, + destination); + + /* Don't audit the message if one of the following conditions is true: + * 1) The AppArmor query indicates that auditing should not happen. + * 2) The message is a reply type. Reply message are not audited because + * the AppArmor policy language does not have the notion of a reply + * message. Unrequested replies will be silently discarded if the sender + * does not have permission to send to the receiver or if the receiver + * does not have permission to receive from the sender. + */ + if ((!src_audit && !dst_audit) || + (msgtype == DBUS_MESSAGE_TYPE_METHOD_RETURN || + msgtype == DBUS_MESSAGE_TYPE_ERROR)) + goto out; + + audit: + if (!_dbus_string_init (&auxdata)) + goto oom; + free_auxdata = TRUE; + + if (!_dbus_append_pair_str (&auxdata, "bus", bustype ? bustype : "unknown")) + goto oom; + + if (path && !_dbus_append_pair_str (&auxdata, "path", path)) + goto oom; + + if (interface && !_dbus_append_pair_str (&auxdata, "interface", interface)) + goto oom; + + if (member && !_dbus_append_pair_str (&auxdata, "member", member)) + goto oom; + + if (error_name && !_dbus_append_pair_str (&auxdata, "error_name", error_name)) + goto oom; + + len = _dbus_string_get_length (&auxdata); + + if (src_audit) + { + if (!_dbus_append_mask (&auxdata, src_perm)) + goto oom; + + if (destination && !_dbus_append_pair_str (&auxdata, "name", destination)) + goto oom; + + if (sender && dbus_connection_get_unix_process_id (sender, &pid) && + !_dbus_append_pair_uint (&auxdata, "pid", pid)) + goto oom; + + if (src_con->label && + !_dbus_append_pair_str (&auxdata, "label", src_con->label)) + goto oom; + + if (proposed_recipient && + dbus_connection_get_unix_process_id (proposed_recipient, &pid) && + !_dbus_append_pair_uint (&auxdata, "peer_pid", pid)) + goto oom; + + if (dst_con->label && + !_dbus_append_pair_str (&auxdata, "peer_label", dst_con->label)) + goto oom; + + if (src_errno && !_dbus_append_pair_str (&auxdata, "info", strerror (src_errno))) + goto oom; + + if (dst_errno && + !_dbus_append_pair_str (&auxdata, "peer_info", strerror (dst_errno))) + goto oom; + + log_message (src_allow, msgtypestr, &auxdata); + } + if (dst_audit) + { + _dbus_string_set_length (&auxdata, len); + + if (source && !_dbus_append_pair_str (&auxdata, "name", source)) + goto oom; + + if (!_dbus_append_mask (&auxdata, dst_perm)) + goto oom; + + if (proposed_recipient && + dbus_connection_get_unix_process_id (proposed_recipient, &pid) && + !_dbus_append_pair_uint (&auxdata, "pid", pid)) + goto oom; + + if (dst_con->label && + !_dbus_append_pair_str (&auxdata, "label", dst_con->label)) + goto oom; + + if (sender && dbus_connection_get_unix_process_id (sender, &pid) && + !_dbus_append_pair_uint (&auxdata, "peer_pid", pid)) + goto oom; + + if (src_con->label && + !_dbus_append_pair_str (&auxdata, "peer_label", src_con->label)) + goto oom; + + if (dst_errno && !_dbus_append_pair_str (&auxdata, "info", strerror (dst_errno))) + goto oom; + + if (src_errno && + !_dbus_append_pair_str (&auxdata, "peer_info", strerror (src_errno))) + goto oom; + + log_message (dst_allow, msgtypestr, &auxdata); + } + + out: + if (src_con != NULL) + bus_apparmor_confinement_unref (src_con); + if (dst_con != NULL) + bus_apparmor_confinement_unref (dst_con); + if (free_auxdata) + _dbus_string_free (&auxdata); + + return src_allow && dst_allow; + + oom: + if (error != NULL && !dbus_error_is_set (error)) + BUS_SET_OOM (error); + src_allow = FALSE; + dst_allow = FALSE; + goto out; + +#else + return TRUE; +#endif /* HAVE_APPARMOR */ +} + +/** + * Check if Apparmor security controls allow the connection to eavesdrop on + * other connections. + * + * @param connection the connection attempting to eavesdrop. + * @param bustype name of the bus + * @param error the reason for failure when FALSE is returned + * @returns TRUE if eavesdropping is permitted + */ +dbus_bool_t +bus_apparmor_allows_eavesdropping (DBusConnection *connection, + const char *bustype, + DBusError *error) +{ +#ifdef HAVE_APPARMOR + BusAppArmorConfinement *con = NULL; + DBusString qstr, auxdata; + dbus_bool_t allow = FALSE, audit = TRUE; + dbus_bool_t free_auxdata = FALSE; + unsigned long pid; + int res, serrno = 0; + + if (!apparmor_enabled) + return TRUE; + + con = bus_connection_dup_apparmor_confinement (connection); + + if (is_unconfined (con->label, con->mode)) + { + allow = TRUE; + audit = FALSE; + goto out; + } + + if (!_dbus_string_init (&qstr)) + goto oom; + + if (!build_eavesdrop_query (&qstr, con->label, bustype)) + { + _dbus_string_free (&qstr); + goto oom; + } + + res = aa_query_label (AA_DBUS_EAVESDROP, + _dbus_string_get_data (&qstr), + _dbus_string_get_length (&qstr), + &allow, &audit); + _dbus_string_free (&qstr); + if (res == -1) + { + serrno = errno; + set_error_from_query_errno (error, serrno); + goto audit; + } + + /* Don't fail operations on profiles in complain mode */ + if (modestr_is_complain (con->mode)) + allow = TRUE; + + if (!allow) + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "Connection \"%s\" is not allowed to eavesdrop due to " + "AppArmor policy", + bus_connection_is_active (connection) ? + bus_connection_get_name (connection) : "(inactive)"); + + if (!audit) + goto out; + + audit: + if (!_dbus_string_init (&auxdata)) + goto oom; + free_auxdata = TRUE; + + if (!_dbus_append_pair_str (&auxdata, "bus", bustype ? bustype : "unknown")) + goto oom; + + if (serrno && !_dbus_append_pair_str (&auxdata, "info", strerror (serrno))) + goto oom; + + if (!_dbus_append_pair_str (&auxdata, "mask", "eavesdrop")) + goto oom; + + if (connection && dbus_connection_get_unix_process_id (connection, &pid) && + !_dbus_append_pair_uint (&auxdata, "pid", pid)) + goto oom; + + if (con->label && !_dbus_append_pair_str (&auxdata, "label", con->label)) + goto oom; + + log_message (allow, "eavesdrop", &auxdata); + + out: + if (con != NULL) + bus_apparmor_confinement_unref (con); + if (free_auxdata) + _dbus_string_free (&auxdata); + + return allow; + + oom: + if (error != NULL && !dbus_error_is_set (error)) + BUS_SET_OOM (error); + allow = FALSE; + goto out; + +#else + return TRUE; +#endif /* HAVE_APPARMOR */ +}
diff --git a/bus/apparmor.h b/bus/apparmor.h new file mode 100644 index 0000000..18f3ee7 --- /dev/null +++ b/bus/apparmor.h
@@ -0,0 +1,65 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * apparmor.c AppArmor security checks for D-Bus + * + * Authors: John Johansen <john.johansen@canonical.com> + * Tyler Hicks <tyhicks@canonical.com> + * Based on: selinux.h by Matthew Rickard + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_APPARMOR_H +#define BUS_APPARMOR_H + +#include <dbus/dbus.h> +#include "bus.h" + +dbus_bool_t bus_apparmor_pre_init (void); +dbus_bool_t bus_apparmor_set_mode_from_config (const char *mode, + DBusError *error); +dbus_bool_t bus_apparmor_full_init (DBusError *error); +void bus_apparmor_shutdown (void); +dbus_bool_t bus_apparmor_enabled (void); + +void bus_apparmor_confinement_unref (BusAppArmorConfinement *confinement); +void bus_apparmor_confinement_ref (BusAppArmorConfinement *confinement); +BusAppArmorConfinement* bus_apparmor_init_connection_confinement (DBusConnection *connection, + DBusError *error); + +dbus_bool_t bus_apparmor_allows_acquire_service (DBusConnection *connection, + const char *bustype, + const char *service_name, + DBusError *error); +dbus_bool_t bus_apparmor_allows_send (DBusConnection *sender, + DBusConnection *proposed_recipient, + dbus_bool_t requested_reply, + const char *bustype, + int msgtype, + const char *path, + const char *interface, + const char *member, + const char *error_name, + const char *destination, + const char *source, + DBusError *error); + +dbus_bool_t bus_apparmor_allows_eavesdropping (DBusConnection *connection, + const char *bustype, + DBusError *error); + +#endif /* BUS_APPARMOR_H */
diff --git a/bus/audit.c b/bus/audit.c new file mode 100644 index 0000000..7705e42 --- /dev/null +++ b/bus/audit.c
@@ -0,0 +1,189 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * audit.c - libaudit integration for SELinux and AppArmor + * + * Based on apparmor.c, selinux.c + * + * Copyright © 2014-2015 Canonical, Ltd. + * Copyright © 2015 Collabora Ltd. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "audit.h" + +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif + +#ifdef HAVE_LIBAUDIT +#include <cap-ng.h> +#include <libaudit.h> +#endif + +#include <dbus/dbus-internals.h> +#ifdef DBUS_UNIX +#include <dbus/dbus-userdb.h> +#endif + +#ifdef HAVE_LIBAUDIT +static int audit_fd = -1; +#endif + +/** + * Open the libaudit fd if appropriate. + */ +void +bus_audit_init (BusContext *context) +{ +#ifdef HAVE_LIBAUDIT + int i; + + capng_get_caps_process (); + + /* Work around a bug in libcap-ng < 0.7.7: it leaks a fd, which isn't + * close-on-exec. Assume it will be one of the first few fds. */ + for (i = 3; i < 42; i++) + _dbus_fd_set_close_on_exec (i); + + if (!capng_have_capability (CAPNG_EFFECTIVE, CAP_AUDIT_WRITE)) + return; + + audit_fd = audit_open (); + + if (audit_fd < 0) + { + int e = errno; + + /* If kernel doesn't support audit, bail out */ + if (e == EINVAL || e == EPROTONOSUPPORT || e == EAFNOSUPPORT) + return; + + bus_context_log (context, DBUS_SYSTEM_LOG_WARNING, + "Failed to open connection to the audit subsystem: %s", + _dbus_strerror (e)); + } +#endif /* HAVE_LIBAUDIT */ +} + +/** + * If libaudit is in use and it would be appropriate to write audit records, + * return the libaudit fd. Otherwise return -1. + */ +int +bus_audit_get_fd (void) +{ +#ifdef HAVE_LIBAUDIT + if (audit_fd >= 0) + { + return audit_fd; + } +#endif + + return -1; +} + +/** + * Close the libaudit fd. + */ +void +bus_audit_shutdown (void) +{ +#ifdef HAVE_LIBAUDIT + audit_close (audit_fd); +#endif /* HAVE_LIBAUDIT */ +} + +/* The !HAVE_LIBAUDIT case lives in dbus-sysdeps-util-unix.c */ +#ifdef HAVE_LIBAUDIT +/** + * Changes the user and group the bus is running as. + * + * @param user the user to become + * @param error return location for errors + * @returns #FALSE on failure + */ +dbus_bool_t +_dbus_change_to_daemon_user (const char *user, + DBusError *error) +{ + dbus_uid_t uid; + dbus_gid_t gid; + DBusString u; + + _dbus_string_init_const (&u, user); + + if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "User '%s' does not appear to exist?", + user); + return FALSE; + } + + /* If we were root */ + if (_dbus_geteuid () == 0) + { + int rc; + int have_audit_write; + + have_audit_write = capng_have_capability (CAPNG_PERMITTED, CAP_AUDIT_WRITE); + capng_clear (CAPNG_SELECT_BOTH); + /* Only attempt to retain CAP_AUDIT_WRITE if we had it when + * starting. See: + * https://bugs.freedesktop.org/show_bug.cgi?id=49062#c9 + */ + if (have_audit_write) + capng_update (CAPNG_ADD, CAPNG_EFFECTIVE | CAPNG_PERMITTED, + CAP_AUDIT_WRITE); + rc = capng_change_id (uid, gid, CAPNG_DROP_SUPP_GRP); + if (rc) + { + switch (rc) { + default: + dbus_set_error (error, DBUS_ERROR_FAILED, + "Failed to drop capabilities: %s\n", + _dbus_strerror (errno)); + break; + case -4: + dbus_set_error (error, _dbus_error_from_errno (errno), + "Failed to set GID to %lu: %s", gid, + _dbus_strerror (errno)); + break; + case -5: + _dbus_warn ("Failed to drop supplementary groups: %s\n", + _dbus_strerror (errno)); + break; + case -6: + dbus_set_error (error, _dbus_error_from_errno (errno), + "Failed to set UID to %lu: %s", uid, + _dbus_strerror (errno)); + break; + case -7: + dbus_set_error (error, _dbus_error_from_errno (errno), + "Failed to unset keep-capabilities: %s\n", + _dbus_strerror (errno)); + break; + } + return FALSE; + } + } + + return TRUE; +} +#endif
diff --git a/bus/audit.h b/bus/audit.h new file mode 100644 index 0000000..e17016f --- /dev/null +++ b/bus/audit.h
@@ -0,0 +1,33 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * audit.h - libaudit integration for SELinux and AppArmor + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_AUDIT_H +#define BUS_AUDIT_H + +#include <dbus/dbus.h> + +#include "bus.h" + +void bus_audit_init (BusContext *context); +int bus_audit_get_fd (void); +void bus_audit_shutdown (void); + +#endif
diff --git a/bus/bus.c b/bus/bus.c new file mode 100644 index 0000000..128ae3c --- /dev/null +++ b/bus/bus.c
@@ -0,0 +1,1813 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* bus.c message bus context object + * + * Copyright (C) 2003, 2004 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "bus.h" + +#include <stdio.h> + +#include "activation.h" +#include "connection.h" +#include "services.h" +#include "utils.h" +#include "policy.h" +#include "config-parser.h" +#include "signals.h" +#include "selinux.h" +#include "apparmor.h" +#include "audit.h" +#include "dir-watch.h" +#include <dbus/dbus-list.h> +#include <dbus/dbus-hash.h> +#include <dbus/dbus-credentials.h> +#include <dbus/dbus-internals.h> +#include <dbus/dbus-server-protected.h> + +#ifdef DBUS_CYGWIN +#include <signal.h> +#endif + +struct BusContext +{ + int refcount; + DBusGUID uuid; + char *config_file; + char *type; + char *servicehelper; + char *address; + char *pidfile; + char *user; + char *log_prefix; + DBusLoop *loop; + DBusList *servers; + BusConnections *connections; + BusActivation *activation; + BusRegistry *registry; + BusPolicy *policy; + BusMatchmaker *matchmaker; + BusLimits limits; + DBusRLimit *initial_fd_limit; + unsigned int fork : 1; + unsigned int syslog : 1; + unsigned int keep_umask : 1; + unsigned int allow_anonymous : 1; + unsigned int systemd_activation : 1; + dbus_bool_t watches_enabled; +}; + +static dbus_int32_t server_data_slot = -1; + +typedef struct +{ + BusContext *context; +} BusServerData; + +#define BUS_SERVER_DATA(server) (dbus_server_get_data ((server), server_data_slot)) + +static BusContext* +server_get_context (DBusServer *server) +{ + BusContext *context; + BusServerData *bd; + + if (!dbus_server_allocate_data_slot (&server_data_slot)) + return NULL; + + bd = BUS_SERVER_DATA (server); + if (bd == NULL) + { + dbus_server_free_data_slot (&server_data_slot); + return NULL; + } + + context = bd->context; + + dbus_server_free_data_slot (&server_data_slot); + + return context; +} + +static dbus_bool_t +add_server_watch (DBusWatch *watch, + void *data) +{ + DBusServer *server = data; + BusContext *context; + + context = server_get_context (server); + + return _dbus_loop_add_watch (context->loop, watch); +} + +static void +remove_server_watch (DBusWatch *watch, + void *data) +{ + DBusServer *server = data; + BusContext *context; + + context = server_get_context (server); + + _dbus_loop_remove_watch (context->loop, watch); +} + +static void +toggle_server_watch (DBusWatch *watch, + void *data) +{ + DBusServer *server = data; + BusContext *context; + + context = server_get_context (server); + + _dbus_loop_toggle_watch (context->loop, watch); +} + +static dbus_bool_t +add_server_timeout (DBusTimeout *timeout, + void *data) +{ + DBusServer *server = data; + BusContext *context; + + context = server_get_context (server); + + return _dbus_loop_add_timeout (context->loop, timeout); +} + +static void +remove_server_timeout (DBusTimeout *timeout, + void *data) +{ + DBusServer *server = data; + BusContext *context; + + context = server_get_context (server); + + _dbus_loop_remove_timeout (context->loop, timeout); +} + +static void +new_connection_callback (DBusServer *server, + DBusConnection *new_connection, + void *data) +{ + BusContext *context = data; + + if (!bus_connections_setup_connection (context->connections, new_connection)) + { + _dbus_verbose ("No memory to setup new connection\n"); + + /* if we don't do this, it will get unref'd without + * being disconnected... kind of strange really + * that we have to do this, people won't get it right + * in general. + */ + dbus_connection_close (new_connection); + } + + dbus_connection_set_max_received_size (new_connection, + context->limits.max_incoming_bytes); + + dbus_connection_set_max_message_size (new_connection, + context->limits.max_message_size); + + dbus_connection_set_max_received_unix_fds (new_connection, + context->limits.max_incoming_unix_fds); + + dbus_connection_set_max_message_unix_fds (new_connection, + context->limits.max_message_unix_fds); + + dbus_connection_set_allow_anonymous (new_connection, + context->allow_anonymous); + + /* on OOM, we won't have ref'd the connection so it will die. */ +} + +static void +free_server_data (void *data) +{ + BusServerData *bd = data; + + dbus_free (bd); +} + +static dbus_bool_t +setup_server (BusContext *context, + DBusServer *server, + char **auth_mechanisms, + DBusError *error) +{ + BusServerData *bd; + + bd = dbus_new0 (BusServerData, 1); + if (bd == NULL || !dbus_server_set_data (server, + server_data_slot, + bd, free_server_data)) + { + dbus_free (bd); + BUS_SET_OOM (error); + return FALSE; + } + + bd->context = context; + + if (!dbus_server_set_auth_mechanisms (server, (const char**) auth_mechanisms)) + { + BUS_SET_OOM (error); + return FALSE; + } + + dbus_server_set_new_connection_function (server, + new_connection_callback, + context, NULL); + + if (!dbus_server_set_watch_functions (server, + add_server_watch, + remove_server_watch, + toggle_server_watch, + server, + NULL)) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!dbus_server_set_timeout_functions (server, + add_server_timeout, + remove_server_timeout, + NULL, + server, NULL)) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; +} + +/* This code only gets executed the first time the + * config files are parsed. It is not executed + * when config files are reloaded. + */ +static dbus_bool_t +process_config_first_time_only (BusContext *context, + BusConfigParser *parser, + const DBusString *address, + BusContextFlags flags, + DBusError *error) +{ + DBusString log_prefix; + DBusList *link; + DBusList **addresses; + const char *user, *pidfile; + char **auth_mechanisms; + DBusList **auth_mechanisms_list; + int len; + dbus_bool_t retval; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + retval = FALSE; + auth_mechanisms = NULL; + pidfile = NULL; + + _dbus_init_system_log (TRUE); + + if (flags & BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION) + context->systemd_activation = TRUE; + else + context->systemd_activation = FALSE; + + /* Check for an existing pid file. Of course this is a race; + * we'd have to use fcntl() locks on the pid file to + * avoid that. But we want to check for the pid file + * before overwriting any existing sockets, etc. + */ + + if (flags & BUS_CONTEXT_FLAG_WRITE_PID_FILE) + pidfile = bus_config_parser_get_pidfile (parser); + + if (pidfile != NULL) + { + DBusString u; + DBusStat stbuf; + + _dbus_string_init_const (&u, pidfile); + + if (_dbus_stat (&u, &stbuf, NULL)) + { +#ifdef DBUS_CYGWIN + DBusString p; + long /* int */ pid; + + _dbus_string_init (&p); + _dbus_file_get_contents(&p, &u, NULL); + _dbus_string_parse_int(&p, 0, &pid, NULL); + _dbus_string_free(&p); + + if ((kill((int)pid, 0))) { + dbus_set_error(NULL, DBUS_ERROR_FILE_EXISTS, + "pid %ld not running, removing stale pid file\n", + pid); + _dbus_delete_file(&u, NULL); + } else { +#endif + dbus_set_error (error, DBUS_ERROR_FAILED, + "The pid file \"%s\" exists, if the message bus is not running, remove this file", + pidfile); + goto failed; +#ifdef DBUS_CYGWIN + } +#endif + } + } + + /* keep around the pid filename so we can delete it later */ + context->pidfile = _dbus_strdup (pidfile); + + /* note that type may be NULL */ + context->type = _dbus_strdup (bus_config_parser_get_type (parser)); + if (bus_config_parser_get_type (parser) != NULL && context->type == NULL) + goto oom; + + user = bus_config_parser_get_user (parser); + if (user != NULL) + { + context->user = _dbus_strdup (user); + if (context->user == NULL) + goto oom; + } + + /* Set up the prefix for syslog messages */ + if (!_dbus_string_init (&log_prefix)) + goto oom; + if (context->type && !strcmp (context->type, "system")) + { + if (!_dbus_string_append (&log_prefix, "[system] ")) + goto oom; + } + else if (context->type && !strcmp (context->type, "session")) + { + DBusCredentials *credentials; + + credentials = _dbus_credentials_new_from_current_process (); + if (!credentials) + goto oom; + if (!_dbus_string_append (&log_prefix, "[session ")) + { + _dbus_credentials_unref (credentials); + goto oom; + } + if (!_dbus_credentials_to_string_append (credentials, &log_prefix)) + { + _dbus_credentials_unref (credentials); + goto oom; + } + if (!_dbus_string_append (&log_prefix, "] ")) + { + _dbus_credentials_unref (credentials); + goto oom; + } + _dbus_credentials_unref (credentials); + } + if (!_dbus_string_steal_data (&log_prefix, &context->log_prefix)) + goto oom; + _dbus_string_free (&log_prefix); + + /* Build an array of auth mechanisms */ + + auth_mechanisms_list = bus_config_parser_get_mechanisms (parser); + len = _dbus_list_get_length (auth_mechanisms_list); + + if (len > 0) + { + int i; + + auth_mechanisms = dbus_new0 (char*, len + 1); + if (auth_mechanisms == NULL) + goto oom; + + i = 0; + link = _dbus_list_get_first_link (auth_mechanisms_list); + while (link != NULL) + { + auth_mechanisms[i] = _dbus_strdup (link->data); + if (auth_mechanisms[i] == NULL) + goto oom; + link = _dbus_list_get_next_link (auth_mechanisms_list, link); + i += 1; + } + } + else + { + auth_mechanisms = NULL; + } + + /* Listen on our addresses */ + + if (address) + { + DBusServer *server; + + server = dbus_server_listen (_dbus_string_get_const_data(address), error); + if (server == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + else if (!setup_server (context, server, auth_mechanisms, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + if (!_dbus_list_append (&context->servers, server)) + goto oom; + } + else + { + addresses = bus_config_parser_get_addresses (parser); + + link = _dbus_list_get_first_link (addresses); + while (link != NULL) + { + DBusServer *server; + + server = dbus_server_listen (link->data, error); + if (server == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + else if (!setup_server (context, server, auth_mechanisms, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + if (!_dbus_list_append (&context->servers, server)) + goto oom; + + link = _dbus_list_get_next_link (addresses, link); + } + } + + context->fork = bus_config_parser_get_fork (parser); + context->syslog = bus_config_parser_get_syslog (parser); + context->keep_umask = bus_config_parser_get_keep_umask (parser); + context->allow_anonymous = bus_config_parser_get_allow_anonymous (parser); + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + retval = TRUE; + + failed: + dbus_free_string_array (auth_mechanisms); + return retval; + + oom: + BUS_SET_OOM (error); + dbus_free_string_array (auth_mechanisms); + return FALSE; +} + +/* This code gets executed every time the config files + * are parsed: both during BusContext construction + * and on reloads. This function is slightly screwy + * since it can do a "half reload" in out-of-memory + * situations. Realistically, unlikely to ever matter. + */ +static dbus_bool_t +process_config_every_time (BusContext *context, + BusConfigParser *parser, + dbus_bool_t is_reload, + DBusError *error) +{ + DBusString full_address; + DBusList *link; + DBusList **dirs; + char *addr; + const char *servicehelper; + char *s; + + dbus_bool_t retval; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + addr = NULL; + retval = FALSE; + + if (!_dbus_string_init (&full_address)) + { + BUS_SET_OOM (error); + return FALSE; + } + + /* get our limits and timeout lengths */ + bus_config_parser_get_limits (parser, &context->limits); + + if (context->policy) + bus_policy_unref (context->policy); + context->policy = bus_config_parser_steal_policy (parser); + _dbus_assert (context->policy != NULL); + + /* context->connections is NULL when creating new BusContext */ + if (context->connections) + { + _dbus_verbose ("Reload policy rules for completed connections\n"); + retval = bus_connections_reload_policy (context->connections, error); + if (!retval) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + } + + /* We have to build the address backward, so that + * <listen> later in the config file have priority + */ + link = _dbus_list_get_last_link (&context->servers); + while (link != NULL) + { + addr = dbus_server_get_address (link->data); + if (addr == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + + if (_dbus_string_get_length (&full_address) > 0) + { + if (!_dbus_string_append (&full_address, ";")) + { + BUS_SET_OOM (error); + goto failed; + } + } + + if (!_dbus_string_append (&full_address, addr)) + { + BUS_SET_OOM (error); + goto failed; + } + + dbus_free (addr); + addr = NULL; + + link = _dbus_list_get_prev_link (&context->servers, link); + } + + if (is_reload) + dbus_free (context->address); + + if (!_dbus_string_copy_data (&full_address, &context->address)) + { + BUS_SET_OOM (error); + goto failed; + } + + /* get the service directories */ + dirs = bus_config_parser_get_service_dirs (parser); + + /* and the service helper */ + servicehelper = bus_config_parser_get_servicehelper (parser); + + s = _dbus_strdup(servicehelper); + if (s == NULL && servicehelper != NULL) + { + BUS_SET_OOM (error); + goto failed; + } + else + { + dbus_free(context->servicehelper); + context->servicehelper = s; + } + + /* Create activation subsystem */ + if (context->activation) + { + if (!bus_activation_reload (context->activation, &full_address, dirs, error)) + goto failed; + } + else + { + context->activation = bus_activation_new (context, &full_address, dirs, error); + } + + if (context->activation == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + retval = TRUE; + + failed: + _dbus_string_free (&full_address); + + if (addr) + dbus_free (addr); + + return retval; +} + +static dbus_bool_t +list_concat_new (DBusList **a, + DBusList **b, + DBusList **result) +{ + DBusList *link; + + *result = NULL; + + for (link = _dbus_list_get_first_link (a); link; link = _dbus_list_get_next_link (a, link)) + { + if (!_dbus_list_append (result, link->data)) + goto oom; + } + for (link = _dbus_list_get_first_link (b); link; link = _dbus_list_get_next_link (b, link)) + { + if (!_dbus_list_append (result, link->data)) + goto oom; + } + + return TRUE; +oom: + _dbus_list_clear (result); + return FALSE; +} + +static void +raise_file_descriptor_limit (BusContext *context) +{ +#ifdef DBUS_UNIX + DBusError error = DBUS_ERROR_INIT; + + /* we only do this once */ + if (context->initial_fd_limit != NULL) + return; + + context->initial_fd_limit = _dbus_rlimit_save_fd_limit (&error); + + if (context->initial_fd_limit == NULL) + { + bus_context_log (context, DBUS_SYSTEM_LOG_WARNING, + "%s: %s", error.name, error.message); + dbus_error_free (&error); + return; + } + + /* We used to compute a suitable rlimit based on the configured number + * of connections, but that breaks down as soon as we allow fd-passing, + * because each connection is allowed to pass 64 fds to us, and if + * they all did, we'd hit kernel limits. We now hard-code 64k as a + * good limit, like systemd does: that's enough to avoid DoS from + * anything short of multiple uids conspiring against us. + */ + if (!_dbus_rlimit_raise_fd_limit_if_privileged (65536, &error)) + { + bus_context_log (context, DBUS_SYSTEM_LOG_WARNING, + "%s: %s", error.name, error.message); + dbus_error_free (&error); + return; + } +#endif +} + +static dbus_bool_t +process_config_postinit (BusContext *context, + BusConfigParser *parser, + DBusError *error) +{ + DBusHashTable *service_context_table; + DBusList *watched_dirs = NULL; + + raise_file_descriptor_limit (context); + + service_context_table = bus_config_parser_steal_service_context_table (parser); + if (!bus_registry_set_service_context_table (context->registry, + service_context_table)) + { + BUS_SET_OOM (error); + return FALSE; + } + + _dbus_hash_table_unref (service_context_table); + + /* We need to monitor both the configuration directories and directories + * containing .service files. + */ + if (!list_concat_new (bus_config_parser_get_conf_dirs (parser), + bus_config_parser_get_service_dirs (parser), + &watched_dirs)) + { + BUS_SET_OOM (error); + return FALSE; + } + + bus_set_watched_dirs (context, &watched_dirs); + + _dbus_list_clear (&watched_dirs); + + return TRUE; +} + +BusContext* +bus_context_new (const DBusString *config_file, + BusContextFlags flags, + DBusPipe *print_addr_pipe, + DBusPipe *print_pid_pipe, + const DBusString *address, + DBusError *error) +{ + BusContext *context; + BusConfigParser *parser; + + _dbus_assert ((flags & BUS_CONTEXT_FLAG_FORK_NEVER) == 0 || + (flags & BUS_CONTEXT_FLAG_FORK_ALWAYS) == 0); + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + context = NULL; + parser = NULL; + + if (!dbus_server_allocate_data_slot (&server_data_slot)) + { + BUS_SET_OOM (error); + return NULL; + } + + context = dbus_new0 (BusContext, 1); + if (context == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + context->refcount = 1; + + if (!_dbus_generate_uuid (&context->uuid, error)) + goto failed; + + if (!_dbus_string_copy_data (config_file, &context->config_file)) + { + BUS_SET_OOM (error); + goto failed; + } + + context->loop = _dbus_loop_new (); + if (context->loop == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + + context->watches_enabled = TRUE; + + context->registry = bus_registry_new (context); + if (context->registry == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + + parser = bus_config_load (config_file, TRUE, NULL, error); + if (parser == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + if (!process_config_first_time_only (context, parser, address, flags, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + if (!process_config_every_time (context, parser, FALSE, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + /* we need another ref of the server data slot for the context + * to own + */ + if (!dbus_server_allocate_data_slot (&server_data_slot)) + _dbus_assert_not_reached ("second ref of server data slot failed"); + + /* Note that we don't know whether the print_addr_pipe is + * one of the sockets we're using to listen on, or some + * other random thing. But I think the answer is "don't do + * that then" + */ + if (print_addr_pipe != NULL && _dbus_pipe_is_valid (print_addr_pipe)) + { + DBusString addr; + const char *a = bus_context_get_address (context); + int bytes; + + _dbus_assert (a != NULL); + if (!_dbus_string_init (&addr)) + { + BUS_SET_OOM (error); + goto failed; + } + + if (!_dbus_string_append (&addr, a) || + !_dbus_string_append (&addr, "\n")) + { + _dbus_string_free (&addr); + BUS_SET_OOM (error); + goto failed; + } + + bytes = _dbus_string_get_length (&addr); + if (_dbus_pipe_write (print_addr_pipe, &addr, 0, bytes, error) != bytes) + { + /* pipe write returns an error on failure but not short write */ + if (error != NULL && !dbus_error_is_set (error)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Printing message bus address: did not write all bytes\n"); + } + _dbus_string_free (&addr); + goto failed; + } + + if (!_dbus_pipe_is_stdout_or_stderr (print_addr_pipe)) + _dbus_pipe_close (print_addr_pipe, NULL); + + _dbus_string_free (&addr); + } + + context->connections = bus_connections_new (context); + if (context->connections == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + + context->matchmaker = bus_matchmaker_new (); + if (context->matchmaker == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + + /* check user before we fork */ + if (context->user != NULL) + { + if (!_dbus_verify_daemon_user (context->user)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Could not get UID and GID for username \"%s\"", + context->user); + goto failed; + } + } + + /* Now become a daemon if appropriate and write out pid file in any case */ + { + DBusString u; + + if (context->pidfile) + _dbus_string_init_const (&u, context->pidfile); + + if (((flags & BUS_CONTEXT_FLAG_FORK_NEVER) == 0 && context->fork) || + (flags & BUS_CONTEXT_FLAG_FORK_ALWAYS)) + { + _dbus_verbose ("Forking and becoming daemon\n"); + + if (!_dbus_become_daemon (context->pidfile ? &u : NULL, + print_pid_pipe, + error, + context->keep_umask)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + } + else + { + _dbus_verbose ("Fork not requested\n"); + + /* Need to write PID file and to PID pipe for ourselves, + * not for the child process. This is a no-op if the pidfile + * is NULL and print_pid_pipe is NULL. + */ + if (!_dbus_write_pid_to_file_and_pipe (context->pidfile ? &u : NULL, + print_pid_pipe, + _dbus_getpid (), + error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + } + } + + if (print_pid_pipe && _dbus_pipe_is_valid (print_pid_pipe) && + !_dbus_pipe_is_stdout_or_stderr (print_pid_pipe)) + _dbus_pipe_close (print_pid_pipe, NULL); + + if (!bus_selinux_full_init ()) + { + bus_context_log (context, DBUS_SYSTEM_LOG_FATAL, "SELinux enabled but D-Bus initialization failed; check system log\n"); + } + + if (!bus_apparmor_full_init (error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + if (bus_apparmor_enabled ()) + { + /* Only print AppArmor mediation message when syslog support is enabled */ + if (context->syslog) + bus_context_log (context, DBUS_SYSTEM_LOG_INFO, + "AppArmor D-Bus mediation is enabled\n"); + } + + if (!process_config_postinit (context, parser, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + if (parser != NULL) + { + bus_config_parser_unref (parser); + parser = NULL; + } + + /* Here we change our credentials if required, + * as soon as we've set up our sockets and pidfile + */ + if (context->user != NULL) + { + if (!_dbus_change_to_daemon_user (context->user, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + } + + bus_audit_init (context); + + dbus_server_free_data_slot (&server_data_slot); + + return context; + + failed: + if (parser != NULL) + bus_config_parser_unref (parser); + if (context != NULL) + bus_context_unref (context); + + if (server_data_slot >= 0) + dbus_server_free_data_slot (&server_data_slot); + + return NULL; +} + +dbus_bool_t +bus_context_get_id (BusContext *context, + DBusString *uuid) +{ + return _dbus_uuid_encode (&context->uuid, uuid); +} + +dbus_bool_t +bus_context_reload_config (BusContext *context, + DBusError *error) +{ + BusConfigParser *parser; + DBusString config_file; + dbus_bool_t ret; + + /* Flush the user database cache */ + _dbus_flush_caches (); + + ret = FALSE; + _dbus_string_init_const (&config_file, context->config_file); + parser = bus_config_load (&config_file, TRUE, NULL, error); + if (parser == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + if (!process_config_every_time (context, parser, TRUE, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + if (!process_config_postinit (context, parser, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + ret = TRUE; + + bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Reloaded configuration"); + failed: + if (!ret) + bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Unable to reload configuration: %s", error->message); + if (parser != NULL) + bus_config_parser_unref (parser); + return ret; +} + +static void +shutdown_server (BusContext *context, + DBusServer *server) +{ + if (server == NULL || + !dbus_server_get_is_connected (server)) + return; + + if (!dbus_server_set_watch_functions (server, + NULL, NULL, NULL, + context, + NULL)) + _dbus_assert_not_reached ("setting watch functions to NULL failed"); + + if (!dbus_server_set_timeout_functions (server, + NULL, NULL, NULL, + context, + NULL)) + _dbus_assert_not_reached ("setting timeout functions to NULL failed"); + + dbus_server_disconnect (server); +} + +void +bus_context_shutdown (BusContext *context) +{ + DBusList *link; + + link = _dbus_list_get_first_link (&context->servers); + while (link != NULL) + { + shutdown_server (context, link->data); + + link = _dbus_list_get_next_link (&context->servers, link); + } +} + +BusContext * +bus_context_ref (BusContext *context) +{ + _dbus_assert (context->refcount > 0); + context->refcount += 1; + + return context; +} + +void +bus_context_unref (BusContext *context) +{ + _dbus_assert (context->refcount > 0); + context->refcount -= 1; + + if (context->refcount == 0) + { + DBusList *link; + + _dbus_verbose ("Finalizing bus context %p\n", context); + + bus_context_shutdown (context); + + if (context->connections) + { + bus_connections_unref (context->connections); + context->connections = NULL; + } + + if (context->registry) + { + bus_registry_unref (context->registry); + context->registry = NULL; + } + + if (context->activation) + { + bus_activation_unref (context->activation); + context->activation = NULL; + } + + link = _dbus_list_get_first_link (&context->servers); + while (link != NULL) + { + dbus_server_unref (link->data); + + link = _dbus_list_get_next_link (&context->servers, link); + } + _dbus_list_clear (&context->servers); + + if (context->policy) + { + bus_policy_unref (context->policy); + context->policy = NULL; + } + + if (context->loop) + { + _dbus_loop_unref (context->loop); + context->loop = NULL; + } + + if (context->matchmaker) + { + bus_matchmaker_unref (context->matchmaker); + context->matchmaker = NULL; + } + + dbus_free (context->config_file); + dbus_free (context->log_prefix); + dbus_free (context->type); + dbus_free (context->address); + dbus_free (context->user); + dbus_free (context->servicehelper); + + if (context->pidfile) + { + DBusString u; + _dbus_string_init_const (&u, context->pidfile); + + /* Deliberately ignore errors here, since there's not much + * we can do about it, and we're exiting anyways. + */ + _dbus_delete_file (&u, NULL); + + dbus_free (context->pidfile); + } + + if (context->initial_fd_limit) + _dbus_rlimit_free (context->initial_fd_limit); + + dbus_free (context); + + dbus_server_free_data_slot (&server_data_slot); + } +} + +/* type may be NULL */ +const char* +bus_context_get_type (BusContext *context) +{ + return context->type; +} + +const char* +bus_context_get_address (BusContext *context) +{ + return context->address; +} + +const char* +bus_context_get_servicehelper (BusContext *context) +{ + return context->servicehelper; +} + +dbus_bool_t +bus_context_get_systemd_activation (BusContext *context) +{ + return context->systemd_activation; +} + +BusRegistry* +bus_context_get_registry (BusContext *context) +{ + return context->registry; +} + +BusConnections* +bus_context_get_connections (BusContext *context) +{ + return context->connections; +} + +BusActivation* +bus_context_get_activation (BusContext *context) +{ + return context->activation; +} + +BusMatchmaker* +bus_context_get_matchmaker (BusContext *context) +{ + return context->matchmaker; +} + +DBusLoop* +bus_context_get_loop (BusContext *context) +{ + return context->loop; +} + +dbus_bool_t +bus_context_allow_unix_user (BusContext *context, + unsigned long uid) +{ + return bus_policy_allow_unix_user (context->policy, + uid); +} + +/* For now this is never actually called because the default + * DBusConnection behavior of 'same user that owns the bus can connect' + * is all it would do. + */ +dbus_bool_t +bus_context_allow_windows_user (BusContext *context, + const char *windows_sid) +{ + return bus_policy_allow_windows_user (context->policy, + windows_sid); +} + +BusPolicy * +bus_context_get_policy (BusContext *context) +{ + return context->policy; +} + +BusClientPolicy* +bus_context_create_client_policy (BusContext *context, + DBusConnection *connection, + DBusError *error) +{ + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + return bus_policy_create_client_policy (context->policy, connection, + error); +} + +int +bus_context_get_activation_timeout (BusContext *context) +{ + + return context->limits.activation_timeout; +} + +int +bus_context_get_auth_timeout (BusContext *context) +{ + return context->limits.auth_timeout; +} + +int +bus_context_get_pending_fd_timeout (BusContext *context) +{ + return context->limits.pending_fd_timeout; +} + +int +bus_context_get_max_completed_connections (BusContext *context) +{ + return context->limits.max_completed_connections; +} + +int +bus_context_get_max_incomplete_connections (BusContext *context) +{ + return context->limits.max_incomplete_connections; +} + +int +bus_context_get_max_connections_per_user (BusContext *context) +{ + return context->limits.max_connections_per_user; +} + +int +bus_context_get_max_pending_activations (BusContext *context) +{ + return context->limits.max_pending_activations; +} + +int +bus_context_get_max_services_per_connection (BusContext *context) +{ + return context->limits.max_services_per_connection; +} + +int +bus_context_get_max_match_rules_per_connection (BusContext *context) +{ + return context->limits.max_match_rules_per_connection; +} + +int +bus_context_get_max_replies_per_connection (BusContext *context) +{ + return context->limits.max_replies_per_connection; +} + +int +bus_context_get_reply_timeout (BusContext *context) +{ + return context->limits.reply_timeout; +} + +DBusRLimit * +bus_context_get_initial_fd_limit (BusContext *context) +{ + return context->initial_fd_limit; +} + +void +bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...) +{ + va_list args; + + if (!context->syslog) + { + /* we're not syslogging; just output to stderr */ + va_start (args, msg); + vfprintf (stderr, msg, args); + fprintf (stderr, "\n"); + va_end (args); + + if (severity == DBUS_SYSTEM_LOG_FATAL) + _dbus_exit (1); + + return; + } + + va_start (args, msg); + + if (context->log_prefix) + { + DBusString full_msg; + + if (!_dbus_string_init (&full_msg)) + goto out; + if (!_dbus_string_append (&full_msg, context->log_prefix)) + goto oom_out; + if (!_dbus_string_append_printf_valist (&full_msg, msg, args)) + goto oom_out; + + _dbus_system_log (severity, "%s", _dbus_string_get_const_data (&full_msg)); + oom_out: + _dbus_string_free (&full_msg); + } + else + _dbus_system_logv (severity, msg, args); + +out: + va_end (args); +} + +static inline const char * +nonnull (const char *maybe_null, + const char *if_null) +{ + return (maybe_null ? maybe_null : if_null); +} + +void +bus_context_log_literal (BusContext *context, + DBusSystemLogSeverity severity, + const char *msg) +{ + if (!context->syslog) + { + fputs (msg, stderr); + fputc ('\n', stderr); + + if (severity == DBUS_SYSTEM_LOG_FATAL) + _dbus_exit (1); + } + else + { + _dbus_system_log (severity, "%s%s", nonnull (context->log_prefix, ""), + msg); + } +} + +void +bus_context_log_and_set_error (BusContext *context, + DBusSystemLogSeverity severity, + DBusError *error, + const char *name, + const char *msg, + ...) +{ + DBusError stack_error = DBUS_ERROR_INIT; + va_list args; + + va_start (args, msg); + _dbus_set_error_valist (&stack_error, name, msg, args); + va_end (args); + + /* If we hit OOM while setting the error, this will syslog "out of memory" + * which is itself an indication that something is seriously wrong */ + bus_context_log_literal (context, DBUS_SYSTEM_LOG_SECURITY, + stack_error.message); + + dbus_move_error (&stack_error, error); +} + +/* + * Log something about a message, usually that it was rejected. + */ +static void +complain_about_message (BusContext *context, + const char *error_name, + const char *complaint, + int matched_rules, + DBusMessage *message, + DBusConnection *sender, + DBusConnection *proposed_recipient, + dbus_bool_t requested_reply, + dbus_bool_t log, + DBusError *error) +{ + DBusError stack_error = DBUS_ERROR_INIT; + const char *sender_name; + const char *sender_loginfo; + const char *proposed_recipient_loginfo; + + if (error == NULL && !log) + return; + + if (sender != NULL) + { + sender_name = bus_connection_get_name (sender); + sender_loginfo = bus_connection_get_loginfo (sender); + } + else + { + sender_name = "(unset)"; + sender_loginfo = "(bus)"; + } + + if (proposed_recipient != NULL) + proposed_recipient_loginfo = bus_connection_get_loginfo (proposed_recipient); + else + proposed_recipient_loginfo = "bus"; + + dbus_set_error (&stack_error, error_name, + "%s, %d matched rules; type=\"%s\", sender=\"%s\" (%s) " + "interface=\"%s\" member=\"%s\" error name=\"%s\" " + "requested_reply=\"%d\" destination=\"%s\" (%s)", + complaint, + matched_rules, + dbus_message_type_to_string (dbus_message_get_type (message)), + sender_name, + sender_loginfo, + nonnull (dbus_message_get_interface (message), "(unset)"), + nonnull (dbus_message_get_member (message), "(unset)"), + nonnull (dbus_message_get_error_name (message), "(unset)"), + requested_reply, + nonnull (dbus_message_get_destination (message), DBUS_SERVICE_DBUS), + proposed_recipient_loginfo); + + /* If we hit OOM while setting the error, this will syslog "out of memory" + * which is itself an indication that something is seriously wrong */ + if (log) + bus_context_log_literal (context, DBUS_SYSTEM_LOG_SECURITY, + stack_error.message); + + dbus_move_error (&stack_error, error); +} + +/* + * addressed_recipient is the recipient specified in the message. + * + * proposed_recipient is the recipient we're considering sending + * to right this second, and may be an eavesdropper. + * + * sender is the sender of the message. + * + * NULL for proposed_recipient or sender definitely means the bus driver. + * + * NULL for addressed_recipient may mean the bus driver, or may mean + * no destination was specified in the message (e.g. a signal). + */ +dbus_bool_t +bus_context_check_security_policy (BusContext *context, + BusTransaction *transaction, + DBusConnection *sender, + DBusConnection *addressed_recipient, + DBusConnection *proposed_recipient, + DBusMessage *message, + DBusError *error) +{ + const char *src, *dest; + BusClientPolicy *sender_policy; + BusClientPolicy *recipient_policy; + dbus_int32_t toggles; + dbus_bool_t log; + int type; + dbus_bool_t requested_reply; + + type = dbus_message_get_type (message); + src = dbus_message_get_sender (message); + dest = dbus_message_get_destination (message); + + /* dispatch.c was supposed to ensure these invariants */ + _dbus_assert (dest != NULL || + type == DBUS_MESSAGE_TYPE_SIGNAL || + (sender == NULL && !bus_connection_is_active (proposed_recipient))); + _dbus_assert (type == DBUS_MESSAGE_TYPE_SIGNAL || + addressed_recipient != NULL || + strcmp (dest, DBUS_SERVICE_DBUS) == 0); + + switch (type) + { + case DBUS_MESSAGE_TYPE_METHOD_CALL: + case DBUS_MESSAGE_TYPE_SIGNAL: + case DBUS_MESSAGE_TYPE_METHOD_RETURN: + case DBUS_MESSAGE_TYPE_ERROR: + break; + + default: + _dbus_verbose ("security check disallowing message of unknown type %d\n", + type); + + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "Message bus will not accept messages of unknown type\n"); + + return FALSE; + } + + requested_reply = FALSE; + + if (sender != NULL) + { + if (bus_connection_is_active (sender)) + { + sender_policy = bus_connection_get_policy (sender); + _dbus_assert (sender_policy != NULL); + + /* Fill in requested_reply variable with TRUE if this is a + * reply and the reply was pending. + */ + if (dbus_message_get_reply_serial (message) != 0) + { + if (proposed_recipient != NULL /* not to the bus driver */ && + addressed_recipient == proposed_recipient /* not eavesdropping */) + { + DBusError error2; + + dbus_error_init (&error2); + requested_reply = bus_connections_check_reply (bus_connection_get_connections (sender), + transaction, + sender, addressed_recipient, message, + &error2); + if (dbus_error_is_set (&error2)) + { + dbus_move_error (&error2, error); + return FALSE; + } + } + } + } + else + { + sender_policy = NULL; + } + + /* First verify the SELinux access controls. If allowed then + * go on with the standard checks. + */ + if (!bus_selinux_allows_send (sender, proposed_recipient, + dbus_message_type_to_string (dbus_message_get_type (message)), + dbus_message_get_interface (message), + dbus_message_get_member (message), + dbus_message_get_error_name (message), + dest ? dest : DBUS_SERVICE_DBUS, error)) + { + if (error != NULL && !dbus_error_is_set (error)) + { + /* don't syslog this, just set the error: avc_has_perm should + * have already written to either the audit log or syslog */ + complain_about_message (context, DBUS_ERROR_ACCESS_DENIED, + "An SELinux policy prevents this sender from sending this " + "message to this recipient", + 0, message, sender, proposed_recipient, FALSE, FALSE, error); + _dbus_verbose ("SELinux security check denying send to service\n"); + } + + return FALSE; + } + + /* next verify AppArmor access controls. If allowed then + * go on with the standard checks. + */ + if (!bus_apparmor_allows_send (sender, proposed_recipient, + requested_reply, + bus_context_get_type (context), + dbus_message_get_type (message), + dbus_message_get_path (message), + dbus_message_get_interface (message), + dbus_message_get_member (message), + dbus_message_get_error_name (message), + dest ? dest : DBUS_SERVICE_DBUS, + src ? src : DBUS_SERVICE_DBUS, + error)) + return FALSE; + + if (!bus_connection_is_active (sender)) + { + /* Policy for inactive connections is that they can only send + * the hello message to the bus driver + */ + if (proposed_recipient == NULL && + dbus_message_is_method_call (message, + DBUS_INTERFACE_DBUS, + "Hello")) + { + _dbus_verbose ("security check allowing %s message\n", + "Hello"); + return TRUE; + } + else + { + _dbus_verbose ("security check disallowing non-%s message\n", + "Hello"); + + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "Client tried to send a message other than %s without being registered", + "Hello"); + + return FALSE; + } + } + } + else + { + sender_policy = NULL; + + /* If the sender is the bus driver, we assume any reply was a + * requested reply as bus driver won't send bogus ones + */ + if (addressed_recipient == proposed_recipient /* not eavesdropping */ && + dbus_message_get_reply_serial (message) != 0) + requested_reply = TRUE; + } + + _dbus_assert ((sender != NULL && sender_policy != NULL) || + (sender == NULL && sender_policy == NULL)); + + if (proposed_recipient != NULL) + { + /* only the bus driver can send to an inactive recipient (as it + * owns no services, so other apps can't address it). Inactive + * recipients can receive any message. + */ + if (bus_connection_is_active (proposed_recipient)) + { + recipient_policy = bus_connection_get_policy (proposed_recipient); + _dbus_assert (recipient_policy != NULL); + } + else if (sender == NULL) + { + _dbus_verbose ("security check using NULL recipient policy for message from bus\n"); + recipient_policy = NULL; + } + else + { + _dbus_assert_not_reached ("a message was somehow sent to an inactive recipient from a source other than the message bus\n"); + recipient_policy = NULL; + } + } + else + recipient_policy = NULL; + + _dbus_assert ((proposed_recipient != NULL && recipient_policy != NULL) || + (proposed_recipient != NULL && sender == NULL && recipient_policy == NULL) || + (proposed_recipient == NULL && recipient_policy == NULL)); + + log = FALSE; + if (sender_policy && + !bus_client_policy_check_can_send (sender_policy, + context->registry, + requested_reply, + proposed_recipient, + message, &toggles, &log)) + { + complain_about_message (context, DBUS_ERROR_ACCESS_DENIED, + "Rejected send message", toggles, + message, sender, proposed_recipient, requested_reply, + (addressed_recipient == proposed_recipient), error); + _dbus_verbose ("security policy disallowing message due to sender policy\n"); + return FALSE; + } + + if (log) + { + /* We want to drop this message, and are only not doing so for backwards + * compatibility. */ + complain_about_message (context, DBUS_ERROR_ACCESS_DENIED, + "Would reject message", toggles, + message, sender, proposed_recipient, requested_reply, + TRUE, NULL); + } + + if (recipient_policy && + !bus_client_policy_check_can_receive (recipient_policy, + context->registry, + requested_reply, + sender, + addressed_recipient, proposed_recipient, + message, &toggles)) + { + complain_about_message (context, DBUS_ERROR_ACCESS_DENIED, + "Rejected receive message", toggles, + message, sender, proposed_recipient, requested_reply, + (addressed_recipient == proposed_recipient), error); + _dbus_verbose ("security policy disallowing message due to recipient policy\n"); + return FALSE; + } + + /* See if limits on size have been exceeded */ + if (proposed_recipient && + ((dbus_connection_get_outgoing_size (proposed_recipient) > context->limits.max_outgoing_bytes) || + (dbus_connection_get_outgoing_unix_fds (proposed_recipient) > context->limits.max_outgoing_unix_fds))) + { + complain_about_message (context, DBUS_ERROR_LIMITS_EXCEEDED, + "Rejected: destination has a full message queue", + 0, message, sender, proposed_recipient, requested_reply, TRUE, + error); + _dbus_verbose ("security policy disallowing message due to full message queue\n"); + return FALSE; + } + + /* Record that we will allow a reply here in the future (don't + * bother if the recipient is the bus or this is an eavesdropping + * connection). Only the addressed recipient may reply. + */ + if (type == DBUS_MESSAGE_TYPE_METHOD_CALL && + sender && + addressed_recipient && + addressed_recipient == proposed_recipient && /* not eavesdropping */ + !bus_connections_expect_reply (bus_connection_get_connections (sender), + transaction, + sender, addressed_recipient, + message, error)) + { + _dbus_verbose ("Failed to record reply expectation or problem with the message expecting a reply\n"); + return FALSE; + } + + _dbus_verbose ("security policy allowing message\n"); + return TRUE; +} + +void +bus_context_check_all_watches (BusContext *context) +{ + DBusList *link; + dbus_bool_t enabled = TRUE; + + if (bus_connections_get_n_incomplete (context->connections) >= + bus_context_get_max_incomplete_connections (context)) + { + enabled = FALSE; + } + + if (context->watches_enabled == enabled) + return; + + context->watches_enabled = enabled; + + for (link = _dbus_list_get_first_link (&context->servers); + link != NULL; + link = _dbus_list_get_next_link (&context->servers, link)) + { + /* A BusContext might contains several DBusServer (if there are + * several <listen> configuration items) and a DBusServer might + * contain several DBusWatch in its DBusWatchList (if getaddrinfo + * returns several addresses on a dual IPv4-IPv6 stack or if + * systemd passes several fds). + * We want to enable/disable them all. + */ + DBusServer *server = link->data; + _dbus_server_toggle_all_watches (server, enabled); + } +}
diff --git a/bus/bus.h b/bus/bus.h new file mode 100644 index 0000000..3fab59f --- /dev/null +++ b/bus/bus.h
@@ -0,0 +1,143 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* bus.h message bus context object + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_BUS_H +#define BUS_BUS_H + +#include <dbus/dbus.h> +#include <dbus/dbus-string.h> +#include <dbus/dbus-mainloop.h> +#include <dbus/dbus-pipe.h> +#include <dbus/dbus-sysdeps.h> + +typedef struct BusActivation BusActivation; +typedef struct BusConnections BusConnections; +typedef struct BusContext BusContext; +typedef struct BusPolicy BusPolicy; +typedef struct BusClientPolicy BusClientPolicy; +typedef struct BusPolicyRule BusPolicyRule; +typedef struct BusRegistry BusRegistry; +typedef struct BusSELinuxID BusSELinuxID; +typedef struct BusAppArmorConfinement BusAppArmorConfinement; +typedef struct BusService BusService; +typedef struct BusOwner BusOwner; +typedef struct BusTransaction BusTransaction; +typedef struct BusMatchmaker BusMatchmaker; +typedef struct BusMatchRule BusMatchRule; + +typedef struct +{ + long max_incoming_bytes; /**< How many incoming message bytes for a single connection */ + long max_incoming_unix_fds; /**< How many incoming message unix fds for a single connection */ + long max_outgoing_bytes; /**< How many outgoing bytes can be queued for a single connection */ + long max_outgoing_unix_fds; /**< How many outgoing unix fds can be queued for a single connection */ + long max_message_size; /**< Max size of a single message in bytes */ + long max_message_unix_fds; /**< Max number of unix fds of a single message*/ + int activation_timeout; /**< How long to wait for an activation to time out */ + int auth_timeout; /**< How long to wait for an authentication to time out */ + int pending_fd_timeout; /**< How long to wait for a D-Bus message with a fd to time out */ + int max_completed_connections; /**< Max number of authorized connections */ + int max_incomplete_connections; /**< Max number of incomplete connections */ + int max_connections_per_user; /**< Max number of connections auth'd as same user */ + int max_pending_activations; /**< Max number of pending activations for the entire bus */ + int max_services_per_connection; /**< Max number of owned services for a single connection */ + int max_match_rules_per_connection; /**< Max number of match rules for a single connection */ + int max_replies_per_connection; /**< Max number of replies that can be pending for each connection */ + int reply_timeout; /**< How long to wait before timing out a reply */ +} BusLimits; + +typedef enum +{ + BUS_CONTEXT_FLAG_NONE = 0, + BUS_CONTEXT_FLAG_FORK_ALWAYS = (1 << 1), + BUS_CONTEXT_FLAG_FORK_NEVER = (1 << 2), + BUS_CONTEXT_FLAG_WRITE_PID_FILE = (1 << 3), + BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION = (1 << 4) +} BusContextFlags; + +BusContext* bus_context_new (const DBusString *config_file, + BusContextFlags flags, + DBusPipe *print_addr_pipe, + DBusPipe *print_pid_pipe, + const DBusString *address, + DBusError *error); +dbus_bool_t bus_context_reload_config (BusContext *context, + DBusError *error); +void bus_context_shutdown (BusContext *context); +BusContext* bus_context_ref (BusContext *context); +void bus_context_unref (BusContext *context); +dbus_bool_t bus_context_get_id (BusContext *context, + DBusString *uuid); +const char* bus_context_get_type (BusContext *context); +const char* bus_context_get_address (BusContext *context); +const char* bus_context_get_servicehelper (BusContext *context); +dbus_bool_t bus_context_get_systemd_activation (BusContext *context); +BusRegistry* bus_context_get_registry (BusContext *context); +BusConnections* bus_context_get_connections (BusContext *context); +BusActivation* bus_context_get_activation (BusContext *context); +BusMatchmaker* bus_context_get_matchmaker (BusContext *context); +DBusLoop* bus_context_get_loop (BusContext *context); +dbus_bool_t bus_context_allow_unix_user (BusContext *context, + unsigned long uid); +dbus_bool_t bus_context_allow_windows_user (BusContext *context, + const char *windows_sid); +BusPolicy* bus_context_get_policy (BusContext *context); + +BusClientPolicy* bus_context_create_client_policy (BusContext *context, + DBusConnection *connection, + DBusError *error); +int bus_context_get_activation_timeout (BusContext *context); +int bus_context_get_auth_timeout (BusContext *context); +int bus_context_get_pending_fd_timeout (BusContext *context); +int bus_context_get_max_completed_connections (BusContext *context); +int bus_context_get_max_incomplete_connections (BusContext *context); +int bus_context_get_max_connections_per_user (BusContext *context); +int bus_context_get_max_pending_activations (BusContext *context); +int bus_context_get_max_services_per_connection (BusContext *context); +int bus_context_get_max_match_rules_per_connection (BusContext *context); +int bus_context_get_max_replies_per_connection (BusContext *context); +int bus_context_get_reply_timeout (BusContext *context); +DBusRLimit * bus_context_get_initial_fd_limit (BusContext *context); +void bus_context_log (BusContext *context, + DBusSystemLogSeverity severity, + const char *msg, + ...) _DBUS_GNUC_PRINTF (3, 4); +void bus_context_log_literal (BusContext *context, + DBusSystemLogSeverity severity, + const char *msg); +void bus_context_log_and_set_error (BusContext *context, + DBusSystemLogSeverity severity, + DBusError *error, + const char *name, + const char *msg, + ...) _DBUS_GNUC_PRINTF (5, 6); +dbus_bool_t bus_context_check_security_policy (BusContext *context, + BusTransaction *transaction, + DBusConnection *sender, + DBusConnection *addressed_recipient, + DBusConnection *proposed_recipient, + DBusMessage *message, + DBusError *error); +void bus_context_check_all_watches (BusContext *context); + +#endif /* BUS_BUS_H */
diff --git a/bus/config-loader-expat.c b/bus/config-loader-expat.c new file mode 100644 index 0000000..b571fda --- /dev/null +++ b/bus/config-loader-expat.c
@@ -0,0 +1,294 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* config-loader-expat.c expat XML loader + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "config-parser.h" +#include <dbus/dbus-internals.h> +#include <expat.h> + +static XML_Memory_Handling_Suite memsuite; + +typedef struct +{ + BusConfigParser *parser; + const char *filename; + DBusString content; + DBusError *error; + dbus_bool_t failed; +} ExpatParseContext; + +static dbus_bool_t +process_content (ExpatParseContext *context) +{ + if (context->failed) + return FALSE; + + if (_dbus_string_get_length (&context->content) > 0) + { + if (!bus_config_parser_content (context->parser, + &context->content, + context->error)) + { + context->failed = TRUE; + return FALSE; + } + _dbus_string_set_length (&context->content, 0); + } + + return TRUE; +} + +static void +expat_StartElementHandler (void *userData, + const XML_Char *name, + const XML_Char **atts) +{ + ExpatParseContext *context = userData; + int i; + char **names; + char **values; + + /* Expat seems to suck and can't abort the parse if we + * throw an error. Expat 2.0 is supposed to fix this. + */ + if (context->failed) + return; + + if (!process_content (context)) + return; + + /* "atts" is key, value, key, value, NULL */ + for (i = 0; atts[i] != NULL; ++i) + ; /* nothing */ + + _dbus_assert (i % 2 == 0); + names = dbus_new0 (char *, i / 2 + 1); + values = dbus_new0 (char *, i / 2 + 1); + + if (names == NULL || values == NULL) + { + dbus_set_error (context->error, DBUS_ERROR_NO_MEMORY, NULL); + context->failed = TRUE; + dbus_free (names); + dbus_free (values); + return; + } + + i = 0; + while (atts[i] != NULL) + { + _dbus_assert (i % 2 == 0); + names [i / 2] = (char*) atts[i]; + values[i / 2] = (char*) atts[i+1]; + + i += 2; + } + + if (!bus_config_parser_start_element (context->parser, + name, + (const char **) names, + (const char **) values, + context->error)) + { + dbus_free (names); + dbus_free (values); + context->failed = TRUE; + return; + } + + dbus_free (names); + dbus_free (values); +} + +static void +expat_EndElementHandler (void *userData, + const XML_Char *name) +{ + ExpatParseContext *context = userData; + + if (!process_content (context)) + return; + + if (!bus_config_parser_end_element (context->parser, + name, + context->error)) + { + context->failed = TRUE; + return; + } +} + +/* s is not 0 terminated. */ +static void +expat_CharacterDataHandler (void *userData, + const XML_Char *s, + int len) +{ + ExpatParseContext *context = userData; + if (context->failed) + return; + + if (!_dbus_string_append_len (&context->content, + s, len)) + { + dbus_set_error (context->error, DBUS_ERROR_NO_MEMORY, NULL); + context->failed = TRUE; + return; + } +} + + +BusConfigParser* +bus_config_load (const DBusString *file, + dbus_bool_t is_toplevel, + const BusConfigParser *parent, + DBusError *error) +{ + XML_Parser expat; + const char *filename; + BusConfigParser *parser; + ExpatParseContext context; + DBusString dirname; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + parser = NULL; + expat = NULL; + context.error = error; + context.failed = FALSE; + + filename = _dbus_string_get_const_data (file); + + if (!_dbus_string_init (&context.content)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } + + if (!_dbus_string_init (&dirname)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + _dbus_string_free (&context.content); + return NULL; + } + + memsuite.malloc_fcn = dbus_malloc; + memsuite.realloc_fcn = dbus_realloc; + memsuite.free_fcn = dbus_free; + + expat = XML_ParserCreate_MM ("UTF-8", &memsuite, NULL); + if (expat == NULL) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto failed; + } + + if (!_dbus_string_get_dirname (file, &dirname)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto failed; + } + + parser = bus_config_parser_new (&dirname, is_toplevel, parent); + if (parser == NULL) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto failed; + } + context.parser = parser; + + XML_SetUserData (expat, &context); + XML_SetElementHandler (expat, + expat_StartElementHandler, + expat_EndElementHandler); + XML_SetCharacterDataHandler (expat, + expat_CharacterDataHandler); + + { + DBusString data; + const char *data_str; + + if (!_dbus_string_init (&data)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto failed; + } + + if (!_dbus_file_get_contents (&data, file, error)) + { + _dbus_string_free (&data); + goto failed; + } + + data_str = _dbus_string_get_const_data (&data); + + if (!XML_Parse (expat, data_str, _dbus_string_get_length (&data), TRUE)) + { + if (context.error != NULL && + !dbus_error_is_set (context.error)) + { + enum XML_Error e; + + e = XML_GetErrorCode (expat); + if (e == XML_ERROR_NO_MEMORY) + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + else + dbus_set_error (error, DBUS_ERROR_FAILED, + "Error in file %s, line %d, column %d: %s\n", + filename, + XML_GetCurrentLineNumber (expat), + XML_GetCurrentColumnNumber (expat), + XML_ErrorString (e)); + } + + _dbus_string_free (&data); + goto failed; + } + + _dbus_string_free (&data); + + if (context.failed) + goto failed; + } + + if (!bus_config_parser_finished (parser, error)) + goto failed; + + _dbus_string_free (&dirname); + _dbus_string_free (&context.content); + XML_ParserFree (expat); + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + return parser; + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + + _dbus_string_free (&dirname); + _dbus_string_free (&context.content); + if (expat) + XML_ParserFree (expat); + if (parser) + bus_config_parser_unref (parser); + return NULL; +}
diff --git a/bus/config-parser-common.c b/bus/config-parser-common.c new file mode 100644 index 0000000..5db6b28 --- /dev/null +++ b/bus/config-parser-common.c
@@ -0,0 +1,196 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* config-parser-common.c Common defines and routines for config file parsing + * + * Copyright (C) 2007 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include <dbus/dbus-internals.h> +#include <string.h> + +#include "config-parser-common.h" +#include "utils.h" + +ElementType +bus_config_parser_element_name_to_type (const char *name) +{ + if (strcmp (name, "none") == 0) + { + return ELEMENT_NONE; + } + else if (strcmp (name, "busconfig") == 0) + { + return ELEMENT_BUSCONFIG; + } + else if (strcmp (name, "user") == 0) + { + return ELEMENT_USER; + } + else if (strcmp (name, "auth") == 0) + { + return ELEMENT_AUTH; + } + else if (strcmp (name, "type") == 0) + { + return ELEMENT_CONFIGTYPE; + } + else if (strcmp (name, "fork") == 0) + { + return ELEMENT_FORK; + } + else if (strcmp (name, "pidfile") == 0) + { + return ELEMENT_PIDFILE; + } + else if (strcmp (name, "listen") == 0) + { + return ELEMENT_LISTEN; + } + else if (strcmp (name, "auth") == 0) + { + return ELEMENT_AUTH; + } + else if (strcmp (name, "allow") == 0) + { + return ELEMENT_ALLOW; + } + else if (strcmp (name, "deny") == 0) + { + return ELEMENT_DENY; + } + else if (strcmp (name, "servicehelper") == 0) + { + return ELEMENT_SERVICEHELPER; + } + else if (strcmp (name, "includedir") == 0) + { + return ELEMENT_INCLUDEDIR; + } + else if (strcmp (name, "standard_session_servicedirs") == 0) + { + return ELEMENT_STANDARD_SESSION_SERVICEDIRS; + } + else if (strcmp (name, "standard_system_servicedirs") == 0) + { + return ELEMENT_STANDARD_SYSTEM_SERVICEDIRS; + } + else if (strcmp (name, "servicedir") == 0) + { + return ELEMENT_SERVICEDIR; + } + else if (strcmp (name, "include") == 0) + { + return ELEMENT_INCLUDE; + } + else if (strcmp (name, "policy") == 0) + { + return ELEMENT_POLICY; + } + else if (strcmp (name, "limit") == 0) + { + return ELEMENT_LIMIT; + } + else if (strcmp (name, "selinux") == 0) + { + return ELEMENT_SELINUX; + } + else if (strcmp (name, "associate") == 0) + { + return ELEMENT_ASSOCIATE; + } + else if (strcmp (name, "syslog") == 0) + { + return ELEMENT_SYSLOG; + } + else if (strcmp (name, "keep_umask") == 0) + { + return ELEMENT_KEEP_UMASK; + } + else if (strcmp (name, "allow_anonymous") == 0) + { + return ELEMENT_ALLOW_ANONYMOUS; + } + else if (strcmp (name, "apparmor") == 0) + { + return ELEMENT_APPARMOR; + } + return ELEMENT_NONE; +} + +const char* +bus_config_parser_element_type_to_name (ElementType type) +{ + switch (type) + { + case ELEMENT_NONE: + return NULL; + case ELEMENT_BUSCONFIG: + return "busconfig"; + case ELEMENT_INCLUDE: + return "include"; + case ELEMENT_USER: + return "user"; + case ELEMENT_LISTEN: + return "listen"; + case ELEMENT_AUTH: + return "auth"; + case ELEMENT_POLICY: + return "policy"; + case ELEMENT_LIMIT: + return "limit"; + case ELEMENT_ALLOW: + return "allow"; + case ELEMENT_DENY: + return "deny"; + case ELEMENT_FORK: + return "fork"; + case ELEMENT_PIDFILE: + return "pidfile"; + case ELEMENT_STANDARD_SESSION_SERVICEDIRS: + return "standard_session_servicedirs"; + case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS: + return "standard_system_servicedirs"; + case ELEMENT_SERVICEDIR: + return "servicedir"; + case ELEMENT_SERVICEHELPER: + return "servicehelper"; + case ELEMENT_INCLUDEDIR: + return "includedir"; + case ELEMENT_CONFIGTYPE: + return "type"; + case ELEMENT_SELINUX: + return "selinux"; + case ELEMENT_ASSOCIATE: + return "associate"; + case ELEMENT_SYSLOG: + return "syslog"; + case ELEMENT_KEEP_UMASK: + return "keep_umask"; + case ELEMENT_ALLOW_ANONYMOUS: + return "allow_anonymous"; + case ELEMENT_APPARMOR: + return "apparmor"; + } + + _dbus_assert_not_reached ("bad element type"); + + return NULL; +} +
diff --git a/bus/config-parser-common.h b/bus/config-parser-common.h new file mode 100644 index 0000000..382a014 --- /dev/null +++ b/bus/config-parser-common.h
@@ -0,0 +1,60 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* config-parser-common.h Common defines and routines for config file parsing + * + * Copyright (C) 2007 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_CONFIG_PARSER_COMMON_H +#define BUS_CONFIG_PARSER_COMMON_H + +typedef enum +{ + ELEMENT_NONE, + ELEMENT_BUSCONFIG, + ELEMENT_INCLUDE, + ELEMENT_USER, + ELEMENT_LISTEN, + ELEMENT_AUTH, + ELEMENT_POLICY, + ELEMENT_LIMIT, + ELEMENT_ALLOW, + ELEMENT_DENY, + ELEMENT_FORK, + ELEMENT_PIDFILE, + ELEMENT_SERVICEDIR, + ELEMENT_SERVICEHELPER, + ELEMENT_INCLUDEDIR, + /* this is really <type>, but winioctl.h defines ELEMENT_TYPE */ + ELEMENT_CONFIGTYPE, + ELEMENT_SELINUX, + ELEMENT_ASSOCIATE, + ELEMENT_STANDARD_SESSION_SERVICEDIRS, + ELEMENT_STANDARD_SYSTEM_SERVICEDIRS, + ELEMENT_KEEP_UMASK, + ELEMENT_SYSLOG, + ELEMENT_ALLOW_ANONYMOUS, + ELEMENT_APPARMOR +} ElementType; + +ElementType bus_config_parser_element_name_to_type (const char *element_name); +const char* bus_config_parser_element_type_to_name (ElementType type); + +#endif /* BUS_CONFIG_PARSER_COMMON_H */ +
diff --git a/bus/config-parser-trivial.c b/bus/config-parser-trivial.c new file mode 100644 index 0000000..03ad838 --- /dev/null +++ b/bus/config-parser-trivial.c
@@ -0,0 +1,725 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* config-parser-trivial.c XML-library-agnostic configuration file parser + * Does not do includes or anything remotely complicated. + * + * Copyright (C) 2003, 2004, 2007 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "config-parser-common.h" +#include "config-parser-trivial.h" +#include "utils.h" +#include <dbus/dbus-list.h> +#include <dbus/dbus-internals.h> +#include <string.h> + +/** + * TRIVIAL parser for bus configuration file. + */ +struct BusConfigParser +{ + ElementType type; + DBusString user; /**< User the dbus-daemon runs as */ + DBusString bus_type; /**< Message bus type */ + DBusString service_helper; /**< Location of the setuid helper */ + DBusList *service_dirs; /**< Directories to look for services in */ +}; + +static dbus_bool_t +service_dirs_find_dir (DBusList **service_dirs, + const char *dir) +{ + DBusList *link; + + _dbus_assert (dir != NULL); + + for (link = *service_dirs; link; link = _dbus_list_get_next_link(service_dirs, link)) + { + const char *link_dir; + + link_dir = (const char *)link->data; + if (strcmp (dir, link_dir) == 0) + return TRUE; + } + + return FALSE; +} + +static void +service_dirs_append_link_unique_or_free (DBusList **service_dirs, + DBusList *dir_link) +{ + if (!service_dirs_find_dir (service_dirs, dir_link->data)) + { + _dbus_list_append_link (service_dirs, dir_link); + } + else + { + dbus_free (dir_link->data); + _dbus_list_free_link (dir_link); + } +} + +BusConfigParser* +bus_config_parser_new (const DBusString *basedir, + dbus_bool_t is_toplevel, + const BusConfigParser *parent) +{ + BusConfigParser *parser; + + parser = dbus_new0 (BusConfigParser, 1); + if (parser == NULL) + goto failed; + + parser->type = ELEMENT_NONE; + + /* init the lists */ + parser->service_dirs = NULL; + + /* init the strings */ + if (!_dbus_string_init (&parser->user)) + goto failed_parser; + if (!_dbus_string_init (&parser->bus_type)) + goto failed_type; + if (!_dbus_string_init (&parser->service_helper)) + goto failed_helper; + + /* woot! */ + return parser; + +/* argh. we have do do this carefully because of OOM */ +failed_helper: + _dbus_string_free (&parser->bus_type); +failed_type: + _dbus_string_free (&parser->user); +failed_parser: + dbus_free (parser); +failed: + return NULL; +} + +void +bus_config_parser_unref (BusConfigParser *parser) +{ + _dbus_string_free (&parser->user); + _dbus_string_free (&parser->service_helper); + _dbus_string_free (&parser->bus_type); + + _dbus_list_foreach (&parser->service_dirs, + (DBusForeachFunction) dbus_free, + NULL); + + _dbus_list_clear (&parser->service_dirs); + + dbus_free (parser); +} + +dbus_bool_t +bus_config_parser_check_doctype (BusConfigParser *parser, + const char *doctype, + DBusError *error) +{ + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (strcmp (doctype, "busconfig") != 0) + { + dbus_set_error (error, + DBUS_ERROR_FAILED, + "Configuration file has the wrong document type %s", + doctype); + return FALSE; + } + else + return TRUE; +} + +dbus_bool_t +bus_config_parser_start_element (BusConfigParser *parser, + const char *element_name, + const char **attribute_names, + const char **attribute_values, + DBusError *error) +{ + /* we don't do processing of attribute names, we don't need to */ + parser->type = bus_config_parser_element_name_to_type (element_name); + + switch (parser->type) + { + case ELEMENT_SERVICEHELPER: + case ELEMENT_USER: + case ELEMENT_CONFIGTYPE: + /* content about to be handled */ + break; + + case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS: + { + DBusList *link; + DBusList *dirs; + dirs = NULL; + + if (!_dbus_get_standard_system_servicedirs (&dirs)) + { + BUS_SET_OOM (error); + return FALSE; + } + + while ((link = _dbus_list_pop_first_link (&dirs))) + service_dirs_append_link_unique_or_free (&parser->service_dirs, link); + break; + } + + default: + { + /* we really don't care about the others... */ + _dbus_verbose (" START We don't care about '%s' type '%i'\n", element_name, parser->type); + break; + } + } + return TRUE; +} + +dbus_bool_t +bus_config_parser_end_element (BusConfigParser *parser, + const char *element_name, + DBusError *error) +{ + /* we don't care */ + return TRUE; +} + +dbus_bool_t +bus_config_parser_content (BusConfigParser *parser, + const DBusString *content, + DBusError *error) +{ + DBusString content_sane; + dbus_bool_t retval; + + retval = FALSE; + + if (!_dbus_string_init (&content_sane)) + { + BUS_SET_OOM (error); + goto out; + } + if (!_dbus_string_copy (content, 0, &content_sane, 0)) + { + BUS_SET_OOM (error); + goto out_content; + } + + /* rip out white space */ + _dbus_string_chop_white (&content_sane); + if (_dbus_string_get_length (&content_sane) == 0) + { + /* optimise, there is no content */ + retval = TRUE; + goto out_content; + } + + switch (parser->type) + { + case ELEMENT_SERVICEDIR: + { + char *cpath; + + /* copy the sane data into a char array */ + if (!_dbus_string_copy_data(&content_sane, &cpath)) + { + BUS_SET_OOM (error); + goto out_content; + } + + /* append the dynamic char string to service dirs */ + if (!_dbus_list_append (&parser->service_dirs, cpath)) + { + dbus_free (cpath); + BUS_SET_OOM (error); + goto out_content; + } + } + break; + + case ELEMENT_SERVICEHELPER: + { + if (!_dbus_string_copy (&content_sane, 0, &parser->service_helper, 0)) + { + BUS_SET_OOM (error); + goto out_content; + } + } + break; + + case ELEMENT_USER: + { + if (!_dbus_string_copy (&content_sane, 0, &parser->user, 0)) + { + BUS_SET_OOM (error); + goto out_content; + } + } + break; + + case ELEMENT_CONFIGTYPE: + { + if (!_dbus_string_copy (&content_sane, 0, &parser->bus_type, 0)) + { + BUS_SET_OOM (error); + goto out_content; + } + } + break; + default: + { + /* we don't care about the others... really */ + _dbus_verbose (" CONTENTS We don't care about '%s' type '%i'\n", _dbus_string_get_const_data (&content_sane), parser->type); + break; + } + } + + /* woot! */ + retval = TRUE; + +out_content: + _dbus_string_free (&content_sane); +out: + return retval; +} + +dbus_bool_t +bus_config_parser_finished (BusConfigParser *parser, + DBusError *error) +{ + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + _dbus_verbose ("finished scanning!\n"); + return TRUE; +} + +const char* +bus_config_parser_get_user (BusConfigParser *parser) +{ + return _dbus_string_get_const_data (&parser->user); +} + +const char* +bus_config_parser_get_type (BusConfigParser *parser) +{ + return _dbus_string_get_const_data (&parser->bus_type); +} + +DBusList** +bus_config_parser_get_service_dirs (BusConfigParser *parser) +{ + return &parser->service_dirs; +} + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS +#include <stdio.h> +#include "test.h" + +typedef enum +{ + VALID, + INVALID, + UNKNOWN +} Validity; + +static dbus_bool_t +check_return_values (const DBusString *full_path) +{ + BusConfigParser *parser; + DBusError error; + dbus_bool_t retval; + const char *user; + const char *type; + DBusList **dirs; + + dbus_error_init (&error); + retval = FALSE; + + printf ("Testing values from: %s\n", _dbus_string_get_const_data (full_path)); + + parser = bus_config_load (full_path, TRUE, NULL, &error); + if (parser == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + _dbus_verbose ("Failed to load valid file due to OOM\n"); + goto finish; + } + _DBUS_ASSERT_ERROR_IS_CLEAR (&error); + + /* check user return value is okay */ + user = bus_config_parser_get_user (parser); + if (user == NULL) + { + _dbus_warn ("User was NULL!\n"); + goto finish; + } +#if 0 + /* the username can be configured in configure.in so this test doesn't work */ + if (strcmp (user, "dbus") != 0) + { + _dbus_warn ("User was invalid; '%s'!\n", user); + goto finish; + } + printf (" <user>dbus</user> OKAY!\n"); +#endif + + /* check type return value is okay */ + type = bus_config_parser_get_type (parser); + if (type == NULL) + { + _dbus_warn ("Type was NULL!\n"); + goto finish; + } + if (strcmp (type, "system") != 0) + { + _dbus_warn ("Type was invalid; '%s'!\n", user); + goto finish; + } + printf (" <type>system</type> OKAY!\n"); + + /* check dirs return value is okay */ + dirs = bus_config_parser_get_service_dirs (parser); + if (dirs == NULL) + { + _dbus_warn ("Service dirs are NULL!\n"); + goto finish; + } + printf (" <standard_system_service_dirs/> OKAY!\n"); + /* NOTE: We tested the specific return values in the config-parser tests */ + + /* woohoo! */ + retval = TRUE; +finish: + if (parser != NULL) + bus_config_parser_unref (parser); + dbus_error_free (&error); + return retval; +} + +static dbus_bool_t +do_load (const DBusString *full_path, + Validity validity, + dbus_bool_t oom_possible) +{ + BusConfigParser *parser; + DBusError error; + + dbus_error_init (&error); + + parser = bus_config_load (full_path, TRUE, NULL, &error); + if (parser == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + + if (oom_possible && + dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + _dbus_verbose ("Failed to load valid file due to OOM\n"); + dbus_error_free (&error); + return TRUE; + } + else if (validity == VALID) + { + _dbus_warn ("Failed to load valid file but still had memory: %s\n", + error.message); + + dbus_error_free (&error); + return FALSE; + } + else + { + dbus_error_free (&error); + return TRUE; + } + } + else + { + _DBUS_ASSERT_ERROR_IS_CLEAR (&error); + + bus_config_parser_unref (parser); + + if (validity == INVALID) + { + _dbus_warn ("Accepted invalid file\n"); + return FALSE; + } + + return TRUE; + } +} + +typedef struct +{ + const DBusString *full_path; + Validity validity; +} LoaderOomData; + +static dbus_bool_t +check_loader_oom_func (void *data) +{ + LoaderOomData *d = data; + + return do_load (d->full_path, d->validity, TRUE); +} + +static dbus_bool_t +process_test_valid_subdir (const DBusString *test_base_dir, + const char *subdir, + Validity validity) +{ + DBusString test_directory; + DBusString filename; + DBusDirIter *dir; + dbus_bool_t retval; + DBusError error; + + retval = FALSE; + dir = NULL; + + if (!_dbus_string_init (&test_directory)) + _dbus_assert_not_reached ("didn't allocate test_directory\n"); + + _dbus_string_init_const (&filename, subdir); + + if (!_dbus_string_copy (test_base_dir, 0, + &test_directory, 0)) + _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory"); + + if (!_dbus_concat_dir_and_file (&test_directory, &filename)) + _dbus_assert_not_reached ("couldn't allocate full path"); + + _dbus_string_free (&filename); + if (!_dbus_string_init (&filename)) + _dbus_assert_not_reached ("didn't allocate filename string\n"); + + dbus_error_init (&error); + dir = _dbus_directory_open (&test_directory, &error); + if (dir == NULL) + { + _dbus_warn ("Could not open %s: %s\n", + _dbus_string_get_const_data (&test_directory), + error.message); + dbus_error_free (&error); + goto failed; + } + + if (validity == VALID) + printf ("Testing valid files:\n"); + else if (validity == INVALID) + printf ("Testing invalid files:\n"); + else + printf ("Testing unknown files:\n"); + + next: + while (_dbus_directory_get_next_file (dir, &filename, &error)) + { + DBusString full_path; + LoaderOomData d; + + if (!_dbus_string_init (&full_path)) + _dbus_assert_not_reached ("couldn't init string"); + + if (!_dbus_string_copy (&test_directory, 0, &full_path, 0)) + _dbus_assert_not_reached ("couldn't copy dir to full_path"); + + if (!_dbus_concat_dir_and_file (&full_path, &filename)) + _dbus_assert_not_reached ("couldn't concat file to dir"); + + if (!_dbus_string_ends_with_c_str (&full_path, ".conf")) + { + _dbus_verbose ("Skipping non-.conf file %s\n", + _dbus_string_get_const_data (&filename)); + _dbus_string_free (&full_path); + goto next; + } + + printf (" %s\n", _dbus_string_get_const_data (&filename)); + + _dbus_verbose (" expecting %s\n", + validity == VALID ? "valid" : + (validity == INVALID ? "invalid" : + (validity == UNKNOWN ? "unknown" : "???"))); + + d.full_path = &full_path; + d.validity = validity; + + /* FIXME hackaround for an expat problem, see + * https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=124747 + * http://freedesktop.org/pipermail/dbus/2004-May/001153.html + */ + /* if (!_dbus_test_oom_handling ("config-loader", check_loader_oom_func, &d)) */ + if (!check_loader_oom_func (&d)) + _dbus_assert_not_reached ("test failed"); + + _dbus_string_free (&full_path); + } + + if (dbus_error_is_set (&error)) + { + _dbus_warn ("Could not get next file in %s: %s\n", + _dbus_string_get_const_data (&test_directory), + error.message); + dbus_error_free (&error); + goto failed; + } + + retval = TRUE; + + failed: + + if (dir) + _dbus_directory_close (dir); + _dbus_string_free (&test_directory); + _dbus_string_free (&filename); + + return retval; +} + +/* convenience function, do not reuse outside of TEST */ +static dbus_bool_t +make_full_path (const DBusString *test_data_dir, + const char *subdir, + const char *file, + DBusString *full_path) +{ + DBusString filename; + dbus_bool_t retval; + + retval = FALSE; + + if (!_dbus_string_init (full_path)) + { + _dbus_warn ("couldn't allocate full path"); + goto finish; + } + + if (!_dbus_string_copy (test_data_dir, 0, full_path, 0)) + { + _dbus_warn ("couldn't allocate full path"); + goto finish; + } + + _dbus_string_init_const (&filename, subdir); + if (!_dbus_concat_dir_and_file (full_path, &filename)) + { + _dbus_warn ("couldn't allocate full path"); + goto finish; + } + _dbus_string_free (&filename); + + _dbus_string_init_const (&filename, file); + if (!_dbus_concat_dir_and_file (full_path, &filename)) + { + _dbus_warn ("couldn't allocate full path"); + goto finish; + } + + /* woot! */ + retval = TRUE; + +finish: + _dbus_string_free (&filename); + return retval; +} + +static dbus_bool_t +check_file_valid (DBusString *full_path, + Validity validity) +{ + dbus_bool_t retval; + + if (validity == VALID) + printf ("Testing valid file:\n"); + else if (validity == INVALID) + printf ("Testing invalid file:\n"); + else + printf ("Testing unknown file:\n"); + + /* print the filename, just so we match the other output */ + printf (" %s\n", _dbus_string_get_const_data (full_path)); + + /* only test one file */ + retval = do_load (full_path, validity, TRUE); + + return retval; +} + +dbus_bool_t +bus_config_parser_trivial_test (const DBusString *test_data_dir) +{ + DBusString full_path; + dbus_bool_t retval; + + retval = FALSE; + + if (test_data_dir == NULL || + _dbus_string_get_length (test_data_dir) == 0) + { + printf ("No test data\n"); + return TRUE; + } + + /* We already test default_session_servicedirs and default_system_servicedirs + * in bus_config_parser_test() */ + if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID)) + goto finish; + +#ifndef DBUS_WIN + /* We already test default_session_servicedirs and default_system_servicedirs + * in bus_config_parser_test() */ + if (!process_test_valid_subdir (test_data_dir, "valid-config-files-system", VALID)) + goto finish; +#endif + + /* we don't process all the invalid files, as the trivial parser can't hope + * to validate them all for all different syntaxes. We just check one broken + * file to see if junk is received */ + if (!make_full_path (test_data_dir, "invalid-config-files", "not-well-formed.conf", &full_path)) + goto finish; + if (!check_file_valid (&full_path, INVALID)) + goto finish; + _dbus_string_free (&full_path); + +#ifndef DBUS_WIN + /* just test if the check_file_valid works okay and we got sane values */ + if (!make_full_path (test_data_dir, "valid-config-files-system", "system.conf", &full_path)) + goto finish; + if (!check_file_valid (&full_path, VALID)) + goto finish; + /* check to see if we got the correct values from the parser */ + if (!check_return_values (&full_path)) + goto finish; +#endif + + /* woot! */ + retval = TRUE; + +finish: + _dbus_string_free (&full_path); + + /* we don't process equiv-config-files as we don't handle <include> */ + return retval; +} + +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */ +
diff --git a/bus/config-parser-trivial.h b/bus/config-parser-trivial.h new file mode 100644 index 0000000..31ddef6 --- /dev/null +++ b/bus/config-parser-trivial.h
@@ -0,0 +1,72 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* config-parser-trivial.h XML-library-agnostic configuration file parser + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_CONFIG_PARSER_TRIVIAL_H +#define BUS_CONFIG_PARSER_TRIVIAL_H + +#include <dbus/dbus.h> +#include <dbus/dbus-string.h> +#include <dbus/dbus-list.h> +#include <dbus/dbus-hash.h> + +/* Whatever XML library we're using just pushes data into this API */ + +typedef struct BusConfigParser BusConfigParser; + +BusConfigParser* bus_config_parser_new (const DBusString *basedir, + dbus_bool_t is_toplevel, + const BusConfigParser *parent); + +BusConfigParser* bus_config_parser_ref (BusConfigParser *parser); +void bus_config_parser_unref (BusConfigParser *parser); +dbus_bool_t bus_config_parser_check_doctype (BusConfigParser *parser, + const char *doctype, + DBusError *error); +dbus_bool_t bus_config_parser_start_element (BusConfigParser *parser, + const char *element_name, + const char **attribute_names, + const char **attribute_values, + DBusError *error); +dbus_bool_t bus_config_parser_end_element (BusConfigParser *parser, + const char *element_name, + DBusError *error); +dbus_bool_t bus_config_parser_content (BusConfigParser *parser, + const DBusString *content, + DBusError *error); +dbus_bool_t bus_config_parser_finished (BusConfigParser *parser, + DBusError *error); + +/* Functions for extracting the parse results */ +const char* bus_config_parser_get_user (BusConfigParser *parser); +const char* bus_config_parser_get_type (BusConfigParser *parser); +DBusList** bus_config_parser_get_service_dirs (BusConfigParser *parser); + +/* Loader functions (backended off one of the XML parsers). Returns a + * finished ConfigParser. + */ +BusConfigParser* bus_config_load (const DBusString *file, + dbus_bool_t is_toplevel, + const BusConfigParser *parent, + DBusError *error); + +#endif /* BUS_CONFIG_PARSER_TRIVIAL_H */
diff --git a/bus/config-parser.c b/bus/config-parser.c new file mode 100644 index 0000000..d9f6042 --- /dev/null +++ b/bus/config-parser.c
@@ -0,0 +1,3698 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* config-parser.c XML-library-agnostic configuration file parser + * + * Copyright (C) 2003, 2004 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "config-parser-common.h" +#include "config-parser.h" +#include "test.h" +#include "utils.h" +#include "policy.h" +#include "selinux.h" +#include "apparmor.h" +#include <dbus/dbus-list.h> +#include <dbus/dbus-internals.h> +#include <dbus/dbus-misc.h> +#include <dbus/dbus-sysdeps.h> +#include <string.h> + +typedef enum +{ + /* we ignore policies for unknown groups/users */ + POLICY_IGNORED, + + /* non-ignored */ + POLICY_DEFAULT, + POLICY_MANDATORY, + POLICY_USER, + POLICY_GROUP, + POLICY_CONSOLE +} PolicyType; + +typedef struct +{ + ElementType type; + + unsigned int had_content : 1; + + union + { + struct + { + unsigned int ignore_missing : 1; + unsigned int if_selinux_enabled : 1; + unsigned int selinux_root_relative : 1; + } include; + + struct + { + PolicyType type; + unsigned long gid_uid_or_at_console; + } policy; + + struct + { + char *name; + long value; + } limit; + + } d; + +} Element; + +/** + * Parser for bus configuration file. + */ +struct BusConfigParser +{ + int refcount; /**< Reference count */ + + DBusString basedir; /**< Directory we resolve paths relative to */ + + DBusList *stack; /**< stack of Element */ + + char *user; /**< user to run as */ + + char *servicehelper; /**< location of the setuid helper */ + + char *bus_type; /**< Message bus type */ + + DBusList *listen_on; /**< List of addresses to listen to */ + + DBusList *mechanisms; /**< Auth mechanisms */ + + DBusList *service_dirs; /**< Directories to look for session services in */ + + DBusList *conf_dirs; /**< Directories to look for policy configuration in */ + + BusPolicy *policy; /**< Security policy */ + + BusLimits limits; /**< Limits */ + + char *pidfile; /**< PID file */ + + DBusList *included_files; /**< Included files stack */ + + DBusHashTable *service_context_table; /**< Map service names to SELinux contexts */ + + unsigned int fork : 1; /**< TRUE to fork into daemon mode */ + + unsigned int syslog : 1; /**< TRUE to enable syslog */ + unsigned int keep_umask : 1; /**< TRUE to keep original umask when forking */ + + unsigned int is_toplevel : 1; /**< FALSE if we are a sub-config-file inside another one */ + + unsigned int allow_anonymous : 1; /**< TRUE to allow anonymous connections */ +}; + +static Element* +push_element (BusConfigParser *parser, + ElementType type) +{ + Element *e; + + _dbus_assert (type != ELEMENT_NONE); + + e = dbus_new0 (Element, 1); + if (e == NULL) + return NULL; + + if (!_dbus_list_append (&parser->stack, e)) + { + dbus_free (e); + return NULL; + } + + e->type = type; + + return e; +} + +static void +element_free (Element *e) +{ + if (e->type == ELEMENT_LIMIT) + dbus_free (e->d.limit.name); + + dbus_free (e); +} + +static void +pop_element (BusConfigParser *parser) +{ + Element *e; + + e = _dbus_list_pop_last (&parser->stack); + + element_free (e); +} + +static Element* +peek_element (BusConfigParser *parser) +{ + Element *e; + + e = _dbus_list_get_last (&parser->stack); + + return e; +} + +static ElementType +top_element_type (BusConfigParser *parser) +{ + Element *e; + + e = _dbus_list_get_last (&parser->stack); + + if (e) + return e->type; + else + return ELEMENT_NONE; +} + +static dbus_bool_t +merge_service_context_hash (DBusHashTable *dest, + DBusHashTable *from) +{ + DBusHashIter iter; + char *service_copy; + char *context_copy; + + service_copy = NULL; + context_copy = NULL; + + _dbus_hash_iter_init (from, &iter); + while (_dbus_hash_iter_next (&iter)) + { + const char *service = _dbus_hash_iter_get_string_key (&iter); + const char *context = _dbus_hash_iter_get_value (&iter); + + service_copy = _dbus_strdup (service); + if (service_copy == NULL) + goto fail; + context_copy = _dbus_strdup (context); + if (context_copy == NULL) + goto fail; + + if (!_dbus_hash_table_insert_string (dest, service_copy, context_copy)) + goto fail; + + service_copy = NULL; + context_copy = NULL; + } + + return TRUE; + + fail: + if (service_copy) + dbus_free (service_copy); + + if (context_copy) + dbus_free (context_copy); + + return FALSE; +} + +static dbus_bool_t +service_dirs_find_dir (DBusList **service_dirs, + const char *dir) +{ + DBusList *link; + + _dbus_assert (dir != NULL); + + for (link = *service_dirs; link; link = _dbus_list_get_next_link(service_dirs, link)) + { + const char *link_dir; + + link_dir = (const char *)link->data; + if (strcmp (dir, link_dir) == 0) + return TRUE; + } + + return FALSE; +} + +static dbus_bool_t +service_dirs_append_unique_or_free (DBusList **service_dirs, + char *dir) +{ + if (!service_dirs_find_dir (service_dirs, dir)) + return _dbus_list_append (service_dirs, dir); + + dbus_free (dir); + return TRUE; +} + +static void +service_dirs_append_link_unique_or_free (DBusList **service_dirs, + DBusList *dir_link) +{ + if (!service_dirs_find_dir (service_dirs, dir_link->data)) + { + _dbus_list_append_link (service_dirs, dir_link); + } + else + { + dbus_free (dir_link->data); + _dbus_list_free_link (dir_link); + } +} + +static dbus_bool_t +merge_included (BusConfigParser *parser, + BusConfigParser *included, + DBusError *error) +{ + DBusList *link; + + if (!bus_policy_merge (parser->policy, + included->policy)) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!merge_service_context_hash (parser->service_context_table, + included->service_context_table)) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (included->user != NULL) + { + dbus_free (parser->user); + parser->user = included->user; + included->user = NULL; + } + + if (included->bus_type != NULL) + { + dbus_free (parser->bus_type); + parser->bus_type = included->bus_type; + included->bus_type = NULL; + } + + if (included->fork) + parser->fork = TRUE; + + if (included->keep_umask) + parser->keep_umask = TRUE; + + if (included->allow_anonymous) + parser->allow_anonymous = TRUE; + + if (included->pidfile != NULL) + { + dbus_free (parser->pidfile); + parser->pidfile = included->pidfile; + included->pidfile = NULL; + } + + if (included->servicehelper != NULL) + { + dbus_free (parser->servicehelper); + parser->servicehelper = included->servicehelper; + included->servicehelper = NULL; + } + + while ((link = _dbus_list_pop_first_link (&included->listen_on))) + _dbus_list_append_link (&parser->listen_on, link); + + while ((link = _dbus_list_pop_first_link (&included->mechanisms))) + _dbus_list_append_link (&parser->mechanisms, link); + + while ((link = _dbus_list_pop_first_link (&included->service_dirs))) + service_dirs_append_link_unique_or_free (&parser->service_dirs, link); + + while ((link = _dbus_list_pop_first_link (&included->conf_dirs))) + _dbus_list_append_link (&parser->conf_dirs, link); + + return TRUE; +} + +static dbus_bool_t +seen_include (BusConfigParser *parser, + const DBusString *file) +{ + DBusList *iter; + + iter = parser->included_files; + while (iter != NULL) + { + if (! strcmp (_dbus_string_get_const_data (file), iter->data)) + return TRUE; + + iter = _dbus_list_get_next_link (&parser->included_files, iter); + } + + return FALSE; +} + +BusConfigParser* +bus_config_parser_new (const DBusString *basedir, + dbus_bool_t is_toplevel, + const BusConfigParser *parent) +{ + BusConfigParser *parser; + + parser = dbus_new0 (BusConfigParser, 1); + if (parser == NULL) + return NULL; + + parser->is_toplevel = !!is_toplevel; + + if (!_dbus_string_init (&parser->basedir)) + { + dbus_free (parser); + return NULL; + } + + if (((parser->policy = bus_policy_new ()) == NULL) || + !_dbus_string_copy (basedir, 0, &parser->basedir, 0) || + ((parser->service_context_table = _dbus_hash_table_new (DBUS_HASH_STRING, + dbus_free, + dbus_free)) == NULL)) + { + if (parser->policy) + bus_policy_unref (parser->policy); + + _dbus_string_free (&parser->basedir); + + dbus_free (parser); + return NULL; + } + + if (parent != NULL) + { + /* Initialize the parser's limits from the parent. */ + parser->limits = parent->limits; + + /* Use the parent's list of included_files to avoid + circular inclusions. */ + parser->included_files = parent->included_files; + } + else + { + + /* Make up some numbers! woot! */ + parser->limits.max_incoming_bytes = _DBUS_ONE_MEGABYTE * 127; + parser->limits.max_outgoing_bytes = _DBUS_ONE_MEGABYTE * 127; + parser->limits.max_message_size = _DBUS_ONE_MEGABYTE * 32; + + /* We set relatively conservative values here since due to the + way SCM_RIGHTS works we need to preallocate an array for the + maximum number of file descriptors we can receive. Picking a + high value here thus translates directly to more memory + allocation. */ + parser->limits.max_incoming_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS*4; + parser->limits.max_outgoing_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS*4; + parser->limits.max_message_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS; + + /* Making this long means the user has to wait longer for an error + * message if something screws up, but making it too short means + * they might see a false failure. + */ + parser->limits.activation_timeout = 25000; /* 25 seconds */ + + /* Making this long risks making a DOS attack easier, but too short + * and legitimate auth will fail. If interactive auth (ask user for + * password) is allowed, then potentially it has to be quite long. + */ + parser->limits.auth_timeout = 30000; /* 30 seconds */ + + /* Do not allow a fd to stay forever in dbus-daemon + * https://bugs.freedesktop.org/show_bug.cgi?id=80559 + */ + parser->limits.pending_fd_timeout = 150000; /* 2.5 minutes */ + + parser->limits.max_incomplete_connections = 64; + parser->limits.max_connections_per_user = 256; + + /* Note that max_completed_connections / max_connections_per_user + * is the number of users that would have to work together to + * DOS all the other users. + */ + parser->limits.max_completed_connections = 2048; + + parser->limits.max_pending_activations = 512; + parser->limits.max_services_per_connection = 512; + + /* For this one, keep in mind that it isn't only the memory used + * by the match rules, but slowdown from linearly walking a big + * list of them. A client adding more than this is almost + * certainly a bad idea for that reason, and should change to a + * smaller number of wider-net match rules - getting every last + * message to the bus is probably better than having a thousand + * match rules. + */ + parser->limits.max_match_rules_per_connection = 512; + + parser->limits.reply_timeout = -1; /* never */ + + /* this is effectively a limit on message queue size for messages + * that require a reply + */ + parser->limits.max_replies_per_connection = 128; + } + + parser->refcount = 1; + + return parser; +} + +BusConfigParser * +bus_config_parser_ref (BusConfigParser *parser) +{ + _dbus_assert (parser->refcount > 0); + + parser->refcount += 1; + + return parser; +} + +void +bus_config_parser_unref (BusConfigParser *parser) +{ + _dbus_assert (parser->refcount > 0); + + parser->refcount -= 1; + + if (parser->refcount == 0) + { + while (parser->stack != NULL) + pop_element (parser); + + dbus_free (parser->user); + dbus_free (parser->servicehelper); + dbus_free (parser->bus_type); + dbus_free (parser->pidfile); + + _dbus_list_foreach (&parser->listen_on, + (DBusForeachFunction) dbus_free, + NULL); + + _dbus_list_clear (&parser->listen_on); + + _dbus_list_foreach (&parser->service_dirs, + (DBusForeachFunction) dbus_free, + NULL); + + _dbus_list_clear (&parser->service_dirs); + + _dbus_list_foreach (&parser->conf_dirs, + (DBusForeachFunction) dbus_free, + NULL); + + _dbus_list_clear (&parser->conf_dirs); + + _dbus_list_foreach (&parser->mechanisms, + (DBusForeachFunction) dbus_free, + NULL); + + _dbus_list_clear (&parser->mechanisms); + + _dbus_string_free (&parser->basedir); + + if (parser->policy) + bus_policy_unref (parser->policy); + + if (parser->service_context_table) + _dbus_hash_table_unref (parser->service_context_table); + + dbus_free (parser); + } +} + +dbus_bool_t +bus_config_parser_check_doctype (BusConfigParser *parser, + const char *doctype, + DBusError *error) +{ + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (strcmp (doctype, "busconfig") != 0) + { + dbus_set_error (error, + DBUS_ERROR_FAILED, + "Configuration file has the wrong document type %s", + doctype); + return FALSE; + } + else + return TRUE; +} + +typedef struct +{ + const char *name; + const char **retloc; +} LocateAttr; + +static dbus_bool_t +locate_attributes (BusConfigParser *parser, + const char *element_name, + const char **attribute_names, + const char **attribute_values, + DBusError *error, + const char *first_attribute_name, + const char **first_attribute_retloc, + ...) +{ + va_list args; + const char *name; + const char **retloc; + int n_attrs; +#define MAX_ATTRS 24 + LocateAttr attrs[MAX_ATTRS]; + dbus_bool_t retval; + int i; + + _dbus_assert (first_attribute_name != NULL); + _dbus_assert (first_attribute_retloc != NULL); + + retval = TRUE; + + n_attrs = 1; + attrs[0].name = first_attribute_name; + attrs[0].retloc = first_attribute_retloc; + *first_attribute_retloc = NULL; + + va_start (args, first_attribute_retloc); + + name = va_arg (args, const char*); + retloc = va_arg (args, const char**); + + while (name != NULL) + { + _dbus_assert (retloc != NULL); + _dbus_assert (n_attrs < MAX_ATTRS); + + attrs[n_attrs].name = name; + attrs[n_attrs].retloc = retloc; + n_attrs += 1; + *retloc = NULL; + + name = va_arg (args, const char*); + retloc = va_arg (args, const char**); + } + + va_end (args); + + i = 0; + while (attribute_names[i]) + { + int j; + dbus_bool_t found; + + found = FALSE; + j = 0; + while (j < n_attrs) + { + if (strcmp (attrs[j].name, attribute_names[i]) == 0) + { + retloc = attrs[j].retloc; + + if (*retloc != NULL) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Attribute \"%s\" repeated twice on the same <%s> element", + attrs[j].name, element_name); + retval = FALSE; + goto out; + } + + *retloc = attribute_values[i]; + found = TRUE; + } + + ++j; + } + + if (!found) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Attribute \"%s\" is invalid on <%s> element in this context", + attribute_names[i], element_name); + retval = FALSE; + goto out; + } + + ++i; + } + + out: + return retval; +} + +static dbus_bool_t +check_no_attributes (BusConfigParser *parser, + const char *element_name, + const char **attribute_names, + const char **attribute_values, + DBusError *error) +{ + if (attribute_names[0] != NULL) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Attribute \"%s\" is invalid on <%s> element in this context", + attribute_names[0], element_name); + return FALSE; + } + + return TRUE; +} + +static dbus_bool_t +start_busconfig_child (BusConfigParser *parser, + const char *element_name, + const char **attribute_names, + const char **attribute_values, + DBusError *error) +{ + ElementType element_type; + + element_type = bus_config_parser_element_name_to_type (element_name); + + if (element_type == ELEMENT_USER) + { + if (!check_no_attributes (parser, "user", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_USER) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else if (element_type == ELEMENT_CONFIGTYPE) + { + if (!check_no_attributes (parser, "type", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_CONFIGTYPE) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else if (element_type == ELEMENT_FORK) + { + if (!check_no_attributes (parser, "fork", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_FORK) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + parser->fork = TRUE; + + return TRUE; + } + else if (element_type == ELEMENT_SYSLOG) + { + if (!check_no_attributes (parser, "syslog", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_SYSLOG) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + parser->syslog = TRUE; + + return TRUE; + } + else if (element_type == ELEMENT_KEEP_UMASK) + { + if (!check_no_attributes (parser, "keep_umask", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_KEEP_UMASK) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + parser->keep_umask = TRUE; + + return TRUE; + } + else if (element_type == ELEMENT_PIDFILE) + { + if (!check_no_attributes (parser, "pidfile", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_PIDFILE) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else if (element_type == ELEMENT_LISTEN) + { + if (!check_no_attributes (parser, "listen", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_LISTEN) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else if (element_type == ELEMENT_AUTH) + { + if (!check_no_attributes (parser, "auth", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_AUTH) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else if (element_type == ELEMENT_SERVICEHELPER) + { + if (!check_no_attributes (parser, "servicehelper", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_SERVICEHELPER) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else if (element_type == ELEMENT_INCLUDEDIR) + { + if (!check_no_attributes (parser, "includedir", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_INCLUDEDIR) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else if (element_type == ELEMENT_STANDARD_SESSION_SERVICEDIRS) + { + DBusList *link; + DBusList *dirs; + dirs = NULL; + + if (!check_no_attributes (parser, "standard_session_servicedirs", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_STANDARD_SESSION_SERVICEDIRS) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!_dbus_get_standard_session_servicedirs (&dirs)) + { + BUS_SET_OOM (error); + return FALSE; + } + + while ((link = _dbus_list_pop_first_link (&dirs))) + service_dirs_append_link_unique_or_free (&parser->service_dirs, link); + + return TRUE; + } + else if (element_type == ELEMENT_STANDARD_SYSTEM_SERVICEDIRS) + { + DBusList *link; + DBusList *dirs; + dirs = NULL; + + if (!check_no_attributes (parser, "standard_system_servicedirs", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_STANDARD_SYSTEM_SERVICEDIRS) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!_dbus_get_standard_system_servicedirs (&dirs)) + { + BUS_SET_OOM (error); + return FALSE; + } + + while ((link = _dbus_list_pop_first_link (&dirs))) + service_dirs_append_link_unique_or_free (&parser->service_dirs, link); + + return TRUE; + } + else if (element_type == ELEMENT_ALLOW_ANONYMOUS) + { + if (!check_no_attributes (parser, "allow_anonymous", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_ALLOW_ANONYMOUS) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + parser->allow_anonymous = TRUE; + return TRUE; + } + else if (element_type == ELEMENT_SERVICEDIR) + { + if (!check_no_attributes (parser, "servicedir", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_SERVICEDIR) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else if (element_type == ELEMENT_INCLUDE) + { + Element *e; + const char *if_selinux_enabled; + const char *ignore_missing; + const char *selinux_root_relative; + + if ((e = push_element (parser, ELEMENT_INCLUDE)) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + e->d.include.ignore_missing = FALSE; + e->d.include.if_selinux_enabled = FALSE; + e->d.include.selinux_root_relative = FALSE; + + if (!locate_attributes (parser, "include", + attribute_names, + attribute_values, + error, + "ignore_missing", &ignore_missing, + "if_selinux_enabled", &if_selinux_enabled, + "selinux_root_relative", &selinux_root_relative, + NULL)) + return FALSE; + + if (ignore_missing != NULL) + { + if (strcmp (ignore_missing, "yes") == 0) + e->d.include.ignore_missing = TRUE; + else if (strcmp (ignore_missing, "no") == 0) + e->d.include.ignore_missing = FALSE; + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "ignore_missing attribute must have value \"yes\" or \"no\""); + return FALSE; + } + } + + if (if_selinux_enabled != NULL) + { + if (strcmp (if_selinux_enabled, "yes") == 0) + e->d.include.if_selinux_enabled = TRUE; + else if (strcmp (if_selinux_enabled, "no") == 0) + e->d.include.if_selinux_enabled = FALSE; + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "if_selinux_enabled attribute must have value" + " \"yes\" or \"no\""); + return FALSE; + } + } + + if (selinux_root_relative != NULL) + { + if (strcmp (selinux_root_relative, "yes") == 0) + e->d.include.selinux_root_relative = TRUE; + else if (strcmp (selinux_root_relative, "no") == 0) + e->d.include.selinux_root_relative = FALSE; + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "selinux_root_relative attribute must have value" + " \"yes\" or \"no\""); + return FALSE; + } + } + + return TRUE; + } + else if (element_type == ELEMENT_POLICY) + { + Element *e; + const char *context; + const char *user; + const char *group; + const char *at_console; + + if ((e = push_element (parser, ELEMENT_POLICY)) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + e->d.policy.type = POLICY_IGNORED; + + if (!locate_attributes (parser, "policy", + attribute_names, + attribute_values, + error, + "context", &context, + "user", &user, + "group", &group, + "at_console", &at_console, + NULL)) + return FALSE; + + if (((context && user) || + (context && group) || + (context && at_console)) || + ((user && group) || + (user && at_console)) || + (group && at_console) || + !(context || user || group || at_console)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "<policy> element must have exactly one of (context|user|group|at_console) attributes"); + return FALSE; + } + + if (context != NULL) + { + if (strcmp (context, "default") == 0) + { + e->d.policy.type = POLICY_DEFAULT; + } + else if (strcmp (context, "mandatory") == 0) + { + e->d.policy.type = POLICY_MANDATORY; + } + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "context attribute on <policy> must have the value \"default\" or \"mandatory\", not \"%s\"", + context); + return FALSE; + } + } + else if (user != NULL) + { + DBusString username; + _dbus_string_init_const (&username, user); + + if (_dbus_parse_unix_user_from_config (&username, + &e->d.policy.gid_uid_or_at_console)) + e->d.policy.type = POLICY_USER; + else + _dbus_warn ("Unknown username \"%s\" in message bus configuration file\n", + user); + } + else if (group != NULL) + { + DBusString group_name; + _dbus_string_init_const (&group_name, group); + + if (_dbus_parse_unix_group_from_config (&group_name, + &e->d.policy.gid_uid_or_at_console)) + e->d.policy.type = POLICY_GROUP; + else + _dbus_warn ("Unknown group \"%s\" in message bus configuration file\n", + group); + } + else if (at_console != NULL) + { + dbus_bool_t t; + t = (strcmp (at_console, "true") == 0); + if (t || strcmp (at_console, "false") == 0) + { + e->d.policy.gid_uid_or_at_console = t; + e->d.policy.type = POLICY_CONSOLE; + } + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Unknown value \"%s\" for at_console in message bus configuration file", + at_console); + + return FALSE; + } + } + else + { + _dbus_assert_not_reached ("all <policy> attributes null and we didn't set error"); + } + + return TRUE; + } + else if (element_type == ELEMENT_LIMIT) + { + Element *e; + const char *name; + + if ((e = push_element (parser, ELEMENT_LIMIT)) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!locate_attributes (parser, "limit", + attribute_names, + attribute_values, + error, + "name", &name, + NULL)) + return FALSE; + + if (name == NULL) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "<limit> element must have a \"name\" attribute"); + return FALSE; + } + + e->d.limit.name = _dbus_strdup (name); + if (e->d.limit.name == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else if (element_type == ELEMENT_SELINUX) + { + if (!check_no_attributes (parser, "selinux", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_SELINUX) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else if (element_type == ELEMENT_APPARMOR) + { + Element *e; + const char *mode; + + if ((e = push_element (parser, ELEMENT_APPARMOR)) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!locate_attributes (parser, "apparmor", + attribute_names, + attribute_values, + error, + "mode", &mode, + NULL)) + return FALSE; + + return bus_apparmor_set_mode_from_config (mode, error); + } + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Element <%s> not allowed inside <%s> in configuration file", + element_name, "busconfig"); + return FALSE; + } +} + +static dbus_bool_t +append_rule_from_element (BusConfigParser *parser, + const char *element_name, + const char **attribute_names, + const char **attribute_values, + dbus_bool_t allow, + DBusError *error) +{ + const char *log; + const char *send_interface; + const char *send_member; + const char *send_error; + const char *send_destination; + const char *send_path; + const char *send_type; + const char *receive_interface; + const char *receive_member; + const char *receive_error; + const char *receive_sender; + const char *receive_path; + const char *receive_type; + const char *eavesdrop; + const char *send_requested_reply; + const char *receive_requested_reply; + const char *own; + const char *own_prefix; + const char *user; + const char *group; + + BusPolicyRule *rule; + + if (!locate_attributes (parser, element_name, + attribute_names, + attribute_values, + error, + "send_interface", &send_interface, + "send_member", &send_member, + "send_error", &send_error, + "send_destination", &send_destination, + "send_path", &send_path, + "send_type", &send_type, + "receive_interface", &receive_interface, + "receive_member", &receive_member, + "receive_error", &receive_error, + "receive_sender", &receive_sender, + "receive_path", &receive_path, + "receive_type", &receive_type, + "eavesdrop", &eavesdrop, + "send_requested_reply", &send_requested_reply, + "receive_requested_reply", &receive_requested_reply, + "own", &own, + "own_prefix", &own_prefix, + "user", &user, + "group", &group, + "log", &log, + NULL)) + return FALSE; + + if (!(send_interface || send_member || send_error || send_destination || + send_type || send_path || + receive_interface || receive_member || receive_error || receive_sender || + receive_type || receive_path || eavesdrop || + send_requested_reply || receive_requested_reply || + own || own_prefix || user || group)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Element <%s> must have one or more attributes", + element_name); + return FALSE; + } + + if ((send_member && (send_interface == NULL && send_path == NULL)) || + (receive_member && (receive_interface == NULL && receive_path == NULL))) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "On element <%s>, if you specify a member you must specify an interface or a path. Keep in mind that not all messages have an interface field.", + element_name); + return FALSE; + } + + /* Allowed combinations of elements are: + * + * base, must be all send or all receive: + * nothing + * interface + * interface + member + * error + * + * base send_ can combine with send_destination, send_path, send_type, send_requested_reply + * base receive_ with receive_sender, receive_path, receive_type, receive_requested_reply, eavesdrop + * + * user, group, own, own_prefix must occur alone + * + * Pretty sure the below stuff is broken, FIXME think about it more. + */ + + if ((send_interface && (send_error || + receive_interface || + receive_member || + receive_error || + receive_sender || + receive_requested_reply || + own || own_prefix || + user || + group)) || + + (send_member && (send_error || + receive_interface || + receive_member || + receive_error || + receive_sender || + receive_requested_reply || + own || own_prefix || + user || + group)) || + + (send_error && (receive_interface || + receive_member || + receive_error || + receive_sender || + receive_requested_reply || + own || own_prefix || + user || + group)) || + + (send_destination && (receive_interface || + receive_member || + receive_error || + receive_sender || + receive_requested_reply || + own || own_prefix || + user || + group)) || + + (send_type && (receive_interface || + receive_member || + receive_error || + receive_sender || + receive_requested_reply || + own || own_prefix || + user || + group)) || + + (send_path && (receive_interface || + receive_member || + receive_error || + receive_sender || + receive_requested_reply || + own || own_prefix || + user || + group)) || + + (send_requested_reply && (receive_interface || + receive_member || + receive_error || + receive_sender || + receive_requested_reply || + own || own_prefix || + user || + group)) || + + (receive_interface && (receive_error || + own || own_prefix || + user || + group)) || + + (receive_member && (receive_error || + own || own_prefix || + user || + group)) || + + (receive_error && (own || own_prefix || + user || + group)) || + + (eavesdrop && (own || own_prefix || + user || + group)) || + + (receive_requested_reply && (own || own_prefix || + user || + group)) || + + (own && (own_prefix || user || group)) || + + (own_prefix && (own || user || group)) || + + (user && group)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Invalid combination of attributes on element <%s>", + element_name); + return FALSE; + } + + rule = NULL; + + /* In BusPolicyRule, NULL represents wildcard. + * In the config file, '*' represents it. + */ +#define IS_WILDCARD(str) ((str) && ((str)[0]) == '*' && ((str)[1]) == '\0') + + if (send_interface || send_member || send_error || send_destination || + send_path || send_type || send_requested_reply) + { + int message_type; + + if (IS_WILDCARD (send_interface)) + send_interface = NULL; + if (IS_WILDCARD (send_member)) + send_member = NULL; + if (IS_WILDCARD (send_error)) + send_error = NULL; + if (IS_WILDCARD (send_destination)) + send_destination = NULL; + if (IS_WILDCARD (send_path)) + send_path = NULL; + if (IS_WILDCARD (send_type)) + send_type = NULL; + + message_type = DBUS_MESSAGE_TYPE_INVALID; + if (send_type != NULL) + { + message_type = dbus_message_type_from_string (send_type); + if (message_type == DBUS_MESSAGE_TYPE_INVALID) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Bad message type \"%s\"", + send_type); + return FALSE; + } + } + + if (eavesdrop && + !(strcmp (eavesdrop, "true") == 0 || + strcmp (eavesdrop, "false") == 0)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Bad value \"%s\" for %s attribute, must be true or false", + "eavesdrop", eavesdrop); + return FALSE; + } + + if (send_requested_reply && + !(strcmp (send_requested_reply, "true") == 0 || + strcmp (send_requested_reply, "false") == 0)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Bad value \"%s\" for %s attribute, must be true or false", + "send_requested_reply", send_requested_reply); + return FALSE; + } + + rule = bus_policy_rule_new (BUS_POLICY_RULE_SEND, allow); + if (rule == NULL) + goto nomem; + + if (eavesdrop) + rule->d.send.eavesdrop = (strcmp (eavesdrop, "true") == 0); + + if (log) + rule->d.send.log = (strcmp (log, "true") == 0); + + if (send_requested_reply) + rule->d.send.requested_reply = (strcmp (send_requested_reply, "true") == 0); + + rule->d.send.message_type = message_type; + rule->d.send.path = _dbus_strdup (send_path); + rule->d.send.interface = _dbus_strdup (send_interface); + rule->d.send.member = _dbus_strdup (send_member); + rule->d.send.error = _dbus_strdup (send_error); + rule->d.send.destination = _dbus_strdup (send_destination); + if (send_path && rule->d.send.path == NULL) + goto nomem; + if (send_interface && rule->d.send.interface == NULL) + goto nomem; + if (send_member && rule->d.send.member == NULL) + goto nomem; + if (send_error && rule->d.send.error == NULL) + goto nomem; + if (send_destination && rule->d.send.destination == NULL) + goto nomem; + } + else if (receive_interface || receive_member || receive_error || receive_sender || + receive_path || receive_type || eavesdrop || receive_requested_reply) + { + int message_type; + + if (IS_WILDCARD (receive_interface)) + receive_interface = NULL; + if (IS_WILDCARD (receive_member)) + receive_member = NULL; + if (IS_WILDCARD (receive_error)) + receive_error = NULL; + if (IS_WILDCARD (receive_sender)) + receive_sender = NULL; + if (IS_WILDCARD (receive_path)) + receive_path = NULL; + if (IS_WILDCARD (receive_type)) + receive_type = NULL; + + message_type = DBUS_MESSAGE_TYPE_INVALID; + if (receive_type != NULL) + { + message_type = dbus_message_type_from_string (receive_type); + if (message_type == DBUS_MESSAGE_TYPE_INVALID) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Bad message type \"%s\"", + receive_type); + return FALSE; + } + } + + + if (eavesdrop && + !(strcmp (eavesdrop, "true") == 0 || + strcmp (eavesdrop, "false") == 0)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Bad value \"%s\" for %s attribute, must be true or false", + "eavesdrop", eavesdrop); + return FALSE; + } + + if (receive_requested_reply && + !(strcmp (receive_requested_reply, "true") == 0 || + strcmp (receive_requested_reply, "false") == 0)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Bad value \"%s\" for %s attribute, must be true or false", + "receive_requested_reply", receive_requested_reply); + return FALSE; + } + + rule = bus_policy_rule_new (BUS_POLICY_RULE_RECEIVE, allow); + if (rule == NULL) + goto nomem; + + if (eavesdrop) + rule->d.receive.eavesdrop = (strcmp (eavesdrop, "true") == 0); + + if (receive_requested_reply) + rule->d.receive.requested_reply = (strcmp (receive_requested_reply, "true") == 0); + + rule->d.receive.message_type = message_type; + rule->d.receive.path = _dbus_strdup (receive_path); + rule->d.receive.interface = _dbus_strdup (receive_interface); + rule->d.receive.member = _dbus_strdup (receive_member); + rule->d.receive.error = _dbus_strdup (receive_error); + rule->d.receive.origin = _dbus_strdup (receive_sender); + + if (receive_path && rule->d.receive.path == NULL) + goto nomem; + if (receive_interface && rule->d.receive.interface == NULL) + goto nomem; + if (receive_member && rule->d.receive.member == NULL) + goto nomem; + if (receive_error && rule->d.receive.error == NULL) + goto nomem; + if (receive_sender && rule->d.receive.origin == NULL) + goto nomem; + } + else if (own || own_prefix) + { + rule = bus_policy_rule_new (BUS_POLICY_RULE_OWN, allow); + if (rule == NULL) + goto nomem; + + if (own) + { + if (IS_WILDCARD (own)) + own = NULL; + + rule->d.own.prefix = 0; + rule->d.own.service_name = _dbus_strdup (own); + if (own && rule->d.own.service_name == NULL) + goto nomem; + } + else + { + rule->d.own.prefix = 1; + rule->d.own.service_name = _dbus_strdup (own_prefix); + if (rule->d.own.service_name == NULL) + goto nomem; + } + } + else if (user) + { + if (IS_WILDCARD (user)) + { + rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow); + if (rule == NULL) + goto nomem; + + rule->d.user.uid = DBUS_UID_UNSET; + } + else + { + DBusString username; + dbus_uid_t uid; + + _dbus_string_init_const (&username, user); + + if (_dbus_parse_unix_user_from_config (&username, &uid)) + { + rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow); + if (rule == NULL) + goto nomem; + + rule->d.user.uid = uid; + } + else + { + _dbus_warn ("Unknown username \"%s\" on element <%s>\n", + user, element_name); + } + } + } + else if (group) + { + if (IS_WILDCARD (group)) + { + rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow); + if (rule == NULL) + goto nomem; + + rule->d.group.gid = DBUS_GID_UNSET; + } + else + { + DBusString groupname; + dbus_gid_t gid; + + _dbus_string_init_const (&groupname, group); + + if (_dbus_parse_unix_group_from_config (&groupname, &gid)) + { + rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow); + if (rule == NULL) + goto nomem; + + rule->d.group.gid = gid; + } + else + { + _dbus_warn ("Unknown group \"%s\" on element <%s>\n", + group, element_name); + } + } + } + else + _dbus_assert_not_reached ("Did not handle some combination of attributes on <allow> or <deny>"); + + if (rule != NULL) + { + Element *pe; + + pe = peek_element (parser); + _dbus_assert (pe != NULL); + _dbus_assert (pe->type == ELEMENT_POLICY); + + switch (pe->d.policy.type) + { + case POLICY_IGNORED: + /* drop the rule on the floor */ + break; + + case POLICY_DEFAULT: + if (!bus_policy_append_default_rule (parser->policy, rule)) + goto nomem; + break; + case POLICY_MANDATORY: + if (!bus_policy_append_mandatory_rule (parser->policy, rule)) + goto nomem; + break; + case POLICY_USER: + if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "<%s> rule cannot be per-user because it has bus-global semantics", + element_name); + goto failed; + } + + if (!bus_policy_append_user_rule (parser->policy, pe->d.policy.gid_uid_or_at_console, + rule)) + goto nomem; + break; + case POLICY_GROUP: + if (!BUS_POLICY_RULE_IS_PER_CLIENT (rule)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "<%s> rule cannot be per-group because it has bus-global semantics", + element_name); + goto failed; + } + + if (!bus_policy_append_group_rule (parser->policy, pe->d.policy.gid_uid_or_at_console, + rule)) + goto nomem; + break; + + + case POLICY_CONSOLE: + if (!bus_policy_append_console_rule (parser->policy, pe->d.policy.gid_uid_or_at_console, + rule)) + goto nomem; + break; + } + + bus_policy_rule_unref (rule); + rule = NULL; + } + + return TRUE; + + nomem: + BUS_SET_OOM (error); + failed: + if (rule) + bus_policy_rule_unref (rule); + return FALSE; +} + +static dbus_bool_t +start_policy_child (BusConfigParser *parser, + const char *element_name, + const char **attribute_names, + const char **attribute_values, + DBusError *error) +{ + if (strcmp (element_name, "allow") == 0) + { + if (!append_rule_from_element (parser, element_name, + attribute_names, attribute_values, + TRUE, error)) + return FALSE; + + if (push_element (parser, ELEMENT_ALLOW) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else if (strcmp (element_name, "deny") == 0) + { + if (!append_rule_from_element (parser, element_name, + attribute_names, attribute_values, + FALSE, error)) + return FALSE; + + if (push_element (parser, ELEMENT_DENY) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Element <%s> not allowed inside <%s> in configuration file", + element_name, "policy"); + return FALSE; + } +} + +static dbus_bool_t +start_selinux_child (BusConfigParser *parser, + const char *element_name, + const char **attribute_names, + const char **attribute_values, + DBusError *error) +{ + char *own_copy; + char *context_copy; + + own_copy = NULL; + context_copy = NULL; + + if (strcmp (element_name, "associate") == 0) + { + const char *own; + const char *context; + + if (!locate_attributes (parser, "associate", + attribute_names, + attribute_values, + error, + "own", &own, + "context", &context, + NULL)) + return FALSE; + + if (push_element (parser, ELEMENT_ASSOCIATE) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (own == NULL || context == NULL) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Element <associate> must have attributes own=\"<servicename>\" and context=\"<selinux context>\""); + return FALSE; + } + + own_copy = _dbus_strdup (own); + if (own_copy == NULL) + goto oom; + context_copy = _dbus_strdup (context); + if (context_copy == NULL) + goto oom; + + if (!_dbus_hash_table_insert_string (parser->service_context_table, + own_copy, context_copy)) + goto oom; + + return TRUE; + } + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Element <%s> not allowed inside <%s> in configuration file", + element_name, "selinux"); + return FALSE; + } + + oom: + if (own_copy) + dbus_free (own_copy); + + if (context_copy) + dbus_free (context_copy); + + BUS_SET_OOM (error); + return FALSE; +} + +dbus_bool_t +bus_config_parser_start_element (BusConfigParser *parser, + const char *element_name, + const char **attribute_names, + const char **attribute_values, + DBusError *error) +{ + ElementType t; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + /* printf ("START: %s\n", element_name); */ + + t = top_element_type (parser); + + if (t == ELEMENT_NONE) + { + if (strcmp (element_name, "busconfig") == 0) + { + if (!check_no_attributes (parser, "busconfig", attribute_names, attribute_values, error)) + return FALSE; + + if (push_element (parser, ELEMENT_BUSCONFIG) == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; + } + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Unknown element <%s> at root of configuration file", + element_name); + return FALSE; + } + } + else if (t == ELEMENT_BUSCONFIG) + { + return start_busconfig_child (parser, element_name, + attribute_names, attribute_values, + error); + } + else if (t == ELEMENT_POLICY) + { + return start_policy_child (parser, element_name, + attribute_names, attribute_values, + error); + } + else if (t == ELEMENT_SELINUX) + { + return start_selinux_child (parser, element_name, + attribute_names, attribute_values, + error); + } + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Element <%s> is not allowed in this context", + element_name); + return FALSE; + } +} + +static dbus_bool_t +set_limit (BusConfigParser *parser, + const char *name, + long value, + DBusError *error) +{ + dbus_bool_t must_be_positive; + dbus_bool_t must_be_int; + + must_be_int = FALSE; + must_be_positive = FALSE; + + if (strcmp (name, "max_incoming_bytes") == 0) + { + must_be_positive = TRUE; + parser->limits.max_incoming_bytes = value; + } + else if (strcmp (name, "max_incoming_unix_fds") == 0) + { + must_be_positive = TRUE; + parser->limits.max_incoming_unix_fds = value; + } + else if (strcmp (name, "max_outgoing_bytes") == 0) + { + must_be_positive = TRUE; + parser->limits.max_outgoing_bytes = value; + } + else if (strcmp (name, "max_outgoing_unix_fds") == 0) + { + must_be_positive = TRUE; + parser->limits.max_outgoing_unix_fds = value; + } + else if (strcmp (name, "max_message_size") == 0) + { + must_be_positive = TRUE; + parser->limits.max_message_size = value; + } + else if (strcmp (name, "max_message_unix_fds") == 0) + { + must_be_positive = TRUE; + parser->limits.max_message_unix_fds = value; + } + else if (strcmp (name, "service_start_timeout") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.activation_timeout = value; + } + else if (strcmp (name, "auth_timeout") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.auth_timeout = value; + } + else if (strcmp (name, "pending_fd_timeout") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.pending_fd_timeout = value; + } + else if (strcmp (name, "reply_timeout") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.reply_timeout = value; + } + else if (strcmp (name, "max_completed_connections") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.max_completed_connections = value; + } + else if (strcmp (name, "max_incomplete_connections") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.max_incomplete_connections = value; + } + else if (strcmp (name, "max_connections_per_user") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.max_connections_per_user = value; + } + else if (strcmp (name, "max_pending_service_starts") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.max_pending_activations = value; + } + else if (strcmp (name, "max_names_per_connection") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.max_services_per_connection = value; + } + else if (strcmp (name, "max_match_rules_per_connection") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.max_match_rules_per_connection = value; + } + else if (strcmp (name, "max_replies_per_connection") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.max_replies_per_connection = value; + } + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "There is no limit called \"%s\"\n", + name); + return FALSE; + } + + if (must_be_positive && value < 0) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "<limit name=\"%s\"> must be a positive number\n", + name); + return FALSE; + } + + if (must_be_int && + (value < _DBUS_INT_MIN || value > _DBUS_INT_MAX)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "<limit name=\"%s\"> value is too large\n", + name); + return FALSE; + } + + return TRUE; +} + +dbus_bool_t +bus_config_parser_end_element (BusConfigParser *parser, + const char *element_name, + DBusError *error) +{ + ElementType t; + const char *n; + Element *e; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + /* printf ("END: %s\n", element_name); */ + + t = top_element_type (parser); + + if (t == ELEMENT_NONE) + { + /* should probably be an assertion failure but + * being paranoid about XML parsers + */ + dbus_set_error (error, DBUS_ERROR_FAILED, + "XML parser ended element with no element on the stack"); + return FALSE; + } + + n = bus_config_parser_element_type_to_name (t); + _dbus_assert (n != NULL); + if (strcmp (n, element_name) != 0) + { + /* should probably be an assertion failure but + * being paranoid about XML parsers + */ + dbus_set_error (error, DBUS_ERROR_FAILED, + "XML element <%s> ended but topmost element on the stack was <%s>", + element_name, n); + return FALSE; + } + + e = peek_element (parser); + _dbus_assert (e != NULL); + + switch (e->type) + { + case ELEMENT_NONE: + _dbus_assert_not_reached ("element in stack has no type"); + break; + + case ELEMENT_INCLUDE: + case ELEMENT_USER: + case ELEMENT_CONFIGTYPE: + case ELEMENT_LISTEN: + case ELEMENT_PIDFILE: + case ELEMENT_AUTH: + case ELEMENT_SERVICEDIR: + case ELEMENT_SERVICEHELPER: + case ELEMENT_INCLUDEDIR: + case ELEMENT_LIMIT: + if (!e->had_content) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "XML element <%s> was expected to have content inside it", + bus_config_parser_element_type_to_name (e->type)); + return FALSE; + } + + if (e->type == ELEMENT_LIMIT) + { + if (!set_limit (parser, e->d.limit.name, e->d.limit.value, + error)) + return FALSE; + } + break; + + case ELEMENT_BUSCONFIG: + case ELEMENT_POLICY: + case ELEMENT_ALLOW: + case ELEMENT_DENY: + case ELEMENT_FORK: + case ELEMENT_SYSLOG: + case ELEMENT_KEEP_UMASK: + case ELEMENT_SELINUX: + case ELEMENT_ASSOCIATE: + case ELEMENT_STANDARD_SESSION_SERVICEDIRS: + case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS: + case ELEMENT_ALLOW_ANONYMOUS: + case ELEMENT_APPARMOR: + break; + } + + pop_element (parser); + + return TRUE; +} + +static dbus_bool_t +all_whitespace (const DBusString *str) +{ + int i; + + _dbus_string_skip_white (str, 0, &i); + + return i == _dbus_string_get_length (str); +} + +static dbus_bool_t +make_full_path (const DBusString *basedir, + const DBusString *filename, + DBusString *full_path) +{ + if (_dbus_path_is_absolute (filename)) + { + return _dbus_string_copy (filename, 0, full_path, 0); + } + else + { + if (!_dbus_string_copy (basedir, 0, full_path, 0)) + return FALSE; + + if (!_dbus_concat_dir_and_file (full_path, filename)) + return FALSE; + + return TRUE; + } +} + +static dbus_bool_t +include_file (BusConfigParser *parser, + const DBusString *filename, + dbus_bool_t ignore_missing, + DBusError *error) +{ + /* FIXME good test case for this would load each config file in the + * test suite both alone, and as an include, and check + * that the result is the same + */ + BusConfigParser *included; + const char *filename_str; + DBusError tmp_error; + + dbus_error_init (&tmp_error); + + filename_str = _dbus_string_get_const_data (filename); + + /* Check to make sure this file hasn't already been included. */ + if (seen_include (parser, filename)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Circular inclusion of file '%s'", + filename_str); + return FALSE; + } + + if (! _dbus_list_append (&parser->included_files, (void *) filename_str)) + { + BUS_SET_OOM (error); + return FALSE; + } + + /* Since parser is passed in as the parent, included + inherits parser's limits. */ + included = bus_config_load (filename, FALSE, parser, &tmp_error); + + _dbus_list_pop_last (&parser->included_files); + + if (included == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (&tmp_error); + + if (dbus_error_has_name (&tmp_error, DBUS_ERROR_FILE_NOT_FOUND) && + ignore_missing) + { + dbus_error_free (&tmp_error); + return TRUE; + } + else + { + dbus_move_error (&tmp_error, error); + return FALSE; + } + } + else + { + _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error); + + if (!merge_included (parser, included, error)) + { + bus_config_parser_unref (included); + return FALSE; + } + + /* Copy included's limits back to parser. */ + parser->limits = included->limits; + + bus_config_parser_unref (included); + return TRUE; + } +} + +static dbus_bool_t +servicehelper_path (BusConfigParser *parser, + const DBusString *filename, + DBusError *error) +{ + const char *filename_str; + char *servicehelper; + + filename_str = _dbus_string_get_const_data (filename); + + /* copy to avoid overwriting with NULL on OOM */ + servicehelper = _dbus_strdup (filename_str); + + /* check for OOM */ + if (servicehelper == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + /* save the latest servicehelper only if not OOM */ + dbus_free (parser->servicehelper); + parser->servicehelper = servicehelper; + + /* We don't check whether the helper exists; instead we + * would just fail to ever activate anything if it doesn't. + * This allows an admin to fix the problem if it doesn't exist. + * It also allows the parser test suite to successfully parse + * test cases without installing the helper. ;-) + */ + + return TRUE; +} + +static dbus_bool_t +include_dir (BusConfigParser *parser, + const DBusString *dirname, + DBusError *error) +{ + DBusString filename; + dbus_bool_t retval; + DBusError tmp_error; + DBusDirIter *dir; + char *s; + + if (!_dbus_string_init (&filename)) + { + BUS_SET_OOM (error); + return FALSE; + } + + retval = FALSE; + + dir = _dbus_directory_open (dirname, error); + + if (dir == NULL) + { + if (dbus_error_has_name (error, DBUS_ERROR_FILE_NOT_FOUND)) + { + dbus_error_free (error); + goto success; + } + else + goto failed; + } + + dbus_error_init (&tmp_error); + while (_dbus_directory_get_next_file (dir, &filename, &tmp_error)) + { + DBusString full_path; + + if (!_dbus_string_init (&full_path)) + { + BUS_SET_OOM (error); + goto failed; + } + + if (!_dbus_string_copy (dirname, 0, &full_path, 0)) + { + BUS_SET_OOM (error); + _dbus_string_free (&full_path); + goto failed; + } + + if (!_dbus_concat_dir_and_file (&full_path, &filename)) + { + BUS_SET_OOM (error); + _dbus_string_free (&full_path); + goto failed; + } + + if (_dbus_string_ends_with_c_str (&full_path, ".conf")) + { + if (!include_file (parser, &full_path, TRUE, error)) + { + if (dbus_error_is_set (error)) + { + /* We log to syslog unconditionally here, because this is + * the configuration parser, so we don't yet know whether + * this bus is going to want to write to syslog! (There's + * also some layer inversion going on, if we want to use + * the bus context.) */ + _dbus_system_log (DBUS_SYSTEM_LOG_INFO, + "Encountered error '%s' while parsing '%s'\n", + error->message, + _dbus_string_get_const_data (&full_path)); + dbus_error_free (error); + } + } + } + + _dbus_string_free (&full_path); + } + + if (dbus_error_is_set (&tmp_error)) + { + dbus_move_error (&tmp_error, error); + goto failed; + } + + + if (!_dbus_string_copy_data (dirname, &s)) + { + BUS_SET_OOM (error); + goto failed; + } + + if (!_dbus_list_append (&parser->conf_dirs, s)) + { + dbus_free (s); + BUS_SET_OOM (error); + goto failed; + } + + success: + retval = TRUE; + + failed: + _dbus_string_free (&filename); + + if (dir) + _dbus_directory_close (dir); + + return retval; +} + +dbus_bool_t +bus_config_parser_content (BusConfigParser *parser, + const DBusString *content, + DBusError *error) +{ + Element *e; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + +#if 0 + { + const char *c_str; + + _dbus_string_get_const_data (content, &c_str); + + printf ("CONTENT %d bytes: %s\n", _dbus_string_get_length (content), c_str); + } +#endif + + e = peek_element (parser); + if (e == NULL) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Text content outside of any XML element in configuration file"); + return FALSE; + } + else if (e->had_content) + { + _dbus_assert_not_reached ("Element had multiple content blocks"); + return FALSE; + } + + switch (top_element_type (parser)) + { + case ELEMENT_NONE: + _dbus_assert_not_reached ("element at top of stack has no type"); + return FALSE; + + case ELEMENT_BUSCONFIG: + case ELEMENT_POLICY: + case ELEMENT_ALLOW: + case ELEMENT_DENY: + case ELEMENT_FORK: + case ELEMENT_SYSLOG: + case ELEMENT_KEEP_UMASK: + case ELEMENT_STANDARD_SESSION_SERVICEDIRS: + case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS: + case ELEMENT_ALLOW_ANONYMOUS: + case ELEMENT_SELINUX: + case ELEMENT_ASSOCIATE: + case ELEMENT_APPARMOR: + if (all_whitespace (content)) + return TRUE; + else + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "No text content expected inside XML element %s in configuration file", + bus_config_parser_element_type_to_name (top_element_type (parser))); + return FALSE; + } + + case ELEMENT_PIDFILE: + { + char *s; + + e->had_content = TRUE; + + if (!_dbus_string_copy_data (content, &s)) + goto nomem; + + dbus_free (parser->pidfile); + parser->pidfile = s; + } + break; + + case ELEMENT_INCLUDE: + { + DBusString full_path, selinux_policy_root; + + e->had_content = TRUE; + + if (e->d.include.if_selinux_enabled + && !bus_selinux_enabled ()) + break; + + if (!_dbus_string_init (&full_path)) + goto nomem; + + if (e->d.include.selinux_root_relative) + { + if (!bus_selinux_get_policy_root ()) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Could not determine SELinux policy root for relative inclusion"); + _dbus_string_free (&full_path); + return FALSE; + } + _dbus_string_init_const (&selinux_policy_root, + bus_selinux_get_policy_root ()); + if (!make_full_path (&selinux_policy_root, content, &full_path)) + { + _dbus_string_free (&full_path); + goto nomem; + } + } + else if (!make_full_path (&parser->basedir, content, &full_path)) + { + _dbus_string_free (&full_path); + goto nomem; + } + + if (!include_file (parser, &full_path, + e->d.include.ignore_missing, error)) + { + _dbus_string_free (&full_path); + return FALSE; + } + + _dbus_string_free (&full_path); + } + break; + + case ELEMENT_SERVICEHELPER: + { + DBusString full_path; + + e->had_content = TRUE; + + if (!_dbus_string_init (&full_path)) + goto nomem; + + if (!make_full_path (&parser->basedir, content, &full_path)) + { + _dbus_string_free (&full_path); + goto nomem; + } + + if (!servicehelper_path (parser, &full_path, error)) + { + _dbus_string_free (&full_path); + return FALSE; + } + + _dbus_string_free (&full_path); + } + break; + + case ELEMENT_INCLUDEDIR: + { + DBusString full_path; + + e->had_content = TRUE; + + if (!_dbus_string_init (&full_path)) + goto nomem; + + if (!make_full_path (&parser->basedir, content, &full_path)) + { + _dbus_string_free (&full_path); + goto nomem; + } + + if (!include_dir (parser, &full_path, error)) + { + _dbus_string_free (&full_path); + return FALSE; + } + + _dbus_string_free (&full_path); + } + break; + + case ELEMENT_USER: + { + char *s; + + e->had_content = TRUE; + + if (!_dbus_string_copy_data (content, &s)) + goto nomem; + + dbus_free (parser->user); + parser->user = s; + } + break; + + case ELEMENT_CONFIGTYPE: + { + char *s; + + e->had_content = TRUE; + + if (!_dbus_string_copy_data (content, &s)) + goto nomem; + + dbus_free (parser->bus_type); + parser->bus_type = s; + } + break; + + case ELEMENT_LISTEN: + { + char *s; + + e->had_content = TRUE; + + if (!_dbus_string_copy_data (content, &s)) + goto nomem; + + if (!_dbus_list_append (&parser->listen_on, + s)) + { + dbus_free (s); + goto nomem; + } + } + break; + + case ELEMENT_AUTH: + { + char *s; + + e->had_content = TRUE; + + if (!_dbus_string_copy_data (content, &s)) + goto nomem; + + if (!_dbus_list_append (&parser->mechanisms, + s)) + { + dbus_free (s); + goto nomem; + } + } + break; + + case ELEMENT_SERVICEDIR: + { + char *s; + DBusString full_path; + + e->had_content = TRUE; + + if (!_dbus_string_init (&full_path)) + goto nomem; + + if (!make_full_path (&parser->basedir, content, &full_path)) + { + _dbus_string_free (&full_path); + goto nomem; + } + + if (!_dbus_string_copy_data (&full_path, &s)) + { + _dbus_string_free (&full_path); + goto nomem; + } + + /* _only_ extra session directories can be specified */ + if (!service_dirs_append_unique_or_free (&parser->service_dirs, s)) + { + _dbus_string_free (&full_path); + dbus_free (s); + goto nomem; + } + + _dbus_string_free (&full_path); + } + break; + + case ELEMENT_LIMIT: + { + long val; + + e->had_content = TRUE; + + val = 0; + if (!_dbus_string_parse_int (content, 0, &val, NULL)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "<limit name=\"%s\"> element has invalid value (could not parse as integer)", + e->d.limit.name); + return FALSE; + } + + e->d.limit.value = val; + + _dbus_verbose ("Loaded value %ld for limit %s\n", + e->d.limit.value, + e->d.limit.name); + } + break; + } + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + return TRUE; + + nomem: + BUS_SET_OOM (error); + return FALSE; +} + +dbus_bool_t +bus_config_parser_finished (BusConfigParser *parser, + DBusError *error) +{ + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (parser->stack != NULL) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Element <%s> was not closed in configuration file", + bus_config_parser_element_type_to_name (top_element_type (parser))); + + return FALSE; + } + + if (parser->is_toplevel && parser->listen_on == NULL) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Configuration file needs one or more <listen> elements giving addresses"); + return FALSE; + } + + return TRUE; +} + +const char* +bus_config_parser_get_user (BusConfigParser *parser) +{ + return parser->user; +} + +const char* +bus_config_parser_get_type (BusConfigParser *parser) +{ + return parser->bus_type; +} + +DBusList** +bus_config_parser_get_addresses (BusConfigParser *parser) +{ + return &parser->listen_on; +} + +DBusList** +bus_config_parser_get_mechanisms (BusConfigParser *parser) +{ + return &parser->mechanisms; +} + +DBusList** +bus_config_parser_get_service_dirs (BusConfigParser *parser) +{ + return &parser->service_dirs; +} + +DBusList** +bus_config_parser_get_conf_dirs (BusConfigParser *parser) +{ + return &parser->conf_dirs; +} + +dbus_bool_t +bus_config_parser_get_fork (BusConfigParser *parser) +{ + return parser->fork; +} + +dbus_bool_t +bus_config_parser_get_syslog (BusConfigParser *parser) +{ + return parser->syslog; +} + +dbus_bool_t +bus_config_parser_get_keep_umask (BusConfigParser *parser) +{ + return parser->keep_umask; +} + +dbus_bool_t +bus_config_parser_get_allow_anonymous (BusConfigParser *parser) +{ + return parser->allow_anonymous; +} + +const char * +bus_config_parser_get_pidfile (BusConfigParser *parser) +{ + return parser->pidfile; +} + +const char * +bus_config_parser_get_servicehelper (BusConfigParser *parser) +{ + return parser->servicehelper; +} + +BusPolicy* +bus_config_parser_steal_policy (BusConfigParser *parser) +{ + BusPolicy *policy; + + _dbus_assert (parser->policy != NULL); /* can only steal the policy 1 time */ + + policy = parser->policy; + + parser->policy = NULL; + + return policy; +} + +/* Overwrite any limits that were set in the configuration file */ +void +bus_config_parser_get_limits (BusConfigParser *parser, + BusLimits *limits) +{ + *limits = parser->limits; +} + +DBusHashTable* +bus_config_parser_steal_service_context_table (BusConfigParser *parser) +{ + DBusHashTable *table; + + _dbus_assert (parser->service_context_table != NULL); /* can only steal once */ + + table = parser->service_context_table; + + parser->service_context_table = NULL; + + return table; +} + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS +#include <stdio.h> + +typedef enum +{ + VALID, + INVALID, + UNKNOWN +} Validity; + +static dbus_bool_t +do_check_own_rules (BusPolicy *policy) +{ + const struct { + char *name; + dbus_bool_t allowed; + } checks[] = { + {"org.freedesktop", FALSE}, + {"org.freedesktop.ManySystem", FALSE}, + {"org.freedesktop.ManySystems", TRUE}, + {"org.freedesktop.ManySystems.foo", TRUE}, + {"org.freedesktop.ManySystems.foo.bar", TRUE}, + {"org.freedesktop.ManySystems2", FALSE}, + {"org.freedesktop.ManySystems2.foo", FALSE}, + {"org.freedesktop.ManySystems2.foo.bar", FALSE}, + {NULL, FALSE} + }; + int i = 0; + + while (checks[i].name) + { + DBusString service_name; + dbus_bool_t ret; + + if (!_dbus_string_init (&service_name)) + _dbus_assert_not_reached ("couldn't init string"); + if (!_dbus_string_append (&service_name, checks[i].name)) + _dbus_assert_not_reached ("couldn't append string"); + + ret = bus_policy_check_can_own (policy, &service_name); + printf (" Check name %s: %s\n", checks[i].name, + ret ? "allowed" : "not allowed"); + if (checks[i].allowed && !ret) + { + _dbus_warn ("Cannot own %s\n", checks[i].name); + return FALSE; + } + if (!checks[i].allowed && ret) + { + _dbus_warn ("Can own %s\n", checks[i].name); + return FALSE; + } + _dbus_string_free (&service_name); + + i++; + } + + return TRUE; +} + +static dbus_bool_t +do_load (const DBusString *full_path, + Validity validity, + dbus_bool_t oom_possible, + dbus_bool_t check_own_rules) +{ + BusConfigParser *parser; + DBusError error; + + dbus_error_init (&error); + + parser = bus_config_load (full_path, TRUE, NULL, &error); + if (parser == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + + if (oom_possible && + dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + _dbus_verbose ("Failed to load valid file due to OOM\n"); + dbus_error_free (&error); + return TRUE; + } + else if (validity == VALID) + { + _dbus_warn ("Failed to load valid file but still had memory: %s\n", + error.message); + + dbus_error_free (&error); + return FALSE; + } + else + { + dbus_error_free (&error); + return TRUE; + } + } + else + { + _DBUS_ASSERT_ERROR_IS_CLEAR (&error); + + if (check_own_rules && do_check_own_rules (parser->policy) == FALSE) + { + return FALSE; + } + + bus_config_parser_unref (parser); + + if (validity == INVALID) + { + _dbus_warn ("Accepted invalid file\n"); + return FALSE; + } + + return TRUE; + } +} + +typedef struct +{ + const DBusString *full_path; + Validity validity; + dbus_bool_t check_own_rules; +} LoaderOomData; + +static dbus_bool_t +check_loader_oom_func (void *data) +{ + LoaderOomData *d = data; + + return do_load (d->full_path, d->validity, TRUE, d->check_own_rules); +} + +static dbus_bool_t +process_test_valid_subdir (const DBusString *test_base_dir, + const char *subdir, + Validity validity) +{ + DBusString test_directory; + DBusString filename; + DBusDirIter *dir; + dbus_bool_t retval; + DBusError error; + + retval = FALSE; + dir = NULL; + + if (!_dbus_string_init (&test_directory)) + _dbus_assert_not_reached ("didn't allocate test_directory\n"); + + _dbus_string_init_const (&filename, subdir); + + if (!_dbus_string_copy (test_base_dir, 0, + &test_directory, 0)) + _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory"); + + if (!_dbus_concat_dir_and_file (&test_directory, &filename)) + _dbus_assert_not_reached ("couldn't allocate full path"); + + _dbus_string_free (&filename); + if (!_dbus_string_init (&filename)) + _dbus_assert_not_reached ("didn't allocate filename string\n"); + + dbus_error_init (&error); + dir = _dbus_directory_open (&test_directory, &error); + if (dir == NULL) + { + _dbus_warn ("Could not open %s: %s\n", + _dbus_string_get_const_data (&test_directory), + error.message); + dbus_error_free (&error); + goto failed; + } + + if (validity == VALID) + printf ("Testing valid files:\n"); + else if (validity == INVALID) + printf ("Testing invalid files:\n"); + else + printf ("Testing unknown files:\n"); + + next: + while (_dbus_directory_get_next_file (dir, &filename, &error)) + { + DBusString full_path; + LoaderOomData d; + + if (!_dbus_string_init (&full_path)) + _dbus_assert_not_reached ("couldn't init string"); + + if (!_dbus_string_copy (&test_directory, 0, &full_path, 0)) + _dbus_assert_not_reached ("couldn't copy dir to full_path"); + + if (!_dbus_concat_dir_and_file (&full_path, &filename)) + _dbus_assert_not_reached ("couldn't concat file to dir"); + + if (!_dbus_string_ends_with_c_str (&full_path, ".conf")) + { + _dbus_verbose ("Skipping non-.conf file %s\n", + _dbus_string_get_const_data (&filename)); + _dbus_string_free (&full_path); + goto next; + } + + printf (" %s\n", _dbus_string_get_const_data (&filename)); + + _dbus_verbose (" expecting %s\n", + validity == VALID ? "valid" : + (validity == INVALID ? "invalid" : + (validity == UNKNOWN ? "unknown" : "???"))); + + d.full_path = &full_path; + d.validity = validity; + d.check_own_rules = _dbus_string_ends_with_c_str (&full_path, + "check-own-rules.conf"); + + /* FIXME hackaround for an expat problem, see + * https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=124747 + * http://freedesktop.org/pipermail/dbus/2004-May/001153.html + */ + /* if (!_dbus_test_oom_handling ("config-loader", check_loader_oom_func, &d)) */ + if (!check_loader_oom_func (&d)) + _dbus_assert_not_reached ("test failed"); + + _dbus_string_free (&full_path); + } + + if (dbus_error_is_set (&error)) + { + _dbus_warn ("Could not get next file in %s: %s\n", + _dbus_string_get_const_data (&test_directory), + error.message); + dbus_error_free (&error); + goto failed; + } + + retval = TRUE; + + failed: + + if (dir) + _dbus_directory_close (dir); + _dbus_string_free (&test_directory); + _dbus_string_free (&filename); + + return retval; +} + +static dbus_bool_t +bools_equal (dbus_bool_t a, + dbus_bool_t b) +{ + return a ? b : !b; +} + +static dbus_bool_t +strings_equal_or_both_null (const char *a, + const char *b) +{ + if (a == NULL || b == NULL) + return a == b; + else + return !strcmp (a, b); +} + +static dbus_bool_t +elements_equal (const Element *a, + const Element *b) +{ + if (a->type != b->type) + return FALSE; + + if (!bools_equal (a->had_content, b->had_content)) + return FALSE; + + switch (a->type) + { + + case ELEMENT_INCLUDE: + if (!bools_equal (a->d.include.ignore_missing, + b->d.include.ignore_missing)) + return FALSE; + break; + + case ELEMENT_POLICY: + if (a->d.policy.type != b->d.policy.type) + return FALSE; + if (a->d.policy.gid_uid_or_at_console != b->d.policy.gid_uid_or_at_console) + return FALSE; + break; + + case ELEMENT_LIMIT: + if (strcmp (a->d.limit.name, b->d.limit.name)) + return FALSE; + if (a->d.limit.value != b->d.limit.value) + return FALSE; + break; + + default: + /* do nothing */ + break; + } + + return TRUE; + +} + +static dbus_bool_t +lists_of_elements_equal (DBusList *a, + DBusList *b) +{ + DBusList *ia; + DBusList *ib; + + ia = a; + ib = b; + + while (ia != NULL && ib != NULL) + { + if (elements_equal (ia->data, ib->data)) + return FALSE; + ia = _dbus_list_get_next_link (&a, ia); + ib = _dbus_list_get_next_link (&b, ib); + } + + return ia == NULL && ib == NULL; +} + +static dbus_bool_t +lists_of_c_strings_equal (DBusList *a, + DBusList *b) +{ + DBusList *ia; + DBusList *ib; + + ia = a; + ib = b; + + while (ia != NULL && ib != NULL) + { + if (strcmp (ia->data, ib->data)) + return FALSE; + ia = _dbus_list_get_next_link (&a, ia); + ib = _dbus_list_get_next_link (&b, ib); + } + + return ia == NULL && ib == NULL; +} + +static dbus_bool_t +limits_equal (const BusLimits *a, + const BusLimits *b) +{ + return + (a->max_incoming_bytes == b->max_incoming_bytes + || a->max_incoming_unix_fds == b->max_incoming_unix_fds + || a->max_outgoing_bytes == b->max_outgoing_bytes + || a->max_outgoing_unix_fds == b->max_outgoing_unix_fds + || a->max_message_size == b->max_message_size + || a->max_message_unix_fds == b->max_message_unix_fds + || a->activation_timeout == b->activation_timeout + || a->auth_timeout == b->auth_timeout + || a->pending_fd_timeout == b->pending_fd_timeout + || a->max_completed_connections == b->max_completed_connections + || a->max_incomplete_connections == b->max_incomplete_connections + || a->max_connections_per_user == b->max_connections_per_user + || a->max_pending_activations == b->max_pending_activations + || a->max_services_per_connection == b->max_services_per_connection + || a->max_match_rules_per_connection == b->max_match_rules_per_connection + || a->max_replies_per_connection == b->max_replies_per_connection + || a->reply_timeout == b->reply_timeout); +} + +static dbus_bool_t +config_parsers_equal (const BusConfigParser *a, + const BusConfigParser *b) +{ + if (!_dbus_string_equal (&a->basedir, &b->basedir)) + return FALSE; + + if (!lists_of_elements_equal (a->stack, b->stack)) + return FALSE; + + if (!strings_equal_or_both_null (a->user, b->user)) + return FALSE; + + if (!lists_of_c_strings_equal (a->listen_on, b->listen_on)) + return FALSE; + + if (!lists_of_c_strings_equal (a->mechanisms, b->mechanisms)) + return FALSE; + + if (!lists_of_c_strings_equal (a->service_dirs, b->service_dirs)) + return FALSE; + + /* FIXME: compare policy */ + + /* FIXME: compare service selinux ID table */ + + if (! limits_equal (&a->limits, &b->limits)) + return FALSE; + + if (!strings_equal_or_both_null (a->pidfile, b->pidfile)) + return FALSE; + + if (! bools_equal (a->fork, b->fork)) + return FALSE; + + if (! bools_equal (a->keep_umask, b->keep_umask)) + return FALSE; + + if (! bools_equal (a->is_toplevel, b->is_toplevel)) + return FALSE; + + return TRUE; +} + +static dbus_bool_t +all_are_equiv (const DBusString *target_directory) +{ + DBusString filename; + DBusDirIter *dir; + BusConfigParser *first_parser; + BusConfigParser *parser; + DBusError error; + dbus_bool_t equal; + dbus_bool_t retval; + + dir = NULL; + first_parser = NULL; + parser = NULL; + retval = FALSE; + + if (!_dbus_string_init (&filename)) + _dbus_assert_not_reached ("didn't allocate filename string"); + + dbus_error_init (&error); + dir = _dbus_directory_open (target_directory, &error); + if (dir == NULL) + { + _dbus_warn ("Could not open %s: %s\n", + _dbus_string_get_const_data (target_directory), + error.message); + dbus_error_free (&error); + goto finished; + } + + printf ("Comparing equivalent files:\n"); + + next: + while (_dbus_directory_get_next_file (dir, &filename, &error)) + { + DBusString full_path; + + if (!_dbus_string_init (&full_path)) + _dbus_assert_not_reached ("couldn't init string"); + + if (!_dbus_string_copy (target_directory, 0, &full_path, 0)) + _dbus_assert_not_reached ("couldn't copy dir to full_path"); + + if (!_dbus_concat_dir_and_file (&full_path, &filename)) + _dbus_assert_not_reached ("couldn't concat file to dir"); + + if (!_dbus_string_ends_with_c_str (&full_path, ".conf")) + { + _dbus_verbose ("Skipping non-.conf file %s\n", + _dbus_string_get_const_data (&filename)); + _dbus_string_free (&full_path); + goto next; + } + + printf (" %s\n", _dbus_string_get_const_data (&filename)); + + parser = bus_config_load (&full_path, TRUE, NULL, &error); + + if (parser == NULL) + { + _dbus_warn ("Could not load file %s: %s\n", + _dbus_string_get_const_data (&full_path), + error.message); + _dbus_string_free (&full_path); + dbus_error_free (&error); + goto finished; + } + else if (first_parser == NULL) + { + _dbus_string_free (&full_path); + first_parser = parser; + } + else + { + _dbus_string_free (&full_path); + equal = config_parsers_equal (first_parser, parser); + bus_config_parser_unref (parser); + if (! equal) + goto finished; + } + } + + retval = TRUE; + + finished: + _dbus_string_free (&filename); + if (first_parser) + bus_config_parser_unref (first_parser); + if (dir) + _dbus_directory_close (dir); + + return retval; + +} + +static dbus_bool_t +process_test_equiv_subdir (const DBusString *test_base_dir, + const char *subdir) +{ + DBusString test_directory; + DBusString filename; + DBusDirIter *dir; + DBusError error; + dbus_bool_t equal; + dbus_bool_t retval; + + dir = NULL; + retval = FALSE; + + if (!_dbus_string_init (&test_directory)) + _dbus_assert_not_reached ("didn't allocate test_directory"); + + _dbus_string_init_const (&filename, subdir); + + if (!_dbus_string_copy (test_base_dir, 0, + &test_directory, 0)) + _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory"); + + if (!_dbus_concat_dir_and_file (&test_directory, &filename)) + _dbus_assert_not_reached ("couldn't allocate full path"); + + _dbus_string_free (&filename); + if (!_dbus_string_init (&filename)) + _dbus_assert_not_reached ("didn't allocate filename string"); + + dbus_error_init (&error); + dir = _dbus_directory_open (&test_directory, &error); + if (dir == NULL) + { + _dbus_warn ("Could not open %s: %s\n", + _dbus_string_get_const_data (&test_directory), + error.message); + dbus_error_free (&error); + goto finished; + } + + while (_dbus_directory_get_next_file (dir, &filename, &error)) + { + DBusString full_path; + + /* Skip CVS's magic directories! */ + if (_dbus_string_equal_c_str (&filename, "CVS")) + continue; + + if (!_dbus_string_init (&full_path)) + _dbus_assert_not_reached ("couldn't init string"); + + if (!_dbus_string_copy (&test_directory, 0, &full_path, 0)) + _dbus_assert_not_reached ("couldn't copy dir to full_path"); + + if (!_dbus_concat_dir_and_file (&full_path, &filename)) + _dbus_assert_not_reached ("couldn't concat file to dir"); + + equal = all_are_equiv (&full_path); + _dbus_string_free (&full_path); + + if (!equal) + goto finished; + } + + retval = TRUE; + + finished: + _dbus_string_free (&test_directory); + _dbus_string_free (&filename); + if (dir) + _dbus_directory_close (dir); + + return retval; + +} + +static const char *test_session_service_dir_matches[] = + { +#ifdef DBUS_UNIX + "/testhome/foo/.testlocal/testshare/dbus-1/services", + "/testusr/testlocal/testshare/dbus-1/services", + "/testusr/testshare/dbus-1/services", + DBUS_DATADIR"/dbus-1/services", +#endif +/* will be filled in test_default_session_servicedirs() */ +#ifdef DBUS_WIN + NULL, + NULL, +#endif + NULL + }; + +static dbus_bool_t +test_default_session_servicedirs (void) +{ + DBusList *dirs; + DBusList *link; + DBusString progs; + DBusString install_root_based; + int i; + dbus_bool_t ret = FALSE; +#ifdef DBUS_WIN + const char *tmp; + const char *common_progs; +#endif + + /* On Unix we don't actually use these, but it's easier to handle the + * deallocation if we always allocate them, whether needed or not */ + if (!_dbus_string_init (&progs) || + !_dbus_string_init (&install_root_based)) + _dbus_assert_not_reached ("OOM allocating strings"); + +#ifdef DBUS_WIN + if (!_dbus_string_append (&install_root_based, DBUS_DATADIR) || + !_dbus_string_append (&install_root_based, "/dbus-1/services")) + goto out; + + tmp = _dbus_replace_install_prefix ( + _dbus_string_get_const_data (&install_root_based)); + + if (tmp == NULL || + !_dbus_string_set_length (&install_root_based, 0) || + !_dbus_string_append (&install_root_based, tmp)) + goto out; + + test_session_service_dir_matches[0] = _dbus_string_get_const_data ( + &install_root_based); + + common_progs = _dbus_getenv ("CommonProgramFiles"); + + if (common_progs) + { + if (!_dbus_string_append (&progs, common_progs)) + goto out; + + if (!_dbus_string_append (&progs, "/dbus-1/services")) + goto out; + + test_session_service_dir_matches[1] = _dbus_string_get_const_data(&progs); + } +#endif + dirs = NULL; + + printf ("Testing retrieving the default session service directories\n"); + if (!_dbus_get_standard_session_servicedirs (&dirs)) + _dbus_assert_not_reached ("couldn't get stardard dirs"); + + /* make sure our defaults end with share/dbus-1/service */ + while ((link = _dbus_list_pop_first_link (&dirs))) + { + DBusString path; + + printf (" default service dir: %s\n", (char *)link->data); + _dbus_string_init_const (&path, (char *)link->data); + if (!_dbus_string_ends_with_c_str (&path, "dbus-1/services")) + { + printf ("error with default session service directories\n"); + dbus_free (link->data); + _dbus_list_free_link (link); + goto out; + } + + dbus_free (link->data); + _dbus_list_free_link (link); + } + +#ifdef DBUS_UNIX + if (!dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare")) + _dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME"); + + if (!dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:")) + _dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS"); +#endif + if (!_dbus_get_standard_session_servicedirs (&dirs)) + _dbus_assert_not_reached ("couldn't get stardard dirs"); + + /* make sure we read and parse the env variable correctly */ + i = 0; + while ((link = _dbus_list_pop_first_link (&dirs))) + { + printf (" test service dir: %s\n", (char *)link->data); + if (test_session_service_dir_matches[i] == NULL) + { + printf ("more directories parsed than in match set\n"); + dbus_free (link->data); + _dbus_list_free_link (link); + goto out; + } + + if (strcmp (test_session_service_dir_matches[i], + (char *)link->data) != 0) + { + printf ("%s directory does not match %s in the match set\n", + (char *)link->data, + test_session_service_dir_matches[i]); + dbus_free (link->data); + _dbus_list_free_link (link); + goto out; + } + + ++i; + + dbus_free (link->data); + _dbus_list_free_link (link); + } + + if (test_session_service_dir_matches[i] != NULL) + { + printf ("extra data %s in the match set was not matched\n", + test_session_service_dir_matches[i]); + goto out; + } + + ret = TRUE; + +out: + _dbus_string_free (&install_root_based); + _dbus_string_free (&progs); + return ret; +} + +static const char *test_system_service_dir_matches[] = + { +#ifdef DBUS_UNIX + "/usr/local/share/dbus-1/system-services", + "/usr/share/dbus-1/system-services", +#endif + DBUS_DATADIR"/dbus-1/system-services", +#ifdef DBUS_UNIX + "/lib/dbus-1/system-services", +#endif + +#ifdef DBUS_WIN + NULL, +#endif + NULL + }; + +static dbus_bool_t +test_default_system_servicedirs (void) +{ + DBusList *dirs; + DBusList *link; + DBusString progs; +#ifndef DBUS_UNIX + const char *common_progs; +#endif + int i; + + /* On Unix we don't actually use this variable, but it's easier to handle the + * deallocation if we always allocate it, whether needed or not */ + if (!_dbus_string_init (&progs)) + _dbus_assert_not_reached ("OOM allocating progs"); + +#ifndef DBUS_UNIX + common_progs = _dbus_getenv ("CommonProgramFiles"); + + if (common_progs) + { + if (!_dbus_string_append (&progs, common_progs)) + { + _dbus_string_free (&progs); + return FALSE; + } + + if (!_dbus_string_append (&progs, "/dbus-1/system-services")) + { + _dbus_string_free (&progs); + return FALSE; + } + test_system_service_dir_matches[1] = _dbus_string_get_const_data(&progs); + } +#endif + dirs = NULL; + + printf ("Testing retrieving the default system service directories\n"); + if (!_dbus_get_standard_system_servicedirs (&dirs)) + _dbus_assert_not_reached ("couldn't get stardard dirs"); + + /* make sure our defaults end with share/dbus-1/system-service */ + while ((link = _dbus_list_pop_first_link (&dirs))) + { + DBusString path; + + printf (" default service dir: %s\n", (char *)link->data); + _dbus_string_init_const (&path, (char *)link->data); + if (!_dbus_string_ends_with_c_str (&path, "dbus-1/system-services")) + { + printf ("error with default system service directories\n"); + dbus_free (link->data); + _dbus_list_free_link (link); + _dbus_string_free (&progs); + return FALSE; + } + + dbus_free (link->data); + _dbus_list_free_link (link); + } + +#ifdef DBUS_UNIX + if (!dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare")) + _dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME"); + + if (!dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:")) + _dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS"); +#endif + if (!_dbus_get_standard_system_servicedirs (&dirs)) + _dbus_assert_not_reached ("couldn't get stardard dirs"); + + /* make sure we read and parse the env variable correctly */ + i = 0; + while ((link = _dbus_list_pop_first_link (&dirs))) + { + printf (" test service dir: %s\n", (char *)link->data); + if (test_system_service_dir_matches[i] == NULL) + { + printf ("more directories parsed than in match set\n"); + dbus_free (link->data); + _dbus_list_free_link (link); + _dbus_string_free (&progs); + return FALSE; + } + + if (strcmp (test_system_service_dir_matches[i], + (char *)link->data) != 0) + { + printf ("%s directory does not match %s in the match set\n", + (char *)link->data, + test_system_service_dir_matches[i]); + dbus_free (link->data); + _dbus_list_free_link (link); + _dbus_string_free (&progs); + return FALSE; + } + + ++i; + + dbus_free (link->data); + _dbus_list_free_link (link); + } + + if (test_system_service_dir_matches[i] != NULL) + { + printf ("extra data %s in the match set was not matched\n", + test_system_service_dir_matches[i]); + + _dbus_string_free (&progs); + return FALSE; + } + + _dbus_string_free (&progs); + return TRUE; +} + +dbus_bool_t +bus_config_parser_test (const DBusString *test_data_dir) +{ + if (test_data_dir == NULL || + _dbus_string_get_length (test_data_dir) == 0) + { + printf ("No test data\n"); + return TRUE; + } + + if (!test_default_session_servicedirs()) + return FALSE; + +#ifdef DBUS_WIN + printf("default system service dir skipped\n"); +#else + if (!test_default_system_servicedirs()) + return FALSE; +#endif + + if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID)) + return FALSE; + +#ifndef DBUS_WIN + if (!process_test_valid_subdir (test_data_dir, "valid-config-files-system", VALID)) + return FALSE; +#endif + + if (!process_test_valid_subdir (test_data_dir, "invalid-config-files", INVALID)) + return FALSE; + + if (!process_test_equiv_subdir (test_data_dir, "equiv-config-files")) + return FALSE; + + return TRUE; +} + +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */ +
diff --git a/bus/config-parser.h b/bus/config-parser.h new file mode 100644 index 0000000..ba5bf74 --- /dev/null +++ b/bus/config-parser.h
@@ -0,0 +1,87 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* config-parser.h XML-library-agnostic configuration file parser + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_CONFIG_PARSER_H +#define BUS_CONFIG_PARSER_H + +#include <dbus/dbus.h> +#include <dbus/dbus-string.h> +#include <dbus/dbus-list.h> +#include <dbus/dbus-hash.h> +#include "bus.h" + +/* Whatever XML library we're using just pushes data into this API */ + +typedef struct BusConfigParser BusConfigParser; + +BusConfigParser* bus_config_parser_new (const DBusString *basedir, + dbus_bool_t is_toplevel, + const BusConfigParser *parent); + +BusConfigParser* bus_config_parser_ref (BusConfigParser *parser); +void bus_config_parser_unref (BusConfigParser *parser); +dbus_bool_t bus_config_parser_check_doctype (BusConfigParser *parser, + const char *doctype, + DBusError *error); +dbus_bool_t bus_config_parser_start_element (BusConfigParser *parser, + const char *element_name, + const char **attribute_names, + const char **attribute_values, + DBusError *error); +dbus_bool_t bus_config_parser_end_element (BusConfigParser *parser, + const char *element_name, + DBusError *error); +dbus_bool_t bus_config_parser_content (BusConfigParser *parser, + const DBusString *content, + DBusError *error); +dbus_bool_t bus_config_parser_finished (BusConfigParser *parser, + DBusError *error); + +/* Functions for extracting the parse results */ +const char* bus_config_parser_get_user (BusConfigParser *parser); +const char* bus_config_parser_get_type (BusConfigParser *parser); +DBusList** bus_config_parser_get_addresses (BusConfigParser *parser); +DBusList** bus_config_parser_get_mechanisms (BusConfigParser *parser); +dbus_bool_t bus_config_parser_get_fork (BusConfigParser *parser); +dbus_bool_t bus_config_parser_get_allow_anonymous (BusConfigParser *parser); +dbus_bool_t bus_config_parser_get_syslog (BusConfigParser *parser); +dbus_bool_t bus_config_parser_get_keep_umask (BusConfigParser *parser); +const char* bus_config_parser_get_pidfile (BusConfigParser *parser); +const char* bus_config_parser_get_servicehelper (BusConfigParser *parser); +DBusList** bus_config_parser_get_service_dirs (BusConfigParser *parser); +DBusList** bus_config_parser_get_conf_dirs (BusConfigParser *parser); +BusPolicy* bus_config_parser_steal_policy (BusConfigParser *parser); +void bus_config_parser_get_limits (BusConfigParser *parser, + BusLimits *limits); + +DBusHashTable* bus_config_parser_steal_service_context_table (BusConfigParser *parser); + +/* Loader functions (backended off one of the XML parsers). Returns a + * finished ConfigParser. + */ +BusConfigParser* bus_config_load (const DBusString *file, + dbus_bool_t is_toplevel, + const BusConfigParser *parent, + DBusError *error); + +#endif /* BUS_CONFIG_PARSER_H */
diff --git a/bus/connection.c b/bus/connection.c new file mode 100644 index 0000000..95e20a6 --- /dev/null +++ b/bus/connection.c
@@ -0,0 +1,2811 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* connection.c Client connections + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "connection.h" +#include "dispatch.h" +#include "policy.h" +#include "services.h" +#include "utils.h" +#include "signals.h" +#include "expirelist.h" +#include "selinux.h" +#include "apparmor.h" +#include <dbus/dbus-list.h> +#include <dbus/dbus-hash.h> +#include <dbus/dbus-timeout.h> +#include <dbus/dbus-connection-internal.h> +#include <dbus/dbus-internals.h> + +/* Trim executed commands to this length; we want to keep logs readable */ +#define MAX_LOG_COMMAND_LEN 50 + +static void bus_connection_remove_transactions (DBusConnection *connection); + +typedef struct +{ + BusExpireItem expire_item; + + DBusConnection *will_get_reply; + DBusConnection *will_send_reply; + + dbus_uint32_t reply_serial; + +} BusPendingReply; + +struct BusConnections +{ + int refcount; + DBusList *completed; /**< List of all completed connections */ + int n_completed; /**< Length of completed list */ + DBusList *incomplete; /**< List of all not-yet-active connections */ + int n_incomplete; /**< Length of incomplete list */ + BusContext *context; + DBusHashTable *completed_by_user; /**< Number of completed connections for each UID */ + DBusTimeout *expire_timeout; /**< Timeout for expiring incomplete connections. */ + int stamp; /**< Incrementing number */ + BusExpireList *pending_replies; /**< List of pending replies */ + + /** List of all monitoring connections, a subset of completed. + * Each member is a #DBusConnection. */ + DBusList *monitors; + BusMatchmaker *monitor_matchmaker; + +#ifdef DBUS_ENABLE_STATS + int total_match_rules; + int peak_match_rules; + int peak_match_rules_per_conn; + + int total_bus_names; + int peak_bus_names; + int peak_bus_names_per_conn; +#endif +}; + +static dbus_int32_t connection_data_slot = -1; + +typedef struct +{ + BusConnections *connections; + DBusList *link_in_connection_list; + DBusConnection *connection; + DBusList *services_owned; + int n_services_owned; + DBusList *match_rules; + int n_match_rules; + char *name; + DBusList *transaction_messages; /**< Stuff we need to send as part of a transaction */ + DBusMessage *oom_message; + DBusPreallocatedSend *oom_preallocated; + BusClientPolicy *policy; + + char *cached_loginfo_string; + BusSELinuxID *selinux_id; + BusAppArmorConfinement *apparmor_confinement; + + long connection_tv_sec; /**< Time when we connected (seconds component) */ + long connection_tv_usec; /**< Time when we connected (microsec component) */ + int stamp; /**< connections->stamp last time we were traversed */ + +#ifdef DBUS_ENABLE_STATS + int peak_match_rules; + int peak_bus_names; +#endif + int n_pending_unix_fds; + DBusTimeout *pending_unix_fds_timeout; + + /** non-NULL if and only if this is a monitor */ + DBusList *link_in_monitors; +} BusConnectionData; + +static dbus_bool_t bus_pending_reply_expired (BusExpireList *list, + DBusList *link, + void *data); + +static void bus_connection_drop_pending_replies (BusConnections *connections, + DBusConnection *connection); + +static dbus_bool_t expire_incomplete_timeout (void *data); + +#define BUS_CONNECTION_DATA(connection) (dbus_connection_get_data ((connection), connection_data_slot)) + +static DBusLoop* +connection_get_loop (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); + + return bus_context_get_loop (d->connections->context); +} + + +static int +get_connections_for_uid (BusConnections *connections, + dbus_uid_t uid) +{ + void *val; + int current_count; + + /* val is NULL is 0 when it isn't in the hash yet */ + + val = _dbus_hash_table_lookup_uintptr (connections->completed_by_user, + uid); + + current_count = _DBUS_POINTER_TO_INT (val); + + return current_count; +} + +static dbus_bool_t +adjust_connections_for_uid (BusConnections *connections, + dbus_uid_t uid, + int adjustment) +{ + int current_count; + + current_count = get_connections_for_uid (connections, uid); + + _dbus_verbose ("Adjusting connection count for UID " DBUS_UID_FORMAT + ": was %d adjustment %d making %d\n", + uid, current_count, adjustment, current_count + adjustment); + + _dbus_assert (current_count >= 0); + + current_count += adjustment; + + _dbus_assert (current_count >= 0); + + if (current_count == 0) + { + _dbus_hash_table_remove_uintptr (connections->completed_by_user, uid); + return TRUE; + } + else + { + dbus_bool_t retval; + + retval = _dbus_hash_table_insert_uintptr (connections->completed_by_user, + uid, _DBUS_INT_TO_POINTER (current_count)); + + /* only positive adjustment can fail as otherwise + * a hash entry should already exist + */ + _dbus_assert (adjustment > 0 || + (adjustment <= 0 && retval)); + + return retval; + } +} + +void +bus_connection_disconnected (DBusConnection *connection) +{ + BusConnectionData *d; + BusService *service; + BusMatchmaker *matchmaker; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + _dbus_verbose ("%s disconnected, dropping all service ownership and releasing\n", + d->name ? d->name : "(inactive)"); + + /* Delete our match rules */ + if (d->n_match_rules > 0) + { + matchmaker = bus_context_get_matchmaker (d->connections->context); + bus_matchmaker_disconnected (matchmaker, connection); + } + + /* Drop any service ownership. Unfortunately, this requires + * memory allocation and there doesn't seem to be a good way to + * handle it other than sleeping; we can't "fail" the operation of + * disconnecting a client, and preallocating a broadcast "service is + * now gone" message for every client-service pair seems kind of + * involved. + */ + while ((service = _dbus_list_get_last (&d->services_owned))) + { + BusTransaction *transaction; + DBusError error; + + retry: + + dbus_error_init (&error); + + while ((transaction = bus_transaction_new (d->connections->context)) == NULL) + _dbus_wait_for_memory (); + + if (!bus_service_remove_owner (service, connection, + transaction, &error)) + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + dbus_error_free (&error); + bus_transaction_cancel_and_free (transaction); + _dbus_wait_for_memory (); + goto retry; + } + else + { + _dbus_verbose ("Failed to remove service owner: %s %s\n", + error.name, error.message); + _dbus_assert_not_reached ("Removing service owner failed for non-memory-related reason"); + } + } + + bus_transaction_execute_and_free (transaction); + } + + bus_dispatch_remove_connection (connection); + + /* no more watching */ + if (!dbus_connection_set_watch_functions (connection, + NULL, NULL, NULL, + connection, + NULL)) + _dbus_assert_not_reached ("setting watch functions to NULL failed"); + + if (!dbus_connection_set_timeout_functions (connection, + NULL, NULL, NULL, + connection, + NULL)) + _dbus_assert_not_reached ("setting timeout functions to NULL failed"); + + dbus_connection_set_unix_user_function (connection, + NULL, NULL, NULL); + dbus_connection_set_windows_user_function (connection, + NULL, NULL, NULL); + + dbus_connection_set_dispatch_status_function (connection, + NULL, NULL, NULL); + + if (d->pending_unix_fds_timeout) + { + _dbus_loop_remove_timeout (bus_context_get_loop (d->connections->context), + d->pending_unix_fds_timeout); + _dbus_timeout_unref (d->pending_unix_fds_timeout); + } + d->pending_unix_fds_timeout = NULL; + _dbus_connection_set_pending_fds_function (connection, NULL, NULL); + + bus_connection_remove_transactions (connection); + + if (d->link_in_monitors != NULL) + { + BusMatchmaker *mm = d->connections->monitor_matchmaker; + + if (mm != NULL) + bus_matchmaker_disconnected (mm, connection); + + _dbus_list_remove_link (&d->connections->monitors, d->link_in_monitors); + d->link_in_monitors = NULL; + } + + if (d->link_in_connection_list != NULL) + { + if (d->name != NULL) + { + unsigned long uid; + + _dbus_list_remove_link (&d->connections->completed, d->link_in_connection_list); + d->link_in_connection_list = NULL; + d->connections->n_completed -= 1; + + if (dbus_connection_get_unix_user (connection, &uid)) + { + if (!adjust_connections_for_uid (d->connections, + uid, -1)) + _dbus_assert_not_reached ("adjusting downward should never fail"); + } + } + else + { + _dbus_list_remove_link (&d->connections->incomplete, d->link_in_connection_list); + d->link_in_connection_list = NULL; + d->connections->n_incomplete -= 1; + + /* If we have dropped below the max. number of incomplete + * connections, start accept()ing again */ + bus_context_check_all_watches (d->connections->context); + } + + _dbus_assert (d->connections->n_incomplete >= 0); + _dbus_assert (d->connections->n_completed >= 0); + } + + bus_connection_drop_pending_replies (d->connections, connection); + + /* frees "d" as side effect */ + dbus_connection_set_data (connection, + connection_data_slot, + NULL, NULL); + + dbus_connection_unref (connection); +} + +static dbus_bool_t +add_connection_watch (DBusWatch *watch, + void *data) +{ + DBusConnection *connection = data; + + return _dbus_loop_add_watch (connection_get_loop (connection), watch); +} + +static void +remove_connection_watch (DBusWatch *watch, + void *data) +{ + DBusConnection *connection = data; + + _dbus_loop_remove_watch (connection_get_loop (connection), watch); +} + +static void +toggle_connection_watch (DBusWatch *watch, + void *data) +{ + DBusConnection *connection = data; + + _dbus_loop_toggle_watch (connection_get_loop (connection), watch); +} + +static dbus_bool_t +add_connection_timeout (DBusTimeout *timeout, + void *data) +{ + DBusConnection *connection = data; + + return _dbus_loop_add_timeout (connection_get_loop (connection), timeout); +} + +static void +remove_connection_timeout (DBusTimeout *timeout, + void *data) +{ + DBusConnection *connection = data; + + _dbus_loop_remove_timeout (connection_get_loop (connection), timeout); +} + +static void +dispatch_status_function (DBusConnection *connection, + DBusDispatchStatus new_status, + void *data) +{ + DBusLoop *loop = data; + + if (new_status != DBUS_DISPATCH_COMPLETE) + { + while (!_dbus_loop_queue_dispatch (loop, connection)) + _dbus_wait_for_memory (); + } +} + +static dbus_bool_t +allow_unix_user_function (DBusConnection *connection, + unsigned long uid, + void *data) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + + return bus_context_allow_unix_user (d->connections->context, uid); +} + +static void +free_connection_data (void *data) +{ + BusConnectionData *d = data; + + /* services_owned should be NULL since we should be disconnected */ + _dbus_assert (d->services_owned == NULL); + _dbus_assert (d->n_services_owned == 0); + /* similarly */ + _dbus_assert (d->transaction_messages == NULL); + + if (d->oom_preallocated) + dbus_connection_free_preallocated_send (d->connection, d->oom_preallocated); + + if (d->oom_message) + dbus_message_unref (d->oom_message); + + if (d->policy) + bus_client_policy_unref (d->policy); + + if (d->selinux_id) + bus_selinux_id_unref (d->selinux_id); + + if (d->apparmor_confinement) + bus_apparmor_confinement_unref (d->apparmor_confinement); + + dbus_free (d->cached_loginfo_string); + + dbus_free (d->name); + + dbus_free (d); +} + +BusConnections* +bus_connections_new (BusContext *context) +{ + BusConnections *connections; + + if (!dbus_connection_allocate_data_slot (&connection_data_slot)) + goto failed_0; + + connections = dbus_new0 (BusConnections, 1); + if (connections == NULL) + goto failed_1; + + connections->completed_by_user = _dbus_hash_table_new (DBUS_HASH_UINTPTR, + NULL, NULL); + if (connections->completed_by_user == NULL) + goto failed_2; + + connections->expire_timeout = _dbus_timeout_new (100, /* irrelevant */ + expire_incomplete_timeout, + connections, NULL); + if (connections->expire_timeout == NULL) + goto failed_3; + + _dbus_timeout_set_enabled (connections->expire_timeout, FALSE); + + connections->pending_replies = bus_expire_list_new (bus_context_get_loop (context), + bus_context_get_reply_timeout (context), + bus_pending_reply_expired, + connections); + if (connections->pending_replies == NULL) + goto failed_4; + + if (!_dbus_loop_add_timeout (bus_context_get_loop (context), + connections->expire_timeout)) + goto failed_5; + + connections->refcount = 1; + connections->context = context; + + return connections; + + failed_5: + bus_expire_list_free (connections->pending_replies); + failed_4: + _dbus_timeout_unref (connections->expire_timeout); + failed_3: + _dbus_hash_table_unref (connections->completed_by_user); + failed_2: + dbus_free (connections); + failed_1: + dbus_connection_free_data_slot (&connection_data_slot); + failed_0: + return NULL; +} + +BusConnections * +bus_connections_ref (BusConnections *connections) +{ + _dbus_assert (connections->refcount > 0); + connections->refcount += 1; + + return connections; +} + +void +bus_connections_unref (BusConnections *connections) +{ + _dbus_assert (connections->refcount > 0); + connections->refcount -= 1; + if (connections->refcount == 0) + { + /* drop all incomplete */ + while (connections->incomplete != NULL) + { + DBusConnection *connection; + + connection = connections->incomplete->data; + + dbus_connection_ref (connection); + dbus_connection_close (connection); + bus_connection_disconnected (connection); + dbus_connection_unref (connection); + } + + _dbus_assert (connections->n_incomplete == 0); + + /* drop all monitors */ + _dbus_list_clear (&connections->monitors); + + /* drop all real connections */ + while (connections->completed != NULL) + { + DBusConnection *connection; + + connection = connections->completed->data; + + dbus_connection_ref (connection); + dbus_connection_close (connection); + bus_connection_disconnected (connection); + dbus_connection_unref (connection); + } + + _dbus_assert (connections->n_completed == 0); + + bus_expire_list_free (connections->pending_replies); + + _dbus_loop_remove_timeout (bus_context_get_loop (connections->context), + connections->expire_timeout); + + _dbus_timeout_unref (connections->expire_timeout); + + _dbus_hash_table_unref (connections->completed_by_user); + + if (connections->monitor_matchmaker != NULL) + bus_matchmaker_unref (connections->monitor_matchmaker); + + dbus_free (connections); + + dbus_connection_free_data_slot (&connection_data_slot); + } +} + +/* Used for logging */ +static dbus_bool_t +cache_peer_loginfo_string (BusConnectionData *d, + DBusConnection *connection) +{ + DBusString loginfo_buf; + unsigned long uid; + unsigned long pid; + char *windows_sid; + dbus_bool_t prev_added; + + if (!_dbus_string_init (&loginfo_buf)) + return FALSE; + + prev_added = FALSE; + if (dbus_connection_get_unix_user (connection, &uid)) + { + if (!_dbus_string_append_printf (&loginfo_buf, "uid=%ld", uid)) + goto oom; + else + prev_added = TRUE; + } + + if (dbus_connection_get_unix_process_id (connection, &pid)) + { + if (prev_added) + { + if (!_dbus_string_append_byte (&loginfo_buf, ' ')) + goto oom; + } + if (!_dbus_string_append_printf (&loginfo_buf, "pid=%ld comm=\"", pid)) + goto oom; + /* Ignore errors here; we may not have permissions to read the + * proc file. */ + _dbus_command_for_pid (pid, &loginfo_buf, MAX_LOG_COMMAND_LEN, NULL); + if (!_dbus_string_append_byte (&loginfo_buf, '"')) + goto oom; + } + + if (dbus_connection_get_windows_user (connection, &windows_sid)) + { + dbus_bool_t did_append; + did_append = _dbus_string_append_printf (&loginfo_buf, + "sid=\"%s\" ", windows_sid); + dbus_free (windows_sid); + if (!did_append) + goto oom; + } + + if (!_dbus_string_steal_data (&loginfo_buf, &(d->cached_loginfo_string))) + goto oom; + + _dbus_string_free (&loginfo_buf); + + return TRUE; +oom: + _dbus_string_free (&loginfo_buf); + return FALSE; +} + +static void +check_pending_fds_cb (DBusConnection *connection) +{ + BusConnectionData *d = BUS_CONNECTION_DATA (connection); + int n_pending_unix_fds_old; + int n_pending_unix_fds_new; + + _dbus_assert(d != NULL); + + n_pending_unix_fds_old = d->n_pending_unix_fds; + n_pending_unix_fds_new = _dbus_connection_get_pending_fds_count (connection); + + _dbus_verbose ("Pending fds count changed on connection %p: %d -> %d\n", + connection, n_pending_unix_fds_old, n_pending_unix_fds_new); + + if (n_pending_unix_fds_old == 0 && n_pending_unix_fds_new > 0) + { + _dbus_timeout_set_interval (d->pending_unix_fds_timeout, + bus_context_get_pending_fd_timeout (d->connections->context)); + _dbus_timeout_set_enabled (d->pending_unix_fds_timeout, TRUE); + } + + if (n_pending_unix_fds_old > 0 && n_pending_unix_fds_new == 0) + { + _dbus_timeout_set_enabled (d->pending_unix_fds_timeout, FALSE); + } + + + d->n_pending_unix_fds = n_pending_unix_fds_new; +} + +static dbus_bool_t +pending_unix_fds_timeout_cb (void *data) +{ + DBusConnection *connection = data; + dbus_connection_close (connection); + return TRUE; +} + +dbus_bool_t +bus_connections_setup_connection (BusConnections *connections, + DBusConnection *connection) +{ + + BusConnectionData *d; + dbus_bool_t retval; + DBusError error; + + + d = dbus_new0 (BusConnectionData, 1); + + if (d == NULL) + return FALSE; + + d->connections = connections; + d->connection = connection; + + _dbus_get_monotonic_time (&d->connection_tv_sec, + &d->connection_tv_usec); + + _dbus_assert (connection_data_slot >= 0); + + if (!dbus_connection_set_data (connection, + connection_data_slot, + d, free_connection_data)) + { + dbus_free (d); + return FALSE; + } + + dbus_connection_set_route_peer_messages (connection, TRUE); + + retval = FALSE; + + dbus_error_init (&error); + d->selinux_id = bus_selinux_init_connection_id (connection, + &error); + if (dbus_error_is_set (&error)) + { + /* This is a bit bogus because we pretend all errors + * are OOM; this is done because we know that in bus.c + * an OOM error disconnects the connection, which is + * the same thing we want on any other error. + */ + dbus_error_free (&error); + goto out; + } + + d->apparmor_confinement = bus_apparmor_init_connection_confinement (connection, + &error); + if (dbus_error_is_set (&error)) + { + /* This is a bit bogus because we pretend all errors + * are OOM; this is done because we know that in bus.c + * an OOM error disconnects the connection, which is + * the same thing we want on any other error. + */ + dbus_error_free (&error); + goto out; + } + + if (!dbus_connection_set_watch_functions (connection, + add_connection_watch, + remove_connection_watch, + toggle_connection_watch, + connection, + NULL)) + goto out; + + if (!dbus_connection_set_timeout_functions (connection, + add_connection_timeout, + remove_connection_timeout, + NULL, + connection, NULL)) + goto out; + + /* For now we don't need to set a Windows user function because + * there are no policies in the config file controlling what + * Windows users can connect. The default 'same user that owns the + * bus can connect' behavior of DBusConnection is fine on Windows. + */ + dbus_connection_set_unix_user_function (connection, + allow_unix_user_function, + NULL, NULL); + + dbus_connection_set_dispatch_status_function (connection, + dispatch_status_function, + bus_context_get_loop (connections->context), + NULL); + + d->link_in_connection_list = _dbus_list_alloc_link (connection); + if (d->link_in_connection_list == NULL) + goto out; + + /* Setup the connection with the dispatcher */ + if (!bus_dispatch_add_connection (connection)) + goto out; + + if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE) + { + if (!_dbus_loop_queue_dispatch (bus_context_get_loop (connections->context), connection)) + { + bus_dispatch_remove_connection (connection); + goto out; + } + } + + /* Setup pending fds timeout (see #80559) */ + d->pending_unix_fds_timeout = _dbus_timeout_new (100, /* irrelevant */ + pending_unix_fds_timeout_cb, + connection, NULL); + if (d->pending_unix_fds_timeout == NULL) + goto out; + + _dbus_timeout_set_enabled (d->pending_unix_fds_timeout, FALSE); + if (!_dbus_loop_add_timeout (bus_context_get_loop (connections->context), + d->pending_unix_fds_timeout)) + goto out; + + _dbus_connection_set_pending_fds_function (connection, + (DBusPendingFdsChangeFunction) check_pending_fds_cb, + connection); + + _dbus_list_append_link (&connections->incomplete, d->link_in_connection_list); + connections->n_incomplete += 1; + + dbus_connection_ref (connection); + + bus_connections_expire_incomplete (connections); + + /* The listening socket is removed from the main loop, + * i.e. does not accept(), while n_incomplete is at its + * maximum value; so we shouldn't get here in that case */ + _dbus_assert (connections->n_incomplete <= + bus_context_get_max_incomplete_connections (connections->context)); + + /* If we have the maximum number of incomplete connections, + * stop accept()ing any more, to avert a DoS. See fd.o #80919 */ + bus_context_check_all_watches (d->connections->context); + + retval = TRUE; + + out: + if (!retval) + { + if (d->selinux_id) + bus_selinux_id_unref (d->selinux_id); + d->selinux_id = NULL; + + if (d->apparmor_confinement) + bus_apparmor_confinement_unref (d->apparmor_confinement); + d->apparmor_confinement = NULL; + + if (!dbus_connection_set_watch_functions (connection, + NULL, NULL, NULL, + connection, + NULL)) + _dbus_assert_not_reached ("setting watch functions to NULL failed"); + + if (!dbus_connection_set_timeout_functions (connection, + NULL, NULL, NULL, + connection, + NULL)) + _dbus_assert_not_reached ("setting timeout functions to NULL failed"); + + dbus_connection_set_unix_user_function (connection, + NULL, NULL, NULL); + + dbus_connection_set_windows_user_function (connection, + NULL, NULL, NULL); + + dbus_connection_set_dispatch_status_function (connection, + NULL, NULL, NULL); + + if (d->pending_unix_fds_timeout) + _dbus_timeout_unref (d->pending_unix_fds_timeout); + + d->pending_unix_fds_timeout = NULL; + + _dbus_connection_set_pending_fds_function (connection, NULL, NULL); + + if (d->link_in_connection_list != NULL) + { + _dbus_assert (d->link_in_connection_list->next == NULL); + _dbus_assert (d->link_in_connection_list->prev == NULL); + _dbus_list_free_link (d->link_in_connection_list); + d->link_in_connection_list = NULL; + } + + if (!dbus_connection_set_data (connection, + connection_data_slot, + NULL, NULL)) + _dbus_assert_not_reached ("failed to set connection data to null"); + + /* "d" has now been freed */ + } + + return retval; +} + +void +bus_connections_expire_incomplete (BusConnections *connections) +{ + int next_interval; + + next_interval = -1; + + if (connections->incomplete != NULL) + { + long tv_sec, tv_usec; + DBusList *link; + int auth_timeout; + + _dbus_get_monotonic_time (&tv_sec, &tv_usec); + auth_timeout = bus_context_get_auth_timeout (connections->context); + + link = _dbus_list_get_first_link (&connections->incomplete); + while (link != NULL) + { + DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link); + DBusConnection *connection; + BusConnectionData *d; + double elapsed; + + connection = link->data; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + + elapsed = ELAPSED_MILLISECONDS_SINCE (d->connection_tv_sec, + d->connection_tv_usec, + tv_sec, tv_usec); + + if (elapsed >= (double) auth_timeout) + { + /* Unfortunately, we can't identify the connection: it doesn't + * have a unique name yet, we don't know its uid/pid yet, + * and so on. */ + bus_context_log (connections->context, DBUS_SYSTEM_LOG_WARNING, + "Connection has not authenticated soon enough, closing it " + "(auth_timeout=%dms, elapsed: %.0fms)", + auth_timeout, elapsed); + + _dbus_verbose ("Timing out authentication for connection %p\n", connection); + dbus_connection_close (connection); + } + else + { + /* We can end the loop, since the connections are in oldest-first order */ + next_interval = ((double)auth_timeout) - elapsed; + _dbus_verbose ("Connection %p authentication expires in %d milliseconds\n", + connection, next_interval); + + break; + } + + link = next; + } + } + + bus_expire_timeout_set_interval (connections->expire_timeout, + next_interval); +} + +static dbus_bool_t +expire_incomplete_timeout (void *data) +{ + BusConnections *connections = data; + + _dbus_verbose ("Running\n"); + + /* note that this may remove the timeout */ + bus_connections_expire_incomplete (connections); + + return TRUE; +} + +dbus_bool_t +bus_connection_get_unix_groups (DBusConnection *connection, + unsigned long **groups, + int *n_groups, + DBusError *error) +{ + unsigned long uid; + + *groups = NULL; + *n_groups = 0; + + if (dbus_connection_get_unix_user (connection, &uid)) + { + if (!_dbus_unix_groups_from_uid (uid, groups, n_groups)) + { + _dbus_verbose ("Did not get any groups for UID %lu\n", + uid); + return FALSE; + } + else + { + _dbus_verbose ("Got %d groups for UID %lu\n", + *n_groups, uid); + return TRUE; + } + } + else + return TRUE; /* successfully got 0 groups */ +} + +dbus_bool_t +bus_connection_is_in_unix_group (DBusConnection *connection, + unsigned long gid) +{ + int i; + unsigned long *group_ids; + int n_group_ids; + + if (!bus_connection_get_unix_groups (connection, &group_ids, &n_group_ids, + NULL)) + return FALSE; + + i = 0; + while (i < n_group_ids) + { + if (group_ids[i] == gid) + { + dbus_free (group_ids); + return TRUE; + } + ++i; + } + + dbus_free (group_ids); + return FALSE; +} + +const char * +bus_connection_get_loginfo (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); + + if (!bus_connection_is_active (connection)) + return "inactive"; + return d->cached_loginfo_string; +} + +BusClientPolicy* +bus_connection_get_policy (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + _dbus_assert (d->policy != NULL); + + return d->policy; +} + +static dbus_bool_t +foreach_active (BusConnections *connections, + BusConnectionForeachFunction function, + void *data) +{ + DBusList *link; + + link = _dbus_list_get_first_link (&connections->completed); + while (link != NULL) + { + DBusConnection *connection = link->data; + DBusList *next = _dbus_list_get_next_link (&connections->completed, link); + + if (!(* function) (connection, data)) + return FALSE; + + link = next; + } + + return TRUE; +} + +static dbus_bool_t +foreach_inactive (BusConnections *connections, + BusConnectionForeachFunction function, + void *data) +{ + DBusList *link; + + link = _dbus_list_get_first_link (&connections->incomplete); + while (link != NULL) + { + DBusConnection *connection = link->data; + DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link); + + if (!(* function) (connection, data)) + return FALSE; + + link = next; + } + + return TRUE; +} + +/** + * Calls function on each active connection; if the function returns + * #FALSE, stops iterating. Active connections are authenticated + * and have sent a Hello message. + * + * @param connections the connections object + * @param function the function + * @param data data to pass to it as a second arg + */ +void +bus_connections_foreach_active (BusConnections *connections, + BusConnectionForeachFunction function, + void *data) +{ + foreach_active (connections, function, data); +} + +/** + * Calls function on each connection; if the function returns + * #FALSE, stops iterating. + * + * @param connections the connections object + * @param function the function + * @param data data to pass to it as a second arg + */ +void +bus_connections_foreach (BusConnections *connections, + BusConnectionForeachFunction function, + void *data) +{ + if (!foreach_active (connections, function, data)) + return; + + foreach_inactive (connections, function, data); +} + +BusContext* +bus_connections_get_context (BusConnections *connections) +{ + return connections->context; +} + +/* + * This is used to avoid covering the same connection twice when + * traversing connections. Note that it assumes we will + * bus_connection_mark_stamp() each connection at least once per + * INT_MAX increments of the global stamp, or wraparound would break + * things. + */ +void +bus_connections_increment_stamp (BusConnections *connections) +{ + connections->stamp += 1; +} + +/* Mark connection with current stamp, return TRUE if it + * didn't already have that stamp + */ +dbus_bool_t +bus_connection_mark_stamp (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + + if (d->stamp == d->connections->stamp) + return FALSE; + else + { + d->stamp = d->connections->stamp; + return TRUE; + } +} + +BusContext* +bus_connection_get_context (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + + return d->connections->context; +} + +BusConnections* +bus_connection_get_connections (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + + return d->connections; +} + +BusRegistry* +bus_connection_get_registry (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + + return bus_context_get_registry (d->connections->context); +} + +BusActivation* +bus_connection_get_activation (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + + return bus_context_get_activation (d->connections->context); +} + +BusMatchmaker* +bus_connection_get_matchmaker (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + + return bus_context_get_matchmaker (d->connections->context); +} + +BusSELinuxID* +bus_connection_get_selinux_id (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + + return d->selinux_id; +} + +BusAppArmorConfinement* +bus_connection_dup_apparmor_confinement (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + + bus_apparmor_confinement_ref (d->apparmor_confinement); + return d->apparmor_confinement; +} + +/** + * Checks whether the connection is registered with the message bus. + * + * @param connection the connection + * @returns #TRUE if we're an active message bus participant + */ +dbus_bool_t +bus_connection_is_active (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); + + return d->name != NULL; +} + +dbus_bool_t +bus_connection_preallocate_oom_error (DBusConnection *connection) +{ + DBusMessage *message; + DBusPreallocatedSend *preallocated; + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + + if (d->oom_preallocated != NULL) + return TRUE; + + preallocated = dbus_connection_preallocate_send (connection); + if (preallocated == NULL) + return FALSE; + + message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR); + + if (message == NULL) + { + dbus_connection_free_preallocated_send (connection, preallocated); + return FALSE; + } + + /* d->name may be NULL, but that is OK */ + if (!dbus_message_set_error_name (message, DBUS_ERROR_NO_MEMORY) || + !dbus_message_set_destination (message, d->name) || + !dbus_message_set_sender (message, + DBUS_SERVICE_DBUS)) + { + dbus_connection_free_preallocated_send (connection, preallocated); + dbus_message_unref (message); + return FALSE; + } + + /* set reply serial to placeholder value just so space is already allocated + * for it. + */ + if (!dbus_message_set_reply_serial (message, 14)) + { + dbus_connection_free_preallocated_send (connection, preallocated); + dbus_message_unref (message); + return FALSE; + } + + d->oom_message = message; + d->oom_preallocated = preallocated; + + return TRUE; +} + +void +bus_connection_send_oom_error (DBusConnection *connection, + DBusMessage *in_reply_to) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + _dbus_assert (d != NULL); + _dbus_assert (d->oom_message != NULL); + + bus_context_log (d->connections->context, DBUS_SYSTEM_LOG_WARNING, + "dbus-daemon transaction failed (OOM), sending error to " + "sender %s", bus_connection_get_loginfo (connection)); + + /* should always succeed since we set it to a placeholder earlier */ + if (!dbus_message_set_reply_serial (d->oom_message, + dbus_message_get_serial (in_reply_to))) + _dbus_assert_not_reached ("Failed to set reply serial for preallocated oom message"); + + _dbus_assert (dbus_message_get_sender (d->oom_message) != NULL); + + dbus_connection_send_preallocated (connection, d->oom_preallocated, + d->oom_message, NULL); + + dbus_message_unref (d->oom_message); + d->oom_message = NULL; + d->oom_preallocated = NULL; +} + +#ifdef DBUS_ENABLE_STATS +static void +update_peak (int *peak, + int n) +{ + if (*peak < n) + *peak = n; +} +#endif + +void +bus_connection_add_match_rule_link (DBusConnection *connection, + DBusList *link) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + _dbus_list_append_link (&d->match_rules, link); + + d->n_match_rules += 1; + +#ifdef DBUS_ENABLE_STATS + update_peak (&d->peak_match_rules, d->n_match_rules); + update_peak (&d->connections->peak_match_rules_per_conn, d->n_match_rules); + + d->connections->total_match_rules += 1; + update_peak (&d->connections->peak_match_rules, + d->connections->total_match_rules); +#endif +} + +dbus_bool_t +bus_connection_add_match_rule (DBusConnection *connection, + BusMatchRule *rule) +{ + DBusList *link; + + link = _dbus_list_alloc_link (rule); + + if (link == NULL) + return FALSE; + + bus_connection_add_match_rule_link (connection, link); + + return TRUE; +} + +void +bus_connection_remove_match_rule (DBusConnection *connection, + BusMatchRule *rule) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + _dbus_list_remove_last (&d->match_rules, rule); + + d->n_match_rules -= 1; + _dbus_assert (d->n_match_rules >= 0); + +#ifdef DBUS_ENABLE_STATS + d->connections->total_match_rules -= 1; +#endif +} + +int +bus_connection_get_n_match_rules (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + return d->n_match_rules; +} + +void +bus_connection_add_owned_service_link (DBusConnection *connection, + DBusList *link) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + _dbus_list_append_link (&d->services_owned, link); + + d->n_services_owned += 1; + +#ifdef DBUS_ENABLE_STATS + update_peak (&d->peak_bus_names, d->n_services_owned); + update_peak (&d->connections->peak_bus_names_per_conn, + d->n_services_owned); + + d->connections->total_bus_names += 1; + update_peak (&d->connections->peak_bus_names, + d->connections->total_bus_names); +#endif +} + +dbus_bool_t +bus_connection_add_owned_service (DBusConnection *connection, + BusService *service) +{ + DBusList *link; + + link = _dbus_list_alloc_link (service); + + if (link == NULL) + return FALSE; + + bus_connection_add_owned_service_link (connection, link); + + return TRUE; +} + +void +bus_connection_remove_owned_service (DBusConnection *connection, + BusService *service) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + _dbus_list_remove_last (&d->services_owned, service); + + d->n_services_owned -= 1; + _dbus_assert (d->n_services_owned >= 0); + +#ifdef DBUS_ENABLE_STATS + d->connections->total_bus_names -= 1; +#endif +} + +int +bus_connection_get_n_services_owned (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + return d->n_services_owned; +} + +dbus_bool_t +bus_connection_complete (DBusConnection *connection, + const DBusString *name, + DBusError *error) +{ + BusConnectionData *d; + unsigned long uid; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + _dbus_assert (d->name == NULL); + _dbus_assert (d->policy == NULL); + + _dbus_assert (!bus_connection_is_active (connection)); + + if (!_dbus_string_copy_data (name, &d->name)) + { + BUS_SET_OOM (error); + return FALSE; + } + + _dbus_assert (d->name != NULL); + + _dbus_verbose ("Name %s assigned to %p\n", d->name, connection); + + d->policy = bus_context_create_client_policy (d->connections->context, + connection, + error); + + /* we may have a NULL policy on OOM or error getting list of + * groups for a user. In the latter case we don't handle it so + * well currently, as it will just keep failing over and over. + */ + + if (d->policy == NULL) + { + _dbus_verbose ("Failed to create security policy for connection %p\n", + connection); + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_free (d->name); + d->name = NULL; + return FALSE; + } + + if (dbus_connection_get_unix_user (connection, &uid)) + { + if (!adjust_connections_for_uid (d->connections, + uid, 1)) + goto fail; + } + + /* Create and cache a string which holds information about the + * peer process; used for logging purposes. + */ + if (!cache_peer_loginfo_string (d, connection)) + goto fail; + + /* Now the connection is active, move it between lists */ + _dbus_list_unlink (&d->connections->incomplete, + d->link_in_connection_list); + d->connections->n_incomplete -= 1; + _dbus_list_append_link (&d->connections->completed, + d->link_in_connection_list); + d->connections->n_completed += 1; + + _dbus_assert (d->connections->n_incomplete >= 0); + _dbus_assert (d->connections->n_completed > 0); + + /* If we have dropped below the max. number of incomplete + * connections, start accept()ing again */ + bus_context_check_all_watches (d->connections->context); + + /* See if we can remove the timeout */ + bus_connections_expire_incomplete (d->connections); + + _dbus_assert (bus_connection_is_active (connection)); + + return TRUE; +fail: + BUS_SET_OOM (error); + dbus_free (d->name); + d->name = NULL; + if (d->policy) + bus_client_policy_unref (d->policy); + d->policy = NULL; + return FALSE; +} + +dbus_bool_t +bus_connections_reload_policy (BusConnections *connections, + DBusError *error) +{ + BusConnectionData *d; + DBusConnection *connection; + DBusList *link; + + _dbus_assert (connections != NULL); + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + for (link = _dbus_list_get_first_link (&(connections->completed)); + link; + link = _dbus_list_get_next_link (&(connections->completed), link)) + { + connection = link->data; + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + _dbus_assert (d->policy != NULL); + + bus_client_policy_unref (d->policy); + d->policy = bus_context_create_client_policy (connections->context, + connection, + error); + if (d->policy == NULL) + { + _dbus_verbose ("Failed to create security policy for connection %p\n", + connection); + _DBUS_ASSERT_ERROR_IS_SET (error); + return FALSE; + } + } + + return TRUE; +} + +const char * +bus_connection_get_name (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + return d->name; +} + +/** + * Check whether completing the passed-in connection would + * exceed limits, and if so set error and return #FALSE + */ +dbus_bool_t +bus_connections_check_limits (BusConnections *connections, + DBusConnection *requesting_completion, + DBusError *error) +{ + unsigned long uid; + + if (connections->n_completed >= + bus_context_get_max_completed_connections (connections->context)) + { + dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED, + "The maximum number of active connections has been reached"); + return FALSE; + } + + if (dbus_connection_get_unix_user (requesting_completion, &uid)) + { + if (get_connections_for_uid (connections, uid) >= + bus_context_get_max_connections_per_user (connections->context)) + { + dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED, + "The maximum number of active connections for UID %lu has been reached", + uid); + return FALSE; + } + } + + return TRUE; +} + +static void +bus_pending_reply_free (BusPendingReply *pending) +{ + _dbus_verbose ("Freeing pending reply %p, replier %p receiver %p serial %u\n", + pending, + pending->will_send_reply, + pending->will_get_reply, + pending->reply_serial); + + dbus_free (pending); +} + +static dbus_bool_t +bus_pending_reply_send_no_reply (BusConnections *connections, + BusTransaction *transaction, + BusPendingReply *pending) +{ + DBusMessage *message; + DBusMessageIter iter; + dbus_bool_t retval; + const char *errmsg; + + retval = FALSE; + + message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR); + if (message == NULL) + return FALSE; + + dbus_message_set_no_reply (message, TRUE); + + if (!dbus_message_set_reply_serial (message, + pending->reply_serial)) + goto out; + + if (!dbus_message_set_error_name (message, + DBUS_ERROR_NO_REPLY)) + goto out; + + /* If you change these messages, adjust test/dbus-daemon.c to match */ + if (pending->will_send_reply == NULL) + errmsg = "Message recipient disconnected from message bus without replying"; + else + errmsg = "Message did not receive a reply (timeout by message bus)"; + + dbus_message_iter_init_append (message, &iter); + if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &errmsg)) + goto out; + + if (!bus_transaction_send_from_driver (transaction, pending->will_get_reply, + message)) + goto out; + + retval = TRUE; + + out: + dbus_message_unref (message); + return retval; +} + +static dbus_bool_t +bus_pending_reply_expired (BusExpireList *list, + DBusList *link, + void *data) +{ + BusPendingReply *pending = link->data; + BusConnections *connections = data; + BusTransaction *transaction; + + /* No reply is forthcoming. So nuke it if we can. If not, + * leave it in the list to try expiring again later when we + * get more memory. + */ + + _dbus_verbose ("Expiring pending reply %p, replier %p receiver %p serial %u\n", + pending, + pending->will_send_reply, + pending->will_get_reply, + pending->reply_serial); + + transaction = bus_transaction_new (connections->context); + if (transaction == NULL) + return FALSE; + + if (!bus_pending_reply_send_no_reply (connections, + transaction, + pending)) + { + bus_transaction_cancel_and_free (transaction); + return FALSE; + } + + bus_expire_list_remove_link (connections->pending_replies, link); + + bus_pending_reply_free (pending); + bus_transaction_execute_and_free (transaction); + + return TRUE; +} + +static void +bus_connection_drop_pending_replies (BusConnections *connections, + DBusConnection *connection) +{ + /* The DBusConnection is almost 100% finalized here, so you can't + * do anything with it except check for pointer equality + */ + DBusList *link; + + _dbus_verbose ("Dropping pending replies that involve connection %p\n", + connection); + + link = bus_expire_list_get_first_link (connections->pending_replies); + while (link != NULL) + { + DBusList *next; + BusPendingReply *pending; + + next = bus_expire_list_get_next_link (connections->pending_replies, + link); + pending = link->data; + + if (pending->will_get_reply == connection) + { + /* We don't need to track this pending reply anymore */ + + _dbus_verbose ("Dropping pending reply %p, replier %p receiver %p serial %u\n", + pending, + pending->will_send_reply, + pending->will_get_reply, + pending->reply_serial); + + bus_expire_list_remove_link (connections->pending_replies, + link); + bus_pending_reply_free (pending); + } + else if (pending->will_send_reply == connection) + { + /* The reply isn't going to be sent, so set things + * up so it will be expired right away + */ + _dbus_verbose ("Will expire pending reply %p, replier %p receiver %p serial %u\n", + pending, + pending->will_send_reply, + pending->will_get_reply, + pending->reply_serial); + + pending->will_send_reply = NULL; + pending->expire_item.added_tv_sec = 0; + pending->expire_item.added_tv_usec = 0; + + bus_expire_list_recheck_immediately (connections->pending_replies); + } + + link = next; + } +} + + +typedef struct +{ + BusPendingReply *pending; + BusConnections *connections; +} CancelPendingReplyData; + +static void +cancel_pending_reply (void *data) +{ + CancelPendingReplyData *d = data; + + _dbus_verbose ("d = %p\n", d); + + if (!bus_expire_list_remove (d->connections->pending_replies, + &d->pending->expire_item)) + _dbus_assert_not_reached ("pending reply did not exist to be cancelled"); + + bus_pending_reply_free (d->pending); /* since it's been cancelled */ +} + +static void +cancel_pending_reply_data_free (void *data) +{ + CancelPendingReplyData *d = data; + + _dbus_verbose ("d = %p\n", d); + + /* d->pending should be either freed or still + * in the list of pending replies (owned by someone + * else) + */ + + dbus_free (d); +} + +/* + * Record that a reply is allowed; return TRUE on success. + */ +dbus_bool_t +bus_connections_expect_reply (BusConnections *connections, + BusTransaction *transaction, + DBusConnection *will_get_reply, + DBusConnection *will_send_reply, + DBusMessage *reply_to_this, + DBusError *error) +{ + BusPendingReply *pending; + dbus_uint32_t reply_serial; + DBusList *link; + CancelPendingReplyData *cprd; + int count; + + _dbus_assert (will_get_reply != NULL); + _dbus_assert (will_send_reply != NULL); + _dbus_assert (reply_to_this != NULL); + + if (dbus_message_get_no_reply (reply_to_this)) + return TRUE; /* we won't allow a reply, since client doesn't care for one. */ + + reply_serial = dbus_message_get_serial (reply_to_this); + + link = bus_expire_list_get_first_link (connections->pending_replies); + count = 0; + while (link != NULL) + { + pending = link->data; + + if (pending->reply_serial == reply_serial && + pending->will_get_reply == will_get_reply && + pending->will_send_reply == will_send_reply) + { + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "Message has the same reply serial as a currently-outstanding existing method call"); + return FALSE; + } + + link = bus_expire_list_get_next_link (connections->pending_replies, + link); + if (pending->will_get_reply == will_get_reply) + ++count; + } + + if (count >= + bus_context_get_max_replies_per_connection (connections->context)) + { + dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED, + "The maximum number of pending replies per connection has been reached"); + return FALSE; + } + + pending = dbus_new0 (BusPendingReply, 1); + if (pending == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + +#ifdef DBUS_ENABLE_VERBOSE_MODE + /* so we can see a not-yet-added pending reply */ + pending->expire_item.added_tv_sec = 1; + pending->expire_item.added_tv_usec = 1; +#endif + + pending->will_get_reply = will_get_reply; + pending->will_send_reply = will_send_reply; + pending->reply_serial = reply_serial; + + cprd = dbus_new0 (CancelPendingReplyData, 1); + if (cprd == NULL) + { + BUS_SET_OOM (error); + bus_pending_reply_free (pending); + return FALSE; + } + + if (!bus_expire_list_add (connections->pending_replies, + &pending->expire_item)) + { + BUS_SET_OOM (error); + dbus_free (cprd); + bus_pending_reply_free (pending); + return FALSE; + } + + if (!bus_transaction_add_cancel_hook (transaction, + cancel_pending_reply, + cprd, + cancel_pending_reply_data_free)) + { + BUS_SET_OOM (error); + bus_expire_list_remove (connections->pending_replies, &pending->expire_item); + dbus_free (cprd); + bus_pending_reply_free (pending); + return FALSE; + } + + cprd->pending = pending; + cprd->connections = connections; + + _dbus_get_monotonic_time (&pending->expire_item.added_tv_sec, + &pending->expire_item.added_tv_usec); + + _dbus_verbose ("Added pending reply %p, replier %p receiver %p serial %u\n", + pending, + pending->will_send_reply, + pending->will_get_reply, + pending->reply_serial); + + return TRUE; +} + +typedef struct +{ + DBusList *link; + BusConnections *connections; +} CheckPendingReplyData; + +static void +cancel_check_pending_reply (void *data) +{ + CheckPendingReplyData *d = data; + + _dbus_verbose ("d = %p\n",d); + + bus_expire_list_add_link (d->connections->pending_replies, + d->link); + d->link = NULL; +} + +static void +check_pending_reply_data_free (void *data) +{ + CheckPendingReplyData *d = data; + + _dbus_verbose ("d = %p\n",d); + + if (d->link != NULL) + { + BusPendingReply *pending = d->link->data; + + _dbus_assert (!bus_expire_list_contains_item (d->connections->pending_replies, + &pending->expire_item)); + + bus_pending_reply_free (pending); + _dbus_list_free_link (d->link); + } + + dbus_free (d); +} + +/* + * Check whether a reply is allowed, remove BusPendingReply + * if so, return TRUE if so. + */ +dbus_bool_t +bus_connections_check_reply (BusConnections *connections, + BusTransaction *transaction, + DBusConnection *sending_reply, + DBusConnection *receiving_reply, + DBusMessage *reply, + DBusError *error) +{ + CheckPendingReplyData *cprd; + DBusList *link; + dbus_uint32_t reply_serial; + + _dbus_assert (sending_reply != NULL); + _dbus_assert (receiving_reply != NULL); + + reply_serial = dbus_message_get_reply_serial (reply); + + link = bus_expire_list_get_first_link (connections->pending_replies); + while (link != NULL) + { + BusPendingReply *pending = link->data; + + if (pending->reply_serial == reply_serial && + pending->will_get_reply == receiving_reply && + pending->will_send_reply == sending_reply) + { + _dbus_verbose ("Found pending reply with serial %u\n", reply_serial); + break; + } + + link = bus_expire_list_get_next_link (connections->pending_replies, + link); + } + + if (link == NULL) + { + _dbus_verbose ("No pending reply expected\n"); + + return FALSE; + } + + cprd = dbus_new0 (CheckPendingReplyData, 1); + if (cprd == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!bus_transaction_add_cancel_hook (transaction, + cancel_check_pending_reply, + cprd, + check_pending_reply_data_free)) + { + BUS_SET_OOM (error); + dbus_free (cprd); + return FALSE; + } + + cprd->link = link; + cprd->connections = connections; + + bus_expire_list_unlink (connections->pending_replies, + link); + + _dbus_assert (!bus_expire_list_contains_item (connections->pending_replies, link->data)); + + return TRUE; +} + +/* + * Transactions + * + * Note that this is fairly fragile; in particular, don't try to use + * one transaction across any main loop iterations. + */ + +typedef struct +{ + BusTransaction *transaction; + DBusMessage *message; + DBusPreallocatedSend *preallocated; +} MessageToSend; + +typedef struct +{ + BusTransactionCancelFunction cancel_function; + DBusFreeFunction free_data_function; + void *data; +} CancelHook; + +struct BusTransaction +{ + DBusList *connections; + BusContext *context; + DBusList *cancel_hooks; +}; + +static void +message_to_send_free (DBusConnection *connection, + MessageToSend *to_send) +{ + if (to_send->message) + dbus_message_unref (to_send->message); + + if (to_send->preallocated) + dbus_connection_free_preallocated_send (connection, to_send->preallocated); + + dbus_free (to_send); +} + +static void +cancel_hook_cancel (void *element, + void *data) +{ + CancelHook *ch = element; + + _dbus_verbose ("Running transaction cancel hook\n"); + + if (ch->cancel_function) + (* ch->cancel_function) (ch->data); +} + +static void +cancel_hook_free (void *element, + void *data) +{ + CancelHook *ch = element; + + if (ch->free_data_function) + (* ch->free_data_function) (ch->data); + + dbus_free (ch); +} + +static void +free_cancel_hooks (BusTransaction *transaction) +{ + _dbus_list_foreach (&transaction->cancel_hooks, + cancel_hook_free, NULL); + + _dbus_list_clear (&transaction->cancel_hooks); +} + +BusTransaction* +bus_transaction_new (BusContext *context) +{ + BusTransaction *transaction; + + transaction = dbus_new0 (BusTransaction, 1); + if (transaction == NULL) + return NULL; + + transaction->context = context; + + return transaction; +} + +BusContext* +bus_transaction_get_context (BusTransaction *transaction) +{ + return transaction->context; +} + +/** + * Reserve enough memory to capture the given message if the + * transaction goes through. + */ +dbus_bool_t +bus_transaction_capture (BusTransaction *transaction, + DBusConnection *sender, + DBusMessage *message) +{ + BusConnections *connections; + BusMatchmaker *mm; + DBusList *link; + DBusList *recipients = NULL; + dbus_bool_t ret = FALSE; + + connections = bus_context_get_connections (transaction->context); + + /* shortcut: don't compose the message unless someone wants it */ + if (connections->monitors == NULL) + return TRUE; + + mm = connections->monitor_matchmaker; + /* This is non-null if there has ever been a monitor - we don't GC it. + * There's little point, since there is up to 1 per process. */ + _dbus_assert (mm != NULL); + + if (!bus_matchmaker_get_recipients (mm, connections, sender, NULL, message, + &recipients)) + goto out; + + for (link = _dbus_list_get_first_link (&recipients); + link != NULL; + link = _dbus_list_get_next_link (&recipients, link)) + { + DBusConnection *recipient = link->data; + + if (!bus_transaction_send (transaction, recipient, message)) + goto out; + } + + ret = TRUE; + +out: + _dbus_list_clear (&recipients); + return ret; +} + +dbus_bool_t +bus_transaction_capture_error_reply (BusTransaction *transaction, + const DBusError *error, + DBusMessage *in_reply_to) +{ + BusConnections *connections; + DBusMessage *reply; + dbus_bool_t ret = FALSE; + + _dbus_assert (error != NULL); + _DBUS_ASSERT_ERROR_IS_SET (error); + + connections = bus_context_get_connections (transaction->context); + + /* shortcut: don't compose the message unless someone wants it */ + if (connections->monitors == NULL) + return TRUE; + + reply = dbus_message_new_error (in_reply_to, + error->name, + error->message); + + if (reply == NULL) + return FALSE; + + if (!dbus_message_set_sender (reply, DBUS_SERVICE_DBUS)) + goto out; + + ret = bus_transaction_capture (transaction, NULL, reply); + +out: + dbus_message_unref (reply); + return ret; +} + +dbus_bool_t +bus_transaction_send_from_driver (BusTransaction *transaction, + DBusConnection *connection, + DBusMessage *message) +{ + DBusError error = DBUS_ERROR_INIT; + + /* We have to set the sender to the driver, and have + * to check security policy since it was not done in + * dispatch.c + */ + _dbus_verbose ("Sending %s %s %s from driver\n", + dbus_message_get_interface (message) ? + dbus_message_get_interface (message) : "(no interface)", + dbus_message_get_member (message) ? + dbus_message_get_member (message) : "(no member)", + dbus_message_get_error_name (message) ? + dbus_message_get_error_name (message) : "(no error name)"); + + if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS)) + return FALSE; + + if (bus_connection_is_active (connection)) + { + if (!dbus_message_set_destination (message, + bus_connection_get_name (connection))) + return FALSE; + } + + /* bus driver never wants a reply */ + dbus_message_set_no_reply (message, TRUE); + + /* Capture it for monitors, even if the real recipient's receive policy + * does not allow it to receive this message from us (which would be odd). + */ + if (!bus_transaction_capture (transaction, NULL, message)) + return FALSE; + + /* If security policy doesn't allow the message, we would silently + * eat it; the driver doesn't care about getting a reply. However, + * if we're actively capturing messages, it's nice to log that we + * tried to send it and did not allow ourselves to do so. + */ + if (!bus_context_check_security_policy (bus_transaction_get_context (transaction), + transaction, + NULL, connection, connection, message, &error)) + { + if (!bus_transaction_capture_error_reply (transaction, &error, message)) + { + bus_context_log (transaction->context, DBUS_SYSTEM_LOG_WARNING, + "message from dbus-daemon rejected but not enough " + "memory to capture it"); + } + + /* This is not fatal to the transaction so silently eat the disallowed + * message (see reasoning above) */ + dbus_error_free (&error); + return TRUE; + } + + return bus_transaction_send (transaction, connection, message); +} + +dbus_bool_t +bus_transaction_send (BusTransaction *transaction, + DBusConnection *connection, + DBusMessage *message) +{ + MessageToSend *to_send; + BusConnectionData *d; + DBusList *link; + + _dbus_verbose (" trying to add %s interface=%s member=%s error=%s to transaction%s\n", + dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR ? "error" : + dbus_message_get_reply_serial (message) != 0 ? "reply" : + "message", + dbus_message_get_interface (message) ? + dbus_message_get_interface (message) : "(unset)", + dbus_message_get_member (message) ? + dbus_message_get_member (message) : "(unset)", + dbus_message_get_error_name (message) ? + dbus_message_get_error_name (message) : "(unset)", + dbus_connection_get_is_connected (connection) ? + "" : " (disconnected)"); + + _dbus_assert (dbus_message_get_sender (message) != NULL); + + if (!dbus_connection_get_is_connected (connection)) + return TRUE; /* silently ignore disconnected connections */ + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + to_send = dbus_new (MessageToSend, 1); + if (to_send == NULL) + { + return FALSE; + } + + to_send->preallocated = dbus_connection_preallocate_send (connection); + if (to_send->preallocated == NULL) + { + dbus_free (to_send); + return FALSE; + } + + dbus_message_ref (message); + to_send->message = message; + to_send->transaction = transaction; + + _dbus_verbose ("about to prepend message\n"); + + if (!_dbus_list_prepend (&d->transaction_messages, to_send)) + { + message_to_send_free (connection, to_send); + return FALSE; + } + + _dbus_verbose ("prepended message\n"); + + /* See if we already had this connection in the list + * for this transaction. If we have a pending message, + * then we should already be in transaction->connections + */ + link = _dbus_list_get_first_link (&d->transaction_messages); + _dbus_assert (link->data == to_send); + link = _dbus_list_get_next_link (&d->transaction_messages, link); + while (link != NULL) + { + MessageToSend *m = link->data; + DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link); + + if (m->transaction == transaction) + break; + + link = next; + } + + if (link == NULL) + { + if (!_dbus_list_prepend (&transaction->connections, connection)) + { + _dbus_list_remove (&d->transaction_messages, to_send); + message_to_send_free (connection, to_send); + return FALSE; + } + } + + return TRUE; +} + +static void +transaction_free (BusTransaction *transaction) +{ + _dbus_assert (transaction->connections == NULL); + + free_cancel_hooks (transaction); + + dbus_free (transaction); +} + +static void +connection_cancel_transaction (DBusConnection *connection, + BusTransaction *transaction) +{ + DBusList *link; + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + link = _dbus_list_get_first_link (&d->transaction_messages); + while (link != NULL) + { + MessageToSend *m = link->data; + DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link); + + if (m->transaction == transaction) + { + _dbus_list_remove_link (&d->transaction_messages, + link); + + message_to_send_free (connection, m); + } + + link = next; + } +} + +void +bus_transaction_cancel_and_free (BusTransaction *transaction) +{ + DBusConnection *connection; + + _dbus_verbose ("TRANSACTION: cancelled\n"); + + while ((connection = _dbus_list_pop_first (&transaction->connections))) + connection_cancel_transaction (connection, transaction); + + _dbus_list_foreach (&transaction->cancel_hooks, + cancel_hook_cancel, NULL); + + transaction_free (transaction); +} + +static void +connection_execute_transaction (DBusConnection *connection, + BusTransaction *transaction) +{ + DBusList *link; + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + /* Send the queue in order (FIFO) */ + link = _dbus_list_get_last_link (&d->transaction_messages); + while (link != NULL) + { + MessageToSend *m = link->data; + DBusList *prev = _dbus_list_get_prev_link (&d->transaction_messages, link); + + if (m->transaction == transaction) + { + _dbus_list_remove_link (&d->transaction_messages, + link); + + _dbus_assert (dbus_message_get_sender (m->message) != NULL); + + dbus_connection_send_preallocated (connection, + m->preallocated, + m->message, + NULL); + + m->preallocated = NULL; /* so we don't double-free it */ + + message_to_send_free (connection, m); + } + + link = prev; + } +} + +void +bus_transaction_execute_and_free (BusTransaction *transaction) +{ + /* For each connection in transaction->connections + * send the messages + */ + DBusConnection *connection; + + _dbus_verbose ("TRANSACTION: executing\n"); + + while ((connection = _dbus_list_pop_first (&transaction->connections))) + connection_execute_transaction (connection, transaction); + + transaction_free (transaction); +} + +static void +bus_connection_remove_transactions (DBusConnection *connection) +{ + MessageToSend *to_send; + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + while ((to_send = _dbus_list_get_first (&d->transaction_messages))) + { + /* only has an effect for the first MessageToSend listing this transaction */ + _dbus_list_remove (&to_send->transaction->connections, + connection); + + _dbus_list_remove (&d->transaction_messages, to_send); + message_to_send_free (connection, to_send); + } +} + +/** + * Converts the DBusError to a message reply + */ +dbus_bool_t +bus_transaction_send_error_reply (BusTransaction *transaction, + DBusConnection *connection, + const DBusError *error, + DBusMessage *in_reply_to) +{ + DBusMessage *reply; + + _dbus_assert (error != NULL); + _DBUS_ASSERT_ERROR_IS_SET (error); + + _dbus_verbose ("Sending error reply %s \"%s\"\n", + error->name, error->message); + + reply = dbus_message_new_error (in_reply_to, + error->name, + error->message); + if (reply == NULL) + return FALSE; + + if (!bus_transaction_send_from_driver (transaction, connection, reply)) + { + dbus_message_unref (reply); + return FALSE; + } + + dbus_message_unref (reply); + + return TRUE; +} + +dbus_bool_t +bus_transaction_add_cancel_hook (BusTransaction *transaction, + BusTransactionCancelFunction cancel_function, + void *data, + DBusFreeFunction free_data_function) +{ + CancelHook *ch; + + ch = dbus_new (CancelHook, 1); + if (ch == NULL) + return FALSE; + + _dbus_verbose (" adding cancel hook function = %p data = %p\n", + cancel_function, data); + + ch->cancel_function = cancel_function; + ch->data = data; + ch->free_data_function = free_data_function; + + /* It's important that the hooks get run in reverse order that they + * were added + */ + if (!_dbus_list_prepend (&transaction->cancel_hooks, ch)) + { + dbus_free (ch); + return FALSE; + } + + return TRUE; +} + +int +bus_connections_get_n_active (BusConnections *connections) +{ + return connections->n_completed; +} + +int +bus_connections_get_n_incomplete (BusConnections *connections) +{ + return connections->n_incomplete; +} + +#ifdef DBUS_ENABLE_STATS +int +bus_connections_get_total_match_rules (BusConnections *connections) +{ + return connections->total_match_rules; +} + +int +bus_connections_get_peak_match_rules (BusConnections *connections) +{ + return connections->peak_match_rules; +} + +int +bus_connections_get_peak_match_rules_per_conn (BusConnections *connections) +{ + return connections->peak_match_rules_per_conn; +} + +int +bus_connections_get_total_bus_names (BusConnections *connections) +{ + return connections->total_bus_names; +} + +int +bus_connections_get_peak_bus_names (BusConnections *connections) +{ + return connections->peak_bus_names; +} + +int +bus_connections_get_peak_bus_names_per_conn (BusConnections *connections) +{ + return connections->peak_bus_names_per_conn; +} + +int +bus_connection_get_peak_match_rules (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); + + return d->peak_match_rules; +} + +int +bus_connection_get_peak_bus_names (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); + + return d->peak_bus_names; +} +#endif /* DBUS_ENABLE_STATS */ + +dbus_bool_t +bus_connection_is_monitor (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert(d != NULL); + + return d->link_in_monitors != NULL; +} + +static dbus_bool_t +bcd_add_monitor_rules (BusConnectionData *d, + DBusConnection *connection, + DBusList **rules) +{ + BusMatchmaker *mm = d->connections->monitor_matchmaker; + DBusList *iter; + + if (mm == NULL) + { + mm = bus_matchmaker_new (); + + if (mm == NULL) + return FALSE; + + d->connections->monitor_matchmaker = mm; + } + + for (iter = _dbus_list_get_first_link (rules); + iter != NULL; + iter = _dbus_list_get_next_link (rules, iter)) + { + if (!bus_matchmaker_add_rule (mm, iter->data)) + { + bus_matchmaker_disconnected (mm, connection); + return FALSE; + } + } + + return TRUE; +} + +static void +bcd_drop_monitor_rules (BusConnectionData *d, + DBusConnection *connection) +{ + BusMatchmaker *mm = d->connections->monitor_matchmaker; + + if (mm != NULL) + bus_matchmaker_disconnected (mm, connection); +} + +dbus_bool_t +bus_connection_be_monitor (DBusConnection *connection, + BusTransaction *transaction, + DBusList **rules, + DBusError *error) +{ + BusConnectionData *d; + DBusList *link; + DBusList *tmp; + DBusList *iter; + + d = BUS_CONNECTION_DATA (connection); + _dbus_assert (d != NULL); + + link = _dbus_list_alloc_link (connection); + + if (link == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!bcd_add_monitor_rules (d, connection, rules)) + { + _dbus_list_free_link (link); + BUS_SET_OOM (error); + return FALSE; + } + + /* release all its names */ + if (!_dbus_list_copy (&d->services_owned, &tmp)) + { + bcd_drop_monitor_rules (d, connection); + _dbus_list_free_link (link); + BUS_SET_OOM (error); + return FALSE; + } + + for (iter = _dbus_list_get_first_link (&tmp); + iter != NULL; + iter = _dbus_list_get_next_link (&tmp, iter)) + { + BusService *service = iter->data; + + /* This call is transactional: if there isn't enough memory to + * do everything, then the service gets all its names back when + * the transaction is cancelled due to OOM. */ + if (!bus_service_remove_owner (service, connection, transaction, error)) + { + bcd_drop_monitor_rules (d, connection); + _dbus_list_free_link (link); + _dbus_list_clear (&tmp); + return FALSE; + } + } + + /* We have now done everything that can fail, so there is no problem + * with doing the irrevocable stuff. */ + + _dbus_list_clear (&tmp); + + bus_context_log (transaction->context, DBUS_SYSTEM_LOG_INFO, + "Connection %s (%s) became a monitor.", d->name, + d->cached_loginfo_string); + + if (d->n_match_rules > 0) + { + BusMatchmaker *mm; + + mm = bus_context_get_matchmaker (d->connections->context); + bus_matchmaker_disconnected (mm, connection); + } + + /* flag it as a monitor */ + d->link_in_monitors = link; + _dbus_list_append_link (&d->connections->monitors, link); + + /* it isn't allowed to reply, and it is no longer relevant whether it + * receives replies */ + bus_connection_drop_pending_replies (d->connections, connection); + + return TRUE; +}
diff --git a/bus/connection.h b/bus/connection.h new file mode 100644 index 0000000..8c68d0a --- /dev/null +++ b/bus/connection.h
@@ -0,0 +1,169 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* connection.h Client connections + * + * Copyright (C) 2003, 2004 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_CONNECTION_H +#define BUS_CONNECTION_H + +#include <dbus/dbus.h> +#include <dbus/dbus-list.h> +#include "bus.h" + +typedef dbus_bool_t (* BusConnectionForeachFunction) (DBusConnection *connection, + void *data); + + +BusConnections* bus_connections_new (BusContext *context); +BusConnections* bus_connections_ref (BusConnections *connections); +void bus_connections_unref (BusConnections *connections); +dbus_bool_t bus_connections_setup_connection (BusConnections *connections, + DBusConnection *connection); +void bus_connections_foreach (BusConnections *connections, + BusConnectionForeachFunction function, + void *data); +void bus_connections_foreach_active (BusConnections *connections, + BusConnectionForeachFunction function, + void *data); +BusContext* bus_connections_get_context (BusConnections *connections); +void bus_connections_increment_stamp (BusConnections *connections); +dbus_bool_t bus_connections_reload_policy (BusConnections *connections, + DBusError *error); +BusContext* bus_connection_get_context (DBusConnection *connection); +BusConnections* bus_connection_get_connections (DBusConnection *connection); +BusRegistry* bus_connection_get_registry (DBusConnection *connection); +BusActivation* bus_connection_get_activation (DBusConnection *connection); +BusMatchmaker* bus_connection_get_matchmaker (DBusConnection *connection); +const char * bus_connection_get_loginfo (DBusConnection *connection); +BusSELinuxID* bus_connection_get_selinux_id (DBusConnection *connection); +BusAppArmorConfinement* bus_connection_dup_apparmor_confinement (DBusConnection *connection); +dbus_bool_t bus_connections_check_limits (BusConnections *connections, + DBusConnection *requesting_completion, + DBusError *error); +void bus_connections_expire_incomplete (BusConnections *connections); + +dbus_bool_t bus_connections_expect_reply (BusConnections *connections, + BusTransaction *transaction, + DBusConnection *will_get_reply, + DBusConnection *will_send_reply, + DBusMessage *reply_to_this, + DBusError *error); +dbus_bool_t bus_connections_check_reply (BusConnections *connections, + BusTransaction *transaction, + DBusConnection *sending_reply, + DBusConnection *receiving_reply, + DBusMessage *reply, + DBusError *error); + +dbus_bool_t bus_connection_mark_stamp (DBusConnection *connection); + +dbus_bool_t bus_connection_is_active (DBusConnection *connection); +const char *bus_connection_get_name (DBusConnection *connection); + +dbus_bool_t bus_connection_preallocate_oom_error (DBusConnection *connection); +void bus_connection_send_oom_error (DBusConnection *connection, + DBusMessage *in_reply_to); + +/* called by signals.c */ +dbus_bool_t bus_connection_add_match_rule (DBusConnection *connection, + BusMatchRule *rule); +void bus_connection_add_match_rule_link (DBusConnection *connection, + DBusList *link); +void bus_connection_remove_match_rule (DBusConnection *connection, + BusMatchRule *rule); +int bus_connection_get_n_match_rules (DBusConnection *connection); + + +/* called by services.c */ +dbus_bool_t bus_connection_add_owned_service (DBusConnection *connection, + BusService *service); +void bus_connection_remove_owned_service (DBusConnection *connection, + BusService *service); +void bus_connection_add_owned_service_link (DBusConnection *connection, + DBusList *link); +int bus_connection_get_n_services_owned (DBusConnection *connection); + +/* called by driver.c */ +dbus_bool_t bus_connection_complete (DBusConnection *connection, + const DBusString *name, + DBusError *error); + +/* called by dispatch.c when the connection is dropped */ +void bus_connection_disconnected (DBusConnection *connection); + +dbus_bool_t bus_connection_is_in_unix_group (DBusConnection *connection, + unsigned long gid); +dbus_bool_t bus_connection_get_unix_groups (DBusConnection *connection, + unsigned long **groups, + int *n_groups, + DBusError *error); +BusClientPolicy* bus_connection_get_policy (DBusConnection *connection); + +dbus_bool_t bus_connection_is_monitor (DBusConnection *connection); +dbus_bool_t bus_connection_be_monitor (DBusConnection *connection, + BusTransaction *transaction, + DBusList **rules, + DBusError *error); + +/* transaction API so we can send or not send a block of messages as a whole */ + +typedef void (* BusTransactionCancelFunction) (void *data); + +BusTransaction* bus_transaction_new (BusContext *context); +BusContext* bus_transaction_get_context (BusTransaction *transaction); +dbus_bool_t bus_transaction_send (BusTransaction *transaction, + DBusConnection *connection, + DBusMessage *message); +dbus_bool_t bus_transaction_capture (BusTransaction *transaction, + DBusConnection *connection, + DBusMessage *message); +dbus_bool_t bus_transaction_capture_error_reply (BusTransaction *transaction, + const DBusError *error, + DBusMessage *in_reply_to); +dbus_bool_t bus_transaction_send_from_driver (BusTransaction *transaction, + DBusConnection *connection, + DBusMessage *message); +dbus_bool_t bus_transaction_send_error_reply (BusTransaction *transaction, + DBusConnection *connection, + const DBusError *error, + DBusMessage *in_reply_to); +void bus_transaction_cancel_and_free (BusTransaction *transaction); +void bus_transaction_execute_and_free (BusTransaction *transaction); +dbus_bool_t bus_transaction_add_cancel_hook (BusTransaction *transaction, + BusTransactionCancelFunction cancel_function, + void *data, + DBusFreeFunction free_data_function); + +int bus_connections_get_n_active (BusConnections *connections); +int bus_connections_get_n_incomplete (BusConnections *connections); + +/* called by stats.c, only present if DBUS_ENABLE_STATS */ +int bus_connections_get_total_match_rules (BusConnections *connections); +int bus_connections_get_peak_match_rules (BusConnections *connections); +int bus_connections_get_peak_match_rules_per_conn (BusConnections *connections); +int bus_connections_get_total_bus_names (BusConnections *connections); +int bus_connections_get_peak_bus_names (BusConnections *connections); +int bus_connections_get_peak_bus_names_per_conn (BusConnections *connections); + +int bus_connection_get_peak_match_rules (DBusConnection *connection); +int bus_connection_get_peak_bus_names (DBusConnection *connection); + +#endif /* BUS_CONNECTION_H */
diff --git a/bus/dbus.service.in b/bus/dbus.service.in new file mode 100644 index 0000000..3bc4726 --- /dev/null +++ b/bus/dbus.service.in
@@ -0,0 +1,9 @@ +[Unit] +Description=D-Bus System Message Bus +Documentation=man:dbus-daemon(1) +Requires=dbus.socket + +[Service] +ExecStart=@EXPANDED_BINDIR@/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation +ExecReload=@EXPANDED_BINDIR@/dbus-send --print-reply --system --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig +OOMScoreAdjust=-900
diff --git a/bus/dbus.socket.in b/bus/dbus.socket.in new file mode 100644 index 0000000..74cbe58 --- /dev/null +++ b/bus/dbus.socket.in
@@ -0,0 +1,5 @@ +[Unit] +Description=D-Bus System Message Bus Socket + +[Socket] +ListenStream=@DBUS_SYSTEM_SOCKET@
diff --git a/bus/desktop-file.c b/bus/desktop-file.c new file mode 100644 index 0000000..bfeb72e --- /dev/null +++ b/bus/desktop-file.c
@@ -0,0 +1,808 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* desktop-file.c .desktop file parser + * + * Copyright (C) 2003 CodeFactory AB + * Copyright (C) 2003 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include <dbus/dbus-sysdeps.h> +#include <dbus/dbus-internals.h> +#include "desktop-file.h" +#include "utils.h" + +typedef struct +{ + char *key; + char *value; +} BusDesktopFileLine; + +typedef struct +{ + char *section_name; + + int n_lines; + BusDesktopFileLine *lines; + int n_allocated_lines; +} BusDesktopFileSection; + +struct BusDesktopFile +{ + int n_sections; + BusDesktopFileSection *sections; + int n_allocated_sections; +}; + +/** + * Parser for service files. + */ +typedef struct +{ + DBusString data; /**< The data from the file */ + + BusDesktopFile *desktop_file; /**< The resulting object */ + int current_section; /**< The current section being parsed */ + + int pos; /**< Current position */ + int len; /**< Length */ + int line_num; /**< Current line number */ + +} BusDesktopFileParser; + +#define VALID_KEY_CHAR 1 +#define VALID_LOCALE_CHAR 2 +static unsigned char valid[256] = { + 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , + 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , + 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x3 , 0x2 , 0x0 , + 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , + 0x0 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , + 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x0 , 0x0 , 0x0 , 0x0 , 0x2 , + 0x0 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , + 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x3 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , + 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , + 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , + 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , + 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , + 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , + 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , + 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , + 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , +}; + +static void report_error (BusDesktopFileParser *parser, + char *message, + const char *error_name, + DBusError *error); + +static void +parser_free (BusDesktopFileParser *parser) +{ + bus_desktop_file_free (parser->desktop_file); + + _dbus_string_free (&parser->data); +} + +static void +bus_desktop_file_line_free (BusDesktopFileLine *line) +{ + dbus_free (line->key); + dbus_free (line->value); +} + +static void +bus_desktop_file_section_free (BusDesktopFileSection *section) +{ + int i; + + for (i = 0; i < section->n_lines; i++) + bus_desktop_file_line_free (§ion->lines[i]); + + dbus_free (section->lines); + dbus_free (section->section_name); +} + +void +bus_desktop_file_free (BusDesktopFile *desktop_file) +{ + int i; + + for (i = 0; i < desktop_file->n_sections; i++) + bus_desktop_file_section_free (&desktop_file->sections[i]); + dbus_free (desktop_file->sections); + + dbus_free (desktop_file); +} + +static dbus_bool_t +grow_lines_in_section (BusDesktopFileSection *section) +{ + BusDesktopFileLine *lines; + + int new_n_lines; + + if (section->n_allocated_lines == 0) + new_n_lines = 1; + else + new_n_lines = section->n_allocated_lines*2; + + lines = dbus_realloc (section->lines, + sizeof (BusDesktopFileLine) * new_n_lines); + + if (lines == NULL) + return FALSE; + + section->lines = lines; + section->n_allocated_lines = new_n_lines; + + return TRUE; +} + +static dbus_bool_t +grow_sections (BusDesktopFile *desktop_file) +{ + int new_n_sections; + BusDesktopFileSection *sections; + + if (desktop_file->n_allocated_sections == 0) + new_n_sections = 1; + else + new_n_sections = desktop_file->n_allocated_sections*2; + + sections = dbus_realloc (desktop_file->sections, + sizeof (BusDesktopFileSection) * new_n_sections); + if (sections == NULL) + return FALSE; + + desktop_file->sections = sections; + + desktop_file->n_allocated_sections = new_n_sections; + + return TRUE; +} + +static char * +unescape_string (BusDesktopFileParser *parser, + const DBusString *str, + int pos, + int end_pos, + DBusError *error) +{ + char *retval, *q; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + /* len + 1 is enough, because unescaping never makes the + * string longer + */ + retval = dbus_malloc (end_pos - pos + 1); + if (retval == NULL) + { + BUS_SET_OOM (error); + return NULL; + } + + q = retval; + + while (pos < end_pos) + { + if (_dbus_string_get_byte (str, pos) == 0) + { + /* Found an embedded null */ + dbus_free (retval); + report_error (parser, "Text to be unescaped contains embedded nul", + BUS_DESKTOP_PARSE_ERROR_INVALID_ESCAPES, error); + return NULL; + } + + if (_dbus_string_get_byte (str, pos) == '\\') + { + pos ++; + + if (pos >= end_pos) + { + /* Escape at end of string */ + dbus_free (retval); + report_error (parser, "Text to be unescaped ended in \\", + BUS_DESKTOP_PARSE_ERROR_INVALID_ESCAPES, error); + return NULL; + } + + switch (_dbus_string_get_byte (str, pos)) + { + case 's': + *q++ = ' '; + break; + case 't': + *q++ = '\t'; + break; + case 'n': + *q++ = '\n'; + break; + case 'r': + *q++ = '\r'; + break; + case '\\': + *q++ = '\\'; + break; + default: + /* Invalid escape code */ + dbus_free (retval); + report_error (parser, "Text to be unescaped had invalid escape sequence", + BUS_DESKTOP_PARSE_ERROR_INVALID_ESCAPES, error); + return NULL; + } + pos++; + } + else + { + *q++ =_dbus_string_get_byte (str, pos); + + pos++; + } + } + + *q = 0; + + return retval; +} + +static BusDesktopFileSection* +new_section (BusDesktopFile *desktop_file, + const char *name) +{ + int n; + char *name_copy; + + if (desktop_file->n_allocated_sections == desktop_file->n_sections) + { + if (!grow_sections (desktop_file)) + return NULL; + } + + name_copy = _dbus_strdup (name); + if (name_copy == NULL) + return NULL; + + n = desktop_file->n_sections; + desktop_file->sections[n].section_name = name_copy; + + desktop_file->sections[n].n_lines = 0; + desktop_file->sections[n].lines = NULL; + desktop_file->sections[n].n_allocated_lines = 0; + + if (!grow_lines_in_section (&desktop_file->sections[n])) + { + dbus_free (desktop_file->sections[n].section_name); + desktop_file->sections[n].section_name = NULL; + return NULL; + } + + desktop_file->n_sections += 1; + + return &desktop_file->sections[n]; +} + +static BusDesktopFileSection* +open_section (BusDesktopFileParser *parser, + char *name) +{ + BusDesktopFileSection *section; + + section = new_section (parser->desktop_file, name); + if (section == NULL) + return NULL; + + parser->current_section = parser->desktop_file->n_sections - 1; + _dbus_assert (&parser->desktop_file->sections[parser->current_section] == section); + + return section; +} + +static BusDesktopFileLine * +new_line (BusDesktopFileParser *parser) +{ + BusDesktopFileSection *section; + BusDesktopFileLine *line; + + section = &parser->desktop_file->sections[parser->current_section]; + + if (section->n_allocated_lines == section->n_lines) + { + if (!grow_lines_in_section (section)) + return NULL; + } + + line = §ion->lines[section->n_lines++]; + + _DBUS_ZERO(*line); + + return line; +} + +static dbus_bool_t +is_blank_line (BusDesktopFileParser *parser) +{ + int p; + char c; + + p = parser->pos; + + c = _dbus_string_get_byte (&parser->data, p); + + while (c && c != '\n') + { + if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f')) + return FALSE; + + p++; + c = _dbus_string_get_byte (&parser->data, p); + } + + return TRUE; +} + +static void +parse_comment_or_blank (BusDesktopFileParser *parser) +{ + int line_end, eol_len; + + if (!_dbus_string_find_eol (&parser->data, parser->pos, &line_end, &eol_len)) + line_end = parser->len; + + if (line_end == parser->len) + parser->pos = parser->len; + else + parser->pos = line_end + eol_len; + + parser->line_num += 1; +} + +static dbus_bool_t +is_valid_section_name (const char *name) +{ + /* 5. Group names may contain all ASCII characters except for control characters and '[' and ']'. */ + + while (*name) + { + if (!((*name >= 'A' && *name <= 'Z') || (*name >= 'a' || *name <= 'z') || + *name == '\n' || *name == '\t')) + return FALSE; + + name++; + } + + return TRUE; +} + +static dbus_bool_t +parse_section_start (BusDesktopFileParser *parser, DBusError *error) +{ + int line_end, eol_len; + char *section_name; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!_dbus_string_find_eol (&parser->data, parser->pos, &line_end, &eol_len)) + line_end = parser->len; + + if (line_end - parser->pos <= 2 || + _dbus_string_get_byte (&parser->data, line_end - 1) != ']') + { + report_error (parser, "Invalid syntax for section header", BUS_DESKTOP_PARSE_ERROR_INVALID_SYNTAX, error); + parser_free (parser); + return FALSE; + } + + section_name = unescape_string (parser, + &parser->data, parser->pos + 1, line_end - 1, + error); + + if (section_name == NULL) + { + parser_free (parser); + return FALSE; + } + + if (!is_valid_section_name (section_name)) + { + report_error (parser, "Invalid characters in section name", BUS_DESKTOP_PARSE_ERROR_INVALID_CHARS, error); + parser_free (parser); + dbus_free (section_name); + return FALSE; + } + + if (open_section (parser, section_name) == NULL) + { + dbus_free (section_name); + parser_free (parser); + BUS_SET_OOM (error); + return FALSE; + } + + if (line_end == parser->len) + parser->pos = parser->len; + else + parser->pos = line_end + eol_len; + + parser->line_num += 1; + + dbus_free (section_name); + + return TRUE; +} + +static dbus_bool_t +parse_key_value (BusDesktopFileParser *parser, DBusError *error) +{ + int line_end, eol_len; + int key_start, key_end; + int value_start; + int p; + char *value, *tmp; + DBusString key; + BusDesktopFileLine *line; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!_dbus_string_find_eol (&parser->data, parser->pos, &line_end, &eol_len)) + line_end = parser->len; + + p = parser->pos; + key_start = p; + while (p < line_end && + (valid[_dbus_string_get_byte (&parser->data, p)] & VALID_KEY_CHAR)) + p++; + key_end = p; + + if (key_start == key_end) + { + report_error (parser, "Empty key name", BUS_DESKTOP_PARSE_ERROR_INVALID_SYNTAX, error); + parser_free (parser); + return FALSE; + } + + /* We ignore locales for now */ + if (p < line_end && _dbus_string_get_byte (&parser->data, p) == '[') + { + if (line_end == parser->len) + parser->pos = parser->len; + else + parser->pos = line_end + eol_len; + + parser->line_num += 1; + + return TRUE; + } + + /* Skip space before '=' */ + while (p < line_end && _dbus_string_get_byte (&parser->data, p) == ' ') + p++; + + if (p < line_end && _dbus_string_get_byte (&parser->data, p) != '=') + { + report_error (parser, "Invalid characters in key name", BUS_DESKTOP_PARSE_ERROR_INVALID_CHARS, error); + parser_free (parser); + return FALSE; + } + + if (p == line_end) + { + report_error (parser, "No '=' in key/value pair", BUS_DESKTOP_PARSE_ERROR_INVALID_SYNTAX, error); + parser_free (parser); + return FALSE; + } + + /* Skip the '=' */ + p++; + + /* Skip space after '=' */ + while (p < line_end && _dbus_string_get_byte (&parser->data, p) == ' ') + p++; + + value_start = p; + + value = unescape_string (parser, &parser->data, value_start, line_end, error); + if (value == NULL) + { + parser_free (parser); + return FALSE; + } + + line = new_line (parser); + if (line == NULL) + { + dbus_free (value); + parser_free (parser); + BUS_SET_OOM (error); + return FALSE; + } + + if (!_dbus_string_init (&key)) + { + dbus_free (value); + parser_free (parser); + BUS_SET_OOM (error); + return FALSE; + } + + if (!_dbus_string_copy_len (&parser->data, key_start, key_end - key_start, + &key, 0)) + { + _dbus_string_free (&key); + dbus_free (value); + parser_free (parser); + BUS_SET_OOM (error); + return FALSE; + } + + if (!_dbus_string_steal_data (&key, &tmp)) + { + _dbus_string_free (&key); + dbus_free (value); + parser_free (parser); + BUS_SET_OOM (error); + return FALSE; + } + + _dbus_string_free (&key); + + line->key = tmp; + line->value = value; + + if (line_end == parser->len) + parser->pos = parser->len; + else + parser->pos = line_end + eol_len; + + parser->line_num += 1; + + return TRUE; +} + +static void +report_error (BusDesktopFileParser *parser, + char *message, + const char *error_name, + DBusError *error) +{ + const char *section_name = NULL; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (parser->current_section != -1) + section_name = parser->desktop_file->sections[parser->current_section].section_name; + + if (section_name) + dbus_set_error (error, error_name, + "Error in section %s at line %d: %s\n", section_name, parser->line_num, message); + else + dbus_set_error (error, error_name, + "Error at line %d: %s\n", parser->line_num, message); +} + +#if 0 +static void +dump_desktop_file (BusDesktopFile *file) +{ + int i; + + for (i = 0; i < file->n_sections; i++) + { + int j; + + printf ("[%s]\n", file->sections[i].section_name); + + for (j = 0; j < file->sections[i].n_lines; j++) + { + printf ("%s=%s\n", file->sections[i].lines[j].key, + file->sections[i].lines[j].value); + } + } +} +#endif + +BusDesktopFile* +bus_desktop_file_load (DBusString *filename, + DBusError *error) +{ + DBusString str; + BusDesktopFileParser parser; + DBusStat sb; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + /* Clearly there's a race here, but it's just to make it unlikely + * that we do something silly, we still handle doing it below. + */ + if (!_dbus_stat (filename, &sb, error)) + return NULL; + + if (sb.size > _DBUS_ONE_KILOBYTE * 128) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Desktop file size (%ld bytes) is too large", (long) sb.size); + return NULL; + } + + if (!_dbus_string_init (&str)) + { + BUS_SET_OOM (error); + return NULL; + } + + if (!_dbus_file_get_contents (&str, filename, error)) + { + _dbus_string_free (&str); + return NULL; + } + + if (!_dbus_string_validate_utf8 (&str, 0, _dbus_string_get_length (&str))) + { + _dbus_string_free (&str); + dbus_set_error (error, DBUS_ERROR_FAILED, + "invalid UTF-8"); + return NULL; + } + + parser.desktop_file = dbus_new0 (BusDesktopFile, 1); + if (parser.desktop_file == NULL) + { + _dbus_string_free (&str); + BUS_SET_OOM (error); + return NULL; + } + + parser.data = str; + parser.line_num = 1; + parser.pos = 0; + parser.len = _dbus_string_get_length (&parser.data); + parser.current_section = -1; + + while (parser.pos < parser.len) + { + if (_dbus_string_get_byte (&parser.data, parser.pos) == '[') + { + if (!parse_section_start (&parser, error)) + { + return NULL; + } + } + else if (is_blank_line (&parser) || + _dbus_string_get_byte (&parser.data, parser.pos) == '#') + parse_comment_or_blank (&parser); + else if (parser.current_section < 0) + { + dbus_set_error(error, DBUS_ERROR_FAILED, + "invalid service file: key=value before [Section]"); + return NULL; + } + else + { + if (!parse_key_value (&parser, error)) + { + return NULL; + } + } + } + + _dbus_string_free (&parser.data); + + return parser.desktop_file; +} + +static BusDesktopFileSection * +lookup_section (BusDesktopFile *desktop_file, + const char *section_name) +{ + BusDesktopFileSection *section; + int i; + + if (section_name == NULL) + return NULL; + + for (i = 0; i < desktop_file->n_sections; i ++) + { + section = &desktop_file->sections[i]; + + if (strcmp (section->section_name, section_name) == 0) + return section; + } + + return NULL; +} + +static BusDesktopFileLine * +lookup_line (BusDesktopFile *desktop_file, + BusDesktopFileSection *section, + const char *keyname) +{ + BusDesktopFileLine *line; + int i; + + for (i = 0; i < section->n_lines; i++) + { + line = §ion->lines[i]; + + if (strcmp (line->key, keyname) == 0) + return line; + } + + return NULL; +} + +dbus_bool_t +bus_desktop_file_get_raw (BusDesktopFile *desktop_file, + const char *section_name, + const char *keyname, + const char **val) +{ + BusDesktopFileSection *section; + BusDesktopFileLine *line; + + *val = NULL; + + section = lookup_section (desktop_file, section_name); + + if (!section) + return FALSE; + + line = lookup_line (desktop_file, + section, + keyname); + + if (!line) + return FALSE; + + *val = line->value; + + return TRUE; +} + +dbus_bool_t +bus_desktop_file_get_string (BusDesktopFile *desktop_file, + const char *section, + const char *keyname, + char **val, + DBusError *error) +{ + const char *raw; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + *val = NULL; + + if (!bus_desktop_file_get_raw (desktop_file, section, keyname, &raw)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "No \"%s\" key in .service file\n", keyname); + return FALSE; + } + + *val = _dbus_strdup (raw); + + if (*val == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; +}
diff --git a/bus/desktop-file.h b/bus/desktop-file.h new file mode 100644 index 0000000..e405625 --- /dev/null +++ b/bus/desktop-file.h
@@ -0,0 +1,56 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* desktop-file.h .desktop file parser + * + * Copyright (C) 2003 CodeFactory AB + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#ifndef BUS_DESKTOP_FILE_H +#define BUS_DESKTOP_FILE_H + +#include <dbus/dbus.h> +#include <dbus/dbus-string.h> + +#define BUS_DESKTOP_PARSE_ERROR_INVALID_SYNTAX "org.freedesktop.DBus.DesktopParseError.InvalidSyntax" +#define BUS_DESKTOP_PARSE_ERROR_INVALID_ESCAPES "org.freedesktop.DBus.DesktopParseError.InvalidEscapes" +#define BUS_DESKTOP_PARSE_ERROR_INVALID_CHARS "org.freedesktop.DBus.DesktopParseError.InvalidChars" + +#define DBUS_SERVICE_SECTION "D-BUS Service" +#define DBUS_SERVICE_NAME "Name" +#define DBUS_SERVICE_EXEC "Exec" +#define DBUS_SERVICE_USER "User" +#define DBUS_SERVICE_SYSTEMD_SERVICE "SystemdService" + +typedef struct BusDesktopFile BusDesktopFile; + +BusDesktopFile *bus_desktop_file_load (DBusString *filename, + DBusError *error); +void bus_desktop_file_free (BusDesktopFile *file); + +dbus_bool_t bus_desktop_file_get_raw (BusDesktopFile *desktop_file, + const char *section_name, + const char *keyname, + const char **val); +dbus_bool_t bus_desktop_file_get_string (BusDesktopFile *desktop_file, + const char *section, + const char *keyname, + char **val, + DBusError *error); + + +#endif /* BUS_DESKTOP_FILE_H */
diff --git a/bus/dir-watch-default.c b/bus/dir-watch-default.c new file mode 100644 index 0000000..69361b1 --- /dev/null +++ b/bus/dir-watch-default.c
@@ -0,0 +1,35 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dir-watch-default.c OS specific directory change notification for message bus + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> + +#include <dbus/dbus-internals.h> +#include "dir-watch.h" + + +/* NoOp */ + +void +bus_set_watched_dirs (BusContext *context, DBusList **directories) +{ +}
diff --git a/bus/dir-watch-inotify.c b/bus/dir-watch-inotify.c new file mode 100644 index 0000000..ce19fdc --- /dev/null +++ b/bus/dir-watch-inotify.c
@@ -0,0 +1,287 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dir-watch-inotify.c OS specific directory change notification for message bus + * + * Copyright (C) 2003 Red Hat, Inc. + * (c) 2006 Mandriva + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* Be careful, this file is not Linux-only: QNX also uses it */ + +#include <config.h> + +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +/* QNX's inotify is broken, and requires stdint.h to be manually included first */ +#include <stdint.h> +#include <sys/inotify.h> +#include <sys/types.h> +#include <signal.h> +#include <errno.h> + +#include <dbus/dbus-internals.h> +#include <dbus/dbus-list.h> +#include <dbus/dbus-sysdeps-unix.h> +#include <dbus/dbus-watch.h> +#include "dir-watch.h" + +#define MAX_DIRS_TO_WATCH 128 +#define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event)) +#define INOTIFY_BUF_LEN (1024 * (INOTIFY_EVENT_SIZE + 16)) + +/* use a static array to avoid handling OOM */ +static int wds[MAX_DIRS_TO_WATCH]; +static char *dirs[MAX_DIRS_TO_WATCH]; +static int num_wds = 0; +static int inotify_fd = -1; +static DBusWatch *watch = NULL; +static DBusLoop *loop = NULL; + +static dbus_bool_t +_handle_inotify_watch (DBusWatch *passed_watch, unsigned int flags, void *data) +{ + char buffer[INOTIFY_BUF_LEN]; + ssize_t ret = 0; + int i = 0; + + ret = read (inotify_fd, buffer, INOTIFY_BUF_LEN); + if (ret < 0) + _dbus_verbose ("Error reading inotify event: '%s'\n", _dbus_strerror(errno)); + else if (!ret) + _dbus_verbose ("Error reading inotify event: buffer too small\n"); + else + { + _dbus_verbose ("Sending SIGHUP signal on reception of %ld inotify event(s)\n", (long) ret); + (void) kill (_dbus_getpid (), SIGHUP); + } + +#ifdef DBUS_ENABLE_VERBOSE_MODE + while (i < ret) + { + struct inotify_event *ev; + + ev = (struct inotify_event *) &buffer[i]; + i += INOTIFY_EVENT_SIZE + ev->len; + if (ev->len) + _dbus_verbose ("event name: '%s'\n", ev->name); + _dbus_verbose ("inotify event: wd=%d mask=%u cookie=%u len=%u\n", ev->wd, ev->mask, ev->cookie, ev->len); + } +#endif + + return TRUE; +} + +#include <stdio.h> + +static void +_set_watched_dirs_internal (DBusList **directories) +{ + int new_wds[MAX_DIRS_TO_WATCH]; + char *new_dirs[MAX_DIRS_TO_WATCH]; + DBusList *link; + int i, j, wd; + + for (i = 0; i < MAX_DIRS_TO_WATCH; i++) + { + new_wds[i] = -1; + new_dirs[i] = NULL; + } + + i = 0; + link = _dbus_list_get_first_link (directories); + while (link != NULL) + { + new_dirs[i++] = (char *)link->data; + link = _dbus_list_get_next_link (directories, link); + } + + /* Look for directories in both the old and new sets, if + * we find one, move its data into the new set. + */ + for (i = 0; new_dirs[i]; i++) + { + for (j = 0; j < num_wds; j++) + { + if (dirs[j] && strcmp (new_dirs[i], dirs[j]) == 0) + { + new_wds[i] = wds[j]; + new_dirs[i] = dirs[j]; + wds[j] = -1; + dirs[j] = NULL; + break; + } + } + } + + /* Any directories we find in "wds" with a nonzero fd must + * not be in the new set, so perform cleanup now. + */ + for (j = 0; j < num_wds; j++) + { + if (wds[j] != -1) + { + inotify_rm_watch (inotify_fd, wds[j]); + dbus_free (dirs[j]); + wds[j] = -1; + dirs[j] = NULL; + } + } + + for (i = 0; new_dirs[i]; i++) + { + if (new_wds[i] == -1) + { + /* FIXME - less lame error handling for failing to add a watch; we may need to sleep. */ + wd = inotify_add_watch (inotify_fd, new_dirs[i], IN_CLOSE_WRITE | IN_DELETE | IN_MOVED_TO | IN_MOVED_FROM); + if (wd < 0) + { + /* Not all service directories need to exist. */ + if (errno != ENOENT) + { + _dbus_warn ("Cannot setup inotify for '%s'; error '%s'\n", new_dirs[i], _dbus_strerror (errno)); + goto out; + } + else + { + new_wds[i] = -1; + new_dirs[i] = NULL; + continue; + } + } + new_wds[i] = wd; + new_dirs[i] = _dbus_strdup (new_dirs[i]); + if (!new_dirs[i]) + { + /* FIXME have less lame handling for OOM, we just silently fail to + * watch. (In reality though, the whole OOM handling in dbus is stupid + * but we won't go into that in this comment =) ) + */ + inotify_rm_watch (inotify_fd, wd); + new_wds[i] = -1; + } + } + } + + num_wds = i; + + for (i = 0; i < MAX_DIRS_TO_WATCH; i++) + { + wds[i] = new_wds[i]; + dirs[i] = new_dirs[i]; + } + + out:; +} + +#include <stdio.h> +static void +_shutdown_inotify (void *data) +{ + DBusList *empty = NULL; + + if (inotify_fd == -1) + return; + + _set_watched_dirs_internal (&empty); + + if (watch != NULL) + { + _dbus_loop_remove_watch (loop, watch); + _dbus_watch_invalidate (watch); + _dbus_watch_unref (watch); + _dbus_loop_unref (loop); + } + watch = NULL; + loop = NULL; + + close (inotify_fd); + inotify_fd = -1; +} + +static int +_init_inotify (BusContext *context) +{ + int ret = 0; + + if (inotify_fd == -1) + { +#ifdef HAVE_INOTIFY_INIT1 + inotify_fd = inotify_init1 (IN_CLOEXEC); + /* This ensures we still run on older Linux kernels. + * https://bugs.freedesktop.org/show_bug.cgi?id=23957 + */ + if (inotify_fd < 0) + inotify_fd = inotify_init (); +#else + inotify_fd = inotify_init (); +#endif + if (inotify_fd <= 0) + { + _dbus_warn ("Cannot initialize inotify\n"); + goto out; + } + + /* In the inotify_init1 case this is unnecessary but harmless, + * in the other cases it's necessary */ + _dbus_fd_set_close_on_exec (inotify_fd); + + loop = bus_context_get_loop (context); + _dbus_loop_ref (loop); + + watch = _dbus_watch_new (inotify_fd, DBUS_WATCH_READABLE, TRUE, + _handle_inotify_watch, NULL, NULL); + + if (watch == NULL) + { + _dbus_warn ("Unable to create inotify watch\n"); + goto out; + } + + if (!_dbus_loop_add_watch (loop, watch)) + { + _dbus_warn ("Unable to add reload watch to main loop"); + _dbus_watch_unref (watch); + watch = NULL; + goto out; + } + + if (!_dbus_register_shutdown_func (_shutdown_inotify, NULL)) + { + _dbus_warn ("Unable to register shutdown func"); + _dbus_watch_unref (watch); + watch = NULL; + goto out; + } + } + + ret = 1; + +out: + return ret; +} + +void +bus_set_watched_dirs (BusContext *context, DBusList **directories) +{ + if (!_init_inotify (context)) + return; + + _set_watched_dirs_internal (directories); +}
diff --git a/bus/dir-watch-kqueue.c b/bus/dir-watch-kqueue.c new file mode 100644 index 0000000..c1e8324 --- /dev/null +++ b/bus/dir-watch-kqueue.c
@@ -0,0 +1,329 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dir-watch-kqueue.c OS specific directory change notification for message bus + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> + +#include <sys/types.h> +#include <sys/event.h> +#include <sys/time.h> +#include <signal.h> +#include <fcntl.h> +#include <unistd.h> +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif + +#include "bus.h" +#include <dbus/dbus-watch.h> + +#include <dbus/dbus-internals.h> +#include <dbus/dbus-list.h> +#include <dbus/dbus-sysdeps-unix.h> +#include "dir-watch.h" + +#define MAX_DIRS_TO_WATCH 128 + +static int kq = -1; +static int fds[MAX_DIRS_TO_WATCH]; +static char *dirs[MAX_DIRS_TO_WATCH]; +static int num_fds = 0; +static DBusWatch *watch = NULL; +static DBusLoop *loop = NULL; + +static dbus_bool_t +_handle_kqueue_watch (DBusWatch *watch, unsigned int flags, void *data) +{ + struct kevent ev; + struct timespec nullts = { 0, 0 }; + int res; + pid_t pid; + + res = kevent (kq, NULL, 0, &ev, 1, &nullts); + + /* Sleep for half a second to avoid a race when files are install(1)'d + * to system.d. */ + usleep(500000); + + if (res > 0) + { + pid = getpid (); + _dbus_verbose ("Sending SIGHUP signal on reception of a kevent\n"); + (void) kill (pid, SIGHUP); + } + else if (res < 0 && errno == EBADF) + { + kq = -1; + if (watch != NULL) + { + _dbus_loop_remove_watch (loop, watch); + _dbus_watch_invalidate (watch); + _dbus_watch_unref (watch); + watch = NULL; + } + pid = getpid (); + _dbus_verbose ("Sending SIGHUP signal since kqueue has been closed\n"); + (void) kill (pid, SIGHUP); + } + + return TRUE; +} + +static void _shutdown_kqueue (void *data) +{ + int i; + + if (kq < 0) + return; + + for (i = 0; i < MAX_DIRS_TO_WATCH; i++) + { + if (fds[i] >= 0) + { + close (fds[i]); + fds[i] = -1; + } + if (dirs[i] != NULL) + { + /* dbus_free() is necessary to pass memleak check */ + dbus_free (dirs[i]); + dirs[i] = NULL; + } + } + + if (loop) + { + _dbus_loop_remove_watch (loop, watch); + _dbus_loop_unref (loop); + loop = NULL; + } + + if (watch) + { + _dbus_watch_invalidate (watch); + _dbus_watch_unref (watch); + watch = NULL; + } + + close (kq); + kq = -1; +} + +static int +_init_kqueue (BusContext *context) +{ + if (kq < 0) + { + + kq = kqueue (); + if (kq < 0) + { + _dbus_warn ("Cannot create kqueue; error '%s'\n", _dbus_strerror (errno)); + goto out; + } + + loop = bus_context_get_loop (context); + _dbus_loop_ref (loop); + + watch = _dbus_watch_new (kq, DBUS_WATCH_READABLE, TRUE, + _handle_kqueue_watch, NULL, NULL); + + if (watch == NULL) + { + _dbus_warn ("Unable to create kqueue watch\n"); + goto out1; + } + + if (!_dbus_loop_add_watch (loop, watch)) + { + _dbus_warn ("Unable to add reload watch to main loop"); + goto out2; + } + + if (!_dbus_register_shutdown_func (_shutdown_kqueue, NULL)) + { + _dbus_warn ("Unable to register shutdown function"); + goto out3; + } + } + + return 1; + +out3: + _dbus_loop_remove_watch (loop, watch); + +out2: + if (watch) + { + _dbus_watch_invalidate (watch); + _dbus_watch_unref (watch); + watch = NULL; + } + +out1: + if (kq >= 0) + { + close (kq); + kq = -1; + } + if (loop) + { + _dbus_loop_unref (loop); + loop = NULL; + } + +out: + return 0; +} + +void +bus_set_watched_dirs (BusContext *context, DBusList **directories) +{ + int new_fds[MAX_DIRS_TO_WATCH]; + char *new_dirs[MAX_DIRS_TO_WATCH]; + DBusList *link; + int i, j, fd; + struct kevent ev; +#ifdef O_CLOEXEC + dbus_bool_t cloexec_done = 0; +#endif + + if (!_init_kqueue (context)) + goto out; + + for (i = 0; i < MAX_DIRS_TO_WATCH; i++) + { + new_fds[i] = -1; + new_dirs[i] = NULL; + } + + i = 0; + link = _dbus_list_get_first_link (directories); + while (link != NULL) + { + new_dirs[i++] = (char *)link->data; + link = _dbus_list_get_next_link (directories, link); + } + + /* Look for directories in both the old and new sets, if + * we find one, move its data into the new set. + */ + for (i = 0; new_dirs[i]; i++) + { + for (j = 0; j < num_fds; j++) + { + if (dirs[j] && strcmp (new_dirs[i], dirs[j]) == 0) + { + new_fds[i] = fds[j]; + new_dirs[i] = dirs[j]; + fds[j] = -1; + dirs[j] = NULL; + break; + } + } + } + + /* Any directory we find in "fds" with a nonzero fd must + * not be in the new set, so perform cleanup now. + */ + for (j = 0; j < num_fds; j++) + { + if (fds[j] != -1) + { + close (fds[j]); + dbus_free (dirs[j]); + fds[j] = -1; + dirs[j] = NULL; + } + } + + for (i = 0; new_dirs[i]; i++) + { + if (new_fds[i] == -1) + { + /* FIXME - less lame error handling for failing to add a watch; + * we may need to sleep. + */ +#ifdef O_CLOEXEC + fd = open (new_dirs[i], O_RDONLY | O_CLOEXEC); + cloexec_done = (fd >= 0); + + if (fd < 0 && errno == EINVAL) +#endif + { + fd = open (new_dirs[i], O_RDONLY); + } + if (fd < 0) + { + if (errno != ENOENT) + { + _dbus_warn ("Cannot open directory '%s'; error '%s'\n", new_dirs[i], _dbus_strerror (errno)); + goto out; + } + else + { + new_fds[i] = -1; + new_dirs[i] = NULL; + continue; + } + } +#ifdef O_CLOEXEC + if (!cloexec_done) +#endif + { + _dbus_fd_set_close_on_exec (fd); + } + + EV_SET (&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, + NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_RENAME, 0, 0); + if (kevent (kq, &ev, 1, NULL, 0, NULL) == -1) + { + _dbus_warn ("Cannot setup a kevent for '%s'; error '%s'\n", new_dirs[i], _dbus_strerror (errno)); + close (fd); + goto out; + } + + new_fds[i] = fd; + new_dirs[i] = _dbus_strdup (new_dirs[i]); + if (!new_dirs[i]) + { + /* FIXME have less lame handling for OOM, we just silently fail to + * watch. (In reality though, the whole OOM handling in dbus is + * stupid but we won't go into that in this comment =) ) + */ + close (fd); + new_fds[i] = -1; + } + } + } + + num_fds = i; + + for (i = 0; i < MAX_DIRS_TO_WATCH; i++) + { + fds[i] = new_fds[i]; + dirs[i] = new_dirs[i]; + } + + out: + ; +}
diff --git a/bus/dir-watch.h b/bus/dir-watch.h new file mode 100644 index 0000000..b44529e --- /dev/null +++ b/bus/dir-watch.h
@@ -0,0 +1,40 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dir-watch.h Watch directories + * + * Copyright (C) 2005 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "bus.h" + +#ifndef DIR_WATCH_H +#define DIR_WATCH_H + +/** + * Update the set of directories to monitor for changes. The + * operating-system-specific implementation of this function should + * avoid creating a window where a directory in both the + * old and new set isn't monitored. + * + * @param context The bus context + * @param dirs List of strings which are directory paths + */ +void bus_set_watched_dirs (BusContext *context, DBusList **dirs); + +#endif /* DIR_WATCH_H */
diff --git a/bus/dispatch.c b/bus/dispatch.c new file mode 100644 index 0000000..edfa1b4 --- /dev/null +++ b/bus/dispatch.c
@@ -0,0 +1,5200 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dispatch.c Message dispatcher + * + * Copyright (C) 2003 CodeFactory AB + * Copyright (C) 2003, 2004, 2005 Red Hat, Inc. + * Copyright (C) 2004 Imendio HB + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "dispatch.h" +#include "connection.h" +#include "driver.h" +#include "services.h" +#include "activation.h" +#include "utils.h" +#include "bus.h" +#include "signals.h" +#include "test.h" +#include <dbus/dbus-internals.h> +#include <dbus/dbus-misc.h> +#include <string.h> + +#ifdef HAVE_UNIX_FD_PASSING +#include <dbus/dbus-sysdeps-unix.h> +#include <unistd.h> +#endif + +/* This is hard-coded in the files in valid-config-files-*. We have to use + * the debug-pipe transport because the tests in this file require that + * dbus_connection_open_private() does not block. */ +#define TEST_DEBUG_PIPE "debug-pipe:name=test-server" + +static inline const char * +nonnull (const char *maybe_null, + const char *if_null) +{ + return (maybe_null ? maybe_null : if_null); +} + +static dbus_bool_t +send_one_message (DBusConnection *connection, + BusContext *context, + DBusConnection *sender, + DBusConnection *addressed_recipient, + DBusMessage *message, + BusTransaction *transaction, + DBusError *error) +{ + DBusError stack_error = DBUS_ERROR_INIT; + + if (!bus_context_check_security_policy (context, transaction, + sender, + addressed_recipient, + connection, + message, + &stack_error)) + { + if (!bus_transaction_capture_error_reply (transaction, &stack_error, + message)) + { + bus_context_log (context, DBUS_SYSTEM_LOG_WARNING, + "broadcast rejected, but not enough " + "memory to tell monitors"); + } + + dbus_error_free (&stack_error); + return TRUE; /* don't send it but don't return an error either */ + } + + if (dbus_message_contains_unix_fds(message) && + !dbus_connection_can_send_type(connection, DBUS_TYPE_UNIX_FD)) + { + dbus_set_error (&stack_error, DBUS_ERROR_NOT_SUPPORTED, + "broadcast cannot be delivered to %s (%s) because " + "it does not support receiving Unix fds", + bus_connection_get_name (connection), + bus_connection_get_loginfo (connection)); + + if (!bus_transaction_capture_error_reply (transaction, &stack_error, + message)) + { + bus_context_log (context, DBUS_SYSTEM_LOG_WARNING, + "broadcast with Unix fd not delivered, but not " + "enough memory to tell monitors"); + } + + dbus_error_free (&stack_error); + return TRUE; /* don't send it but don't return an error either */ + } + + if (!bus_transaction_send (transaction, + connection, + message)) + { + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; +} + +dbus_bool_t +bus_dispatch_matches (BusTransaction *transaction, + DBusConnection *sender, + DBusConnection *addressed_recipient, + DBusMessage *message, + DBusError *error) +{ + DBusError tmp_error; + BusConnections *connections; + DBusList *recipients; + BusMatchmaker *matchmaker; + DBusList *link; + BusContext *context; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + /* sender and recipient can both be NULL for the bus driver, + * or for signals with no particular recipient + */ + + _dbus_assert (sender == NULL || bus_connection_is_active (sender)); + _dbus_assert (dbus_message_get_sender (message) != NULL); + + context = bus_transaction_get_context (transaction); + + /* First, send the message to the addressed_recipient, if there is one. */ + if (addressed_recipient != NULL) + { + if (!bus_context_check_security_policy (context, transaction, + sender, addressed_recipient, + addressed_recipient, + message, error)) + return FALSE; + + if (dbus_message_contains_unix_fds (message) && + !dbus_connection_can_send_type (addressed_recipient, + DBUS_TYPE_UNIX_FD)) + { + dbus_set_error (error, + DBUS_ERROR_NOT_SUPPORTED, + "Tried to send message with Unix file descriptors" + "to a client that doesn't support that."); + return FALSE; + } + + /* Dispatch the message */ + if (!bus_transaction_send (transaction, addressed_recipient, message)) + { + BUS_SET_OOM (error); + return FALSE; + } + } + + /* Now dispatch to others who look interested in this message */ + connections = bus_context_get_connections (context); + dbus_error_init (&tmp_error); + matchmaker = bus_context_get_matchmaker (context); + + recipients = NULL; + if (!bus_matchmaker_get_recipients (matchmaker, connections, + sender, addressed_recipient, message, + &recipients)) + { + BUS_SET_OOM (error); + return FALSE; + } + + link = _dbus_list_get_first_link (&recipients); + while (link != NULL) + { + DBusConnection *dest; + + dest = link->data; + + if (!send_one_message (dest, context, sender, addressed_recipient, + message, transaction, &tmp_error)) + break; + + link = _dbus_list_get_next_link (&recipients, link); + } + + _dbus_list_clear (&recipients); + + if (dbus_error_is_set (&tmp_error)) + { + dbus_move_error (&tmp_error, error); + return FALSE; + } + else + return TRUE; +} + +static DBusHandlerResult +bus_dispatch (DBusConnection *connection, + DBusMessage *message) +{ + const char *sender, *service_name; + DBusError error; + BusTransaction *transaction; + BusContext *context; + DBusHandlerResult result; + DBusConnection *addressed_recipient; + + result = DBUS_HANDLER_RESULT_HANDLED; + + transaction = NULL; + addressed_recipient = NULL; + dbus_error_init (&error); + + context = bus_connection_get_context (connection); + _dbus_assert (context != NULL); + + /* If we can't even allocate an OOM error, we just go to sleep + * until we can. + */ + while (!bus_connection_preallocate_oom_error (connection)) + _dbus_wait_for_memory (); + + /* Ref connection in case we disconnect it at some point in here */ + dbus_connection_ref (connection); + + /* Monitors aren't meant to send messages to us. */ + if (bus_connection_is_monitor (connection)) + { + sender = bus_connection_get_name (connection); + + /* should never happen */ + if (sender == NULL) + sender = "(unknown)"; + + if (dbus_message_is_signal (message, + DBUS_INTERFACE_LOCAL, + "Disconnected")) + { + bus_context_log (context, DBUS_SYSTEM_LOG_INFO, + "Monitoring connection %s closed.", sender); + bus_connection_disconnected (connection); + goto out; + } + else + { + /* Monitors are not allowed to send messages, because that + * probably indicates that the monitor is incorrectly replying + * to its eavesdropped messages, and we want the authors of + * such monitors to fix them. + */ + bus_context_log (context, DBUS_SYSTEM_LOG_WARNING, + "Monitoring connection %s (%s) is not allowed " + "to send messages; closing it. Please fix the " + "monitor to not do that. " + "(message type=\"%s\" interface=\"%s\" " + "member=\"%s\" error name=\"%s\" " + "destination=\"%s\")", + sender, bus_connection_get_loginfo (connection), + dbus_message_type_to_string ( + dbus_message_get_type (message)), + nonnull (dbus_message_get_interface (message), + "(unset)"), + nonnull (dbus_message_get_member (message), + "(unset)"), + nonnull (dbus_message_get_error_name (message), + "(unset)"), + nonnull (dbus_message_get_destination (message), + DBUS_SERVICE_DBUS)); + dbus_connection_close (connection); + goto out; + } + } + + service_name = dbus_message_get_destination (message); + +#ifdef DBUS_ENABLE_VERBOSE_MODE + { + const char *interface_name, *member_name, *error_name; + + interface_name = dbus_message_get_interface (message); + member_name = dbus_message_get_member (message); + error_name = dbus_message_get_error_name (message); + + _dbus_verbose ("DISPATCH: %s %s %s to %s\n", + interface_name ? interface_name : "(no interface)", + member_name ? member_name : "(no member)", + error_name ? error_name : "(no error name)", + service_name ? service_name : "peer"); + } +#endif /* DBUS_ENABLE_VERBOSE_MODE */ + + /* If service_name is NULL, if it's a signal we send it to all + * connections with a match rule. If it's not a signal, there + * are some special cases here but mostly we just bail out. + */ + if (service_name == NULL) + { + if (dbus_message_is_signal (message, + DBUS_INTERFACE_LOCAL, + "Disconnected")) + { + bus_connection_disconnected (connection); + goto out; + } + + if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL) + { + /* DBusConnection also handles some of these automatically, we leave + * it to do so. + * + * FIXME: this means monitors won't get the opportunity to see + * non-signals with NULL destination, or their replies (which in + * practice are UnknownMethod errors) + */ + result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + goto out; + } + } + + /* Create our transaction */ + transaction = bus_transaction_new (context); + if (transaction == NULL) + { + BUS_SET_OOM (&error); + goto out; + } + + /* Assign a sender to the message */ + if (bus_connection_is_active (connection)) + { + sender = bus_connection_get_name (connection); + _dbus_assert (sender != NULL); + + if (!dbus_message_set_sender (message, sender)) + { + BUS_SET_OOM (&error); + goto out; + } + } + else + { + /* For monitors' benefit: we don't want the sender to be able to + * trick the monitor by supplying a forged sender, and we also + * don't want the message to have no sender at all. */ + if (!dbus_message_set_sender (message, ":not.active.yet")) + { + BUS_SET_OOM (&error); + goto out; + } + } + + /* We need to refetch the service name here, because + * dbus_message_set_sender can cause the header to be + * reallocated, and thus the service_name pointer will become + * invalid. + */ + service_name = dbus_message_get_destination (message); + + if (!bus_transaction_capture (transaction, connection, message)) + { + BUS_SET_OOM (&error); + goto out; + } + + if (service_name && + strcmp (service_name, DBUS_SERVICE_DBUS) == 0) /* to bus driver */ + { + if (!bus_context_check_security_policy (context, transaction, + connection, NULL, NULL, message, &error)) + { + _dbus_verbose ("Security policy rejected message\n"); + goto out; + } + + _dbus_verbose ("Giving message to %s\n", DBUS_SERVICE_DBUS); + if (!bus_driver_handle_message (connection, transaction, message, &error)) + goto out; + } + else if (!bus_connection_is_active (connection)) /* clients must talk to bus driver first */ + { + _dbus_verbose ("Received message from non-registered client. Disconnecting.\n"); + dbus_connection_close (connection); + goto out; + } + else if (service_name != NULL) /* route to named service */ + { + DBusString service_string; + BusService *service; + BusRegistry *registry; + + _dbus_assert (service_name != NULL); + + registry = bus_connection_get_registry (connection); + + _dbus_string_init_const (&service_string, service_name); + service = bus_registry_lookup (registry, &service_string); + + if (service == NULL && dbus_message_get_auto_start (message)) + { + BusActivation *activation; + /* We can't do the security policy check here, since the addressed + * recipient service doesn't exist yet. We do it before sending the + * message after the service has been created. + */ + activation = bus_connection_get_activation (connection); + + if (!bus_activation_activate_service (activation, connection, transaction, TRUE, + message, service_name, &error)) + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + _dbus_verbose ("bus_activation_activate_service() failed: %s\n", error.name); + goto out; + } + + goto out; + } + else if (service == NULL) + { + dbus_set_error (&error, + DBUS_ERROR_NAME_HAS_NO_OWNER, + "Name \"%s\" does not exist", + service_name); + goto out; + } + else + { + addressed_recipient = bus_service_get_primary_owners_connection (service); + _dbus_assert (addressed_recipient != NULL); + } + } + + /* Now send the message to its destination (or not, if + * addressed_recipient == NULL), and match it against other connections' + * match rules. + */ + if (!bus_dispatch_matches (transaction, connection, addressed_recipient, message, &error)) + goto out; + + out: + if (dbus_error_is_set (&error)) + { + /* Even if we disconnected it, pretend to send it any pending error + * messages so that monitors can observe them. + */ + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + bus_connection_send_oom_error (connection, message); + + /* cancel transaction due to OOM */ + if (transaction != NULL) + { + bus_transaction_cancel_and_free (transaction); + transaction = NULL; + } + } + else + { + /* Try to send the real error, if no mem to do that, send + * the OOM error + */ + _dbus_assert (transaction != NULL); + if (!bus_transaction_send_error_reply (transaction, connection, + &error, message)) + { + bus_connection_send_oom_error (connection, message); + + /* cancel transaction due to OOM */ + if (transaction != NULL) + { + bus_transaction_cancel_and_free (transaction); + transaction = NULL; + } + } + } + + + dbus_error_free (&error); + } + + if (transaction != NULL) + { + bus_transaction_execute_and_free (transaction); + } + + dbus_connection_unref (connection); + + return result; +} + +static DBusHandlerResult +bus_dispatch_message_filter (DBusConnection *connection, + DBusMessage *message, + void *user_data) +{ + return bus_dispatch (connection, message); +} + +dbus_bool_t +bus_dispatch_add_connection (DBusConnection *connection) +{ + if (!dbus_connection_add_filter (connection, + bus_dispatch_message_filter, + NULL, NULL)) + return FALSE; + + return TRUE; +} + +void +bus_dispatch_remove_connection (DBusConnection *connection) +{ + /* Here we tell the bus driver that we want to get off. */ + bus_driver_remove_connection (connection); + + dbus_connection_remove_filter (connection, + bus_dispatch_message_filter, + NULL); +} + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + +#include <stdio.h> + +#include "stats.h" + +/* This is used to know whether we need to block in order to finish + * sending a message, or whether the initial dbus_connection_send() + * already flushed the queue. + */ +#define SEND_PENDING(connection) (dbus_connection_has_messages_to_send (connection)) + +typedef dbus_bool_t (* Check1Func) (BusContext *context); +typedef dbus_bool_t (* Check2Func) (BusContext *context, + DBusConnection *connection); + +static dbus_bool_t check_no_leftovers (BusContext *context); + +static void +block_connection_until_message_from_bus (BusContext *context, + DBusConnection *connection, + const char *what_is_expected) +{ + _dbus_verbose ("expecting: %s\n", what_is_expected); + + while (dbus_connection_get_dispatch_status (connection) == + DBUS_DISPATCH_COMPLETE && + dbus_connection_get_is_connected (connection)) + { + bus_test_run_bus_loop (context, TRUE); + bus_test_run_clients_loop (FALSE); + } +} + +static void +spin_connection_until_authenticated (BusContext *context, + DBusConnection *connection) +{ + _dbus_verbose ("Spinning to auth connection %p\n", connection); + while (!dbus_connection_get_is_authenticated (connection) && + dbus_connection_get_is_connected (connection)) + { + bus_test_run_bus_loop (context, FALSE); + bus_test_run_clients_loop (FALSE); + } + _dbus_verbose (" ... done spinning to auth connection %p\n", connection); +} + +/* compensate for fact that pop_message() can return #NULL due to OOM */ +static DBusMessage* +pop_message_waiting_for_memory (DBusConnection *connection) +{ + while (dbus_connection_get_dispatch_status (connection) == + DBUS_DISPATCH_NEED_MEMORY) + _dbus_wait_for_memory (); + + return dbus_connection_pop_message (connection); +} + +static DBusMessage* +borrow_message_waiting_for_memory (DBusConnection *connection) +{ + while (dbus_connection_get_dispatch_status (connection) == + DBUS_DISPATCH_NEED_MEMORY) + _dbus_wait_for_memory (); + + return dbus_connection_borrow_message (connection); +} + +static void +warn_unexpected_real (DBusConnection *connection, + DBusMessage *message, + const char *expected, + const char *function, + int line) +{ + if (message) + _dbus_warn ("%s:%d received message interface \"%s\" member \"%s\" error name \"%s\" on %p, expecting %s\n", + function, line, + dbus_message_get_interface (message) ? + dbus_message_get_interface (message) : "(unset)", + dbus_message_get_member (message) ? + dbus_message_get_member (message) : "(unset)", + dbus_message_get_error_name (message) ? + dbus_message_get_error_name (message) : "(unset)", + connection, + expected); + else + _dbus_warn ("%s:%d received no message on %p, expecting %s\n", + function, line, connection, expected); +} + +#define warn_unexpected(connection, message, expected) \ + warn_unexpected_real (connection, message, expected, _DBUS_FUNCTION_NAME, __LINE__) + +static void +verbose_message_received (DBusConnection *connection, + DBusMessage *message) +{ + _dbus_verbose ("Received message interface \"%s\" member \"%s\" error name \"%s\" on %p\n", + dbus_message_get_interface (message) ? + dbus_message_get_interface (message) : "(unset)", + dbus_message_get_member (message) ? + dbus_message_get_member (message) : "(unset)", + dbus_message_get_error_name (message) ? + dbus_message_get_error_name (message) : "(unset)", + connection); +} + +typedef enum +{ + SERVICE_CREATED, + OWNER_CHANGED, + SERVICE_DELETED +} ServiceInfoKind; + +typedef struct +{ + ServiceInfoKind expected_kind; + const char *expected_service_name; + dbus_bool_t failed; + DBusConnection *skip_connection; + BusContext *context; +} CheckServiceOwnerChangedData; + +static dbus_bool_t +check_service_owner_changed_foreach (DBusConnection *connection, + void *data) +{ + CheckServiceOwnerChangedData *d = data; + DBusMessage *message; + DBusError error; + const char *service_name, *old_owner, *new_owner; + + if (d->expected_kind == SERVICE_CREATED + && connection == d->skip_connection) + return TRUE; + + dbus_error_init (&error); + d->failed = TRUE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + block_connection_until_message_from_bus (d->context, connection, "NameOwnerChanged"); + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a message on %p, expecting %s\n", + connection, "NameOwnerChanged"); + goto out; + } + } + else if (!dbus_message_is_signal (message, + DBUS_INTERFACE_DBUS, + "NameOwnerChanged")) + { + warn_unexpected (connection, message, "NameOwnerChanged"); + + goto out; + } + else + { + reget_service_info_data: + service_name = NULL; + old_owner = NULL; + new_owner = NULL; + + dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &service_name, + DBUS_TYPE_STRING, &old_owner, + DBUS_TYPE_STRING, &new_owner, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set (&error)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + dbus_error_free (&error); + _dbus_wait_for_memory (); + goto reget_service_info_data; + } + else + { + _dbus_warn ("Did not get the expected arguments\n"); + goto out; + } + } + + if ((d->expected_kind == SERVICE_CREATED && ( old_owner[0] || !new_owner[0])) + || (d->expected_kind == OWNER_CHANGED && (!old_owner[0] || !new_owner[0])) + || (d->expected_kind == SERVICE_DELETED && (!old_owner[0] || new_owner[0]))) + { + _dbus_warn ("inconsistent NameOwnerChanged arguments\n"); + goto out; + } + + if (strcmp (service_name, d->expected_service_name) != 0) + { + _dbus_warn ("expected info on service %s, got info on %s\n", + d->expected_service_name, + service_name); + goto out; + } + + if (*service_name == ':' && new_owner[0] + && strcmp (service_name, new_owner) != 0) + { + _dbus_warn ("inconsistent ServiceOwnedChanged message (\"%s\" [ %s -> %s ])\n", + service_name, old_owner, new_owner); + goto out; + } + } + + d->failed = FALSE; + + out: + dbus_error_free (&error); + + if (message) + dbus_message_unref (message); + + return !d->failed; +} + + +static void +kill_client_connection (BusContext *context, + DBusConnection *connection) +{ + char *base_service; + const char *s; + CheckServiceOwnerChangedData socd; + + _dbus_verbose ("killing connection %p\n", connection); + + s = dbus_bus_get_unique_name (connection); + _dbus_assert (s != NULL); + + while ((base_service = _dbus_strdup (s)) == NULL) + _dbus_wait_for_memory (); + + dbus_connection_ref (connection); + + /* kick in the disconnect handler that unrefs the connection */ + dbus_connection_close (connection); + + bus_test_run_everything (context); + + _dbus_assert (bus_test_client_listed (connection)); + + /* Run disconnect handler in test.c */ + if (bus_connection_dispatch_one_message (connection)) + _dbus_assert_not_reached ("something received on connection being killed other than the disconnect"); + + _dbus_assert (!dbus_connection_get_is_connected (connection)); + dbus_connection_unref (connection); + connection = NULL; + _dbus_assert (!bus_test_client_listed (connection)); + + socd.expected_kind = SERVICE_DELETED; + socd.expected_service_name = base_service; + socd.failed = FALSE; + socd.skip_connection = NULL; + socd.context = context; + + bus_test_clients_foreach (check_service_owner_changed_foreach, + &socd); + + dbus_free (base_service); + + if (socd.failed) + _dbus_assert_not_reached ("didn't get the expected NameOwnerChanged (deletion) messages"); + + if (!check_no_leftovers (context)) + _dbus_assert_not_reached ("stuff left in message queues after disconnecting a client"); +} + +static void +kill_client_connection_unchecked (DBusConnection *connection) +{ + /* This kills the connection without expecting it to affect + * the rest of the bus. + */ + _dbus_verbose ("Unchecked kill of connection %p\n", connection); + + dbus_connection_ref (connection); + dbus_connection_close (connection); + /* dispatching disconnect handler will unref once */ + if (bus_connection_dispatch_one_message (connection)) + _dbus_assert_not_reached ("message other than disconnect dispatched after failure to register"); + + _dbus_assert (!bus_test_client_listed (connection)); + dbus_connection_unref (connection); +} + +typedef struct +{ + dbus_bool_t failed; +} CheckNoMessagesData; + +static dbus_bool_t +check_no_messages_foreach (DBusConnection *connection, + void *data) +{ + CheckNoMessagesData *d = data; + DBusMessage *message; + + message = pop_message_waiting_for_memory (connection); + if (message != NULL) + { + warn_unexpected (connection, message, "no messages"); + + d->failed = TRUE; + } + + if (message) + dbus_message_unref (message); + return !d->failed; +} + +static dbus_bool_t +check_no_leftovers (BusContext *context) +{ + CheckNoMessagesData nmd; + + nmd.failed = FALSE; + bus_test_clients_foreach (check_no_messages_foreach, + &nmd); + + if (nmd.failed) + { + _dbus_verbose ("leftover message found\n"); + return FALSE; + } + else + return TRUE; +} + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_hello_message (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + DBusMessage *name_message; + dbus_uint32_t serial; + dbus_bool_t retval; + DBusError error; + const char *name; + const char *acquired; + + retval = FALSE; + dbus_error_init (&error); + name = NULL; + acquired = NULL; + message = NULL; + name_message = NULL; + + _dbus_verbose ("check_hello_message for %p\n", connection); + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "Hello"); + + if (message == NULL) + return TRUE; + + dbus_connection_ref (connection); /* because we may get disconnected */ + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + dbus_connection_unref (connection); + return TRUE; + } + + _dbus_assert (dbus_message_has_signature (message, "")); + + dbus_message_unref (message); + message = NULL; + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected (presumably auth failed)\n"); + + dbus_connection_unref (connection); + + return TRUE; + } + + /* send our message */ + bus_test_run_clients_loop (SEND_PENDING (connection)); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected (presumably auth failed)\n"); + + dbus_connection_unref (connection); + + return TRUE; + } + + block_connection_until_message_from_bus (context, connection, "reply to Hello"); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected (presumably auth failed)\n"); + + dbus_connection_unref (connection); + + return TRUE; + } + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "Hello", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + CheckServiceOwnerChangedData socd; + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN) + { + ; /* good, expected */ + } + else + { + warn_unexpected (connection, message, "method return for Hello"); + + goto out; + } + + retry_get_hello_name: + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + _dbus_verbose ("no memory to get service name arg from hello\n"); + dbus_error_free (&error); + _dbus_wait_for_memory (); + goto retry_get_hello_name; + } + else + { + _dbus_assert (dbus_error_is_set (&error)); + _dbus_warn ("Did not get the expected single string argument to hello\n"); + goto out; + } + } + + _dbus_verbose ("Got hello name: %s\n", name); + + while (!dbus_bus_set_unique_name (connection, name)) + _dbus_wait_for_memory (); + + socd.expected_kind = SERVICE_CREATED; + socd.expected_service_name = name; + socd.failed = FALSE; + socd.skip_connection = connection; /* we haven't done AddMatch so won't get it ourselves */ + socd.context = context; + + bus_test_clients_foreach (check_service_owner_changed_foreach, + &socd); + + if (socd.failed) + goto out; + + name_message = message; + /* Client should also have gotten ServiceAcquired */ + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + block_connection_until_message_from_bus (context, connection, "signal NameAcquired"); + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Expecting %s, got nothing\n", + "NameAcquired"); + goto out; + } + } + if (! dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, + "NameAcquired")) + { + _dbus_warn ("Expecting %s, got smthg else\n", + "NameAcquired"); + goto out; + } + + retry_get_acquired_name: + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &acquired, + DBUS_TYPE_INVALID)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + _dbus_verbose ("no memory to get service name arg from acquired\n"); + dbus_error_free (&error); + _dbus_wait_for_memory (); + goto retry_get_acquired_name; + } + else + { + _dbus_assert (dbus_error_is_set (&error)); + _dbus_warn ("Did not get the expected single string argument to ServiceAcquired\n"); + goto out; + } + } + + _dbus_verbose ("Got acquired name: %s\n", acquired); + + if (strcmp (acquired, name) != 0) + { + _dbus_warn ("Acquired name is %s but expected %s\n", + acquired, name); + goto out; + } + acquired = NULL; + } + + if (!check_no_leftovers (context)) + goto out; + + retval = TRUE; + + out: + _dbus_verbose ("ending - retval = %d\n", retval); + + dbus_error_free (&error); + + if (message) + dbus_message_unref (message); + + if (name_message) + dbus_message_unref (name_message); + + dbus_connection_unref (connection); + + return retval; +} + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_double_hello_message (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + DBusError error; + + retval = FALSE; + dbus_error_init (&error); + message = NULL; + + _dbus_verbose ("check_double_hello_message for %p\n", connection); + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "Hello"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + /* send our message */ + bus_test_run_clients_loop (SEND_PENDING (connection)); + + dbus_connection_ref (connection); /* because we may get disconnected */ + block_connection_until_message_from_bus (context, connection, "reply to Hello"); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + + dbus_connection_unref (connection); + + return TRUE; + } + + dbus_connection_unref (connection); + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "Hello", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_ERROR) + { + warn_unexpected (connection, message, "method return for Hello"); + goto out; + } + + if (!check_no_leftovers (context)) + goto out; + + retval = TRUE; + + out: + dbus_error_free (&error); + + if (message) + dbus_message_unref (message); + + return retval; +} + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_get_connection_unix_user (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + DBusError error; + const char *base_service_name; + dbus_uint32_t uid; + + retval = FALSE; + dbus_error_init (&error); + message = NULL; + + _dbus_verbose ("check_get_connection_unix_user for %p\n", connection); + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "GetConnectionUnixUser"); + + if (message == NULL) + return TRUE; + + base_service_name = dbus_bus_get_unique_name (connection); + + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &base_service_name, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + return TRUE; + } + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + /* send our message */ + bus_test_run_clients_loop (SEND_PENDING (connection)); + + dbus_message_unref (message); + message = NULL; + + dbus_connection_ref (connection); /* because we may get disconnected */ + block_connection_until_message_from_bus (context, connection, "reply to GetConnectionUnixUser"); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + + dbus_connection_unref (connection); + + return TRUE; + } + + dbus_connection_unref (connection); + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "GetConnectionUnixUser", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } +#ifdef DBUS_WIN + else if (dbus_message_is_error (message, DBUS_ERROR_FAILED)) + { + /* this is OK, Unix uids aren't meaningful on Windows */ + } +#endif + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN) + { + ; /* good, expected */ + } + else + { + warn_unexpected (connection, message, + "method_return for GetConnectionUnixUser"); + + goto out; + } + + retry_get_property: + + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_UINT32, &uid, + DBUS_TYPE_INVALID)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + _dbus_verbose ("no memory to get uid by GetConnectionUnixUser\n"); + dbus_error_free (&error); + _dbus_wait_for_memory (); + goto retry_get_property; + } + else + { + _dbus_assert (dbus_error_is_set (&error)); + _dbus_warn ("Did not get the expected DBUS_TYPE_UINT32 from GetConnectionUnixUser\n"); + goto out; + } + } + } + + if (!check_no_leftovers (context)) + goto out; + + retval = TRUE; + + out: + dbus_error_free (&error); + + if (message) + dbus_message_unref (message); + + return retval; +} + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_get_connection_unix_process_id (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + DBusError error; + const char *base_service_name; +#ifdef DBUS_UNIX + dbus_uint32_t pid; +#endif + + retval = FALSE; + dbus_error_init (&error); + message = NULL; + + _dbus_verbose ("check_get_connection_unix_process_id for %p\n", connection); + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "GetConnectionUnixProcessID"); + + if (message == NULL) + return TRUE; + + base_service_name = dbus_bus_get_unique_name (connection); + + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &base_service_name, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + return TRUE; + } + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + /* send our message */ + bus_test_run_clients_loop (SEND_PENDING (connection)); + + dbus_message_unref (message); + message = NULL; + + dbus_connection_ref (connection); /* because we may get disconnected */ + block_connection_until_message_from_bus (context, connection, "reply to GetConnectionUnixProcessID"); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + + dbus_connection_unref (connection); + + return TRUE; + } + + dbus_connection_unref (connection); + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "GetConnectionUnixProcessID", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } +#ifdef DBUS_WIN + else if (dbus_message_is_error (message, DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN)) + { + /* We are expecting this error, since we know in the test suite we aren't + * talking to a client running on UNIX + */ + _dbus_verbose ("Windows correctly does not support GetConnectionUnixProcessID\n"); + } +#endif + else + { +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__linux__) || \ + defined(__OpenBSD__) + /* In principle NetBSD should also be in that list, but + * its implementation of PID-passing doesn't work + * over a socketpair() as used in the debug-pipe transport. + * We test this functionality in a more realistic situation + * in test/dbus-daemon.c. */ + warn_unexpected (connection, message, "not this error"); + + goto out; +#else + _dbus_verbose ("does not support GetConnectionUnixProcessID but perhaps that's OK?\n"); +#endif + } + } + else + { +#ifdef DBUS_WIN + warn_unexpected (connection, message, "GetConnectionUnixProcessID to fail on Windows"); + goto out; +#else + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN) + { + ; /* good, expected */ + } + else + { + warn_unexpected (connection, message, + "method_return for GetConnectionUnixProcessID"); + + goto out; + } + + retry_get_property: + + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_UINT32, &pid, + DBUS_TYPE_INVALID)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + _dbus_verbose ("no memory to get pid by GetConnectionUnixProcessID\n"); + dbus_error_free (&error); + _dbus_wait_for_memory (); + goto retry_get_property; + } + else + { + _dbus_assert (dbus_error_is_set (&error)); + _dbus_warn ("Did not get the expected DBUS_TYPE_UINT32 from GetConnectionUnixProcessID\n"); + goto out; + } + } + else + { + /* test if returned pid is the same as our own pid + * + * @todo It would probably be good to restructure the tests + * in a way so our parent is the bus that we're testing + * cause then we can test that the pid returned matches + * getppid() + */ + if (pid != (dbus_uint32_t) _dbus_getpid ()) + { + _dbus_assert (dbus_error_is_set (&error)); + _dbus_warn ("Result from GetConnectionUnixProcessID is not our own pid\n"); + goto out; + } + } +#endif /* !DBUS_WIN */ + } + + if (!check_no_leftovers (context)) + goto out; + + retval = TRUE; + + out: + dbus_error_free (&error); + + if (message) + dbus_message_unref (message); + + return retval; +} + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_add_match (BusContext *context, + DBusConnection *connection, + const char *rule) +{ + DBusMessage *message; + dbus_bool_t retval; + dbus_uint32_t serial; + DBusError error; + + retval = FALSE; + dbus_error_init (&error); + message = NULL; + + _dbus_verbose ("check_add_match for connection %p, rule %s\n", + connection, rule); + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "AddMatch"); + + if (message == NULL) + return TRUE; + + if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &rule, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + return TRUE; + } + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + dbus_connection_ref (connection); /* because we may get disconnected */ + + /* send our message */ + bus_test_run_clients_loop (SEND_PENDING (connection)); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + + dbus_connection_unref (connection); + + return TRUE; + } + + block_connection_until_message_from_bus (context, connection, "reply to AddMatch"); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + + dbus_connection_unref (connection); + + return TRUE; + } + + dbus_connection_unref (connection); + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "AddMatch", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN) + { + ; /* good, expected */ + _dbus_assert (dbus_message_get_reply_serial (message) == serial); + } + else + { + warn_unexpected (connection, message, "method return for AddMatch"); + + goto out; + } + } + + if (!check_no_leftovers (context)) + goto out; + + retval = TRUE; + + out: + dbus_error_free (&error); + + if (message) + dbus_message_unref (message); + + return retval; +} + +#ifdef DBUS_ENABLE_STATS +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_get_all_match_rules (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_bool_t retval; + dbus_uint32_t serial; + DBusError error; + + retval = FALSE; + dbus_error_init (&error); + message = NULL; + + _dbus_verbose ("check_get_all_match_rules for connection %p\n", + connection); + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + BUS_INTERFACE_STATS, + "GetAllMatchRules"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + dbus_connection_ref (connection); /* because we may get disconnected */ + + /* send our message */ + bus_test_run_clients_loop (SEND_PENDING (connection)); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + + dbus_connection_unref (connection); + + return TRUE; + } + + block_connection_until_message_from_bus (context, connection, "reply to AddMatch"); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + + dbus_connection_unref (connection); + + return TRUE; + } + + dbus_connection_unref (connection); + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "AddMatch", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN) + { + ; /* good, expected */ + _dbus_assert (dbus_message_get_reply_serial (message) == serial); + } + else + { + warn_unexpected (connection, message, "method return for AddMatch"); + + goto out; + } + } + + if (!check_no_leftovers (context)) + goto out; + + retval = TRUE; + + out: + dbus_error_free (&error); + + if (message) + dbus_message_unref (message); + + return retval; +} +#endif + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_hello_connection (BusContext *context) +{ + DBusConnection *connection; + DBusError error; + + dbus_error_init (&error); + + connection = dbus_connection_open_private (TEST_DEBUG_PIPE, &error); + if (connection == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + dbus_error_free (&error); + return TRUE; + } + + if (!bus_setup_debug_client (connection)) + { + dbus_connection_close (connection); + dbus_connection_unref (connection); + return TRUE; + } + + spin_connection_until_authenticated (context, connection); + + if (!check_hello_message (context, connection)) + return FALSE; + + if (dbus_bus_get_unique_name (connection) == NULL) + { + /* We didn't successfully register, so we can't + * do the usual kill_client_connection() checks + */ + kill_client_connection_unchecked (connection); + } + else + { + if (!check_add_match (context, connection, "")) + return FALSE; + + kill_client_connection (context, connection); + } + + return TRUE; +} + +#define NONEXISTENT_SERVICE_NAME "test.this.service.does.not.exist.ewuoiurjdfxcvn" + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_nonexistent_service_no_auto_start (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + const char *nonexistent = NONEXISTENT_SERVICE_NAME; + dbus_uint32_t flags; + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "StartServiceByName"); + + if (message == NULL) + return TRUE; + + dbus_message_set_auto_start (message, FALSE); + + flags = 0; + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &nonexistent, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + return TRUE; + } + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + block_connection_until_message_from_bus (context, connection, "reply to ActivateService on nonexistent"); + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "StartServiceByName", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_SERVICE_UNKNOWN)) + { + ; /* good, this is expected also */ + } + else + { + warn_unexpected (connection, message, "not this error"); + goto out; + } + } + else + { + _dbus_warn ("Did not expect to successfully activate %s\n", + NONEXISTENT_SERVICE_NAME); + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_nonexistent_service_auto_start (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + + message = dbus_message_new_method_call (NONEXISTENT_SERVICE_NAME, + "/org/freedesktop/TestSuite", + "org.freedesktop.TestSuite", + "Echo"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + block_connection_until_message_from_bus (context, connection, "reply to Echo"); + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "Echo message (auto activation)", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_SERVICE_UNKNOWN)) + { + ; /* good, this is expected also */ + } + else + { + warn_unexpected (connection, message, "not this error"); + goto out; + } + } + else + { + _dbus_warn ("Did not expect to successfully activate %s\n", + NONEXISTENT_SERVICE_NAME); + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + +static dbus_bool_t +check_base_service_activated (BusContext *context, + DBusConnection *connection, + DBusMessage *initial_message, + const char **base_service_p) +{ + DBusMessage *message; + dbus_bool_t retval; + DBusError error; + const char *base_service, *base_service_from_bus, *old_owner; + + retval = FALSE; + + dbus_error_init (&error); + base_service = NULL; + old_owner = NULL; + base_service_from_bus = NULL; + + message = initial_message; + dbus_message_ref (message); + + if (dbus_message_is_signal (message, + DBUS_INTERFACE_DBUS, + "NameOwnerChanged")) + { + CheckServiceOwnerChangedData socd; + + reget_service_name_arg: + base_service = NULL; + old_owner = NULL; + base_service_from_bus = NULL; + + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &base_service, + DBUS_TYPE_STRING, &old_owner, + DBUS_TYPE_STRING, &base_service_from_bus, + DBUS_TYPE_INVALID)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + dbus_error_free (&error); + _dbus_wait_for_memory (); + goto reget_service_name_arg; + } + else + { + _dbus_warn ("Message %s doesn't have a service name: %s\n", + "NameOwnerChanged (creation)", + error.message); + goto out; + } + } + + if (*base_service != ':') + { + _dbus_warn ("Expected base service activation, got \"%s\" instead\n", + base_service); + goto out; + } + + if (strcmp (base_service, base_service_from_bus) != 0) + { + _dbus_warn ("Expected base service activation, got \"%s\" instead with owner \"%s\"\n", + base_service, base_service_from_bus); + goto out; + } + + if (old_owner[0]) + { + _dbus_warn ("Received an old_owner argument during base service activation, \"%s\"\n", + old_owner); + goto out; + } + + socd.expected_kind = SERVICE_CREATED; + socd.expected_service_name = base_service; + socd.failed = FALSE; + socd.skip_connection = connection; + socd.context = context; + + bus_test_clients_foreach (check_service_owner_changed_foreach, + &socd); + + if (socd.failed) + goto out; + } + else + { + warn_unexpected (connection, message, "NameOwnerChanged (creation) for base service"); + + goto out; + } + + if (base_service_p) + *base_service_p = base_service; + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + dbus_error_free (&error); + + return retval; +} + +static dbus_bool_t +check_service_activated (BusContext *context, + DBusConnection *connection, + const char *activated_name, + const char *base_service_name, + DBusMessage *initial_message) +{ + DBusMessage *message; + dbus_bool_t retval; + DBusError error; + dbus_uint32_t activation_result; + + retval = FALSE; + + dbus_error_init (&error); + + message = initial_message; + dbus_message_ref (message); + + if (dbus_message_is_signal (message, + DBUS_INTERFACE_DBUS, + "NameOwnerChanged")) + { + CheckServiceOwnerChangedData socd; + const char *service_name, *base_service_from_bus, *old_owner; + + reget_service_name_arg: + service_name = NULL; + old_owner = NULL; + base_service_from_bus = NULL; + + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &service_name, + DBUS_TYPE_STRING, &old_owner, + DBUS_TYPE_STRING, &base_service_from_bus, + DBUS_TYPE_INVALID)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + dbus_error_free (&error); + _dbus_wait_for_memory (); + goto reget_service_name_arg; + } + else + { + _dbus_warn ("Message %s doesn't have a service name: %s\n", + "NameOwnerChanged (creation)", + error.message); + goto out; + } + } + + if (strcmp (service_name, activated_name) != 0) + { + _dbus_warn ("Expected to see service %s created, saw %s instead\n", + activated_name, service_name); + goto out; + } + + if (strcmp (base_service_name, base_service_from_bus) != 0) + { + _dbus_warn ("NameOwnerChanged reports wrong base service: %s owner, expected %s instead\n", + base_service_from_bus, base_service_name); + goto out; + } + + if (old_owner[0]) + { + _dbus_warn ("expected a %s, got a %s\n", + "NameOwnerChanged (creation)", + "NameOwnerChanged (change)"); + goto out; + } + + socd.expected_kind = SERVICE_CREATED; + socd.skip_connection = connection; + socd.failed = FALSE; + socd.expected_service_name = service_name; + socd.context = context; + + bus_test_clients_foreach (check_service_owner_changed_foreach, + &socd); + + if (socd.failed) + goto out; + + dbus_message_unref (message); + service_name = NULL; + old_owner = NULL; + base_service_from_bus = NULL; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Expected a reply to %s, got nothing\n", + "StartServiceByName"); + goto out; + } + } + else + { + warn_unexpected (connection, message, "NameOwnerChanged for the activated name"); + + goto out; + } + + if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_RETURN) + { + warn_unexpected (connection, message, "reply to StartServiceByName"); + + goto out; + } + + activation_result = 0; + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_UINT32, &activation_result, + DBUS_TYPE_INVALID)) + { + if (!dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + _dbus_warn ("Did not have activation result first argument to %s: %s\n", + "StartServiceByName", error.message); + goto out; + } + + dbus_error_free (&error); + } + else + { + if (activation_result == DBUS_START_REPLY_SUCCESS) + ; /* Good */ + else if (activation_result == DBUS_START_REPLY_ALREADY_RUNNING) + ; /* Good also */ + else + { + _dbus_warn ("Activation result was %u, no good.\n", + activation_result); + goto out; + } + } + + dbus_message_unref (message); + message = NULL; + + if (!check_no_leftovers (context)) + { + _dbus_warn ("Messages were left over after verifying existent activation results\n"); + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + dbus_error_free (&error); + + return retval; +} + +static dbus_bool_t +check_service_auto_activated (BusContext *context, + DBusConnection *connection, + const char *activated_name, + const char *base_service_name, + DBusMessage *initial_message) +{ + DBusMessage *message; + dbus_bool_t retval; + DBusError error; + + retval = FALSE; + + dbus_error_init (&error); + + message = initial_message; + dbus_message_ref (message); + + if (dbus_message_is_signal (message, + DBUS_INTERFACE_DBUS, + "NameOwnerChanged")) + { + const char *service_name; + CheckServiceOwnerChangedData socd; + + reget_service_name_arg: + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &service_name, + DBUS_TYPE_INVALID)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + dbus_error_free (&error); + _dbus_wait_for_memory (); + goto reget_service_name_arg; + } + else + { + _dbus_warn ("Message %s doesn't have a service name: %s\n", + "NameOwnerChanged", + error.message); + dbus_error_free (&error); + goto out; + } + } + + if (strcmp (service_name, activated_name) != 0) + { + _dbus_warn ("Expected to see service %s created, saw %s instead\n", + activated_name, service_name); + goto out; + } + + socd.expected_kind = SERVICE_CREATED; + socd.expected_service_name = service_name; + socd.failed = FALSE; + socd.skip_connection = connection; + socd.context = context; + + bus_test_clients_foreach (check_service_owner_changed_foreach, + &socd); + + if (socd.failed) + goto out; + + /* Note that this differs from regular activation in that we don't get a + * reply to ActivateService here. + */ + + dbus_message_unref (message); + message = NULL; + service_name = NULL; + } + else + { + warn_unexpected (connection, message, "NameOwnerChanged for the activated name"); + + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + +static dbus_bool_t +check_service_deactivated (BusContext *context, + DBusConnection *connection, + const char *activated_name, + const char *base_service) +{ + dbus_bool_t retval; + CheckServiceOwnerChangedData socd; + + retval = FALSE; + + /* Now we are expecting ServiceOwnerChanged (deletion) messages for the base + * service and the activated_name. The base service + * notification is required to come last. + */ + socd.expected_kind = SERVICE_DELETED; + socd.expected_service_name = activated_name; + socd.failed = FALSE; + socd.skip_connection = NULL; + socd.context = context; + + bus_test_clients_foreach (check_service_owner_changed_foreach, + &socd); + + if (socd.failed) + goto out; + + socd.expected_kind = SERVICE_DELETED; + socd.expected_service_name = base_service; + socd.failed = FALSE; + socd.skip_connection = NULL; + socd.context = context; + + bus_test_clients_foreach (check_service_owner_changed_foreach, + &socd); + + if (socd.failed) + goto out; + + retval = TRUE; + + out: + return retval; +} + +static dbus_bool_t +check_send_exit_to_service (BusContext *context, + DBusConnection *connection, + const char *service_name, + const char *base_service) +{ + dbus_bool_t got_error; + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + + _dbus_verbose ("Sending exit message to the test service\n"); + + retval = FALSE; + + /* Kill off the test service by sending it a quit message */ + message = dbus_message_new_method_call (service_name, + "/org/freedesktop/TestSuite", + "org.freedesktop.TestSuite", + "Exit"); + + if (message == NULL) + { + /* Do this again; we still need the service to exit... */ + if (!check_send_exit_to_service (context, connection, + service_name, base_service)) + goto out; + + return TRUE; + } + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + + /* Do this again; we still need the service to exit... */ + if (!check_send_exit_to_service (context, connection, + service_name, base_service)) + goto out; + + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + /* send message */ + bus_test_run_clients_loop (SEND_PENDING (connection)); + + /* read it in and write it out to test service */ + bus_test_run_bus_loop (context, FALSE); + + /* see if we got an error during message bus dispatching */ + bus_test_run_clients_loop (FALSE); + message = borrow_message_waiting_for_memory (connection); + got_error = message != NULL && dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR; + if (message) + { + dbus_connection_return_message (connection, message); + message = NULL; + } + + if (!got_error) + { + /* If no error, wait for the test service to exit */ + block_connection_until_message_from_bus (context, connection, "test service to exit"); + + bus_test_run_everything (context); + } + + if (got_error) + { + message = pop_message_waiting_for_memory (connection); + _dbus_assert (message != NULL); + + if (dbus_message_get_reply_serial (message) != serial) + { + warn_unexpected (connection, message, + "error with the correct reply serial"); + goto out; + } + + if (!dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + warn_unexpected (connection, message, + "a no memory error from asking test service to exit"); + goto out; + } + + _dbus_verbose ("Got error %s when asking test service to exit\n", + dbus_message_get_error_name (message)); + + /* Do this again; we still need the service to exit... */ + if (!check_send_exit_to_service (context, connection, + service_name, base_service)) + goto out; + } + else + { + if (!check_service_deactivated (context, connection, + service_name, base_service)) + goto out; + + /* Should now have a NoReply error from the Exit() method + * call; it should have come after all the deactivation + * stuff. + */ + message = pop_message_waiting_for_memory (connection); + + if (message == NULL) + { + warn_unexpected (connection, NULL, + "reply to Exit() method call"); + goto out; + } + if (!dbus_message_is_error (message, + DBUS_ERROR_NO_REPLY)) + { + warn_unexpected (connection, message, + "NoReply error from Exit() method call"); + goto out; + } + + if (dbus_message_get_reply_serial (message) != serial) + { + warn_unexpected (connection, message, + "error with the correct reply serial"); + goto out; + } + + _dbus_verbose ("Got error %s after test service exited\n", + dbus_message_get_error_name (message)); + + if (!check_no_leftovers (context)) + { + _dbus_warn ("Messages were left over after %s\n", + _DBUS_FUNCTION_NAME); + goto out; + } + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + +static dbus_bool_t +check_got_error (BusContext *context, + DBusConnection *connection, + const char *first_error_name, + ...) +{ + DBusMessage *message; + dbus_bool_t retval; + va_list ap; + dbus_bool_t error_found; + const char *error_name; + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not get an expected error\n"); + goto out; + } + + if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_ERROR) + { + warn_unexpected (connection, message, "an error"); + + goto out; + } + + error_found = FALSE; + + va_start (ap, first_error_name); + error_name = first_error_name; + while (error_name != NULL) + { + if (dbus_message_is_error (message, error_name)) + { + error_found = TRUE; + break; + } + error_name = va_arg (ap, char*); + } + va_end (ap); + + if (!error_found) + { + _dbus_warn ("Expected error %s or other, got %s instead\n", + first_error_name, + dbus_message_get_error_name (message)); + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + +typedef enum +{ + GOT_SERVICE_CREATED, + GOT_SERVICE_DELETED, + GOT_ERROR, + GOT_SOMETHING_ELSE +} GotServiceInfo; + +static GotServiceInfo +check_got_service_info (DBusMessage *message) +{ + GotServiceInfo message_kind; + + if (dbus_message_is_signal (message, + DBUS_INTERFACE_DBUS, + "NameOwnerChanged")) + { + DBusError error; + const char *service_name, *old_owner, *new_owner; + dbus_error_init (&error); + + reget_service_info_data: + service_name = NULL; + old_owner = NULL; + new_owner = NULL; + + dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &service_name, + DBUS_TYPE_STRING, &old_owner, + DBUS_TYPE_STRING, &new_owner, + DBUS_TYPE_INVALID); + if (dbus_error_is_set (&error)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + dbus_error_free (&error); + goto reget_service_info_data; + } + else + { + _dbus_warn ("unexpected arguments for NameOwnerChanged message\n"); + message_kind = GOT_SOMETHING_ELSE; + } + } + else if (!old_owner[0]) + message_kind = GOT_SERVICE_CREATED; + else if (!new_owner[0]) + message_kind = GOT_SERVICE_DELETED; + else + message_kind = GOT_SOMETHING_ELSE; + + dbus_error_free (&error); + } + else if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + message_kind = GOT_ERROR; + else + message_kind = GOT_SOMETHING_ELSE; + + return message_kind; +} + +#define EXISTENT_SERVICE_NAME "org.freedesktop.DBus.TestSuiteEchoService" + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_existent_service_no_auto_start (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + DBusMessage *base_service_message; + const char *base_service; + dbus_uint32_t serial; + dbus_bool_t retval; + const char *existent = EXISTENT_SERVICE_NAME; + dbus_uint32_t flags; + + base_service_message = NULL; + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "StartServiceByName"); + + if (message == NULL) + return TRUE; + + dbus_message_set_auto_start (message, FALSE); + + flags = 0; + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &existent, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + return TRUE; + } + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + + /* now wait for the message bus to hear back from the activated + * service. + */ + block_connection_until_message_from_bus (context, connection, "activated service to connect"); + + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive any messages after %s %d on %p\n", + "StartServiceByName", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + _dbus_verbose (" (after sending %s)\n", "StartServiceByName"); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_SPAWN_CHILD_EXITED) || + dbus_message_is_error (message, + DBUS_ERROR_SPAWN_CHILD_SIGNALED) || + dbus_message_is_error (message, + DBUS_ERROR_SPAWN_EXEC_FAILED)) + { + ; /* good, this is expected also */ + } + else + { + _dbus_warn ("Did not expect error %s\n", + dbus_message_get_error_name (message)); + goto out; + } + } + else + { + GotServiceInfo message_kind; + + if (!check_base_service_activated (context, connection, + message, &base_service)) + goto out; + + base_service_message = message; + message = NULL; + + /* We may need to block here for the test service to exit or finish up */ + block_connection_until_message_from_bus (context, connection, "test service to exit or finish up"); + + message = dbus_connection_borrow_message (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive any messages after base service creation notification\n"); + goto out; + } + + message_kind = check_got_service_info (message); + + dbus_connection_return_message (connection, message); + message = NULL; + + switch (message_kind) + { + case GOT_SOMETHING_ELSE: + _dbus_warn ("Unexpected message after ActivateService " + "(should be an error or a service announcement"); + goto out; + + case GOT_ERROR: + if (!check_got_error (context, connection, + DBUS_ERROR_SPAWN_CHILD_EXITED, + DBUS_ERROR_NO_MEMORY, + NULL)) + goto out; + /* A service deleted should be coming along now after this error. + * We can also get the error *after* the service deleted. + */ + + /* fall through */ + + case GOT_SERVICE_DELETED: + { + /* The service started up and got a base address, but then + * failed to register under EXISTENT_SERVICE_NAME + */ + CheckServiceOwnerChangedData socd; + + socd.expected_kind = SERVICE_DELETED; + socd.expected_service_name = base_service; + socd.failed = FALSE; + socd.skip_connection = NULL; + socd.context = context; + + bus_test_clients_foreach (check_service_owner_changed_foreach, + &socd); + + if (socd.failed) + goto out; + + /* Now we should get an error about the service exiting + * if we didn't get it before. + */ + if (message_kind != GOT_ERROR) + { + block_connection_until_message_from_bus (context, connection, "error about service exiting"); + + /* and process everything again */ + bus_test_run_everything (context); + + if (!check_got_error (context, connection, + DBUS_ERROR_SPAWN_CHILD_EXITED, + DBUS_ERROR_NO_MEMORY, + NULL)) + goto out; + } + break; + } + + case GOT_SERVICE_CREATED: + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Failed to pop message we just put back! " + "should have been a NameOwnerChanged (creation)\n"); + goto out; + } + + if (!check_service_activated (context, connection, EXISTENT_SERVICE_NAME, + base_service, message)) + goto out; + + dbus_message_unref (message); + message = NULL; + + if (!check_no_leftovers (context)) + { + _dbus_warn ("Messages were left over after successful activation\n"); + goto out; + } + + if (!check_send_exit_to_service (context, connection, + EXISTENT_SERVICE_NAME, base_service)) + goto out; + + break; + } + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + if (base_service_message) + dbus_message_unref (base_service_message); + + return retval; +} + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_segfault_service_no_auto_start (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + const char *segv_service; + dbus_uint32_t flags; + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "StartServiceByName"); + + if (message == NULL) + return TRUE; + + dbus_message_set_auto_start (message, FALSE); + + segv_service = "org.freedesktop.DBus.TestSuiteSegfaultService"; + flags = 0; + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &segv_service, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + return TRUE; + } + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + block_connection_until_message_from_bus (context, connection, "reply to activating segfault service"); + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "StartServiceByName", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_FAILED)) + { + const char *servicehelper; + servicehelper = bus_context_get_servicehelper (context); + /* make sure this only happens with the launch helper */ + _dbus_assert (servicehelper != NULL); + } +#ifdef DBUS_WIN + else if (dbus_message_is_error (message, + DBUS_ERROR_SPAWN_CHILD_EXITED)) + { + /* unhandled exceptions are normal exit codes */ + } +#else + else if (dbus_message_is_error (message, + DBUS_ERROR_SPAWN_CHILD_SIGNALED)) + { + ; /* good, this is expected also */ + } +#endif + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + _dbus_warn ("Did not expect to successfully activate segfault service\n"); + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_segfault_service_auto_start (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + + message = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteSegfaultService", + "/org/freedesktop/TestSuite", + "org.freedesktop.TestSuite", + "Echo"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + block_connection_until_message_from_bus (context, connection, "reply to Echo on segfault service"); + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "Echo message (auto activation)", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } +#ifdef DBUS_WIN + else if (dbus_message_is_error (message, + DBUS_ERROR_SPAWN_CHILD_EXITED)) + { + /* unhandled exceptions are normal exit codes */ + } +#else + else if (dbus_message_is_error (message, + DBUS_ERROR_SPAWN_CHILD_SIGNALED)) + { + ; /* good, this is expected also */ + } +#endif + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + _dbus_warn ("Did not expect to successfully activate segfault service\n"); + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + +#define TEST_ECHO_MESSAGE "Test echo message" +#define TEST_RUN_HELLO_FROM_SELF_MESSAGE "Test sending message to self" + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_existent_hello_from_self (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + const char *text; + + message = dbus_message_new_method_call (EXISTENT_SERVICE_NAME, + "/org/freedesktop/TestSuite", + "org.freedesktop.TestSuite", + "RunHelloFromSelf"); + + if (message == NULL) + return TRUE; + + text = TEST_RUN_HELLO_FROM_SELF_MESSAGE; + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &text, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + return TRUE; + } + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + + /* Note: if this test is run in OOM mode, it will block when the bus + * doesn't send a reply due to OOM. + */ + block_connection_until_message_from_bus (context, connection, "reply from running hello from self"); + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Failed to pop message! Should have been reply from RunHelloFromSelf message\n"); + return FALSE; + } + + if (dbus_message_get_reply_serial (message) != serial) + { + _dbus_warn ("Wrong reply serial\n"); + dbus_message_unref (message); + return FALSE; + } + + dbus_message_unref (message); + message = NULL; + + return TRUE; +} + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_existent_ping (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + message = dbus_message_new_method_call (EXISTENT_SERVICE_NAME, + "/org/freedesktop/TestSuite", + "org.freedesktop.DBus.Peer", + "Ping"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + + /* Note: if this test is run in OOM mode, it will block when the bus + * doesn't send a reply due to OOM. + */ + block_connection_until_message_from_bus (context, connection, "reply from running Ping"); + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Failed to pop message! Should have been reply from Ping message\n"); + return FALSE; + } + + if (dbus_message_get_reply_serial (message) != serial) + { + _dbus_warn ("Wrong reply serial\n"); + dbus_message_unref (message); + return FALSE; + } + + if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_RETURN) + { + _dbus_warn ("Unexpected message return during Ping\n"); + dbus_message_unref (message); + return FALSE; + } + + dbus_message_unref (message); + message = NULL; + + return TRUE; +} + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_existent_get_machine_id (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + const char *machine_id; + + message = dbus_message_new_method_call (EXISTENT_SERVICE_NAME, + "/org/freedesktop/TestSuite", + "org.freedesktop.DBus.Peer", + "GetMachineId"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + + /* Note: if this test is run in OOM mode, it will block when the bus + * doesn't send a reply due to OOM. + */ + block_connection_until_message_from_bus (context, connection, "reply from running GetMachineId"); + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Failed to pop message! Should have been reply from GetMachineId message\n"); + return FALSE; + } + + if (dbus_message_get_reply_serial (message) != serial) + { + _dbus_warn ("Wrong reply serial\n"); + dbus_message_unref (message); + return FALSE; + } + + if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_RETURN) + { + _dbus_warn ("Unexpected message return during GetMachineId\n"); + dbus_message_unref (message); + return FALSE; + } + + machine_id = NULL; + if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &machine_id, DBUS_TYPE_INVALID)) + { + _dbus_warn ("Did not get a machine ID in reply to GetMachineId\n"); + dbus_message_unref (message); + return FALSE; + } + + if (machine_id == NULL || strlen (machine_id) != 32) + { + _dbus_warn ("Machine id looks bogus: '%s'\n", machine_id ? machine_id : "null"); + dbus_message_unref (message); + return FALSE; + } + + /* We can't check that the machine id is correct because during make check it is + * just made up for each process separately + */ + + dbus_message_unref (message); + message = NULL; + + return TRUE; +} + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_existent_service_auto_start (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + DBusMessage *base_service_message; + dbus_uint32_t serial; + dbus_bool_t retval; + const char *base_service; + const char *text; + + base_service_message = NULL; + + message = dbus_message_new_method_call (EXISTENT_SERVICE_NAME, + "/org/freedesktop/TestSuite", + "org.freedesktop.TestSuite", + "Echo"); + + if (message == NULL) + return TRUE; + + text = TEST_ECHO_MESSAGE; + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &text, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + return TRUE; + } + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + + /* now wait for the message bus to hear back from the activated + * service. + */ + block_connection_until_message_from_bus (context, connection, "reply to Echo on existent service"); + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive any messages after auto start %d on %p\n", + serial, connection); + goto out; + } + + verbose_message_received (connection, message); + _dbus_verbose (" (after sending %s)\n", "auto start"); + + /* we should get zero or two ServiceOwnerChanged signals */ + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_SIGNAL) + { + GotServiceInfo message_kind; + + if (!check_base_service_activated (context, connection, + message, &base_service)) + goto out; + + base_service_message = message; + message = NULL; + + /* We may need to block here for the test service to exit or finish up */ + block_connection_until_message_from_bus (context, connection, "service to exit"); + + /* Should get a service creation notification for the activated + * service name, or a service deletion on the base service name + */ + message = dbus_connection_borrow_message (connection); + if (message == NULL) + { + _dbus_warn ("No message after auto activation " + "(should be a service announcement)\n"); + dbus_connection_return_message (connection, message); + message = NULL; + goto out; + } + + message_kind = check_got_service_info (message); + + dbus_connection_return_message (connection, message); + message = NULL; + + switch (message_kind) + { + case GOT_SERVICE_CREATED: + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Failed to pop message we just put back! " + "should have been a NameOwnerChanged (creation)\n"); + goto out; + } + + /* Check that ServiceOwnerChanged (creation) was correctly received */ + if (!check_service_auto_activated (context, connection, EXISTENT_SERVICE_NAME, + base_service, message)) + goto out; + + dbus_message_unref (message); + message = NULL; + + break; + + case GOT_SERVICE_DELETED: + { + /* The service started up and got a base address, but then + * failed to register under EXISTENT_SERVICE_NAME + */ + CheckServiceOwnerChangedData socd; + + socd.expected_kind = SERVICE_DELETED; + socd.expected_service_name = base_service; + socd.failed = FALSE; + socd.skip_connection = NULL; + socd.context = context; + + bus_test_clients_foreach (check_service_owner_changed_foreach, + &socd); + + if (socd.failed) + goto out; + + break; + } + + case GOT_ERROR: + case GOT_SOMETHING_ELSE: + _dbus_warn ("Unexpected message after auto activation\n"); + goto out; + } + } + + /* OK, now we've dealt with ServiceOwnerChanged signals, now should + * come the method reply (or error) from the initial method call + */ + + /* Note: if this test is run in OOM mode, it will block when the bus + * doesn't send a reply due to OOM. + */ + block_connection_until_message_from_bus (context, connection, "reply from echo message after auto-activation"); + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Failed to pop message! Should have been reply from echo message\n"); + goto out; + } + + if (dbus_message_get_reply_serial (message) != serial) + { + _dbus_warn ("Wrong reply serial\n"); + goto out; + } + + dbus_message_unref (message); + message = NULL; + + if (!check_existent_ping (context, connection)) + goto out; + + if (!check_existent_get_machine_id (context, connection)) + goto out; + + if (!check_existent_hello_from_self (context, connection)) + goto out; + + if (!check_send_exit_to_service (context, connection, + EXISTENT_SERVICE_NAME, + base_service)) + goto out; + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + if (base_service_message) + dbus_message_unref (base_service_message); + + return retval; +} + +#define SERVICE_FILE_MISSING_NAME "org.freedesktop.DBus.TestSuiteEchoServiceDotServiceFileDoesNotExist" + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_launch_service_file_missing (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + + message = dbus_message_new_method_call (SERVICE_FILE_MISSING_NAME, + "/org/freedesktop/TestSuite", + "org.freedesktop.TestSuite", + "Echo"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + block_connection_until_message_from_bus (context, connection, "reply to service file missing should fail to auto-start"); + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "Echo message (auto activation)", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_SERVICE_UNKNOWN)) + { + _dbus_verbose("got service unknown\n"); + ; /* good, this is expected (only valid when using launch helper) */ + } + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + _dbus_warn ("Did not expect to successfully auto-start missing service\n"); + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + +#define SERVICE_USER_MISSING_NAME "org.freedesktop.DBus.TestSuiteNoUser" + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_launch_service_user_missing (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + + message = dbus_message_new_method_call (SERVICE_USER_MISSING_NAME, + "/org/freedesktop/TestSuite", + "org.freedesktop.TestSuite", + "Echo"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + block_connection_until_message_from_bus (context, connection, + "reply to service which should fail to auto-start (missing User)"); + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_warn ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "Echo message (auto activation)", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_SPAWN_FILE_INVALID)) + { + _dbus_verbose("got service file invalid\n"); + ; /* good, this is expected (only valid when using launch helper) */ + } + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + _dbus_warn ("Did not expect to successfully auto-start missing service\n"); + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + +#define SERVICE_EXEC_MISSING_NAME "org.freedesktop.DBus.TestSuiteNoExec" + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_launch_service_exec_missing (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + + message = dbus_message_new_method_call (SERVICE_EXEC_MISSING_NAME, + "/org/freedesktop/TestSuite", + "org.freedesktop.TestSuite", + "Echo"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + block_connection_until_message_from_bus (context, connection, + "reply to service which should fail to auto-start (missing Exec)"); + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_warn ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "Echo message (auto activation)", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_SERVICE_UNKNOWN)) + { + _dbus_verbose("could not activate as invalid service file was not added\n"); + ; /* good, this is expected as we shouldn't have been added to + * the activation list with a missing Exec key */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_SPAWN_FILE_INVALID)) + { + _dbus_verbose("got service file invalid\n"); + ; /* good, this is allowed, and is the message passed back from the + * launch helper */ + } + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + _dbus_warn ("Did not expect to successfully auto-start missing service\n"); + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + +#define SERVICE_SERVICE_MISSING_NAME "org.freedesktop.DBus.TestSuiteNoService" + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_launch_service_service_missing (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + + message = dbus_message_new_method_call (SERVICE_SERVICE_MISSING_NAME, + "/org/freedesktop/TestSuite", + "org.freedesktop.TestSuite", + "Echo"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + block_connection_until_message_from_bus (context, connection, + "reply to service which should fail to auto-start (missing Service)"); + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_warn ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "Echo message (auto activation)", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_SERVICE_UNKNOWN)) + { + _dbus_verbose("could not activate as invalid service file was not added\n"); + ; /* good, this is expected as we shouldn't have been added to + * the activation list with a missing Exec key */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_SPAWN_FILE_INVALID)) + { + _dbus_verbose("got service file invalid\n"); + ; /* good, this is allowed, and is the message passed back from the + * launch helper */ + } + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + _dbus_warn ("Did not expect to successfully auto-start missing service\n"); + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + +#define SHELL_FAIL_SERVICE_NAME "org.freedesktop.DBus.TestSuiteShellEchoServiceFail" + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_shell_fail_service_auto_start (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + + message = dbus_message_new_method_call (SHELL_FAIL_SERVICE_NAME, + "/org/freedesktop/TestSuite", + "org.freedesktop.TestSuite", + "Echo"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + block_connection_until_message_from_bus (context, connection, "reply to shell Echo on service which should fail to auto-start"); + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + "Echo message (auto activation)", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_INVALID_ARGS)) + { + _dbus_verbose("got invalid args\n"); + ; /* good, this is expected also */ + } + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + _dbus_warn ("Did not expect to successfully auto-start shell fail service\n"); + goto out; + } + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + return retval; +} + +#define SHELL_SUCCESS_SERVICE_NAME "org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess" + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_shell_service_success_auto_start (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + DBusMessage *base_service_message; + dbus_uint32_t serial; + dbus_bool_t retval; + const char *base_service; + const char *argv[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + + base_service_message = NULL; + + message = dbus_message_new_method_call (SHELL_SUCCESS_SERVICE_NAME, + "/org/freedesktop/TestSuite", + "org.freedesktop.TestSuite", + "Echo"); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + + /* now wait for the message bus to hear back from the activated + * service. + */ + block_connection_until_message_from_bus (context, connection, "reply to Echo on shell success service"); + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive any messages after auto start %d on %p\n", + serial, connection); + goto out; + } + + verbose_message_received (connection, message); + _dbus_verbose (" (after sending %s)\n", "auto start"); + + /* we should get zero or two ServiceOwnerChanged signals */ + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_SIGNAL) + { + GotServiceInfo message_kind; + + if (!check_base_service_activated (context, connection, + message, &base_service)) + goto out; + + base_service_message = message; + message = NULL; + + /* We may need to block here for the test service to exit or finish up */ + block_connection_until_message_from_bus (context, connection, "service to exit"); + + /* Should get a service creation notification for the activated + * service name, or a service deletion on the base service name + */ + message = dbus_connection_borrow_message (connection); + if (message == NULL) + { + _dbus_warn ("No message after auto activation " + "(should be a service announcement)\n"); + dbus_connection_return_message (connection, message); + message = NULL; + goto out; + } + + message_kind = check_got_service_info (message); + + dbus_connection_return_message (connection, message); + message = NULL; + + switch (message_kind) + { + case GOT_SERVICE_CREATED: + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Failed to pop message we just put back! " + "should have been a NameOwnerChanged (creation)\n"); + goto out; + } + + /* Check that ServiceOwnerChanged (creation) was correctly received */ + if (!check_service_auto_activated (context, connection, SHELL_SUCCESS_SERVICE_NAME, + base_service, message)) + goto out; + + dbus_message_unref (message); + message = NULL; + + break; + + case GOT_SERVICE_DELETED: + { + /* The service started up and got a base address, but then + * failed to register under SHELL_SUCCESS_SERVICE_NAME + */ + CheckServiceOwnerChangedData socd; + + socd.expected_kind = SERVICE_DELETED; + socd.expected_service_name = base_service; + socd.failed = FALSE; + socd.skip_connection = NULL; + socd.context = context; + + bus_test_clients_foreach (check_service_owner_changed_foreach, + &socd); + + if (socd.failed) + goto out; + + break; + } + + case GOT_ERROR: + case GOT_SOMETHING_ELSE: + _dbus_warn ("Unexpected message after auto activation\n"); + goto out; + } + } + + /* OK, now we've dealt with ServiceOwnerChanged signals, now should + * come the method reply (or error) from the initial method call + */ + + /* Note: if this test is run in OOM mode, it will block when the bus + * doesn't send a reply due to OOM. + */ + block_connection_until_message_from_bus (context, connection, "reply from echo message after auto-activation"); + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Failed to pop message! Should have been reply from echo message\n"); + goto out; + } + + if (dbus_message_get_reply_serial (message) != serial) + { + _dbus_warn ("Wrong reply serial\n"); + goto out; + } + + if (!dbus_message_get_args (message, NULL, + DBUS_TYPE_STRING, &argv[0], + DBUS_TYPE_STRING, &argv[1], + DBUS_TYPE_STRING, &argv[2], + DBUS_TYPE_STRING, &argv[3], + DBUS_TYPE_STRING, &argv[4], + DBUS_TYPE_STRING, &argv[5], + DBUS_TYPE_STRING, &argv[6], + DBUS_TYPE_INVALID)) + { + _dbus_warn ("Error getting arguments from return\n"); + goto out; + } + + /* don't worry about arg[0] as it may be different + depending on the path to the tests + */ + if (strcmp("-test", argv[1]) != 0) + { + _dbus_warn ("Unexpected argv[1] in shell success service test (expected: %s, got: %s)\n", + "-test", argv[1]); + goto out; + } + + if (strcmp("that", argv[2]) != 0) + { + _dbus_warn ("Unexpected argv[2] in shell success service test (expected: %s, got: %s)\n", + "that", argv[2]); + goto out; + } + + if (strcmp("we get", argv[3]) != 0) + { + _dbus_warn ("Unexpected argv[3] in shell success service test (expected: %s, got: %s)\n", + "we get", argv[3]); + goto out; + } + + if (strcmp("back", argv[4]) != 0) + { + _dbus_warn ("Unexpected argv[4] in shell success service test (expected: %s, got: %s)\n", + "back", argv[4]); + goto out; + } + + if (strcmp("--what", argv[5]) != 0) + { + _dbus_warn ("Unexpected argv[5] in shell success service test (expected: %s, got: %s)\n", + "--what", argv[5]); + goto out; + } + + if (strcmp("we put in", argv[6]) != 0) + { + _dbus_warn ("Unexpected argv[6] in shell success service test (expected: %s, got: %s)\n", + "we put in", argv[6]); + goto out; + } + + dbus_message_unref (message); + message = NULL; + + if (!check_send_exit_to_service (context, connection, + SHELL_SUCCESS_SERVICE_NAME, + base_service)) + goto out; + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + if (base_service_message) + dbus_message_unref (base_service_message); + + return retval; +} + +typedef struct +{ + Check1Func func; + BusContext *context; +} Check1Data; + +static dbus_bool_t +check_oom_check1_func (void *data) +{ + Check1Data *d = data; + + if (! (* d->func) (d->context)) + return FALSE; + + if (!check_no_leftovers (d->context)) + { + _dbus_warn ("Messages were left over, should be covered by test suite\n"); + return FALSE; + } + + return TRUE; +} + +static void +check1_try_iterations (BusContext *context, + const char *description, + Check1Func func) +{ + Check1Data d; + + d.func = func; + d.context = context; + + if (!_dbus_test_oom_handling (description, check_oom_check1_func, + &d)) + _dbus_assert_not_reached ("test failed"); +} + +static dbus_bool_t +check_get_services (BusContext *context, + DBusConnection *connection, + const char *method, + char ***services, + int *len) +{ + DBusMessage *message; + dbus_uint32_t serial; + dbus_bool_t retval; + DBusError error; + char **srvs; + int l; + + retval = FALSE; + dbus_error_init (&error); + message = NULL; + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + method); + + if (message == NULL) + return TRUE; + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + /* send our message */ + bus_test_run_clients_loop (SEND_PENDING (connection)); + + dbus_message_unref (message); + message = NULL; + + dbus_connection_ref (connection); /* because we may get disconnected */ + block_connection_until_message_from_bus (context, connection, "reply to ListActivatableNames/ListNames"); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + + dbus_connection_unref (connection); + + return TRUE; + } + + dbus_connection_unref (connection); + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive a reply to %s %d on %p\n", + method, serial, connection); + goto out; + } + + verbose_message_received (connection, message); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (dbus_message_is_error (message, DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else + { + warn_unexpected (connection, message, "not this error"); + + goto out; + } + } + else + { + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN) + { + ; /* good, expected */ + } + else + { + warn_unexpected (connection, message, + "method_return for ListActivatableNames/ListNames"); + + goto out; + } + + retry_get_property: + + if (!dbus_message_get_args (message, &error, + DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING, + &srvs, &l, + DBUS_TYPE_INVALID)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + _dbus_verbose ("no memory to list services by %s\n", method); + dbus_error_free (&error); + _dbus_wait_for_memory (); + goto retry_get_property; + } + else + { + _dbus_assert (dbus_error_is_set (&error)); + _dbus_warn ("Did not get the expected DBUS_TYPE_ARRAY from %s\n", method); + goto out; + } + } else { + *services = srvs; + *len = l; + } + } + + if (!check_no_leftovers (context)) + goto out; + + retval = TRUE; + + out: + dbus_error_free (&error); + + if (message) + dbus_message_unref (message); + + return retval; +} + +/* returns TRUE if the correct thing happens, + * but the correct thing may include OOM errors. + */ +static dbus_bool_t +check_list_services (BusContext *context, + DBusConnection *connection) +{ + DBusMessage *message; + DBusMessage *base_service_message; + const char *base_service; + dbus_uint32_t serial; + dbus_bool_t retval; + const char *existent = EXISTENT_SERVICE_NAME; + dbus_uint32_t flags; + char **services; + int len; + + _dbus_verbose ("check_list_services for %p\n", connection); + + if (!check_get_services (context, connection, "ListActivatableNames", &services, &len)) + { + return TRUE; + } + + if (!_dbus_string_array_contains ((const char **)services, existent)) + { + _dbus_warn ("Did not get the expected %s from ListActivatableNames\n", existent); + dbus_free_string_array (services); + return FALSE; + } + + dbus_free_string_array (services); + + base_service_message = NULL; + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "StartServiceByName"); + + if (message == NULL) + return TRUE; + + dbus_message_set_auto_start (message, FALSE); + + flags = 0; + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &existent, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + return TRUE; + } + + if (!dbus_connection_send (connection, message, &serial)) + { + dbus_message_unref (message); + return TRUE; + } + + dbus_message_unref (message); + message = NULL; + + bus_test_run_everything (context); + + /* now wait for the message bus to hear back from the activated + * service. + */ + block_connection_until_message_from_bus (context, connection, "activated service to connect"); + + bus_test_run_everything (context); + + if (!dbus_connection_get_is_connected (connection)) + { + _dbus_verbose ("connection was disconnected\n"); + return TRUE; + } + + retval = FALSE; + + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive any messages after %s %d on %p\n", + "StartServiceByName", serial, connection); + goto out; + } + + verbose_message_received (connection, message); + _dbus_verbose (" (after sending %s)\n", "StartServiceByName"); + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR) + { + if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) + { + _dbus_warn ("Message has wrong sender %s\n", + dbus_message_get_sender (message) ? + dbus_message_get_sender (message) : "(none)"); + goto out; + } + + if (dbus_message_is_error (message, + DBUS_ERROR_NO_MEMORY)) + { + ; /* good, this is a valid response */ + } + else if (dbus_message_is_error (message, + DBUS_ERROR_SPAWN_CHILD_EXITED) || + dbus_message_is_error (message, + DBUS_ERROR_SPAWN_CHILD_SIGNALED) || + dbus_message_is_error (message, + DBUS_ERROR_SPAWN_EXEC_FAILED)) + { + ; /* good, this is expected also */ + } + else + { + _dbus_warn ("Did not expect error %s\n", + dbus_message_get_error_name (message)); + goto out; + } + } + else + { + GotServiceInfo message_kind; + + if (!check_base_service_activated (context, connection, + message, &base_service)) + goto out; + + base_service_message = message; + message = NULL; + + /* We may need to block here for the test service to exit or finish up */ + block_connection_until_message_from_bus (context, connection, "test service to exit or finish up"); + + message = dbus_connection_borrow_message (connection); + if (message == NULL) + { + _dbus_warn ("Did not receive any messages after base service creation notification\n"); + goto out; + } + + message_kind = check_got_service_info (message); + + dbus_connection_return_message (connection, message); + message = NULL; + + switch (message_kind) + { + case GOT_SOMETHING_ELSE: + case GOT_ERROR: + case GOT_SERVICE_DELETED: + _dbus_warn ("Unexpected message after ActivateService " + "(should be an error or a service announcement)\n"); + goto out; + + case GOT_SERVICE_CREATED: + message = pop_message_waiting_for_memory (connection); + if (message == NULL) + { + _dbus_warn ("Failed to pop message we just put back! " + "should have been a NameOwnerChanged (creation)\n"); + goto out; + } + + if (!check_service_activated (context, connection, EXISTENT_SERVICE_NAME, + base_service, message)) + goto out; + + dbus_message_unref (message); + message = NULL; + + if (!check_no_leftovers (context)) + { + _dbus_warn ("Messages were left over after successful activation\n"); + goto out; + } + + break; + } + } + + if (!check_get_services (context, connection, "ListNames", &services, &len)) + { + return TRUE; + } + + if (!_dbus_string_array_contains ((const char **)services, existent)) + { + _dbus_warn ("Did not get the expected %s from ListNames\n", existent); + goto out; + } + + dbus_free_string_array (services); + + if (!check_send_exit_to_service (context, connection, + EXISTENT_SERVICE_NAME, base_service)) + goto out; + + retval = TRUE; + + out: + if (message) + dbus_message_unref (message); + + if (base_service_message) + dbus_message_unref (base_service_message); + + return retval; +} + +typedef struct +{ + Check2Func func; + BusContext *context; + DBusConnection *connection; +} Check2Data; + +static dbus_bool_t +check_oom_check2_func (void *data) +{ + Check2Data *d = data; + + if (! (* d->func) (d->context, d->connection)) + return FALSE; + + if (!check_no_leftovers (d->context)) + { + _dbus_warn ("Messages were left over, should be covered by test suite\n"); + return FALSE; + } + + return TRUE; +} + +static void +check2_try_iterations (BusContext *context, + DBusConnection *connection, + const char *description, + Check2Func func) +{ + Check2Data d; + + d.func = func; + d.context = context; + d.connection = connection; + + if (!_dbus_test_oom_handling (description, check_oom_check2_func, + &d)) + { + _dbus_warn ("%s failed during oom\n", description); + _dbus_assert_not_reached ("test failed"); + } +} + +static dbus_bool_t +setenv_TEST_LAUNCH_HELPER_CONFIG(const DBusString *test_data_dir, + const char *filename) +{ + DBusString full; + DBusString file; + + if (!_dbus_string_init (&full)) + return FALSE; + + if (!_dbus_string_copy (test_data_dir, 0, &full, 0)) + { + _dbus_string_free (&full); + return FALSE; + } + + _dbus_string_init_const (&file, filename); + + if (!_dbus_concat_dir_and_file (&full, &file)) + { + _dbus_string_free (&full); + return FALSE; + } + + _dbus_verbose ("Setting TEST_LAUNCH_HELPER_CONFIG to '%s'\n", + _dbus_string_get_const_data (&full)); + + dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG", _dbus_string_get_const_data (&full)); + + _dbus_string_free (&full); + + return TRUE; +} + +static dbus_bool_t +bus_dispatch_test_conf (const DBusString *test_data_dir, + const char *filename, + dbus_bool_t use_launcher) +{ + BusContext *context; + DBusConnection *foo; + DBusConnection *bar; + DBusConnection *baz; + DBusError error; + + /* save the config name for the activation helper */ + if (!setenv_TEST_LAUNCH_HELPER_CONFIG (test_data_dir, filename)) + _dbus_assert_not_reached ("no memory setting TEST_LAUNCH_HELPER_CONFIG"); + + dbus_error_init (&error); + + context = bus_context_new_test (test_data_dir, filename); + if (context == NULL) + return FALSE; + + foo = dbus_connection_open_private (TEST_DEBUG_PIPE, &error); + if (foo == NULL) + _dbus_assert_not_reached ("could not alloc connection"); + + if (!bus_setup_debug_client (foo)) + _dbus_assert_not_reached ("could not set up connection"); + + spin_connection_until_authenticated (context, foo); + + if (!check_hello_message (context, foo)) + _dbus_assert_not_reached ("hello message failed"); + + if (!check_double_hello_message (context, foo)) + _dbus_assert_not_reached ("double hello message failed"); + + if (!check_add_match (context, foo, "")) + _dbus_assert_not_reached ("AddMatch message failed"); + + bar = dbus_connection_open_private (TEST_DEBUG_PIPE, &error); + if (bar == NULL) + _dbus_assert_not_reached ("could not alloc connection"); + + if (!bus_setup_debug_client (bar)) + _dbus_assert_not_reached ("could not set up connection"); + + spin_connection_until_authenticated (context, bar); + + if (!check_hello_message (context, bar)) + _dbus_assert_not_reached ("hello message failed"); + + if (!check_add_match (context, bar, "")) + _dbus_assert_not_reached ("AddMatch message failed"); + + baz = dbus_connection_open_private (TEST_DEBUG_PIPE, &error); + if (baz == NULL) + _dbus_assert_not_reached ("could not alloc connection"); + + if (!bus_setup_debug_client (baz)) + _dbus_assert_not_reached ("could not set up connection"); + + spin_connection_until_authenticated (context, baz); + + if (!check_hello_message (context, baz)) + _dbus_assert_not_reached ("hello message failed"); + + if (!check_add_match (context, baz, "")) + _dbus_assert_not_reached ("AddMatch message failed"); + + if (!check_add_match (context, baz, "interface='com.example'")) + _dbus_assert_not_reached ("AddMatch message failed"); + +#ifdef DBUS_ENABLE_STATS + if (!check_get_all_match_rules (context, baz)) + _dbus_assert_not_reached ("GetAllMatchRules message failed"); +#endif + + if (!check_get_connection_unix_user (context, baz)) + _dbus_assert_not_reached ("GetConnectionUnixUser message failed"); + +#ifdef DBUS_WIN_FIXME + _dbus_verbose("TODO: testing of GetConnectionUnixProcessID message skipped for now\n"); +#else + if (!check_get_connection_unix_process_id (context, baz)) + _dbus_assert_not_reached ("GetConnectionUnixProcessID message failed"); +#endif + + if (!check_list_services (context, baz)) + _dbus_assert_not_reached ("ListActivatableNames message failed"); + + if (!check_no_leftovers (context)) + { + _dbus_warn ("Messages were left over after setting up initial connections\n"); + _dbus_assert_not_reached ("initial connection setup failed"); + } + + check1_try_iterations (context, "create_and_hello", + check_hello_connection); + + check2_try_iterations (context, foo, "nonexistent_service_no_auto_start", + check_nonexistent_service_no_auto_start); + + check2_try_iterations (context, foo, "segfault_service_no_auto_start", + check_segfault_service_no_auto_start); + + check2_try_iterations (context, foo, "existent_service_no_auto_start", + check_existent_service_no_auto_start); + + check2_try_iterations (context, foo, "nonexistent_service_auto_start", + check_nonexistent_service_auto_start); + + /* only do the segfault test if we are not using the launcher */ + check2_try_iterations (context, foo, "segfault_service_auto_start", + check_segfault_service_auto_start); + + /* only do the shell fail test if we are not using the launcher */ + check2_try_iterations (context, foo, "shell_fail_service_auto_start", + check_shell_fail_service_auto_start); + + /* specific to launcher */ + if (use_launcher) + if (!check_launch_service_file_missing (context, foo)) + _dbus_assert_not_reached ("did not get service file not found error"); + +#if 0 + /* Note: need to resolve some issues with the testing code in order to run + * this in oom (handle that we sometimes don't get replies back from the bus + * when oom happens, without blocking the test). + */ + check2_try_iterations (context, foo, "existent_service_auto_auto_start", + check_existent_service_auto_start); +#endif + + if (!check_existent_service_auto_start (context, foo)) + _dbus_assert_not_reached ("existent service auto start failed"); + + if (!check_shell_service_success_auto_start (context, foo)) + _dbus_assert_not_reached ("shell success service auto start failed"); + + _dbus_verbose ("Disconnecting foo, bar, and baz\n"); + + kill_client_connection_unchecked (foo); + kill_client_connection_unchecked (bar); + kill_client_connection_unchecked (baz); + + bus_context_unref (context); + + return TRUE; +} + +static dbus_bool_t +bus_dispatch_test_conf_fail (const DBusString *test_data_dir, + const char *filename) +{ + BusContext *context; + DBusConnection *foo; + DBusError error; + + /* save the config name for the activation helper */ + if (!setenv_TEST_LAUNCH_HELPER_CONFIG (test_data_dir, filename)) + _dbus_assert_not_reached ("no memory setting TEST_LAUNCH_HELPER_CONFIG"); + + dbus_error_init (&error); + + context = bus_context_new_test (test_data_dir, filename); + if (context == NULL) + return FALSE; + + foo = dbus_connection_open_private (TEST_DEBUG_PIPE, &error); + if (foo == NULL) + _dbus_assert_not_reached ("could not alloc connection"); + + if (!bus_setup_debug_client (foo)) + _dbus_assert_not_reached ("could not set up connection"); + + spin_connection_until_authenticated (context, foo); + + if (!check_hello_message (context, foo)) + _dbus_assert_not_reached ("hello message failed"); + + if (!check_double_hello_message (context, foo)) + _dbus_assert_not_reached ("double hello message failed"); + + if (!check_add_match (context, foo, "")) + _dbus_assert_not_reached ("AddMatch message failed"); + + /* this only tests the activation.c user check */ + if (!check_launch_service_user_missing (context, foo)) + _dbus_assert_not_reached ("user missing did not trigger error"); + + /* this only tests the desktop.c exec check */ + if (!check_launch_service_exec_missing (context, foo)) + _dbus_assert_not_reached ("exec missing did not trigger error"); + + /* this only tests the desktop.c service check */ + if (!check_launch_service_service_missing (context, foo)) + _dbus_assert_not_reached ("service missing did not trigger error"); + + _dbus_verbose ("Disconnecting foo\n"); + + kill_client_connection_unchecked (foo); + + bus_context_unref (context); + + return TRUE; +} + +dbus_bool_t +bus_dispatch_test (const DBusString *test_data_dir) +{ + /* run normal activation tests */ + _dbus_verbose ("Normal activation tests\n"); + if (!bus_dispatch_test_conf (test_data_dir, + "valid-config-files/debug-allow-all.conf", FALSE)) + return FALSE; + +#ifndef DBUS_WIN + /* run launch-helper activation tests */ + _dbus_verbose ("Launch helper activation tests\n"); + if (!bus_dispatch_test_conf (test_data_dir, + "valid-config-files-system/debug-allow-all-pass.conf", TRUE)) + return FALSE; + + /* run select launch-helper activation tests on broken service files */ + if (!bus_dispatch_test_conf_fail (test_data_dir, + "valid-config-files-system/debug-allow-all-fail.conf")) + return FALSE; +#endif + + return TRUE; +} + +dbus_bool_t +bus_dispatch_sha1_test (const DBusString *test_data_dir) +{ + BusContext *context; + DBusConnection *foo; + DBusError error; + + dbus_error_init (&error); + + /* Test SHA1 authentication */ + _dbus_verbose ("Testing SHA1 context\n"); + + context = bus_context_new_test (test_data_dir, + "valid-config-files/debug-allow-all-sha1.conf"); + if (context == NULL) + return FALSE; + + foo = dbus_connection_open_private (TEST_DEBUG_PIPE, &error); + if (foo == NULL) + _dbus_assert_not_reached ("could not alloc connection"); + + if (!bus_setup_debug_client (foo)) + _dbus_assert_not_reached ("could not set up connection"); + + spin_connection_until_authenticated (context, foo); + + if (!check_hello_message (context, foo)) + _dbus_assert_not_reached ("hello message failed"); + + if (!check_add_match (context, foo, "")) + _dbus_assert_not_reached ("addmatch message failed"); + + if (!check_no_leftovers (context)) + { + _dbus_warn ("Messages were left over after setting up initial SHA-1 connection\n"); + _dbus_assert_not_reached ("initial connection setup failed"); + } + + check1_try_iterations (context, "create_and_hello_sha1", + check_hello_connection); + + kill_client_connection_unchecked (foo); + + bus_context_unref (context); + + return TRUE; +} + +#ifdef HAVE_UNIX_FD_PASSING + +dbus_bool_t +bus_unix_fds_passing_test(const DBusString *test_data_dir) +{ + BusContext *context; + DBusConnection *foo, *bar; + DBusError error; + DBusMessage *m; + DBusSocket one[2], two[2]; + int x, y, z; + char r; + + dbus_error_init (&error); + + context = bus_context_new_test (test_data_dir, "valid-config-files/debug-allow-all.conf"); + if (context == NULL) + _dbus_assert_not_reached ("could not alloc context"); + + foo = dbus_connection_open_private (TEST_DEBUG_PIPE, &error); + if (foo == NULL) + _dbus_assert_not_reached ("could not alloc connection"); + + if (!bus_setup_debug_client (foo)) + _dbus_assert_not_reached ("could not set up connection"); + + spin_connection_until_authenticated (context, foo); + + if (!check_hello_message (context, foo)) + _dbus_assert_not_reached ("hello message failed"); + + if (!check_add_match (context, foo, "")) + _dbus_assert_not_reached ("AddMatch message failed"); + + bar = dbus_connection_open_private (TEST_DEBUG_PIPE, &error); + if (bar == NULL) + _dbus_assert_not_reached ("could not alloc connection"); + + if (!bus_setup_debug_client (bar)) + _dbus_assert_not_reached ("could not set up connection"); + + spin_connection_until_authenticated (context, bar); + + if (!check_hello_message (context, bar)) + _dbus_assert_not_reached ("hello message failed"); + + if (!check_add_match (context, bar, "")) + _dbus_assert_not_reached ("AddMatch message failed"); + + if (!(m = dbus_message_new_signal("/", "a.b.c", "d"))) + _dbus_assert_not_reached ("could not alloc message"); + + if (!(_dbus_socketpair (one, one+1, TRUE, &error))) + _dbus_assert_not_reached("Failed to allocate pipe #1"); + + if (!(_dbus_socketpair (two, two+1, TRUE, &error))) + _dbus_assert_not_reached("Failed to allocate pipe #2"); + + if (!dbus_message_append_args(m, + DBUS_TYPE_UNIX_FD, one, + DBUS_TYPE_UNIX_FD, two, + DBUS_TYPE_UNIX_FD, two, + DBUS_TYPE_INVALID)) + _dbus_assert_not_reached("Failed to attach fds."); + + if (!_dbus_close_socket (one[0], &error)) + _dbus_assert_not_reached("Failed to close pipe #1 "); + if (!_dbus_close_socket (two[0], &error)) + _dbus_assert_not_reached("Failed to close pipe #2 "); + + if (!(dbus_connection_can_send_type(foo, DBUS_TYPE_UNIX_FD))) + _dbus_assert_not_reached("Connection cannot do fd passing"); + + if (!(dbus_connection_can_send_type(bar, DBUS_TYPE_UNIX_FD))) + _dbus_assert_not_reached("Connection cannot do fd passing"); + + if (!dbus_connection_send (foo, m, NULL)) + _dbus_assert_not_reached("Failed to send fds"); + + dbus_message_unref(m); + + bus_test_run_clients_loop (SEND_PENDING (foo)); + + bus_test_run_everything (context); + + block_connection_until_message_from_bus (context, foo, "unix fd reception on foo"); + + if (!(m = pop_message_waiting_for_memory (foo))) + _dbus_assert_not_reached("Failed to receive msg"); + + if (!dbus_message_is_signal(m, "a.b.c", "d")) + _dbus_assert_not_reached("bogus message received"); + + dbus_message_unref(m); + + block_connection_until_message_from_bus (context, bar, "unix fd reception on bar"); + + if (!(m = pop_message_waiting_for_memory (bar))) + _dbus_assert_not_reached("Failed to receive msg"); + + if (!dbus_message_is_signal(m, "a.b.c", "d")) + _dbus_assert_not_reached("bogus message received"); + + if (!dbus_message_get_args(m, + &error, + DBUS_TYPE_UNIX_FD, &x, + DBUS_TYPE_UNIX_FD, &y, + DBUS_TYPE_UNIX_FD, &z, + DBUS_TYPE_INVALID)) + _dbus_assert_not_reached("Failed to parse fds."); + + dbus_message_unref(m); + + if (write(x, "X", 1) != 1) + _dbus_assert_not_reached("Failed to write to pipe #1"); + if (write(y, "Y", 1) != 1) + _dbus_assert_not_reached("Failed to write to pipe #2"); + if (write(z, "Z", 1) != 1) + _dbus_assert_not_reached("Failed to write to pipe #2/2nd fd"); + + if (!_dbus_close(x, &error)) + _dbus_assert_not_reached("Failed to close pipe #1/other side "); + if (!_dbus_close(y, &error)) + _dbus_assert_not_reached("Failed to close pipe #2/other side "); + if (!_dbus_close(z, &error)) + _dbus_assert_not_reached("Failed to close pipe #2/other size 2nd fd "); + + if (read(one[1].fd, &r, 1) != 1 || r != 'X') + _dbus_assert_not_reached("Failed to read value from pipe."); + if (read(two[1].fd, &r, 1) != 1 || r != 'Y') + _dbus_assert_not_reached("Failed to read value from pipe."); + if (read(two[1].fd, &r, 1) != 1 || r != 'Z') + _dbus_assert_not_reached("Failed to read value from pipe."); + + if (!_dbus_close_socket (one[1], &error)) + _dbus_assert_not_reached("Failed to close pipe #1 "); + if (!_dbus_close_socket (two[1], &error)) + _dbus_assert_not_reached("Failed to close pipe #2 "); + + _dbus_verbose ("Disconnecting foo\n"); + kill_client_connection_unchecked (foo); + + _dbus_verbose ("Disconnecting bar\n"); + kill_client_connection_unchecked (bar); + + bus_context_unref (context); + + return TRUE; +} +#endif + +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/bus/dispatch.h b/bus/dispatch.h new file mode 100644 index 0000000..fb5ba7a --- /dev/null +++ b/bus/dispatch.h
@@ -0,0 +1,38 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dispatch.h Message dispatcher + * + * Copyright (C) 2003 CodeFactory AB + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_DISPATCH_H +#define BUS_DISPATCH_H + +#include <dbus/dbus.h> +#include "connection.h" + +dbus_bool_t bus_dispatch_add_connection (DBusConnection *connection); +void bus_dispatch_remove_connection (DBusConnection *connection); +dbus_bool_t bus_dispatch_matches (BusTransaction *transaction, + DBusConnection *sender, + DBusConnection *recipient, + DBusMessage *message, + DBusError *error); + +#endif /* BUS_DISPATCH_H */
diff --git a/bus/driver.c b/bus/driver.c new file mode 100644 index 0000000..b7e1a0a --- /dev/null +++ b/bus/driver.c
@@ -0,0 +1,2736 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* driver.c Bus client (driver) + * + * Copyright (C) 2003 CodeFactory AB + * Copyright (C) 2003, 2004, 2005 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "activation.h" +#include "apparmor.h" +#include "connection.h" +#include "driver.h" +#include "dispatch.h" +#include "services.h" +#include "selinux.h" +#include "signals.h" +#include "stats.h" +#include "utils.h" + +#include <dbus/dbus-asv-util.h> +#include <dbus/dbus-connection-internal.h> +#include <dbus/dbus-string.h> +#include <dbus/dbus-internals.h> +#include <dbus/dbus-message.h> +#include <dbus/dbus-marshal-recursive.h> +#include <dbus/dbus-marshal-validate.h> +#include <string.h> + +typedef enum +{ + BUS_DRIVER_FOUND_SELF, + BUS_DRIVER_FOUND_PEER, + BUS_DRIVER_FOUND_ERROR, +} BusDriverFound; + +static inline const char * +nonnull (const char *maybe_null, + const char *if_null) +{ + return (maybe_null ? maybe_null : if_null); +} + +static DBusConnection * +bus_driver_get_owner_of_name (DBusConnection *connection, + const char *name) +{ + BusRegistry *registry; + BusService *serv; + DBusString str; + + registry = bus_connection_get_registry (connection); + _dbus_string_init_const (&str, name); + serv = bus_registry_lookup (registry, &str); + + if (serv == NULL) + return NULL; + + return bus_service_get_primary_owners_connection (serv); +} + +static BusDriverFound +bus_driver_get_conn_helper (DBusConnection *connection, + DBusMessage *message, + const char *what_we_want, + const char **name_p, + DBusConnection **peer_conn_p, + DBusError *error) +{ + DBusConnection *conn; + const char *name; + + if (!dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + return BUS_DRIVER_FOUND_ERROR; + + _dbus_assert (name != NULL); + _dbus_verbose ("asked for %s of connection %s\n", what_we_want, name); + + if (name_p != NULL) + *name_p = name; + + if (strcmp (name, DBUS_SERVICE_DBUS) == 0) + return BUS_DRIVER_FOUND_SELF; + + conn = bus_driver_get_owner_of_name (connection, name); + + if (conn == NULL) + { + dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER, + "Could not get %s of name '%s': no such name", + what_we_want, name); + return BUS_DRIVER_FOUND_ERROR; + } + + if (peer_conn_p != NULL) + *peer_conn_p = conn; + + return BUS_DRIVER_FOUND_PEER; +} + +/* + * Log a security warning and set error unless the uid of the connection + * is either the uid of this process, or on Unix, uid 0 (root). + * + * This is intended to be a second line of defence after <deny> rules, + * to mitigate incorrect system bus security policy configuration files + * like the ones in CVE-2014-8148 and CVE-2014-8156, and (if present) + * LSM rules; so it doesn't need to be perfect, but as long as we have + * potentially dangerous functionality in the system bus, it does need + * to exist. + */ +static dbus_bool_t +bus_driver_check_caller_is_privileged (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ +#ifdef DBUS_UNIX + unsigned long uid; + + if (!dbus_connection_get_unix_user (connection, &uid)) + { + const char *method = dbus_message_get_member (message); + + bus_context_log_and_set_error (bus_transaction_get_context (transaction), + DBUS_SYSTEM_LOG_SECURITY, error, DBUS_ERROR_ACCESS_DENIED, + "rejected attempt to call %s by connection %s (%s) with " + "unknown uid", method, + nonnull (bus_connection_get_name (connection), "(inactive)"), + bus_connection_get_loginfo (connection)); + return FALSE; + } + + /* I'm writing it in this slightly strange form so that it's more + * obvious that this security-sensitive code is correct. + */ + if (_dbus_unix_user_is_process_owner (uid)) + { + /* OK */ + } + else if (uid == 0) + { + /* OK */ + } + else + { + const char *method = dbus_message_get_member (message); + + bus_context_log_and_set_error (bus_transaction_get_context (transaction), + DBUS_SYSTEM_LOG_SECURITY, error, DBUS_ERROR_ACCESS_DENIED, + "rejected attempt to call %s by connection %s (%s) with " + "uid %lu", method, + nonnull (bus_connection_get_name (connection), "(inactive)"), + bus_connection_get_loginfo (connection), uid); + return FALSE; + } + + return TRUE; +#elif defined(DBUS_WIN) + char *windows_sid = NULL; + dbus_bool_t ret = FALSE; + + if (!dbus_connection_get_windows_user (connection, &windows_sid)) + { + const char *method = dbus_message_get_member (message); + + bus_context_log_and_set_error (bus_transaction_get_context (transaction), + DBUS_SYSTEM_LOG_SECURITY, error, DBUS_ERROR_ACCESS_DENIED, + "rejected attempt to call %s by unknown uid", method); + goto out; + } + + if (!_dbus_windows_user_is_process_owner (windows_sid)) + { + const char *method = dbus_message_get_member (message); + + bus_context_log_and_set_error (bus_transaction_get_context (transaction), + DBUS_SYSTEM_LOG_SECURITY, error, DBUS_ERROR_ACCESS_DENIED, + "rejected attempt to call %s by uid %s", method, windows_sid); + goto out; + } + + ret = TRUE; +out: + dbus_free (windows_sid); + return ret; +#else + /* make sure we fail closed in the hypothetical case that we are neither + * Unix nor Windows */ + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "please teach bus/driver.c how uids work on this platform"); + return FALSE; +#endif +} + +static dbus_bool_t bus_driver_send_welcome_message (DBusConnection *connection, + DBusMessage *hello_message, + BusTransaction *transaction, + DBusError *error); + +dbus_bool_t +bus_driver_send_service_owner_changed (const char *service_name, + const char *old_owner, + const char *new_owner, + BusTransaction *transaction, + DBusError *error) +{ + DBusMessage *message; + dbus_bool_t retval; + const char *null_service; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + null_service = ""; + _dbus_verbose ("sending name owner changed: %s [%s -> %s]\n", + service_name, + old_owner ? old_owner : null_service, + new_owner ? new_owner : null_service); + + message = dbus_message_new_signal (DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "NameOwnerChanged"); + + if (message == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS)) + goto oom; + + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &service_name, + DBUS_TYPE_STRING, old_owner ? &old_owner : &null_service, + DBUS_TYPE_STRING, new_owner ? &new_owner : &null_service, + DBUS_TYPE_INVALID)) + goto oom; + + _dbus_assert (dbus_message_has_signature (message, "sss")); + + if (!bus_transaction_capture (transaction, NULL, message)) + goto oom; + + retval = bus_dispatch_matches (transaction, NULL, NULL, message, error); + dbus_message_unref (message); + + return retval; + + oom: + dbus_message_unref (message); + BUS_SET_OOM (error); + return FALSE; +} + +dbus_bool_t +bus_driver_send_service_lost (DBusConnection *connection, + const char *service_name, + BusTransaction *transaction, + DBusError *error) +{ + DBusMessage *message; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + message = dbus_message_new_signal (DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "NameLost"); + + if (message == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) || + !dbus_message_append_args (message, + DBUS_TYPE_STRING, &service_name, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + BUS_SET_OOM (error); + return FALSE; + } + + if (!bus_transaction_send_from_driver (transaction, connection, message)) + { + dbus_message_unref (message); + BUS_SET_OOM (error); + return FALSE; + } + else + { + dbus_message_unref (message); + return TRUE; + } +} + +dbus_bool_t +bus_driver_send_service_acquired (DBusConnection *connection, + const char *service_name, + BusTransaction *transaction, + DBusError *error) +{ + DBusMessage *message; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + message = dbus_message_new_signal (DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "NameAcquired"); + + if (message == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) || + !dbus_message_append_args (message, + DBUS_TYPE_STRING, &service_name, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + BUS_SET_OOM (error); + return FALSE; + } + + if (!bus_transaction_send_from_driver (transaction, connection, message)) + { + dbus_message_unref (message); + BUS_SET_OOM (error); + return FALSE; + } + else + { + dbus_message_unref (message); + return TRUE; + } +} + +static dbus_bool_t +create_unique_client_name (BusRegistry *registry, + DBusString *str) +{ + /* We never want to use the same unique client name twice, because + * we want to guarantee that if you send a message to a given unique + * name, you always get the same application. So we use two numbers + * for INT_MAX * INT_MAX combinations, should be pretty safe against + * wraparound. + */ + /* FIXME these should be in BusRegistry rather than static vars */ + static int next_major_number = 0; + static int next_minor_number = 0; + int len; + + len = _dbus_string_get_length (str); + + while (TRUE) + { + /* start out with 1-0, go to 1-1, 1-2, 1-3, + * up to 1-MAXINT, then 2-0, 2-1, etc. + */ + if (next_minor_number <= 0) + { + next_major_number += 1; + next_minor_number = 0; + if (next_major_number <= 0) + _dbus_assert_not_reached ("INT_MAX * INT_MAX clients were added"); + } + + _dbus_assert (next_major_number > 0); + _dbus_assert (next_minor_number >= 0); + + /* appname:MAJOR-MINOR */ + + if (!_dbus_string_append (str, ":")) + return FALSE; + + if (!_dbus_string_append_int (str, next_major_number)) + return FALSE; + + if (!_dbus_string_append (str, ".")) + return FALSE; + + if (!_dbus_string_append_int (str, next_minor_number)) + return FALSE; + + next_minor_number += 1; + + /* Check if a client with the name exists */ + if (bus_registry_lookup (registry, str) == NULL) + break; + + /* drop the number again, try the next one. */ + _dbus_string_set_length (str, len); + } + + return TRUE; +} + +static dbus_bool_t +bus_driver_handle_hello (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusString unique_name; + BusService *service; + dbus_bool_t retval; + BusRegistry *registry; + BusConnections *connections; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (bus_connection_is_active (connection)) + { + /* We already handled an Hello message for this connection. */ + dbus_set_error (error, DBUS_ERROR_FAILED, + "Already handled an Hello message"); + return FALSE; + } + + /* Note that when these limits are exceeded we don't disconnect the + * connection; we just sort of leave it hanging there until it times + * out or disconnects itself or is dropped due to the max number of + * incomplete connections. It's even OK if the connection wants to + * retry the hello message, we support that. + */ + connections = bus_connection_get_connections (connection); + if (!bus_connections_check_limits (connections, connection, + error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return FALSE; + } + + if (!_dbus_string_init (&unique_name)) + { + BUS_SET_OOM (error); + return FALSE; + } + + retval = FALSE; + + registry = bus_connection_get_registry (connection); + + if (!create_unique_client_name (registry, &unique_name)) + { + BUS_SET_OOM (error); + goto out_0; + } + + if (!bus_connection_complete (connection, &unique_name, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto out_0; + } + + if (!dbus_message_set_sender (message, + bus_connection_get_name (connection))) + { + BUS_SET_OOM (error); + goto out_0; + } + + if (!bus_driver_send_welcome_message (connection, message, transaction, error)) + goto out_0; + + /* Create the service */ + service = bus_registry_ensure (registry, + &unique_name, connection, 0, transaction, error); + if (service == NULL) + goto out_0; + + _dbus_assert (bus_connection_is_active (connection)); + retval = TRUE; + + out_0: + _dbus_string_free (&unique_name); + return retval; +} + +static dbus_bool_t +bus_driver_send_welcome_message (DBusConnection *connection, + DBusMessage *hello_message, + BusTransaction *transaction, + DBusError *error) +{ + DBusMessage *welcome; + const char *name; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + name = bus_connection_get_name (connection); + _dbus_assert (name != NULL); + + welcome = dbus_message_new_method_return (hello_message); + if (welcome == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!dbus_message_append_args (welcome, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (welcome); + BUS_SET_OOM (error); + return FALSE; + } + + _dbus_assert (dbus_message_has_signature (welcome, DBUS_TYPE_STRING_AS_STRING)); + + if (!bus_transaction_send_from_driver (transaction, connection, welcome)) + { + dbus_message_unref (welcome); + BUS_SET_OOM (error); + return FALSE; + } + else + { + dbus_message_unref (welcome); + return TRUE; + } +} + +static dbus_bool_t +bus_driver_handle_list_services (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply; + int len; + char **services; + BusRegistry *registry; + int i; + DBusMessageIter iter; + DBusMessageIter sub; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + registry = bus_connection_get_registry (connection); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!bus_registry_list_services (registry, &services, &len)) + { + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + + dbus_message_iter_init_append (reply, &iter); + + if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, + &sub)) + { + dbus_free_string_array (services); + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + + { + /* Include the bus driver in the list */ + const char *v_STRING = DBUS_SERVICE_DBUS; + if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING, + &v_STRING)) + { + dbus_free_string_array (services); + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + } + + i = 0; + while (i < len) + { + if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING, + &services[i])) + { + dbus_free_string_array (services); + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + ++i; + } + + dbus_free_string_array (services); + + if (!dbus_message_iter_close_container (&iter, &sub)) + { + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + + if (!bus_transaction_send_from_driver (transaction, connection, reply)) + { + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + else + { + dbus_message_unref (reply); + return TRUE; + } +} + +static dbus_bool_t +bus_driver_handle_list_activatable_services (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply; + int len; + char **services; + BusActivation *activation; + int i; + DBusMessageIter iter; + DBusMessageIter sub; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + activation = bus_connection_get_activation (connection); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!bus_activation_list_services (activation, &services, &len)) + { + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + + dbus_message_iter_init_append (reply, &iter); + + if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, + &sub)) + { + dbus_free_string_array (services); + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + + { + /* Include the bus driver in the list */ + const char *v_STRING = DBUS_SERVICE_DBUS; + if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING, + &v_STRING)) + { + dbus_free_string_array (services); + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + } + + i = 0; + while (i < len) + { + if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING, + &services[i])) + { + dbus_free_string_array (services); + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + ++i; + } + + dbus_free_string_array (services); + + if (!dbus_message_iter_close_container (&iter, &sub)) + { + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + + if (!bus_transaction_send_from_driver (transaction, connection, reply)) + { + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + else + { + dbus_message_unref (reply); + return TRUE; + } +} + +static dbus_bool_t +bus_driver_handle_acquire_service (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply; + DBusString service_name; + const char *name; + dbus_uint32_t service_reply; + dbus_uint32_t flags; + dbus_bool_t retval; + BusRegistry *registry; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + registry = bus_connection_get_registry (connection); + + if (!dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID)) + return FALSE; + + _dbus_verbose ("Trying to own name %s with flags 0x%x\n", name, flags); + + retval = FALSE; + reply = NULL; + + _dbus_string_init_const (&service_name, name); + + if (!bus_registry_acquire_service (registry, connection, + &service_name, flags, + &service_reply, transaction, + error)) + goto out; + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + { + BUS_SET_OOM (error); + goto out; + } + + if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, &service_reply, DBUS_TYPE_INVALID)) + { + BUS_SET_OOM (error); + goto out; + } + + if (!bus_transaction_send_from_driver (transaction, connection, reply)) + { + BUS_SET_OOM (error); + goto out; + } + + retval = TRUE; + + out: + if (reply) + dbus_message_unref (reply); + return retval; +} + +static dbus_bool_t +bus_driver_handle_release_service (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply; + DBusString service_name; + const char *name; + dbus_uint32_t service_reply; + dbus_bool_t retval; + BusRegistry *registry; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + registry = bus_connection_get_registry (connection); + + if (!dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + return FALSE; + + _dbus_verbose ("Trying to release name %s\n", name); + + retval = FALSE; + reply = NULL; + + _dbus_string_init_const (&service_name, name); + + if (!bus_registry_release_service (registry, connection, + &service_name, &service_reply, + transaction, error)) + goto out; + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + { + BUS_SET_OOM (error); + goto out; + } + + if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, &service_reply, DBUS_TYPE_INVALID)) + { + BUS_SET_OOM (error); + goto out; + } + + if (!bus_transaction_send_from_driver (transaction, connection, reply)) + { + BUS_SET_OOM (error); + goto out; + } + + retval = TRUE; + + out: + if (reply) + dbus_message_unref (reply); + return retval; +} + +static dbus_bool_t +bus_driver_handle_service_exists (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply; + DBusString service_name; + BusService *service; + dbus_bool_t service_exists; + const char *name; + dbus_bool_t retval; + BusRegistry *registry; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + registry = bus_connection_get_registry (connection); + + if (!dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + return FALSE; + + retval = FALSE; + + if (strcmp (name, DBUS_SERVICE_DBUS) == 0) + { + service_exists = TRUE; + } + else + { + _dbus_string_init_const (&service_name, name); + service = bus_registry_lookup (registry, &service_name); + service_exists = service != NULL; + } + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + { + BUS_SET_OOM (error); + goto out; + } + + if (!dbus_message_append_args (reply, + DBUS_TYPE_BOOLEAN, &service_exists, + 0)) + { + BUS_SET_OOM (error); + goto out; + } + + if (!bus_transaction_send_from_driver (transaction, connection, reply)) + { + BUS_SET_OOM (error); + goto out; + } + + retval = TRUE; + + out: + if (reply) + dbus_message_unref (reply); + + return retval; +} + +static dbus_bool_t +bus_driver_handle_activate_service (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + dbus_uint32_t flags; + const char *name; + dbus_bool_t retval; + BusActivation *activation; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + activation = bus_connection_get_activation (connection); + + if (!dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_verbose ("No memory to get arguments to StartServiceByName\n"); + return FALSE; + } + + retval = FALSE; + + if (!bus_activation_activate_service (activation, connection, transaction, FALSE, + message, name, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_verbose ("bus_activation_activate_service() failed\n"); + goto out; + } + + retval = TRUE; + + out: + return retval; +} + +static dbus_bool_t +send_ack_reply (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply; + + if (dbus_message_get_no_reply (message)) + return TRUE; + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!bus_transaction_send_from_driver (transaction, connection, reply)) + { + BUS_SET_OOM (error); + dbus_message_unref (reply); + return FALSE; + } + + dbus_message_unref (reply); + + return TRUE; +} + +/* + * Send a message from the driver, activating the destination if necessary. + * The message must already have a destination set. + */ +static dbus_bool_t +bus_driver_send_or_activate (BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + BusContext *context; + BusService *service; + const char *service_name; + DBusString service_string; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + service_name = dbus_message_get_destination (message); + + _dbus_assert (service_name != NULL); + + _dbus_string_init_const (&service_string, service_name); + + context = bus_transaction_get_context (transaction); + + service = bus_registry_lookup (bus_context_get_registry (context), + &service_string); + + if (service == NULL) + { + /* destination isn't connected yet; pass the message to activation */ + BusActivation *activation; + + activation = bus_context_get_activation (context); + + if (!bus_transaction_capture (transaction, NULL, message)) + { + BUS_SET_OOM (error); + _dbus_verbose ("No memory for bus_transaction_capture()"); + return FALSE; + } + + if (!bus_activation_activate_service (activation, NULL, transaction, TRUE, + message, service_name, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_verbose ("bus_activation_activate_service() failed"); + return FALSE; + } + } + else + { + DBusConnection *service_conn; + + service_conn = bus_service_get_primary_owners_connection (service); + + if (!bus_transaction_send_from_driver (transaction, service_conn, message)) + { + BUS_SET_OOM (error); + _dbus_verbose ("No memory for bus_transaction_send_from_driver()"); + return FALSE; + } + } + + return TRUE; +} + +static dbus_bool_t +bus_driver_handle_update_activation_environment (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + dbus_bool_t retval; + BusActivation *activation; + BusContext *context; + DBusMessageIter iter; + DBusMessageIter dict_iter; + DBusMessageIter dict_entry_iter; + int array_type; + int key_type; + DBusList *keys, *key_link; + DBusList *values, *value_link; + DBusMessage *systemd_message; + DBusMessageIter systemd_iter; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!bus_driver_check_message_is_for_us (message, error)) + return FALSE; + +#ifdef DBUS_UNIX + { + /* UpdateActivationEnvironment is basically a recipe for privilege + * escalation so let's be extra-careful: do not allow the sysadmin + * to shoot themselves in the foot. + */ + if (!bus_driver_check_caller_is_privileged (connection, transaction, + message, error)) + return FALSE; + } +#endif + + context = bus_connection_get_context (connection); + + if (bus_context_get_servicehelper (context) != NULL) + { + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "Cannot change activation environment " + "on a system bus."); + return FALSE; + } + + activation = bus_connection_get_activation (connection); + + dbus_message_iter_init (message, &iter); + + /* The message signature has already been checked for us, + * so let's just assert it's right. + */ + _dbus_assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY); + + dbus_message_iter_recurse (&iter, &dict_iter); + + retval = FALSE; + systemd_message = NULL; + + /* Then loop through the sent dictionary, add the location of + * the environment keys and values to lists. The result will + * be in reverse order, so we don't have to constantly search + * for the end of the list in a loop. + */ + keys = NULL; + values = NULL; + while ((array_type = dbus_message_iter_get_arg_type (&dict_iter)) == DBUS_TYPE_DICT_ENTRY) + { + dbus_message_iter_recurse (&dict_iter, &dict_entry_iter); + + while ((key_type = dbus_message_iter_get_arg_type (&dict_entry_iter)) == DBUS_TYPE_STRING) + { + char *key; + char *value; + int value_type; + + dbus_message_iter_get_basic (&dict_entry_iter, &key); + dbus_message_iter_next (&dict_entry_iter); + + value_type = dbus_message_iter_get_arg_type (&dict_entry_iter); + + if (value_type != DBUS_TYPE_STRING) + break; + + dbus_message_iter_get_basic (&dict_entry_iter, &value); + + if (!_dbus_list_append (&keys, key)) + { + BUS_SET_OOM (error); + break; + } + + if (!_dbus_list_append (&values, value)) + { + BUS_SET_OOM (error); + break; + } + + dbus_message_iter_next (&dict_entry_iter); + } + + if (key_type != DBUS_TYPE_INVALID) + break; + + dbus_message_iter_next (&dict_iter); + } + + if (array_type != DBUS_TYPE_INVALID) + goto out; + + _dbus_assert (_dbus_list_get_length (&keys) == _dbus_list_get_length (&values)); + + if (bus_context_get_systemd_activation (bus_connection_get_context (connection))) + { + /* Prepare a call to forward environment updates to systemd */ + systemd_message = dbus_message_new_method_call ("org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "SetEnvironment"); + if (systemd_message == NULL || + !dbus_message_set_sender (systemd_message, DBUS_SERVICE_DBUS)) + { + BUS_SET_OOM (error); + _dbus_verbose ("No memory to create systemd message\n"); + goto out; + } + + dbus_message_set_no_reply (systemd_message, TRUE); + dbus_message_iter_init_append (systemd_message, &iter); + + if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", + &systemd_iter)) + { + BUS_SET_OOM (error); + _dbus_verbose ("No memory to open systemd message container\n"); + goto out; + } + } + + key_link = keys; + value_link = values; + while (key_link != NULL) + { + const char *key; + const char *value; + + key = key_link->data; + value = value_link->data; + + if (!bus_activation_set_environment_variable (activation, + key, value, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_verbose ("bus_activation_set_environment_variable() failed\n"); + break; + } + + if (systemd_message != NULL) + { + DBusString envline; + const char *s; + + /* SetEnvironment wants an array of KEY=VALUE strings */ + if (!_dbus_string_init (&envline) || + !_dbus_string_append_printf (&envline, "%s=%s", key, value)) + { + BUS_SET_OOM (error); + _dbus_verbose ("No memory to format systemd environment line\n"); + _dbus_string_free (&envline); + break; + } + + s = _dbus_string_get_data (&envline); + + if (!dbus_message_iter_append_basic (&systemd_iter, + DBUS_TYPE_STRING, &s)) + { + BUS_SET_OOM (error); + _dbus_verbose ("No memory to append systemd environment line\n"); + _dbus_string_free (&envline); + break; + } + + _dbus_string_free (&envline); + } + + key_link = _dbus_list_get_next_link (&keys, key_link); + value_link = _dbus_list_get_next_link (&values, value_link); + } + + /* FIXME: We can fail early having set only some of the environment variables, + * (because of OOM failure). It's sort of hard to fix and it doesn't really + * matter, so we're punting for now. + */ + if (key_link != NULL) + { + if (systemd_message != NULL) + dbus_message_iter_abandon_container (&iter, &systemd_iter); + goto out; + } + + if (systemd_message != NULL) + { + if (!dbus_message_iter_close_container (&iter, &systemd_iter)) + { + BUS_SET_OOM (error); + _dbus_verbose ("No memory to close systemd message container\n"); + goto out; + } + + if (!bus_driver_send_or_activate (transaction, systemd_message, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_verbose ("bus_driver_send_or_activate() failed\n"); + goto out; + } + } + + if (!send_ack_reply (connection, transaction, + message, error)) + goto out; + + retval = TRUE; + + out: + if (systemd_message != NULL) + dbus_message_unref (systemd_message); + _dbus_list_clear (&keys); + _dbus_list_clear (&values); + return retval; +} + +static dbus_bool_t +bus_driver_handle_add_match (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + BusMatchRule *rule; + const char *text, *bustype; + DBusString str; + BusMatchmaker *matchmaker; + BusContext *context; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + text = NULL; + rule = NULL; + + if (bus_connection_get_n_match_rules (connection) >= + bus_context_get_max_match_rules_per_connection (bus_transaction_get_context (transaction))) + { + dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED, + "Connection \"%s\" is not allowed to add more match rules " + "(increase limits in configuration file if required)", + bus_connection_is_active (connection) ? + bus_connection_get_name (connection) : + "(inactive)"); + goto failed; + } + + if (!dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &text, + DBUS_TYPE_INVALID)) + { + _dbus_verbose ("No memory to get arguments to AddMatch\n"); + goto failed; + } + + _dbus_string_init_const (&str, text); + + rule = bus_match_rule_parse (connection, &str, error); + if (rule == NULL) + goto failed; + + context = bus_transaction_get_context (transaction); + bustype = context ? bus_context_get_type (context) : NULL; + if (bus_match_rule_get_client_is_eavesdropping (rule) && + !bus_apparmor_allows_eavesdropping (connection, bustype, error)) + goto failed; + + matchmaker = bus_connection_get_matchmaker (connection); + + if (!bus_matchmaker_add_rule (matchmaker, rule)) + { + BUS_SET_OOM (error); + goto failed; + } + + if (!send_ack_reply (connection, transaction, + message, error)) + { + bus_matchmaker_remove_rule (matchmaker, rule); + goto failed; + } + + bus_match_rule_unref (rule); + + return TRUE; + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (rule) + bus_match_rule_unref (rule); + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_remove_match (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + BusMatchRule *rule; + const char *text; + DBusString str; + BusMatchmaker *matchmaker; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + text = NULL; + rule = NULL; + + if (!dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &text, + DBUS_TYPE_INVALID)) + { + _dbus_verbose ("No memory to get arguments to RemoveMatch\n"); + goto failed; + } + + _dbus_string_init_const (&str, text); + + rule = bus_match_rule_parse (connection, &str, error); + if (rule == NULL) + goto failed; + + /* Send the ack before we remove the rule, since the ack is undone + * on transaction cancel, but rule removal isn't. + */ + if (!send_ack_reply (connection, transaction, + message, error)) + goto failed; + + matchmaker = bus_connection_get_matchmaker (connection); + + if (!bus_matchmaker_remove_rule_by_value (matchmaker, rule, error)) + goto failed; + + bus_match_rule_unref (rule); + + return TRUE; + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (rule) + bus_match_rule_unref (rule); + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_get_service_owner (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + const char *text; + const char *base_name; + DBusString str; + BusRegistry *registry; + BusService *service; + DBusMessage *reply; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + registry = bus_connection_get_registry (connection); + + text = NULL; + reply = NULL; + + if (! dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &text, + DBUS_TYPE_INVALID)) + goto failed; + + _dbus_string_init_const (&str, text); + service = bus_registry_lookup (registry, &str); + if (service == NULL && + _dbus_string_equal_c_str (&str, DBUS_SERVICE_DBUS)) + { + /* ORG_FREEDESKTOP_DBUS owns itself */ + base_name = DBUS_SERVICE_DBUS; + } + else if (service == NULL) + { + dbus_set_error (error, + DBUS_ERROR_NAME_HAS_NO_OWNER, + "Could not get owner of name '%s': no such name", text); + goto failed; + } + else + { + base_name = bus_connection_get_name (bus_service_get_primary_owners_connection (service)); + if (base_name == NULL) + { + /* FIXME - how is this error possible? */ + dbus_set_error (error, + DBUS_ERROR_FAILED, + "Could not determine unique name for '%s'", text); + goto failed; + } + _dbus_assert (*base_name == ':'); + } + + _dbus_assert (base_name != NULL); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + if (! dbus_message_append_args (reply, + DBUS_TYPE_STRING, &base_name, + DBUS_TYPE_INVALID)) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + + return TRUE; + + oom: + BUS_SET_OOM (error); + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (reply) + dbus_message_unref (reply); + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_list_queued_owners (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + const char *text; + DBusList *base_names; + DBusList *link; + DBusString str; + BusRegistry *registry; + BusService *service; + DBusMessage *reply; + DBusMessageIter iter, array_iter; + char *dbus_service_name = DBUS_SERVICE_DBUS; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + registry = bus_connection_get_registry (connection); + + base_names = NULL; + text = NULL; + reply = NULL; + + if (! dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &text, + DBUS_TYPE_INVALID)) + goto failed; + + _dbus_string_init_const (&str, text); + service = bus_registry_lookup (registry, &str); + if (service == NULL && + _dbus_string_equal_c_str (&str, DBUS_SERVICE_DBUS)) + { + /* ORG_FREEDESKTOP_DBUS owns itself */ + if (! _dbus_list_append (&base_names, dbus_service_name)) + goto oom; + } + else if (service == NULL) + { + dbus_set_error (error, + DBUS_ERROR_NAME_HAS_NO_OWNER, + "Could not get owners of name '%s': no such name", text); + goto failed; + } + else + { + if (!bus_service_list_queued_owners (service, + &base_names, + error)) + goto failed; + } + + _dbus_assert (base_names != NULL); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + dbus_message_iter_init_append (reply, &iter); + if (!dbus_message_iter_open_container (&iter, + DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, + &array_iter)) + goto oom; + + link = _dbus_list_get_first_link (&base_names); + while (link != NULL) + { + char *uname; + + _dbus_assert (link->data != NULL); + uname = (char *)link->data; + + if (!dbus_message_iter_append_basic (&array_iter, + DBUS_TYPE_STRING, + &uname)) + goto oom; + + link = _dbus_list_get_next_link (&base_names, link); + } + + if (! dbus_message_iter_close_container (&iter, &array_iter)) + goto oom; + + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + + return TRUE; + + oom: + BUS_SET_OOM (error); + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (reply) + dbus_message_unref (reply); + + if (base_names) + _dbus_list_clear (&base_names); + + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_get_connection_unix_user (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusConnection *conn; + DBusMessage *reply; + dbus_uid_t uid; + dbus_uint32_t uid32; + const char *service; + BusDriverFound found; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = NULL; + + found = bus_driver_get_conn_helper (connection, message, "UID", &service, + &conn, error); + switch (found) + { + case BUS_DRIVER_FOUND_SELF: + uid = _dbus_getuid (); + break; + case BUS_DRIVER_FOUND_PEER: + if (!dbus_connection_get_unix_user (conn, &uid)) + uid = DBUS_UID_UNSET; + break; + case BUS_DRIVER_FOUND_ERROR: + goto failed; + } + + if (uid == DBUS_UID_UNSET) + { + dbus_set_error (error, + DBUS_ERROR_FAILED, + "Could not determine UID for '%s'", service); + goto failed; + } + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + uid32 = uid; + if (! dbus_message_append_args (reply, + DBUS_TYPE_UINT32, &uid32, + DBUS_TYPE_INVALID)) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + + return TRUE; + + oom: + BUS_SET_OOM (error); + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (reply) + dbus_message_unref (reply); + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusConnection *conn; + DBusMessage *reply; + dbus_pid_t pid; + dbus_uint32_t pid32; + const char *service; + BusDriverFound found; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = NULL; + + found = bus_driver_get_conn_helper (connection, message, "PID", &service, + &conn, error); + switch (found) + { + case BUS_DRIVER_FOUND_SELF: + pid = _dbus_getpid (); + break; + case BUS_DRIVER_FOUND_PEER: + if (!dbus_connection_get_unix_process_id (conn, &pid)) + pid = DBUS_PID_UNSET; + break; + case BUS_DRIVER_FOUND_ERROR: + goto failed; + } + + if (pid == DBUS_PID_UNSET) + { + dbus_set_error (error, + DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN, + "Could not determine PID for '%s'", service); + goto failed; + } + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + pid32 = pid; + if (! dbus_message_append_args (reply, + DBUS_TYPE_UINT32, &pid32, + DBUS_TYPE_INVALID)) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + + return TRUE; + + oom: + BUS_SET_OOM (error); + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (reply) + dbus_message_unref (reply); + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_get_adt_audit_session_data (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusConnection *conn; + DBusMessage *reply; + void *data = NULL; + dbus_uint32_t data_size; + const char *service; + BusDriverFound found; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = NULL; + + found = bus_driver_get_conn_helper (connection, message, "audit session data", + &service, &conn, error); + + if (found == BUS_DRIVER_FOUND_ERROR) + goto failed; + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + /* We don't know how to find "ADT audit session data" for the bus daemon + * itself. Is that even meaningful? + * FIXME: Implement this or briefly note it makes no sense. + */ + if (found != BUS_DRIVER_FOUND_PEER || + !dbus_connection_get_adt_audit_session_data (conn, &data, &data_size) || + data == NULL) + { + dbus_set_error (error, + DBUS_ERROR_ADT_AUDIT_DATA_UNKNOWN, + "Could not determine audit session data for '%s'", service); + goto failed; + } + + if (! dbus_message_append_args (reply, + DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &data, data_size, + DBUS_TYPE_INVALID)) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + + return TRUE; + + oom: + BUS_SET_OOM (error); + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (reply) + dbus_message_unref (reply); + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_get_connection_selinux_security_context (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusConnection *conn; + DBusMessage *reply; + BusSELinuxID *context; + const char *service; + BusDriverFound found; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = NULL; + + found = bus_driver_get_conn_helper (connection, message, "security context", + &service, &conn, error); + + if (found == BUS_DRIVER_FOUND_ERROR) + goto failed; + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + /* FIXME: Obtain the SELinux security context for the bus daemon itself */ + if (found == BUS_DRIVER_FOUND_PEER) + context = bus_connection_get_selinux_id (conn); + else + context = NULL; + + if (!context) + { + dbus_set_error (error, + DBUS_ERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN, + "Could not determine security context for '%s'", service); + goto failed; + } + + if (! bus_selinux_append_context (reply, context, error)) + goto failed; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + + return TRUE; + + oom: + BUS_SET_OOM (error); + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (reply) + dbus_message_unref (reply); + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_get_connection_credentials (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusConnection *conn; + DBusMessage *reply; + DBusMessageIter reply_iter; + DBusMessageIter array_iter; + unsigned long ulong_uid, ulong_pid; + char *s; + const char *service; + BusDriverFound found; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = NULL; + + found = bus_driver_get_conn_helper (connection, message, "credentials", + &service, &conn, error); + + switch (found) + { + case BUS_DRIVER_FOUND_SELF: + ulong_pid = _dbus_getpid (); + ulong_uid = _dbus_getuid (); + break; + + case BUS_DRIVER_FOUND_PEER: + if (!dbus_connection_get_unix_process_id (conn, &ulong_pid)) + ulong_pid = DBUS_PID_UNSET; + if (!dbus_connection_get_unix_user (conn, &ulong_uid)) + ulong_uid = DBUS_UID_UNSET; + break; + case BUS_DRIVER_FOUND_ERROR: + goto failed; + } + + reply = _dbus_asv_new_method_return (message, &reply_iter, &array_iter); + if (reply == NULL) + goto oom; + + /* we can't represent > 32-bit pids; if your system needs them, please + * add ProcessID64 to the spec or something */ + if (ulong_pid <= _DBUS_UINT32_MAX && ulong_pid != DBUS_PID_UNSET && + !_dbus_asv_add_uint32 (&array_iter, "ProcessID", ulong_pid)) + goto oom; + + /* we can't represent > 32-bit uids; if your system needs them, please + * add UnixUserID64 to the spec or something */ + if (ulong_uid <= _DBUS_UINT32_MAX && ulong_uid != DBUS_UID_UNSET && + !_dbus_asv_add_uint32 (&array_iter, "UnixUserID", ulong_uid)) + goto oom; + + /* FIXME: Obtain the Windows user of the bus daemon itself */ + if (found == BUS_DRIVER_FOUND_PEER && + dbus_connection_get_windows_user (conn, &s)) + { + DBusString str; + dbus_bool_t result; + + if (s == NULL) + goto oom; + + _dbus_string_init_const (&str, s); + result = _dbus_validate_utf8 (&str, 0, _dbus_string_get_length (&str)); + _dbus_string_free (&str); + if (result) + { + if (!_dbus_asv_add_string (&array_iter, "WindowsSID", s)) + { + dbus_free (s); + goto oom; + } + } + dbus_free (s); + } + + /* FIXME: Obtain the security label for the bus daemon itself */ + if (found == BUS_DRIVER_FOUND_PEER && + _dbus_connection_get_linux_security_label (conn, &s)) + { + if (s == NULL) + goto oom; + + /* use the GVariant bytestring convention for strings of unknown + * encoding: include the \0 in the payload, for zero-copy reading */ + if (!_dbus_asv_add_byte_array (&array_iter, "LinuxSecurityLabel", + s, strlen (s) + 1)) + { + dbus_free (s); + goto oom; + } + + dbus_free (s); + } + + if (!_dbus_asv_close (&reply_iter, &array_iter)) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + { + /* this time we don't want to close the iterator again, so just + * get rid of the message */ + dbus_message_unref (reply); + reply = NULL; + goto oom; + } + + dbus_message_unref (reply); + + return TRUE; + + oom: + BUS_SET_OOM (error); + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + + if (reply) + { + _dbus_asv_abandon (&reply_iter, &array_iter); + dbus_message_unref (reply); + } + + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_reload_config (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + BusContext *context; + DBusMessage *reply; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = NULL; + + context = bus_connection_get_context (connection); + if (!bus_context_reload_config (context, error)) + goto failed; + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + return TRUE; + + oom: + BUS_SET_OOM (error); + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (reply) + dbus_message_unref (reply); + return FALSE; +} + +#ifdef DBUS_ENABLE_VERBOSE_MODE +static dbus_bool_t +bus_driver_handle_enable_verbose (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply = NULL; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + _dbus_set_verbose(TRUE); + + dbus_message_unref (reply); + return TRUE; + + oom: + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + BUS_SET_OOM (error); + + if (reply) + dbus_message_unref (reply); + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_disable_verbose (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply = NULL; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + _dbus_set_verbose(FALSE); + + dbus_message_unref (reply); + return TRUE; + + oom: + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + BUS_SET_OOM (error); + + if (reply) + dbus_message_unref (reply); + return FALSE; +} +#endif + +static dbus_bool_t +bus_driver_handle_get_id (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + BusContext *context; + DBusMessage *reply; + DBusString uuid; + const char *v_STRING; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!_dbus_string_init (&uuid)) + { + BUS_SET_OOM (error); + return FALSE; + } + + reply = NULL; + + context = bus_connection_get_context (connection); + if (!bus_context_get_id (context, &uuid)) + goto oom; + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + v_STRING = _dbus_string_get_const_data (&uuid); + if (!dbus_message_append_args (reply, + DBUS_TYPE_STRING, &v_STRING, + DBUS_TYPE_INVALID)) + goto oom; + + _dbus_assert (dbus_message_has_signature (reply, "s")); + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + _dbus_string_free (&uuid); + dbus_message_unref (reply); + return TRUE; + + oom: + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + BUS_SET_OOM (error); + + if (reply) + dbus_message_unref (reply); + _dbus_string_free (&uuid); + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_become_monitor (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + char **match_rules = NULL; + const char *bustype; + BusContext *context; + BusMatchRule *rule; + DBusList *rules = NULL; + DBusList *iter; + DBusString str; + int i; + int n_match_rules; + dbus_uint32_t flags; + dbus_bool_t ret = FALSE; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!bus_driver_check_message_is_for_us (message, error)) + goto out; + + context = bus_transaction_get_context (transaction); + bustype = context ? bus_context_get_type (context) : NULL; + if (!bus_apparmor_allows_eavesdropping (connection, bustype, error)) + goto out; + + if (!bus_driver_check_caller_is_privileged (connection, transaction, + message, error)) + goto out; + + if (!dbus_message_get_args (message, error, + DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &match_rules, &n_match_rules, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID)) + goto out; + + if (flags != 0) + { + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "BecomeMonitor does not support any flags yet"); + goto out; + } + + /* Special case: a zero-length array becomes [""] */ + if (n_match_rules == 0) + { + match_rules = dbus_malloc (2 * sizeof (char *)); + + if (match_rules == NULL) + { + BUS_SET_OOM (error); + goto out; + } + + match_rules[0] = _dbus_strdup (""); + + if (match_rules[0] == NULL) + { + BUS_SET_OOM (error); + goto out; + } + + match_rules[1] = NULL; + n_match_rules = 1; + } + + for (i = 0; i < n_match_rules; i++) + { + _dbus_string_init_const (&str, match_rules[i]); + rule = bus_match_rule_parse (connection, &str, error); + + if (rule == NULL) + goto out; + + /* monitors always eavesdrop */ + bus_match_rule_set_client_is_eavesdropping (rule, TRUE); + + if (!_dbus_list_append (&rules, rule)) + { + BUS_SET_OOM (error); + bus_match_rule_unref (rule); + goto out; + } + } + + /* Send the ack before we remove the rule, since the ack is undone + * on transaction cancel, but becoming a monitor isn't. + */ + if (!send_ack_reply (connection, transaction, message, error)) + goto out; + + if (!bus_connection_be_monitor (connection, transaction, &rules, error)) + goto out; + + ret = TRUE; + +out: + if (ret) + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + else + _DBUS_ASSERT_ERROR_IS_SET (error); + + for (iter = _dbus_list_get_first_link (&rules); + iter != NULL; + iter = _dbus_list_get_next_link (&rules, iter)) + bus_match_rule_unref (iter->data); + + _dbus_list_clear (&rules); + + dbus_free_string_array (match_rules); + return ret; +} + +typedef struct +{ + const char *name; + const char *in_args; + const char *out_args; + dbus_bool_t (* handler) (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error); +} MessageHandler; + +/* For speed it might be useful to sort this in order of + * frequency of use (but doesn't matter with only a few items + * anyhow) + */ +static const MessageHandler dbus_message_handlers[] = { + { "Hello", + "", + DBUS_TYPE_STRING_AS_STRING, + bus_driver_handle_hello }, + { "RequestName", + DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING, + DBUS_TYPE_UINT32_AS_STRING, + bus_driver_handle_acquire_service }, + { "ReleaseName", + DBUS_TYPE_STRING_AS_STRING, + DBUS_TYPE_UINT32_AS_STRING, + bus_driver_handle_release_service }, + { "StartServiceByName", + DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING, + DBUS_TYPE_UINT32_AS_STRING, + bus_driver_handle_activate_service }, + { "UpdateActivationEnvironment", + DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING, + "", + bus_driver_handle_update_activation_environment }, + { "NameHasOwner", + DBUS_TYPE_STRING_AS_STRING, + DBUS_TYPE_BOOLEAN_AS_STRING, + bus_driver_handle_service_exists }, + { "ListNames", + "", + DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING, + bus_driver_handle_list_services }, + { "ListActivatableNames", + "", + DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING, + bus_driver_handle_list_activatable_services }, + { "AddMatch", + DBUS_TYPE_STRING_AS_STRING, + "", + bus_driver_handle_add_match }, + { "RemoveMatch", + DBUS_TYPE_STRING_AS_STRING, + "", + bus_driver_handle_remove_match }, + { "GetNameOwner", + DBUS_TYPE_STRING_AS_STRING, + DBUS_TYPE_STRING_AS_STRING, + bus_driver_handle_get_service_owner }, + { "ListQueuedOwners", + DBUS_TYPE_STRING_AS_STRING, + DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING, + bus_driver_handle_list_queued_owners }, + { "GetConnectionUnixUser", + DBUS_TYPE_STRING_AS_STRING, + DBUS_TYPE_UINT32_AS_STRING, + bus_driver_handle_get_connection_unix_user }, + { "GetConnectionUnixProcessID", + DBUS_TYPE_STRING_AS_STRING, + DBUS_TYPE_UINT32_AS_STRING, + bus_driver_handle_get_connection_unix_process_id }, + { "GetAdtAuditSessionData", + DBUS_TYPE_STRING_AS_STRING, + DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING, + bus_driver_handle_get_adt_audit_session_data }, + { "GetConnectionSELinuxSecurityContext", + DBUS_TYPE_STRING_AS_STRING, + DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING, + bus_driver_handle_get_connection_selinux_security_context }, + { "ReloadConfig", + "", + "", + bus_driver_handle_reload_config }, + { "GetId", + "", + DBUS_TYPE_STRING_AS_STRING, + bus_driver_handle_get_id }, + { "GetConnectionCredentials", "s", "a{sv}", + bus_driver_handle_get_connection_credentials }, + { NULL, NULL, NULL, NULL } +}; + +static dbus_bool_t bus_driver_handle_introspect (DBusConnection *, + BusTransaction *, DBusMessage *, DBusError *); + +static const MessageHandler introspectable_message_handlers[] = { + { "Introspect", "", DBUS_TYPE_STRING_AS_STRING, bus_driver_handle_introspect }, + { NULL, NULL, NULL, NULL } +}; + +static const MessageHandler monitoring_message_handlers[] = { + { "BecomeMonitor", "asu", "", bus_driver_handle_become_monitor }, + { NULL, NULL, NULL, NULL } +}; + +#ifdef DBUS_ENABLE_VERBOSE_MODE +static const MessageHandler verbose_message_handlers[] = { + { "EnableVerbose", "", "", bus_driver_handle_enable_verbose}, + { "DisableVerbose", "", "", bus_driver_handle_disable_verbose}, + { NULL, NULL, NULL, NULL } +}; +#endif + +#ifdef DBUS_ENABLE_STATS +static const MessageHandler stats_message_handlers[] = { + { "GetStats", "", "a{sv}", bus_stats_handle_get_stats }, + { "GetConnectionStats", "s", "a{sv}", bus_stats_handle_get_connection_stats }, + { "GetAllMatchRules", "", "a{sas}", bus_stats_handle_get_all_match_rules }, + { NULL, NULL, NULL, NULL } +}; +#endif + +typedef struct { + const char *name; + const MessageHandler *message_handlers; + const char *extra_introspection; +} InterfaceHandler; + +/* These should ideally be sorted by frequency of use, although it + * probably doesn't matter with this few items */ +static InterfaceHandler interface_handlers[] = { + { DBUS_INTERFACE_DBUS, dbus_message_handlers, + " <signal name=\"NameOwnerChanged\">\n" + " <arg type=\"s\"/>\n" + " <arg type=\"s\"/>\n" + " <arg type=\"s\"/>\n" + " </signal>\n" + " <signal name=\"NameLost\">\n" + " <arg type=\"s\"/>\n" + " </signal>\n" + " <signal name=\"NameAcquired\">\n" + " <arg type=\"s\"/>\n" + " </signal>\n" }, + { DBUS_INTERFACE_INTROSPECTABLE, introspectable_message_handlers, NULL }, + { DBUS_INTERFACE_MONITORING, monitoring_message_handlers, NULL }, +#ifdef DBUS_ENABLE_VERBOSE_MODE + { DBUS_INTERFACE_VERBOSE, verbose_message_handlers, NULL }, +#endif +#ifdef DBUS_ENABLE_STATS + { BUS_INTERFACE_STATS, stats_message_handlers, NULL }, +#endif + { NULL, NULL, NULL } +}; + +static dbus_bool_t +write_args_for_direction (DBusString *xml, + const char *signature, + dbus_bool_t in) +{ + DBusTypeReader typereader; + DBusString sigstr; + int current_type; + + _dbus_string_init_const (&sigstr, signature); + _dbus_type_reader_init_types_only (&typereader, &sigstr, 0); + + while ((current_type = _dbus_type_reader_get_current_type (&typereader)) != DBUS_TYPE_INVALID) + { + const DBusString *subsig; + int start, len; + + _dbus_type_reader_get_signature (&typereader, &subsig, &start, &len); + if (!_dbus_string_append_printf (xml, " <arg direction=\"%s\" type=\"", + in ? "in" : "out")) + goto oom; + if (!_dbus_string_append_len (xml, + _dbus_string_get_const_data (subsig) + start, + len)) + goto oom; + if (!_dbus_string_append (xml, "\"/>\n")) + goto oom; + + _dbus_type_reader_next (&typereader); + } + return TRUE; + oom: + return FALSE; +} + +dbus_bool_t +bus_driver_generate_introspect_string (DBusString *xml) +{ + const InterfaceHandler *ih; + const MessageHandler *mh; + + if (!_dbus_string_append (xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE)) + return FALSE; + if (!_dbus_string_append (xml, "<node>\n")) + return FALSE; + + for (ih = interface_handlers; ih->name != NULL; ih++) + { + if (!_dbus_string_append_printf (xml, " <interface name=\"%s\">\n", + ih->name)) + return FALSE; + + for (mh = ih->message_handlers; mh->name != NULL; mh++) + { + if (!_dbus_string_append_printf (xml, " <method name=\"%s\">\n", + mh->name)) + return FALSE; + + if (!write_args_for_direction (xml, mh->in_args, TRUE)) + return FALSE; + + if (!write_args_for_direction (xml, mh->out_args, FALSE)) + return FALSE; + + if (!_dbus_string_append (xml, " </method>\n")) + return FALSE; + } + + if (ih->extra_introspection != NULL && + !_dbus_string_append (xml, ih->extra_introspection)) + return FALSE; + + if (!_dbus_string_append (xml, " </interface>\n")) + return FALSE; + } + + if (!_dbus_string_append (xml, "</node>\n")) + return FALSE; + + return TRUE; +} + +static dbus_bool_t +bus_driver_handle_introspect (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusString xml; + DBusMessage *reply; + const char *v_STRING; + + _dbus_verbose ("Introspect() on bus driver\n"); + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = NULL; + + if (! dbus_message_get_args (message, error, + DBUS_TYPE_INVALID)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return FALSE; + } + + if (!_dbus_string_init (&xml)) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!bus_driver_generate_introspect_string (&xml)) + goto oom; + + v_STRING = _dbus_string_get_const_data (&xml); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + if (! dbus_message_append_args (reply, + DBUS_TYPE_STRING, &v_STRING, + DBUS_TYPE_INVALID)) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + _dbus_string_free (&xml); + + return TRUE; + + oom: + BUS_SET_OOM (error); + + if (reply) + dbus_message_unref (reply); + + _dbus_string_free (&xml); + + return FALSE; +} + +/* + * Set @error and return FALSE if the message is not directed to the + * dbus-daemon by its canonical object path. This is hardening against + * system services with poorly-written security policy files, which + * might allow sending dangerously broad equivalence classes of messages + * such as "anything with this assumed-to-be-safe object path". + * + * dbus-daemon is unusual in that it normally ignores the object path + * of incoming messages; we need to keep that behaviour for the "read" + * read-only method calls like GetConnectionUnixUser for backwards + * compatibility, but it seems safer to be more restrictive for things + * intended to be root-only or privileged-developers-only. + * + * It is possible that there are other system services with the same + * quirk as dbus-daemon. + */ +dbus_bool_t +bus_driver_check_message_is_for_us (DBusMessage *message, + DBusError *error) +{ + if (!dbus_message_has_path (message, DBUS_PATH_DBUS)) + { + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "Method '%s' is only available at the canonical object path '%s'", + dbus_message_get_member (message), DBUS_PATH_DBUS); + + return FALSE; + } + + return TRUE; +} + +dbus_bool_t +bus_driver_handle_message (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + const char *name, *interface; + const InterfaceHandler *ih; + const MessageHandler *mh; + dbus_bool_t found_interface = FALSE; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (dbus_message_is_signal (message, "org.freedesktop.systemd1.Activator", "ActivationFailure")) + { + BusContext *context; + DBusConnection *systemd; + + /* This is a directed signal, not a method call, so the log message + * is a little weird (it talks about "calling" ActivationFailure), + * but it's close enough */ + if (!bus_driver_check_caller_is_privileged (connection, + transaction, + message, + error)) + return FALSE; + + context = bus_connection_get_context (connection); + systemd = bus_driver_get_owner_of_name (connection, + "org.freedesktop.systemd1"); + + if (systemd != connection) + { + const char *attacker; + + attacker = bus_connection_get_name (connection); + bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, + "Ignoring forged ActivationFailure message from " + "connection %s (%s)", + attacker ? attacker : "(unauthenticated)", + bus_connection_get_loginfo (connection)); + /* ignore it */ + return TRUE; + } + + if (!bus_context_get_systemd_activation (context)) + { + bus_context_log (context, DBUS_SYSTEM_LOG_WARNING, + "Ignoring unexpected ActivationFailure message " + "while not using systemd activation"); + return FALSE; + } + + return dbus_activation_systemd_failure(bus_context_get_activation(context), message); + } + + if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL) + { + _dbus_verbose ("Driver got a non-method-call message, ignoring\n"); + return TRUE; /* we just ignore this */ + } + + /* may be NULL, which means "any interface will do" */ + interface = dbus_message_get_interface (message); + + _dbus_assert (dbus_message_get_member (message) != NULL); + + name = dbus_message_get_member (message); + + _dbus_verbose ("Driver got a method call: %s\n", name); + + /* security checks should have kept this from getting here */ + _dbus_assert (dbus_message_get_sender (message) != NULL || + strcmp (name, "Hello") == 0); + + for (ih = interface_handlers; ih->name != NULL; ih++) + { + if (interface != NULL && strcmp (interface, ih->name) != 0) + continue; + + found_interface = TRUE; + + for (mh = ih->message_handlers; mh->name != NULL; mh++) + { + if (strcmp (mh->name, name) != 0) + continue; + + _dbus_verbose ("Found driver handler for %s\n", name); + + if (!dbus_message_has_signature (message, mh->in_args)) + { + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + _dbus_verbose ("Call to %s has wrong args (%s, expected %s)\n", + name, dbus_message_get_signature (message), + mh->in_args); + + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "Call to %s has wrong args (%s, expected %s)\n", + name, dbus_message_get_signature (message), + mh->in_args); + _DBUS_ASSERT_ERROR_IS_SET (error); + return FALSE; + } + + if ((* mh->handler) (connection, transaction, message, error)) + { + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + _dbus_verbose ("Driver handler succeeded\n"); + return TRUE; + } + else + { + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_verbose ("Driver handler returned failure\n"); + return FALSE; + } + } + } + + _dbus_verbose ("No driver handler for message \"%s\"\n", + name); + + dbus_set_error (error, found_interface ? DBUS_ERROR_UNKNOWN_METHOD : DBUS_ERROR_UNKNOWN_INTERFACE, + "%s does not understand message %s", + DBUS_SERVICE_DBUS, name); + + return FALSE; +} + +void +bus_driver_remove_connection (DBusConnection *connection) +{ + /* FIXME 1.0 Does nothing for now, should unregister the connection + * with the bus driver. + */ +}
diff --git a/bus/driver.h b/bus/driver.h new file mode 100644 index 0000000..201709c --- /dev/null +++ b/bus/driver.h
@@ -0,0 +1,52 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* driver.h Bus client (driver) + * + * Copyright (C) 2003 CodeFactory AB + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_DRIVER_H +#define BUS_DRIVER_H + +#include <dbus/dbus.h> +#include "connection.h" + +void bus_driver_remove_connection (DBusConnection *connection); +dbus_bool_t bus_driver_handle_message (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error); +dbus_bool_t bus_driver_send_service_lost (DBusConnection *connection, + const char *service_name, + BusTransaction *transaction, + DBusError *error); +dbus_bool_t bus_driver_send_service_acquired (DBusConnection *connection, + const char *service_name, + BusTransaction *transaction, + DBusError *error); +dbus_bool_t bus_driver_send_service_owner_changed (const char *service_name, + const char *old_owner, + const char *new_owner, + BusTransaction *transaction, + DBusError *error); +dbus_bool_t bus_driver_generate_introspect_string (DBusString *xml); +dbus_bool_t bus_driver_check_message_is_for_us (DBusMessage *message, + DBusError *error); + +#endif /* BUS_DRIVER_H */
diff --git a/bus/example-session-disable-stats.conf.in b/bus/example-session-disable-stats.conf.in new file mode 100644 index 0000000..2863ef0 --- /dev/null +++ b/bus/example-session-disable-stats.conf.in
@@ -0,0 +1,15 @@ +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> +<busconfig> + + <!-- If the Stats interface was enabled at compile-time, users can use it on + the session bus by default. Systems providing isolation of processes + with LSMs might want to restrict this. This can be achieved by copying + this file in @EXPANDED_SYSCONFDIR@/dbus-1/session.d/ --> + + <policy context="default"> + <deny send_destination="org.freedesktop.DBus" + send_interface="org.freedesktop.DBus.Debug.Stats"/> + </policy> + +</busconfig>
diff --git a/bus/example-system-enable-stats.conf.in b/bus/example-system-enable-stats.conf.in new file mode 100644 index 0000000..a85aa83 --- /dev/null +++ b/bus/example-system-enable-stats.conf.in
@@ -0,0 +1,15 @@ +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> +<busconfig> + + <!-- If the Stats interface was enabled at compile-time, only root may use it. + Replace USERNAME and copy this file in @EXPANDED_SYSCONFDIR@/dbus-1/system.d/ + if you want to enable other privileged users to view statistics and + debug info --> + + <policy user="USERNAME"> + <allow send_destination="org.freedesktop.DBus" + send_interface="org.freedesktop.DBus.Debug.Stats"/> + </policy> + +</busconfig>
diff --git a/bus/expirelist.c b/bus/expirelist.c new file mode 100644 index 0000000..9a3886e --- /dev/null +++ b/bus/expirelist.c
@@ -0,0 +1,402 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* expirelist.c List of items that expire + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "expirelist.h" +#include "test.h" +#include <dbus/dbus-internals.h> +#include <dbus/dbus-mainloop.h> +#include <dbus/dbus-timeout.h> + +struct BusExpireList +{ + DBusList *items; /**< List of BusExpireItem */ + DBusTimeout *timeout; + DBusLoop *loop; + BusExpireFunc expire_func; + void *data; + int expire_after; /**< Expire after milliseconds (thousandths) */ +}; + +static dbus_bool_t expire_timeout_handler (void *data); + +BusExpireList* +bus_expire_list_new (DBusLoop *loop, + int expire_after, + BusExpireFunc expire_func, + void *data) +{ + BusExpireList *list; + + list = dbus_new0 (BusExpireList, 1); + if (list == NULL) + return NULL; + + list->expire_func = expire_func; + list->data = data; + list->loop = loop; + list->expire_after = expire_after; + + list->timeout = _dbus_timeout_new (100, /* irrelevant */ + expire_timeout_handler, + list, NULL); + if (list->timeout == NULL) + goto failed; + + _dbus_timeout_set_enabled (list->timeout, FALSE); + + if (!_dbus_loop_add_timeout (list->loop, list->timeout)) + goto failed; + + return list; + + failed: + if (list->timeout) + _dbus_timeout_unref (list->timeout); + + dbus_free (list); + + return NULL; +} + +void +bus_expire_list_free (BusExpireList *list) +{ + _dbus_assert (list->items == NULL); + + _dbus_loop_remove_timeout (list->loop, list->timeout); + + _dbus_timeout_unref (list->timeout); + + dbus_free (list); +} + +void +bus_expire_timeout_set_interval (DBusTimeout *timeout, + int next_interval) +{ + if (next_interval >= 0) + { + _dbus_timeout_set_interval (timeout, + next_interval); + _dbus_timeout_set_enabled (timeout, TRUE); + + _dbus_verbose ("Enabled an expire timeout with interval %d\n", + next_interval); + } + else if (dbus_timeout_get_enabled (timeout)) + { + _dbus_timeout_set_enabled (timeout, FALSE); + + _dbus_verbose ("Disabled an expire timeout\n"); + } + else + _dbus_verbose ("No need to disable this expire timeout\n"); +} + +void +bus_expire_list_recheck_immediately (BusExpireList *list) +{ + _dbus_verbose ("setting interval on expire list to 0 for immediate recheck\n"); + + bus_expire_timeout_set_interval (list->timeout, 0); +} + +static int +do_expiration_with_monotonic_time (BusExpireList *list, + long tv_sec, + long tv_usec) +{ + DBusList *link; + int next_interval, min_wait_time, items_to_expire; + + next_interval = -1; + min_wait_time = 3600 * 1000; /* this is reset anyway if used */ + items_to_expire = 0; + + link = _dbus_list_get_first_link (&list->items); + while (link != NULL) + { + DBusList *next = _dbus_list_get_next_link (&list->items, link); + double elapsed; + BusExpireItem *item; + + item = link->data; + + elapsed = ELAPSED_MILLISECONDS_SINCE (item->added_tv_sec, + item->added_tv_usec, + tv_sec, tv_usec); + + if (((item->added_tv_sec == 0) && (item->added_tv_usec == 0)) || + ((list->expire_after > 0) && (elapsed >= (double) list->expire_after))) + { + _dbus_verbose ("Expiring an item %p\n", item); + + /* If the expire function fails, we just end up expiring + * this item next time we walk through the list. This would + * be an indeterminate time normally, so we set up the + * next_interval to be "shortly" (just enough to avoid + * a busy loop) + */ + if (!(* list->expire_func) (list, link, list->data)) + { + next_interval = _dbus_get_oom_wait (); + break; + } + } + else if (list->expire_after > 0) + { + double to_wait; + + items_to_expire = 1; + to_wait = (double) list->expire_after - elapsed; + if (min_wait_time > to_wait) + min_wait_time = to_wait; + } + + link = next; + } + + if (next_interval < 0 && items_to_expire) + next_interval = min_wait_time; + + return next_interval; +} + +static void +bus_expirelist_expire (BusExpireList *list) +{ + int next_interval; + + next_interval = -1; + + if (list->items != NULL) + { + long tv_sec, tv_usec; + + _dbus_get_monotonic_time (&tv_sec, &tv_usec); + + next_interval = do_expiration_with_monotonic_time (list, tv_sec, tv_usec); + } + + bus_expire_timeout_set_interval (list->timeout, next_interval); +} + +static dbus_bool_t +expire_timeout_handler (void *data) +{ + BusExpireList *list = data; + + _dbus_verbose ("Running\n"); + + /* note that this may remove the timeout */ + bus_expirelist_expire (list); + + return TRUE; +} + +void +bus_expire_list_remove_link (BusExpireList *list, + DBusList *link) +{ + _dbus_list_remove_link (&list->items, link); +} + +dbus_bool_t +bus_expire_list_remove (BusExpireList *list, + BusExpireItem *item) +{ + return _dbus_list_remove (&list->items, item); +} + +void +bus_expire_list_unlink (BusExpireList *list, + DBusList *link) +{ + _dbus_list_unlink (&list->items, link); +} + +dbus_bool_t +bus_expire_list_add (BusExpireList *list, + BusExpireItem *item) +{ + dbus_bool_t ret; + + ret = _dbus_list_prepend (&list->items, item); + if (ret && !dbus_timeout_get_enabled (list->timeout)) + bus_expire_timeout_set_interval (list->timeout, 0); + + return ret; +} + +void +bus_expire_list_add_link (BusExpireList *list, + DBusList *link) +{ + _dbus_assert (link->data != NULL); + + _dbus_list_prepend_link (&list->items, link); + + if (!dbus_timeout_get_enabled (list->timeout)) + bus_expire_timeout_set_interval (list->timeout, 0); +} + +DBusList* +bus_expire_list_get_first_link (BusExpireList *list) +{ + return _dbus_list_get_first_link (&list->items); +} + +DBusList* +bus_expire_list_get_next_link (BusExpireList *list, + DBusList *link) +{ + return _dbus_list_get_next_link (&list->items, link); +} + +dbus_bool_t +bus_expire_list_contains_item (BusExpireList *list, + BusExpireItem *item) +{ + return _dbus_list_find_last (&list->items, item) != NULL; +} + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + +typedef struct +{ + BusExpireItem item; + int expire_count; +} TestExpireItem; + +static dbus_bool_t +test_expire_func (BusExpireList *list, + DBusList *link, + void *data) +{ + TestExpireItem *t; + + t = (TestExpireItem*) link->data; + + t->expire_count += 1; + + return TRUE; +} + +static void +time_add_milliseconds (long *tv_sec, + long *tv_usec, + int milliseconds) +{ + *tv_sec = *tv_sec + milliseconds / 1000; + *tv_usec = *tv_usec + milliseconds * 1000; + if (*tv_usec >= 1000000) + { + *tv_usec -= 1000000; + *tv_sec += 1; + } +} + +dbus_bool_t +bus_expire_list_test (const DBusString *test_data_dir) +{ + DBusLoop *loop; + BusExpireList *list; + long tv_sec, tv_usec; + long tv_sec_not_expired, tv_usec_not_expired; + long tv_sec_expired, tv_usec_expired; + long tv_sec_past, tv_usec_past; + TestExpireItem *item; + int next_interval; + dbus_bool_t result = FALSE; + + + loop = _dbus_loop_new (); + _dbus_assert (loop != NULL); + +#define EXPIRE_AFTER 100 + + list = bus_expire_list_new (loop, EXPIRE_AFTER, + test_expire_func, NULL); + _dbus_assert (list != NULL); + + _dbus_get_monotonic_time (&tv_sec, &tv_usec); + + tv_sec_not_expired = tv_sec; + tv_usec_not_expired = tv_usec; + time_add_milliseconds (&tv_sec_not_expired, + &tv_usec_not_expired, EXPIRE_AFTER - 1); + + tv_sec_expired = tv_sec; + tv_usec_expired = tv_usec; + time_add_milliseconds (&tv_sec_expired, + &tv_usec_expired, EXPIRE_AFTER); + + + tv_sec_past = tv_sec - 1; + tv_usec_past = tv_usec; + + item = dbus_new0 (TestExpireItem, 1); + + if (item == NULL) + goto oom; + + item->item.added_tv_sec = tv_sec; + item->item.added_tv_usec = tv_usec; + if (!bus_expire_list_add (list, &item->item)) + _dbus_assert_not_reached ("out of memory"); + + next_interval = + do_expiration_with_monotonic_time (list, tv_sec_not_expired, + tv_usec_not_expired); + _dbus_assert (item->expire_count == 0); + _dbus_verbose ("next_interval = %d\n", next_interval); + _dbus_assert (next_interval == 1); + + next_interval = + do_expiration_with_monotonic_time (list, tv_sec_expired, + tv_usec_expired); + _dbus_assert (item->expire_count == 1); + _dbus_verbose ("next_interval = %d\n", next_interval); + _dbus_assert (next_interval == -1); + + next_interval = + do_expiration_with_monotonic_time (list, tv_sec_past, + tv_usec_past); + _dbus_assert (item->expire_count == 1); + _dbus_verbose ("next_interval = %d\n", next_interval); + _dbus_assert (next_interval == 1000 + EXPIRE_AFTER); + + bus_expire_list_remove (list, &item->item); + dbus_free (item); + + bus_expire_list_free (list); + _dbus_loop_unref (loop); + + result = TRUE; + + oom: + return result; +} + +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/bus/expirelist.h b/bus/expirelist.h new file mode 100644 index 0000000..887cb97 --- /dev/null +++ b/bus/expirelist.h
@@ -0,0 +1,80 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* expirelist.h List of stuff that expires + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_EXPIRE_LIST_H +#define BUS_EXPIRE_LIST_H + +#include <dbus/dbus.h> +#include <dbus/dbus-list.h> +#include <dbus/dbus-mainloop.h> + +typedef struct BusExpireList BusExpireList; +typedef struct BusExpireItem BusExpireItem; + +typedef dbus_bool_t (* BusExpireFunc) (BusExpireList *list, + DBusList *link, + void *data); + + +/* embed this in a child expire item struct */ +struct BusExpireItem +{ + long added_tv_sec; /**< Time we were added (seconds component) */ + long added_tv_usec; /**< Time we were added (microsec component) */ +}; + +BusExpireList* bus_expire_list_new (DBusLoop *loop, + int expire_after, + BusExpireFunc expire_func, + void *data); +void bus_expire_list_free (BusExpireList *list); +void bus_expire_list_recheck_immediately (BusExpireList *list); +void bus_expire_list_remove_link (BusExpireList *list, + DBusList *link); +dbus_bool_t bus_expire_list_remove (BusExpireList *list, + BusExpireItem *item); +DBusList* bus_expire_list_get_first_link (BusExpireList *list); +DBusList* bus_expire_list_get_next_link (BusExpireList *list, + DBusList *link); +dbus_bool_t bus_expire_list_add (BusExpireList *list, + BusExpireItem *item); +void bus_expire_list_add_link (BusExpireList *list, + DBusList *link); +dbus_bool_t bus_expire_list_contains_item (BusExpireList *list, + BusExpireItem *item); +void bus_expire_list_unlink (BusExpireList *list, + DBusList *link); + +/* this macro and function are semi-related utility functions, not really part of the + * BusExpireList API + */ + +#define ELAPSED_MILLISECONDS_SINCE(orig_tv_sec, orig_tv_usec, \ + now_tv_sec, now_tv_usec) \ + (((double) (now_tv_sec) - (double) (orig_tv_sec)) * 1000.0 + \ + ((double) (now_tv_usec) - (double) (orig_tv_usec)) / 1000.0) + +void bus_expire_timeout_set_interval (DBusTimeout *timeout, + int next_interval); + +#endif /* BUS_EXPIRE_LIST_H */
diff --git a/bus/legacy-config/session.conf.in b/bus/legacy-config/session.conf.in new file mode 100644 index 0000000..b35024e --- /dev/null +++ b/bus/legacy-config/session.conf.in
@@ -0,0 +1,19 @@ +<!-- +This configuration file is no longer required and may be removed. + +In older versions of dbus, this file defined the behaviour of the well-known +session bus. That behaviour is now determined by +@DATADIR_FROM_PKGSYSCONFDIR@/dbus-1/session.conf, which should not be edited. + +For local configuration changes, create a file +session-local.conf or files matching session.d/*.conf in the same directory +as this one, with a <busconfig> element containing configuration directives. +These directives can override D-Bus or OS defaults. + +For upstream or distribution-wide defaults that can be overridden +by a local sysadmin, create files matching +@DATADIR_FROM_PKGSYSCONFDIR@/dbus-1/session.d/*.conf instead. +--> +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> +<busconfig></busconfig>
diff --git a/bus/legacy-config/system.conf.in b/bus/legacy-config/system.conf.in new file mode 100644 index 0000000..17aba08 --- /dev/null +++ b/bus/legacy-config/system.conf.in
@@ -0,0 +1,19 @@ +<!-- +This configuration file is no longer required and may be removed. + +In older versions of dbus, this file defined the behaviour of the well-known +system bus. That behaviour is now determined by +@DATADIR_FROM_PKGSYSCONFDIR@/dbus-1/system.conf, which should not be edited. + +For local configuration changes, create a file +system-local.conf or files matching system.d/*.conf in the same directory +as this one, with a <busconfig> element containing configuration directives. +These directives can override D-Bus or OS defaults. + +For upstream or distribution-wide defaults that can be overridden +by a local sysadmin, create files matching +@DATADIR_FROM_PKGSYSCONFDIR@/dbus-1/system.d/*.conf instead. +--> +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> +<busconfig></busconfig>
diff --git a/bus/main.c b/bus/main.c new file mode 100644 index 0000000..c38f252 --- /dev/null +++ b/bus/main.c
@@ -0,0 +1,693 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* main.c main() for message bus + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "bus.h" +#include "driver.h" +#include <dbus/dbus-internals.h> +#include <dbus/dbus-watch.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#ifdef HAVE_SIGNAL_H +#include <signal.h> +#endif +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif +#ifdef HAVE_UNISTD_H +#include <unistd.h> /* for write() and STDERR_FILENO */ +#endif +#include "selinux.h" +#include "apparmor.h" +#include "audit.h" + +#ifdef DBUS_UNIX +#include <dbus/dbus-sysdeps-unix.h> +#endif + +static BusContext *context; + +#ifdef DBUS_UNIX + +/* Despite its name and its unidirectional nature, this is actually + * a socket pair. */ +static DBusSocket reload_pipe[2]; +#define RELOAD_READ_END 0 +#define RELOAD_WRITE_END 1 + +static void close_reload_pipe (DBusWatch **); + +typedef enum + { + ACTION_RELOAD = 'r', + ACTION_QUIT = 'q' + } SignalAction; + +static void +signal_handler (int sig) +{ + switch (sig) + { + case SIGHUP: + { + DBusString str; + char action[2] = { ACTION_RELOAD, '\0' }; + + _dbus_string_init_const (&str, action); + if ((reload_pipe[RELOAD_WRITE_END].fd > 0) && + !_dbus_write_socket (reload_pipe[RELOAD_WRITE_END], &str, 0, 1)) + { + /* If we receive SIGHUP often enough to fill the pipe buffer (4096 + * times on old Linux, 65536 on modern Linux) before it can be + * drained, let's just warn and ignore. The configuration will be + * reloaded while draining the pipe buffer, which is what we + * wanted. It's harmless that it will be reloaded fewer times than + * we asked for, since the reload is delayed anyway, so new changes + * will be picked up. + * + * We use write() because _dbus_warn uses vfprintf, which isn't + * async-signal-safe. + * + * This is necessarily Unix-specific, but so are POSIX signals, + * so... */ + static const char message[] = + "Unable to write to reload pipe - buffer full?\n"; + + if (write (STDERR_FILENO, message, strlen (message)) != + (ssize_t) strlen (message)) + { + /* ignore failure to write out a warning */ + } + } + } + break; + + case SIGTERM: + { + DBusString str; + char action[2] = { ACTION_QUIT, '\0' }; + _dbus_string_init_const (&str, action); + if ((reload_pipe[RELOAD_WRITE_END].fd < 0) || + !_dbus_write_socket (reload_pipe[RELOAD_WRITE_END], &str, 0, 1)) + { + /* If we can't write to the socket, dying seems a more + * important response to SIGTERM than cleaning up sockets, + * so we exit. We'd use exit(), but that's not async-signal-safe, + * so we'll have to resort to _exit(). */ + static const char message[] = + "Unable to write termination signal to pipe - buffer full?\n" + "Will exit instead.\n"; + + if (write (STDERR_FILENO, message, strlen (message)) != + (ssize_t) strlen (message)) + { + /* ignore failure to write out a warning */ + } + _exit (1); + } + } + break; + } +} +#endif /* DBUS_UNIX */ + +static void +usage (void) +{ + fprintf (stderr, + DBUS_DAEMON_NAME + " [--version]" + " [--session]" + " [--system]" + " [--config-file=FILE]" + " [--print-address[=DESCRIPTOR]]" + " [--print-pid[=DESCRIPTOR]]" + " [--introspect]" + " [--address=ADDRESS]" + " [--nopidfile]" + " [--nofork]" +#ifdef DBUS_UNIX + " [--fork]" + " [--systemd-activation]" +#endif + "\n"); + exit (1); +} + +static void +version (void) +{ + printf ("D-Bus Message Bus Daemon %s\n" + "Copyright (C) 2002, 2003 Red Hat, Inc., CodeFactory AB, and others\n" + "This is free software; see the source for copying conditions.\n" + "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n", + DBUS_VERSION_STRING); + exit (0); +} + +static void +introspect (void) +{ + DBusString xml; + const char *v_STRING; + + if (!_dbus_string_init (&xml)) + goto oom; + + if (!bus_driver_generate_introspect_string (&xml)) + { + _dbus_string_free (&xml); + goto oom; + } + + v_STRING = _dbus_string_get_const_data (&xml); + printf ("%s\n", v_STRING); + + exit (0); + + oom: + _dbus_warn ("Can not introspect - Out of memory\n"); + exit (1); +} + +static void +check_two_config_files (const DBusString *config_file, + const char *extra_arg) +{ + if (_dbus_string_get_length (config_file) > 0) + { + fprintf (stderr, "--%s specified but configuration file %s already requested\n", + extra_arg, _dbus_string_get_const_data (config_file)); + exit (1); + } +} + +static void +check_two_addresses (const DBusString *address, + const char *extra_arg) +{ + if (_dbus_string_get_length (address) > 0) + { + fprintf (stderr, "--%s specified but address %s already requested\n", + extra_arg, _dbus_string_get_const_data (address)); + exit (1); + } +} + +static void +check_two_addr_descriptors (const DBusString *addr_fd, + const char *extra_arg) +{ + if (_dbus_string_get_length (addr_fd) > 0) + { + fprintf (stderr, "--%s specified but printing address to %s already requested\n", + extra_arg, _dbus_string_get_const_data (addr_fd)); + exit (1); + } +} + +static void +check_two_pid_descriptors (const DBusString *pid_fd, + const char *extra_arg) +{ + if (_dbus_string_get_length (pid_fd) > 0) + { + fprintf (stderr, "--%s specified but printing pid to %s already requested\n", + extra_arg, _dbus_string_get_const_data (pid_fd)); + exit (1); + } +} + +#ifdef DBUS_UNIX +static dbus_bool_t +handle_reload_watch (DBusWatch *watch, + unsigned int flags, + void *data) +{ + DBusError error; + DBusString str; + char *action_str; + char action = '\0'; + + while (!_dbus_string_init (&str)) + _dbus_wait_for_memory (); + + if ((reload_pipe[RELOAD_READ_END].fd > 0) && + _dbus_read_socket (reload_pipe[RELOAD_READ_END], &str, 1) != 1) + { + _dbus_warn ("Couldn't read from reload pipe.\n"); + close_reload_pipe (&watch); + return TRUE; + } + + action_str = _dbus_string_get_data (&str); + if (action_str != NULL) + { + action = action_str[0]; + } + _dbus_string_free (&str); + + /* this can only fail if we don't understand the config file + * or OOM. Either way we should just stick with the currently + * loaded config. + */ + dbus_error_init (&error); + + switch (action) + { + case ACTION_RELOAD: + if (! bus_context_reload_config (context, &error)) + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + _dbus_assert (dbus_error_has_name (&error, DBUS_ERROR_FAILED) || + dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)); + _dbus_warn ("Unable to reload configuration: %s\n", + error.message); + dbus_error_free (&error); + } + break; + + case ACTION_QUIT: + { + DBusLoop *loop; + /* + * On OSs without abstract sockets, we want to quit + * gracefully rather than being killed by SIGTERM, + * so that DBusServer gets a chance to clean up the + * sockets from the filesystem. fd.o #38656 + */ + loop = bus_context_get_loop (context); + if (loop != NULL) + { + _dbus_loop_quit (loop); + } + } + break; + + default: + break; + } + + return TRUE; +} + +static void +setup_reload_pipe (DBusLoop *loop) +{ + DBusError error; + DBusWatch *watch; + + dbus_error_init (&error); + + if (!_dbus_socketpair (&reload_pipe[0], &reload_pipe[1], + TRUE, &error)) + { + _dbus_warn ("Unable to create reload pipe: %s\n", + error.message); + dbus_error_free (&error); + exit (1); + } + + watch = _dbus_watch_new (_dbus_socket_get_pollable (reload_pipe[RELOAD_READ_END]), + DBUS_WATCH_READABLE, TRUE, + handle_reload_watch, NULL, NULL); + + if (watch == NULL) + { + _dbus_warn ("Unable to create reload watch: %s\n", + error.message); + dbus_error_free (&error); + exit (1); + } + + if (!_dbus_loop_add_watch (loop, watch)) + { + _dbus_warn ("Unable to add reload watch to main loop: %s\n", + error.message); + dbus_error_free (&error); + exit (1); + } + +} + +static void +close_reload_pipe (DBusWatch **watch) +{ + _dbus_loop_remove_watch (bus_context_get_loop (context), *watch); + _dbus_watch_invalidate (*watch); + _dbus_watch_unref (*watch); + *watch = NULL; + + _dbus_close_socket (reload_pipe[RELOAD_READ_END], NULL); + _dbus_socket_invalidate (&reload_pipe[RELOAD_READ_END]); + + _dbus_close_socket (reload_pipe[RELOAD_WRITE_END], NULL); + _dbus_socket_invalidate (&reload_pipe[RELOAD_WRITE_END]); +} +#endif /* DBUS_UNIX */ + +int +main (int argc, char **argv) +{ + DBusError error; + DBusString config_file; + DBusString address; + DBusString addr_fd; + DBusString pid_fd; + const char *prev_arg; + DBusPipe print_addr_pipe; + DBusPipe print_pid_pipe; + int i; + dbus_bool_t print_address; + dbus_bool_t print_pid; + BusContextFlags flags; +#ifdef DBUS_UNIX + const char *error_str; + + /* Redirect stdin from /dev/null since we will never need it, and + * redirect stdout and stderr to /dev/null if not already open. + * + * We should do this as the very first thing, to ensure that when we + * create other file descriptors (for example for epoll, inotify or + * a socket), they never get assigned as fd 0, 1 or 2. If they were, + * which could happen if our caller had (incorrectly) closed those + * standard fds, they'd get closed when we daemonize - for example, + * closing our listening socket would stop us listening, and closing + * a Linux epoll socket would cause the main loop to fail. */ + if (!_dbus_ensure_standard_fds (DBUS_FORCE_STDIN_NULL, &error_str)) + { + fprintf (stderr, + "dbus-daemon: fatal error setting up standard fds: %s: %s\n", + error_str, _dbus_strerror (errno)); + return 1; + } +#endif + + if (!_dbus_string_init (&config_file)) + return 1; + + if (!_dbus_string_init (&address)) + return 1; + + if (!_dbus_string_init (&addr_fd)) + return 1; + + if (!_dbus_string_init (&pid_fd)) + return 1; + + print_address = FALSE; + print_pid = FALSE; + + flags = BUS_CONTEXT_FLAG_WRITE_PID_FILE; + + prev_arg = NULL; + i = 1; + while (i < argc) + { + const char *arg = argv[i]; + + if (strcmp (arg, "--help") == 0 || + strcmp (arg, "-h") == 0 || + strcmp (arg, "-?") == 0) + { + usage (); + } + else if (strcmp (arg, "--version") == 0) + { + version (); + } + else if (strcmp (arg, "--introspect") == 0) + { + introspect (); + } + else if (strcmp (arg, "--nofork") == 0) + { + flags &= ~BUS_CONTEXT_FLAG_FORK_ALWAYS; + flags |= BUS_CONTEXT_FLAG_FORK_NEVER; + } +#ifdef DBUS_UNIX + else if (strcmp (arg, "--fork") == 0) + { + flags &= ~BUS_CONTEXT_FLAG_FORK_NEVER; + flags |= BUS_CONTEXT_FLAG_FORK_ALWAYS; + } + else if (strcmp (arg, "--systemd-activation") == 0) + { + flags |= BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION; + } +#endif + else if (strcmp (arg, "--nopidfile") == 0) + { + flags &= ~BUS_CONTEXT_FLAG_WRITE_PID_FILE; + } + else if (strcmp (arg, "--system") == 0) + { + check_two_config_files (&config_file, "system"); + + if (!_dbus_append_system_config_file (&config_file)) + exit (1); + } + else if (strcmp (arg, "--session") == 0) + { + check_two_config_files (&config_file, "session"); + + if (!_dbus_append_session_config_file (&config_file)) + exit (1); + } + else if (strstr (arg, "--config-file=") == arg) + { + const char *file; + + check_two_config_files (&config_file, "config-file"); + + file = strchr (arg, '='); + ++file; + + if (!_dbus_string_append (&config_file, file)) + exit (1); + } + else if (prev_arg && + strcmp (prev_arg, "--config-file") == 0) + { + check_two_config_files (&config_file, "config-file"); + + if (!_dbus_string_append (&config_file, arg)) + exit (1); + } + else if (strcmp (arg, "--config-file") == 0) + { + /* wait for next arg */ + } + else if (strstr (arg, "--address=") == arg) + { + const char *file; + + check_two_addresses (&address, "address"); + + file = strchr (arg, '='); + ++file; + + if (!_dbus_string_append (&address, file)) + exit (1); + } + else if (prev_arg && + strcmp (prev_arg, "--address") == 0) + { + check_two_addresses (&address, "address"); + + if (!_dbus_string_append (&address, arg)) + exit (1); + } + else if (strcmp (arg, "--address") == 0) + { + /* wait for next arg */ + } + else if (strstr (arg, "--print-address=") == arg) + { + const char *desc; + + check_two_addr_descriptors (&addr_fd, "print-address"); + + desc = strchr (arg, '='); + ++desc; + + if (!_dbus_string_append (&addr_fd, desc)) + exit (1); + + print_address = TRUE; + } + else if (prev_arg && + strcmp (prev_arg, "--print-address") == 0) + { + check_two_addr_descriptors (&addr_fd, "print-address"); + + if (!_dbus_string_append (&addr_fd, arg)) + exit (1); + + print_address = TRUE; + } + else if (strcmp (arg, "--print-address") == 0) + { + print_address = TRUE; /* and we'll get the next arg if appropriate */ + } + else if (strstr (arg, "--print-pid=") == arg) + { + const char *desc; + + check_two_pid_descriptors (&pid_fd, "print-pid"); + + desc = strchr (arg, '='); + ++desc; + + if (!_dbus_string_append (&pid_fd, desc)) + exit (1); + + print_pid = TRUE; + } + else if (prev_arg && + strcmp (prev_arg, "--print-pid") == 0) + { + check_two_pid_descriptors (&pid_fd, "print-pid"); + + if (!_dbus_string_append (&pid_fd, arg)) + exit (1); + + print_pid = TRUE; + } + else if (strcmp (arg, "--print-pid") == 0) + { + print_pid = TRUE; /* and we'll get the next arg if appropriate */ + } + else + { + usage (); + } + + prev_arg = arg; + + ++i; + } + + if (_dbus_string_get_length (&config_file) == 0) + { + fprintf (stderr, "No configuration file specified.\n"); + usage (); + } + + _dbus_pipe_invalidate (&print_addr_pipe); + if (print_address) + { + _dbus_pipe_init_stdout (&print_addr_pipe); + if (_dbus_string_get_length (&addr_fd) > 0) + { + long val; + int end; + if (!_dbus_string_parse_int (&addr_fd, 0, &val, &end) || + end != _dbus_string_get_length (&addr_fd) || + val < 0 || val > _DBUS_INT_MAX) + { + fprintf (stderr, "Invalid file descriptor: \"%s\"\n", + _dbus_string_get_const_data (&addr_fd)); + exit (1); + } + + _dbus_pipe_init (&print_addr_pipe, val); + } + } + _dbus_string_free (&addr_fd); + + _dbus_pipe_invalidate (&print_pid_pipe); + if (print_pid) + { + _dbus_pipe_init_stdout (&print_pid_pipe); + if (_dbus_string_get_length (&pid_fd) > 0) + { + long val; + int end; + if (!_dbus_string_parse_int (&pid_fd, 0, &val, &end) || + end != _dbus_string_get_length (&pid_fd) || + val < 0 || val > _DBUS_INT_MAX) + { + fprintf (stderr, "Invalid file descriptor: \"%s\"\n", + _dbus_string_get_const_data (&pid_fd)); + exit (1); + } + + _dbus_pipe_init (&print_pid_pipe, val); + } + } + _dbus_string_free (&pid_fd); + + if (!bus_selinux_pre_init ()) + { + _dbus_warn ("SELinux pre-initialization failed\n"); + exit (1); + } + + if (!bus_apparmor_pre_init ()) + { + _dbus_warn ("AppArmor pre-initialization failed: out of memory\n"); + exit (1); + } + + dbus_error_init (&error); + context = bus_context_new (&config_file, flags, + &print_addr_pipe, &print_pid_pipe, + _dbus_string_get_length(&address) > 0 ? &address : NULL, + &error); + _dbus_string_free (&config_file); + if (context == NULL) + { + _dbus_warn ("Failed to start message bus: %s\n", + error.message); + dbus_error_free (&error); + exit (1); + } + + /* bus_context_new() closes the print_addr_pipe and + * print_pid_pipe + */ + +#ifdef DBUS_UNIX + setup_reload_pipe (bus_context_get_loop (context)); + + /* POSIX signals are Unix-specific, and _dbus_set_signal_handler is + * unimplemented (and probably unimplementable) on Windows, so there's + * no point in trying to make the handler portable to non-Unix. */ + + _dbus_set_signal_handler (SIGTERM, signal_handler); + _dbus_set_signal_handler (SIGHUP, signal_handler); +#endif /* DBUS_UNIX */ + + _dbus_verbose ("We are on D-Bus...\n"); + _dbus_loop_run (bus_context_get_loop (context)); + + bus_context_shutdown (context); + bus_context_unref (context); + bus_selinux_shutdown (); + bus_apparmor_shutdown (); + bus_audit_shutdown (); + + return 0; +}
diff --git a/bus/messagebus-config.in b/bus/messagebus-config.in new file mode 100644 index 0000000..39459dc --- /dev/null +++ b/bus/messagebus-config.in
@@ -0,0 +1,178 @@ +#!/bin/sh +# +# messagebus-config, Copyright 2009 Yaakov Selkowitz +# +# This file is part of the Cygwin port of dbus. + +# ====================================================================== +# Initialization +# ====================================================================== +PROGNAME=$(basename $0) +_tdir=$(dirname $0) +PROGDIR=$(cd $_tdir && pwd) + +CSIH_SCRIPT=/usr/share/csih/cygwin-service-installation-helper.sh + +# Subdirectory where the new package is being installed +PREFIX=@prefix@ + +# Directory where the config files are stored +SYSCONFDIR=@sysconfdir@/dbus-1 +DEVDIR=/dev +LOGDIR=/var/log +RUNDIR=$(dirname @DBUS_SYSTEM_PID_FILE@) +SOCKDIR=$(dirname @DBUS_SYSTEM_SOCKET@) + +source ${CSIH_SCRIPT} + +# ====================================================================== +# Routine: install_service +# Install messagebus as a service +# ====================================================================== +install_service() { + + if csih_is_nt + then + + # Check if messagebus is installed and remove on user request. + if cygrunsrv -Q messagebus > /dev/null 2>&1 + then + csih_warning "The messagebus service is already installed." + echo + if csih_request "Do you want to reinstall it with different args?" + then + cygrunsrv -E messagebus + cygrunsrv -R messagebus + fi + fi + + # Install messagebus service if it is not already installed + if ! cygrunsrv -Q messagebus > /dev/null 2>&1 + then + echo + csih_warning "The following function requires administrator privileges!" + if csih_request "Do you want to install messagebus as service?" + then + if cygrunsrv -I messagebus -d "CYGWIN D-Bus system service" -p @EXPANDED_BINDIR@/dbus-daemon -a "--nofork --system" + then + echo + csih_inform "The messagebus service has been installed under the LocalSystem" + csih_inform "account (also known as SYSTEM). To start the service now, call" + csih_inform "\`net start messagebus' or \`cygrunsrv -S messagebus'. Otherwise, it" + csih_inform "will start automatically after the next reboot." + echo + csih_inform "Check ${SYSCONFDIR}/system.conf first, if it suits your needs." + fi + fi # user allowed us to install messagebus + fi # messagebus already installed + fi # csih_is_nt +} # --- End of install_service --- # + + +# ====================================================================== +# Main Entry Point +# ====================================================================== + + +# Check how the script has been started. If +# (1) it has been started by giving the full path and +# that path is /etc/postinstall, OR +# (2) Otherwise, if the environment variable +# CONFIG_AUTO_ANSWER_NO is set +# then set auto_answer to "no". This allows automatic +# creation of the config files in /etc w/o overwriting +# them if they already exist. In both cases, color +# escape sequences are suppressed, so as to prevent +# cluttering setup's logfiles. +if [ "$PROGDIR" = "/etc/postinstall" ] +then + csih_auto_answer="no" + csih_disable_color +fi +if [ -n "${CONFIG_AUTO_ANSWER_NO}" ] +then + csih_auto_answer="no" + csih_disable_color +fi + + +# ====================================================================== +# Parse options +# ====================================================================== +while : +do + case $# in + 0) + break + ;; + esac + + option=$1 + shift + + case "$option" in + -d | --debug ) + set -x + csih_trace_on + ;; + + -y | --yes ) + csih_auto_answer=yes + ;; + + -n | --no ) + csih_auto_answer=no + ;; + + *) + echo "usage: ${PROGNAME} [OPTION]..." + echo + echo "This script creates a basic messagebus configuration." + echo + echo "Options:" + echo " --debug -d Enable shell's debug output." + echo " --yes -y Answer all questions with \"yes\" automatically." + echo " --no -n Answer all questions with \"no\" automatically." + echo + exit 1 + ;; + + esac +done + +# ====================================================================== +# Action! +# ====================================================================== + +# Check for ${SYSCONFDIR} directory +csih_make_dir "${SYSCONFDIR}" "Cannot create global configuration files." +chmod 775 "${SYSCONFDIR}" +setfacl -m u:system:rwx "${SYSCONFDIR}" + +# Check for ${DEVDIR} directory +csih_make_dir "${DEVDIR}" "Syslogging using messagebus will not work." +chmod 775 "${DEVDIR}" +setfacl -m u:system:rwx "${DEVDIR}" + +# Check for ${LOGDIR} directory +csih_make_dir "${LOGDIR}" "Syslogging using messagebus will not work." +chmod 775 "${LOGDIR}" +setfacl -m u:system:rwx "${LOGDIR}" + +# Check for ${RUNDIR} directory +csih_make_dir "${RUNDIR}" "PID files of running processes will not be created." +chmod 775 "${RUNDIR}" +setfacl -m u:system:rwx "${RUNDIR}" + +# Check for ${SOCKDIR} directory +csih_make_dir "${SOCKDIR}" "SOCKET files of running processes will not be created." +chmod 775 "${SOCKDIR}" +setfacl -m u:system:rwx "${SOCKDIR}" + +# maybe: csih_auto_answer=no will skip, +# interactive user will get a chance to override +install_service + + +echo +echo "Configuration finished. Have fun!"
diff --git a/bus/messagebus.in b/bus/messagebus.in new file mode 100644 index 0000000..3e2ee07 --- /dev/null +++ b/bus/messagebus.in
@@ -0,0 +1,92 @@ +#!/bin/sh +# +# messagebus: The D-BUS systemwide message bus +# +# chkconfig: 345 22 85 +# description: This is a daemon which broadcasts notifications of system events \ +# and other messages. See http://www.freedesktop.org/software/dbus/ +# +# processname: dbus-daemon +# pidfile: @DBUS_SYSTEM_PID_FILE@ +# +### BEGIN INIT INFO +# Provides: messagebus +# Required-Start: $syslog $local_fs +# Required-Stop: $syslog $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: The D-Bus systemwide message bus +# Description: This is a daemon which broadcasts notifications of system +# events and other messages. See http://www.freedesktop.org/software/dbus +### END INIT INFO + +# Sanity checks. +[ -x @EXPANDED_BINDIR@/dbus-daemon ] || exit 0 + +# Source function library. +. @EXPANDED_SYSCONFDIR@/rc.d/init.d/functions + +# so we can rearrange this easily +processname=dbus-daemon +servicename=messagebus + +RETVAL=0 + +start() { + echo -n $"Starting system message bus: " + if [ -x @EXPANDED_BINDIR@/dbus-uuidgen ] ; then + @EXPANDED_BINDIR@/dbus-uuidgen --ensure + fi + + daemon --check $servicename $processname --system + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch @EXPANDED_LOCALSTATEDIR@/lock/subsys/$servicename +} + +stop() { + echo -n $"Stopping system message bus: " + + ## we don't want to kill all the per-user $processname, we want + ## to use the pid file *only*; because we use the fake nonexistent + ## program name "$servicename" that should be safe-ish + killproc $servicename -TERM + RETVAL=$? + echo + if [ $RETVAL -eq 0 ]; then + rm -f @EXPANDED_LOCALSTATEDIR@/lock/subsys/$servicename + rm -f @DBUS_SYSTEM_PID_FILE@ + fi +} + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status $servicename + RETVAL=$? + ;; + restart) + stop + start + ;; + condrestart) + if [ -f @EXPANDED_LOCALSTATEDIR@/lock/subsys/$servicename ]; then + stop + start + fi + ;; + reload) + echo "Message bus can't reload its configuration, you have to restart it" + RETVAL=$? + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}" + ;; +esac +exit $RETVAL
diff --git a/bus/org.freedesktop.dbus-session.plist.in b/bus/org.freedesktop.dbus-session.plist.in new file mode 100644 index 0000000..40ff370 --- /dev/null +++ b/bus/org.freedesktop.dbus-session.plist.in
@@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>Label</key> + <string>org.freedesktop.dbus-session</string> + + <key>ServiceIPC</key> + <true/> + + <!-- Please uncomment on 10.4; OnDemand doesn't work properly there. --> + <!-- + <key>OnDemand</key> + <false /> + --> + + <key>ProgramArguments</key> + <array> + <string>@DBUS_DAEMONDIR@/dbus-daemon</string> + <string>--nofork</string> + <string>--session</string> + </array> + + <key>Sockets</key> + <dict> + <key>unix_domain_listener</key> + <dict> + <key>SecureSocketWithKey</key> + <string>DBUS_LAUNCHD_SESSION_BUS_SOCKET</string> + </dict> + </dict> +</dict> +</plist>
diff --git a/bus/policy.c b/bus/policy.c new file mode 100644 index 0000000..082f385 --- /dev/null +++ b/bus/policy.c
@@ -0,0 +1,1313 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* policy.c Bus security policy + * + * Copyright (C) 2003, 2004 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "policy.h" +#include "services.h" +#include "test.h" +#include "utils.h" +#include <dbus/dbus-list.h> +#include <dbus/dbus-hash.h> +#include <dbus/dbus-internals.h> + +BusPolicyRule* +bus_policy_rule_new (BusPolicyRuleType type, + dbus_bool_t allow) +{ + BusPolicyRule *rule; + + rule = dbus_new0 (BusPolicyRule, 1); + if (rule == NULL) + return NULL; + + rule->type = type; + rule->refcount = 1; + rule->allow = allow; + + switch (rule->type) + { + case BUS_POLICY_RULE_USER: + rule->d.user.uid = DBUS_UID_UNSET; + break; + case BUS_POLICY_RULE_GROUP: + rule->d.group.gid = DBUS_GID_UNSET; + break; + case BUS_POLICY_RULE_SEND: + rule->d.send.message_type = DBUS_MESSAGE_TYPE_INVALID; + + /* allow rules default to TRUE (only requested replies allowed) + * deny rules default to FALSE (only unrequested replies denied) + */ + rule->d.send.requested_reply = rule->allow; + break; + case BUS_POLICY_RULE_RECEIVE: + rule->d.receive.message_type = DBUS_MESSAGE_TYPE_INVALID; + /* allow rules default to TRUE (only requested replies allowed) + * deny rules default to FALSE (only unrequested replies denied) + */ + rule->d.receive.requested_reply = rule->allow; + break; + case BUS_POLICY_RULE_OWN: + break; + } + + return rule; +} + +BusPolicyRule * +bus_policy_rule_ref (BusPolicyRule *rule) +{ + _dbus_assert (rule->refcount > 0); + + rule->refcount += 1; + + return rule; +} + +void +bus_policy_rule_unref (BusPolicyRule *rule) +{ + _dbus_assert (rule->refcount > 0); + + rule->refcount -= 1; + + if (rule->refcount == 0) + { + switch (rule->type) + { + case BUS_POLICY_RULE_SEND: + dbus_free (rule->d.send.path); + dbus_free (rule->d.send.interface); + dbus_free (rule->d.send.member); + dbus_free (rule->d.send.error); + dbus_free (rule->d.send.destination); + break; + case BUS_POLICY_RULE_RECEIVE: + dbus_free (rule->d.receive.path); + dbus_free (rule->d.receive.interface); + dbus_free (rule->d.receive.member); + dbus_free (rule->d.receive.error); + dbus_free (rule->d.receive.origin); + break; + case BUS_POLICY_RULE_OWN: + dbus_free (rule->d.own.service_name); + break; + case BUS_POLICY_RULE_USER: + break; + case BUS_POLICY_RULE_GROUP: + break; + } + + dbus_free (rule); + } +} + +struct BusPolicy +{ + int refcount; + + DBusList *default_rules; /**< Default policy rules */ + DBusList *mandatory_rules; /**< Mandatory policy rules */ + DBusHashTable *rules_by_uid; /**< per-UID policy rules */ + DBusHashTable *rules_by_gid; /**< per-GID policy rules */ + DBusList *at_console_true_rules; /**< console user policy rules where at_console="true"*/ + DBusList *at_console_false_rules; /**< console user policy rules where at_console="false"*/ +}; + +static void +free_rule_func (void *data, + void *user_data) +{ + BusPolicyRule *rule = data; + + bus_policy_rule_unref (rule); +} + +static void +free_rule_list_func (void *data) +{ + DBusList **list = data; + + if (list == NULL) /* DBusHashTable is on crack */ + return; + + _dbus_list_foreach (list, free_rule_func, NULL); + + _dbus_list_clear (list); + + dbus_free (list); +} + +BusPolicy* +bus_policy_new (void) +{ + BusPolicy *policy; + + policy = dbus_new0 (BusPolicy, 1); + if (policy == NULL) + return NULL; + + policy->refcount = 1; + + policy->rules_by_uid = _dbus_hash_table_new (DBUS_HASH_UINTPTR, + NULL, + free_rule_list_func); + if (policy->rules_by_uid == NULL) + goto failed; + + policy->rules_by_gid = _dbus_hash_table_new (DBUS_HASH_UINTPTR, + NULL, + free_rule_list_func); + if (policy->rules_by_gid == NULL) + goto failed; + + return policy; + + failed: + bus_policy_unref (policy); + return NULL; +} + +BusPolicy * +bus_policy_ref (BusPolicy *policy) +{ + _dbus_assert (policy->refcount > 0); + + policy->refcount += 1; + + return policy; +} + +void +bus_policy_unref (BusPolicy *policy) +{ + _dbus_assert (policy->refcount > 0); + + policy->refcount -= 1; + + if (policy->refcount == 0) + { + _dbus_list_foreach (&policy->default_rules, free_rule_func, NULL); + _dbus_list_clear (&policy->default_rules); + + _dbus_list_foreach (&policy->mandatory_rules, free_rule_func, NULL); + _dbus_list_clear (&policy->mandatory_rules); + + _dbus_list_foreach (&policy->at_console_true_rules, free_rule_func, NULL); + _dbus_list_clear (&policy->at_console_true_rules); + + _dbus_list_foreach (&policy->at_console_false_rules, free_rule_func, NULL); + _dbus_list_clear (&policy->at_console_false_rules); + + if (policy->rules_by_uid) + { + _dbus_hash_table_unref (policy->rules_by_uid); + policy->rules_by_uid = NULL; + } + + if (policy->rules_by_gid) + { + _dbus_hash_table_unref (policy->rules_by_gid); + policy->rules_by_gid = NULL; + } + + dbus_free (policy); + } +} + +static dbus_bool_t +add_list_to_client (DBusList **list, + BusClientPolicy *client) +{ + DBusList *link; + + link = _dbus_list_get_first_link (list); + while (link != NULL) + { + BusPolicyRule *rule = link->data; + link = _dbus_list_get_next_link (list, link); + + switch (rule->type) + { + case BUS_POLICY_RULE_USER: + case BUS_POLICY_RULE_GROUP: + /* These aren't per-connection policies */ + break; + + case BUS_POLICY_RULE_OWN: + case BUS_POLICY_RULE_SEND: + case BUS_POLICY_RULE_RECEIVE: + /* These are per-connection */ + if (!bus_client_policy_append_rule (client, rule)) + return FALSE; + break; + } + } + + return TRUE; +} + +BusClientPolicy* +bus_policy_create_client_policy (BusPolicy *policy, + DBusConnection *connection, + DBusError *error) +{ + BusClientPolicy *client; + dbus_uid_t uid; + dbus_bool_t at_console; + + _dbus_assert (dbus_connection_get_is_authenticated (connection)); + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + client = bus_client_policy_new (); + if (client == NULL) + goto nomem; + + if (!add_list_to_client (&policy->default_rules, + client)) + goto nomem; + + /* we avoid the overhead of looking up user's groups + * if we don't have any group rules anyway + */ + if (_dbus_hash_table_get_n_entries (policy->rules_by_gid) > 0) + { + unsigned long *groups; + int n_groups; + int i; + + if (!bus_connection_get_unix_groups (connection, &groups, &n_groups, error)) + goto failed; + + i = 0; + while (i < n_groups) + { + DBusList **list; + + list = _dbus_hash_table_lookup_uintptr (policy->rules_by_gid, + groups[i]); + + if (list != NULL) + { + if (!add_list_to_client (list, client)) + { + dbus_free (groups); + goto nomem; + } + } + + ++i; + } + + dbus_free (groups); + } + + if (dbus_connection_get_unix_user (connection, &uid)) + { + if (_dbus_hash_table_get_n_entries (policy->rules_by_uid) > 0) + { + DBusList **list; + + list = _dbus_hash_table_lookup_uintptr (policy->rules_by_uid, + uid); + + if (list != NULL) + { + if (!add_list_to_client (list, client)) + goto nomem; + } + } + + /* Add console rules */ + at_console = _dbus_unix_user_is_at_console (uid, error); + + if (at_console) + { + if (!add_list_to_client (&policy->at_console_true_rules, client)) + goto nomem; + } + else if (dbus_error_is_set (error) == TRUE) + { + goto failed; + } + else if (!add_list_to_client (&policy->at_console_false_rules, client)) + { + goto nomem; + } + } + + if (!add_list_to_client (&policy->mandatory_rules, + client)) + goto nomem; + + bus_client_policy_optimize (client); + + return client; + + nomem: + BUS_SET_OOM (error); + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (client) + bus_client_policy_unref (client); + return NULL; +} + +static dbus_bool_t +list_allows_user (dbus_bool_t def, + DBusList **list, + unsigned long uid, + const unsigned long *group_ids, + int n_group_ids) +{ + DBusList *link; + dbus_bool_t allowed; + + allowed = def; + + link = _dbus_list_get_first_link (list); + while (link != NULL) + { + BusPolicyRule *rule = link->data; + link = _dbus_list_get_next_link (list, link); + + if (rule->type == BUS_POLICY_RULE_USER) + { + _dbus_verbose ("List %p user rule uid="DBUS_UID_FORMAT"\n", + list, rule->d.user.uid); + + if (rule->d.user.uid == DBUS_UID_UNSET) + ; /* '*' wildcard */ + else if (rule->d.user.uid != uid) + continue; + } + else if (rule->type == BUS_POLICY_RULE_GROUP) + { + _dbus_verbose ("List %p group rule gid="DBUS_GID_FORMAT"\n", + list, rule->d.group.gid); + + if (rule->d.group.gid == DBUS_GID_UNSET) + ; /* '*' wildcard */ + else + { + int i; + + i = 0; + while (i < n_group_ids) + { + if (rule->d.group.gid == group_ids[i]) + break; + ++i; + } + + if (i == n_group_ids) + continue; + } + } + else + continue; + + allowed = rule->allow; + } + + return allowed; +} + +dbus_bool_t +bus_policy_allow_unix_user (BusPolicy *policy, + unsigned long uid) +{ + dbus_bool_t allowed; + unsigned long *group_ids; + int n_group_ids; + + /* On OOM or error we always reject the user */ + if (!_dbus_unix_groups_from_uid (uid, &group_ids, &n_group_ids)) + { + _dbus_verbose ("Did not get any groups for UID %lu\n", + uid); + return FALSE; + } + + /* Default to "user owning bus" can connect */ + allowed = _dbus_unix_user_is_process_owner (uid); + + allowed = list_allows_user (allowed, + &policy->default_rules, + uid, + group_ids, n_group_ids); + + allowed = list_allows_user (allowed, + &policy->mandatory_rules, + uid, + group_ids, n_group_ids); + + dbus_free (group_ids); + + _dbus_verbose ("UID %lu allowed = %d\n", uid, allowed); + + return allowed; +} + +/* For now this is never actually called because the default + * DBusConnection behavior of 'same user that owns the bus can + * connect' is all it would do. Set the windows user function in + * connection.c if the config file ever supports doing something + * interesting here. + */ +dbus_bool_t +bus_policy_allow_windows_user (BusPolicy *policy, + const char *windows_sid) +{ + /* Windows has no policies here since only the session bus + * is really used for now, so just checking that the + * connecting person is the same as the bus owner is fine. + */ + return _dbus_windows_user_is_process_owner (windows_sid); +} + +dbus_bool_t +bus_policy_append_default_rule (BusPolicy *policy, + BusPolicyRule *rule) +{ + if (!_dbus_list_append (&policy->default_rules, rule)) + return FALSE; + + bus_policy_rule_ref (rule); + + return TRUE; +} + +dbus_bool_t +bus_policy_append_mandatory_rule (BusPolicy *policy, + BusPolicyRule *rule) +{ + if (!_dbus_list_append (&policy->mandatory_rules, rule)) + return FALSE; + + bus_policy_rule_ref (rule); + + return TRUE; +} + + + +static DBusList** +get_list (DBusHashTable *hash, + unsigned long key) +{ + DBusList **list; + + list = _dbus_hash_table_lookup_uintptr (hash, key); + + if (list == NULL) + { + list = dbus_new0 (DBusList*, 1); + if (list == NULL) + return NULL; + + if (!_dbus_hash_table_insert_uintptr (hash, key, list)) + { + dbus_free (list); + return NULL; + } + } + + return list; +} + +dbus_bool_t +bus_policy_append_user_rule (BusPolicy *policy, + dbus_uid_t uid, + BusPolicyRule *rule) +{ + DBusList **list; + + list = get_list (policy->rules_by_uid, uid); + + if (list == NULL) + return FALSE; + + if (!_dbus_list_append (list, rule)) + return FALSE; + + bus_policy_rule_ref (rule); + + return TRUE; +} + +dbus_bool_t +bus_policy_append_group_rule (BusPolicy *policy, + dbus_gid_t gid, + BusPolicyRule *rule) +{ + DBusList **list; + + list = get_list (policy->rules_by_gid, gid); + + if (list == NULL) + return FALSE; + + if (!_dbus_list_append (list, rule)) + return FALSE; + + bus_policy_rule_ref (rule); + + return TRUE; +} + +dbus_bool_t +bus_policy_append_console_rule (BusPolicy *policy, + dbus_bool_t at_console, + BusPolicyRule *rule) +{ + if (at_console) + { + if (!_dbus_list_append (&policy->at_console_true_rules, rule)) + return FALSE; + } + else + { + if (!_dbus_list_append (&policy->at_console_false_rules, rule)) + return FALSE; + } + + bus_policy_rule_ref (rule); + + return TRUE; + +} + +static dbus_bool_t +append_copy_of_policy_list (DBusList **list, + DBusList **to_append) +{ + DBusList *link; + DBusList *tmp_list; + + tmp_list = NULL; + + /* Preallocate all our links */ + link = _dbus_list_get_first_link (to_append); + while (link != NULL) + { + if (!_dbus_list_append (&tmp_list, link->data)) + { + _dbus_list_clear (&tmp_list); + return FALSE; + } + + link = _dbus_list_get_next_link (to_append, link); + } + + /* Now append them */ + while ((link = _dbus_list_pop_first_link (&tmp_list))) + { + bus_policy_rule_ref (link->data); + _dbus_list_append_link (list, link); + } + + return TRUE; +} + +static dbus_bool_t +merge_id_hash (DBusHashTable *dest, + DBusHashTable *to_absorb) +{ + DBusHashIter iter; + + _dbus_hash_iter_init (to_absorb, &iter); + while (_dbus_hash_iter_next (&iter)) + { + unsigned long id = _dbus_hash_iter_get_uintptr_key (&iter); + DBusList **list = _dbus_hash_iter_get_value (&iter); + DBusList **target = get_list (dest, id); + + if (target == NULL) + return FALSE; + + if (!append_copy_of_policy_list (target, list)) + return FALSE; + } + + return TRUE; +} + +dbus_bool_t +bus_policy_merge (BusPolicy *policy, + BusPolicy *to_absorb) +{ + /* FIXME Not properly atomic, but as used for configuration files we + * don't rely on it quite so much. + */ + + if (!append_copy_of_policy_list (&policy->default_rules, + &to_absorb->default_rules)) + return FALSE; + + if (!append_copy_of_policy_list (&policy->mandatory_rules, + &to_absorb->mandatory_rules)) + return FALSE; + + if (!append_copy_of_policy_list (&policy->at_console_true_rules, + &to_absorb->at_console_true_rules)) + return FALSE; + + if (!append_copy_of_policy_list (&policy->at_console_false_rules, + &to_absorb->at_console_false_rules)) + return FALSE; + + if (!merge_id_hash (policy->rules_by_uid, + to_absorb->rules_by_uid)) + return FALSE; + + if (!merge_id_hash (policy->rules_by_gid, + to_absorb->rules_by_gid)) + return FALSE; + + return TRUE; +} + +struct BusClientPolicy +{ + int refcount; + + DBusList *rules; +}; + +BusClientPolicy* +bus_client_policy_new (void) +{ + BusClientPolicy *policy; + + policy = dbus_new0 (BusClientPolicy, 1); + if (policy == NULL) + return NULL; + + policy->refcount = 1; + + return policy; +} + +BusClientPolicy * +bus_client_policy_ref (BusClientPolicy *policy) +{ + _dbus_assert (policy->refcount > 0); + + policy->refcount += 1; + + return policy; +} + +static void +rule_unref_foreach (void *data, + void *user_data) +{ + BusPolicyRule *rule = data; + + bus_policy_rule_unref (rule); +} + +void +bus_client_policy_unref (BusClientPolicy *policy) +{ + _dbus_assert (policy->refcount > 0); + + policy->refcount -= 1; + + if (policy->refcount == 0) + { + _dbus_list_foreach (&policy->rules, + rule_unref_foreach, + NULL); + + _dbus_list_clear (&policy->rules); + + dbus_free (policy); + } +} + +static void +remove_rules_by_type_up_to (BusClientPolicy *policy, + BusPolicyRuleType type, + DBusList *up_to) +{ + DBusList *link; + + link = _dbus_list_get_first_link (&policy->rules); + while (link != up_to) + { + BusPolicyRule *rule = link->data; + DBusList *next = _dbus_list_get_next_link (&policy->rules, link); + + if (rule->type == type) + { + _dbus_list_remove_link (&policy->rules, link); + bus_policy_rule_unref (rule); + } + + link = next; + } +} + +void +bus_client_policy_optimize (BusClientPolicy *policy) +{ + DBusList *link; + + /* The idea here is that if we have: + * + * <allow send_interface="foo.bar"/> + * <deny send_interface="*"/> + * + * (for example) the deny will always override the allow. So we + * delete the allow. Ditto for deny followed by allow, etc. This is + * a dumb thing to put in a config file, but the <include> feature + * of files allows for an "inheritance and override" pattern where + * it could make sense. If an included file wants to "start over" + * with a blanket deny, no point keeping the rules from the parent + * file. + */ + + _dbus_verbose ("Optimizing policy with %d rules\n", + _dbus_list_get_length (&policy->rules)); + + link = _dbus_list_get_first_link (&policy->rules); + while (link != NULL) + { + BusPolicyRule *rule; + DBusList *next; + dbus_bool_t remove_preceding; + + next = _dbus_list_get_next_link (&policy->rules, link); + rule = link->data; + + remove_preceding = FALSE; + + _dbus_assert (rule != NULL); + + switch (rule->type) + { + case BUS_POLICY_RULE_SEND: + remove_preceding = + rule->d.send.message_type == DBUS_MESSAGE_TYPE_INVALID && + rule->d.send.path == NULL && + rule->d.send.interface == NULL && + rule->d.send.member == NULL && + rule->d.send.error == NULL && + rule->d.send.destination == NULL; + break; + case BUS_POLICY_RULE_RECEIVE: + remove_preceding = + rule->d.receive.message_type == DBUS_MESSAGE_TYPE_INVALID && + rule->d.receive.path == NULL && + rule->d.receive.interface == NULL && + rule->d.receive.member == NULL && + rule->d.receive.error == NULL && + rule->d.receive.origin == NULL; + break; + case BUS_POLICY_RULE_OWN: + remove_preceding = + rule->d.own.service_name == NULL; + break; + case BUS_POLICY_RULE_USER: + case BUS_POLICY_RULE_GROUP: + _dbus_assert_not_reached ("invalid rule"); + break; + } + + if (remove_preceding) + remove_rules_by_type_up_to (policy, rule->type, + link); + + link = next; + } + + _dbus_verbose ("After optimization, policy has %d rules\n", + _dbus_list_get_length (&policy->rules)); +} + +dbus_bool_t +bus_client_policy_append_rule (BusClientPolicy *policy, + BusPolicyRule *rule) +{ + _dbus_verbose ("Appending rule %p with type %d to policy %p\n", + rule, rule->type, policy); + + if (!_dbus_list_append (&policy->rules, rule)) + return FALSE; + + bus_policy_rule_ref (rule); + + return TRUE; +} + +dbus_bool_t +bus_client_policy_check_can_send (BusClientPolicy *policy, + BusRegistry *registry, + dbus_bool_t requested_reply, + DBusConnection *receiver, + DBusMessage *message, + dbus_int32_t *toggles, + dbus_bool_t *log) +{ + DBusList *link; + dbus_bool_t allowed; + + /* policy->rules is in the order the rules appeared + * in the config file, i.e. last rule that applies wins + */ + + _dbus_verbose (" (policy) checking send rules\n"); + *toggles = 0; + + allowed = FALSE; + link = _dbus_list_get_first_link (&policy->rules); + while (link != NULL) + { + BusPolicyRule *rule = link->data; + + link = _dbus_list_get_next_link (&policy->rules, link); + + /* Rule is skipped if it specifies a different + * message name from the message, or a different + * destination from the message + */ + + if (rule->type != BUS_POLICY_RULE_SEND) + { + _dbus_verbose (" (policy) skipping non-send rule\n"); + continue; + } + + if (rule->d.send.message_type != DBUS_MESSAGE_TYPE_INVALID) + { + if (dbus_message_get_type (message) != rule->d.send.message_type) + { + _dbus_verbose (" (policy) skipping rule for different message type\n"); + continue; + } + } + + /* If it's a reply, the requested_reply flag kicks in */ + if (dbus_message_get_reply_serial (message) != 0) + { + /* for allow, requested_reply=true means the rule applies + * only when reply was requested. requested_reply=false means + * always allow. + */ + if (!requested_reply && rule->allow && rule->d.send.requested_reply && !rule->d.send.eavesdrop) + { + _dbus_verbose (" (policy) skipping allow rule since it only applies to requested replies and does not allow eavesdropping\n"); + continue; + } + + /* for deny, requested_reply=false means the rule applies only + * when the reply was not requested. requested_reply=true means the + * rule always applies. + */ + if (requested_reply && !rule->allow && !rule->d.send.requested_reply) + { + _dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n"); + continue; + } + } + + if (rule->d.send.path != NULL) + { + if (dbus_message_get_path (message) != NULL && + strcmp (dbus_message_get_path (message), + rule->d.send.path) != 0) + { + _dbus_verbose (" (policy) skipping rule for different path\n"); + continue; + } + } + + if (rule->d.send.interface != NULL) + { + /* The interface is optional in messages. For allow rules, if the message + * has no interface we want to skip the rule (and thus not allow); + * for deny rules, if the message has no interface we want to use the + * rule (and thus deny). + */ + dbus_bool_t no_interface; + + no_interface = dbus_message_get_interface (message) == NULL; + + if ((no_interface && rule->allow) || + (!no_interface && + strcmp (dbus_message_get_interface (message), + rule->d.send.interface) != 0)) + { + _dbus_verbose (" (policy) skipping rule for different interface\n"); + continue; + } + } + + if (rule->d.send.member != NULL) + { + if (dbus_message_get_member (message) != NULL && + strcmp (dbus_message_get_member (message), + rule->d.send.member) != 0) + { + _dbus_verbose (" (policy) skipping rule for different member\n"); + continue; + } + } + + if (rule->d.send.error != NULL) + { + if (dbus_message_get_error_name (message) != NULL && + strcmp (dbus_message_get_error_name (message), + rule->d.send.error) != 0) + { + _dbus_verbose (" (policy) skipping rule for different error name\n"); + continue; + } + } + + if (rule->d.send.destination != NULL) + { + /* receiver can be NULL for messages that are sent to the + * message bus itself, we check the strings in that case as + * built-in services don't have a DBusConnection but messages + * to them have a destination service name. + */ + if (receiver == NULL) + { + if (!dbus_message_has_destination (message, + rule->d.send.destination)) + { + _dbus_verbose (" (policy) skipping rule because message dest is not %s\n", + rule->d.send.destination); + continue; + } + } + else + { + DBusString str; + BusService *service; + + _dbus_string_init_const (&str, rule->d.send.destination); + + service = bus_registry_lookup (registry, &str); + if (service == NULL) + { + _dbus_verbose (" (policy) skipping rule because dest %s doesn't exist\n", + rule->d.send.destination); + continue; + } + + if (!bus_service_has_owner (service, receiver)) + { + _dbus_verbose (" (policy) skipping rule because dest %s isn't owned by receiver\n", + rule->d.send.destination); + continue; + } + } + } + + /* Use this rule */ + allowed = rule->allow; + *log = rule->d.send.log; + (*toggles)++; + + _dbus_verbose (" (policy) used rule, allow now = %d\n", + allowed); + } + + return allowed; +} + +/* See docs on what the args mean on bus_context_check_security_policy() + * comment + */ +dbus_bool_t +bus_client_policy_check_can_receive (BusClientPolicy *policy, + BusRegistry *registry, + dbus_bool_t requested_reply, + DBusConnection *sender, + DBusConnection *addressed_recipient, + DBusConnection *proposed_recipient, + DBusMessage *message, + dbus_int32_t *toggles) +{ + DBusList *link; + dbus_bool_t allowed; + dbus_bool_t eavesdropping; + + eavesdropping = + addressed_recipient != proposed_recipient && + dbus_message_get_destination (message) != NULL; + + /* policy->rules is in the order the rules appeared + * in the config file, i.e. last rule that applies wins + */ + + _dbus_verbose (" (policy) checking receive rules, eavesdropping = %d\n", eavesdropping); + *toggles = 0; + + allowed = FALSE; + link = _dbus_list_get_first_link (&policy->rules); + while (link != NULL) + { + BusPolicyRule *rule = link->data; + + link = _dbus_list_get_next_link (&policy->rules, link); + + if (rule->type != BUS_POLICY_RULE_RECEIVE) + { + _dbus_verbose (" (policy) skipping non-receive rule\n"); + continue; + } + + if (rule->d.receive.message_type != DBUS_MESSAGE_TYPE_INVALID) + { + if (dbus_message_get_type (message) != rule->d.receive.message_type) + { + _dbus_verbose (" (policy) skipping rule for different message type\n"); + continue; + } + } + + /* for allow, eavesdrop=false means the rule doesn't apply when + * eavesdropping. eavesdrop=true means always allow. + */ + if (eavesdropping && rule->allow && !rule->d.receive.eavesdrop) + { + _dbus_verbose (" (policy) skipping allow rule since it doesn't apply to eavesdropping\n"); + continue; + } + + /* for deny, eavesdrop=true means the rule applies only when + * eavesdropping; eavesdrop=false means always deny. + */ + if (!eavesdropping && !rule->allow && rule->d.receive.eavesdrop) + { + _dbus_verbose (" (policy) skipping deny rule since it only applies to eavesdropping\n"); + continue; + } + + /* If it's a reply, the requested_reply flag kicks in */ + if (dbus_message_get_reply_serial (message) != 0) + { + /* for allow, requested_reply=true means the rule applies + * only when reply was requested. requested_reply=false means + * always allow. + */ + if (!requested_reply && rule->allow && rule->d.receive.requested_reply && !rule->d.receive.eavesdrop) + { + _dbus_verbose (" (policy) skipping allow rule since it only applies to requested replies and does not allow eavesdropping\n"); + continue; + } + + /* for deny, requested_reply=false means the rule applies only + * when the reply was not requested. requested_reply=true means the + * rule always applies. + */ + if (requested_reply && !rule->allow && !rule->d.receive.requested_reply) + { + _dbus_verbose (" (policy) skipping deny rule since it only applies to unrequested replies\n"); + continue; + } + } + + if (rule->d.receive.path != NULL) + { + if (dbus_message_get_path (message) != NULL && + strcmp (dbus_message_get_path (message), + rule->d.receive.path) != 0) + { + _dbus_verbose (" (policy) skipping rule for different path\n"); + continue; + } + } + + if (rule->d.receive.interface != NULL) + { + /* The interface is optional in messages. For allow rules, if the message + * has no interface we want to skip the rule (and thus not allow); + * for deny rules, if the message has no interface we want to use the + * rule (and thus deny). + */ + dbus_bool_t no_interface; + + no_interface = dbus_message_get_interface (message) == NULL; + + if ((no_interface && rule->allow) || + (!no_interface && + strcmp (dbus_message_get_interface (message), + rule->d.receive.interface) != 0)) + { + _dbus_verbose (" (policy) skipping rule for different interface\n"); + continue; + } + } + + if (rule->d.receive.member != NULL) + { + if (dbus_message_get_member (message) != NULL && + strcmp (dbus_message_get_member (message), + rule->d.receive.member) != 0) + { + _dbus_verbose (" (policy) skipping rule for different member\n"); + continue; + } + } + + if (rule->d.receive.error != NULL) + { + if (dbus_message_get_error_name (message) != NULL && + strcmp (dbus_message_get_error_name (message), + rule->d.receive.error) != 0) + { + _dbus_verbose (" (policy) skipping rule for different error name\n"); + continue; + } + } + + if (rule->d.receive.origin != NULL) + { + /* sender can be NULL for messages that originate from the + * message bus itself, we check the strings in that case as + * built-in services don't have a DBusConnection but will + * still set the sender on their messages. + */ + if (sender == NULL) + { + if (!dbus_message_has_sender (message, + rule->d.receive.origin)) + { + _dbus_verbose (" (policy) skipping rule because message sender is not %s\n", + rule->d.receive.origin); + continue; + } + } + else + { + BusService *service; + DBusString str; + + _dbus_string_init_const (&str, rule->d.receive.origin); + + service = bus_registry_lookup (registry, &str); + + if (service == NULL) + { + _dbus_verbose (" (policy) skipping rule because origin %s doesn't exist\n", + rule->d.receive.origin); + continue; + } + + if (!bus_service_has_owner (service, sender)) + { + _dbus_verbose (" (policy) skipping rule because origin %s isn't owned by sender\n", + rule->d.receive.origin); + continue; + } + } + } + + /* Use this rule */ + allowed = rule->allow; + (*toggles)++; + + _dbus_verbose (" (policy) used rule, allow now = %d\n", + allowed); + } + + return allowed; +} + + + +static dbus_bool_t +bus_rules_check_can_own (DBusList *rules, + const DBusString *service_name) +{ + DBusList *link; + dbus_bool_t allowed; + + /* rules is in the order the rules appeared + * in the config file, i.e. last rule that applies wins + */ + + allowed = FALSE; + link = _dbus_list_get_first_link (&rules); + while (link != NULL) + { + BusPolicyRule *rule = link->data; + + link = _dbus_list_get_next_link (&rules, link); + + /* Rule is skipped if it specifies a different service name from + * the desired one. + */ + + if (rule->type != BUS_POLICY_RULE_OWN) + continue; + + if (!rule->d.own.prefix && rule->d.own.service_name != NULL) + { + if (!_dbus_string_equal_c_str (service_name, + rule->d.own.service_name)) + continue; + } + else if (rule->d.own.prefix) + { + const char *data; + char next_char; + if (!_dbus_string_starts_with_c_str (service_name, + rule->d.own.service_name)) + continue; + + data = _dbus_string_get_const_data (service_name); + next_char = data[strlen (rule->d.own.service_name)]; + if (next_char != '\0' && next_char != '.') + continue; + } + + /* Use this rule */ + allowed = rule->allow; + } + + return allowed; +} + +dbus_bool_t +bus_client_policy_check_can_own (BusClientPolicy *policy, + const DBusString *service_name) +{ + return bus_rules_check_can_own (policy->rules, service_name); +} + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS +dbus_bool_t +bus_policy_check_can_own (BusPolicy *policy, + const DBusString *service_name) +{ + return bus_rules_check_can_own (policy->default_rules, service_name); +} +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */ +
diff --git a/bus/policy.h b/bus/policy.h new file mode 100644 index 0000000..d1d3e72 --- /dev/null +++ b/bus/policy.h
@@ -0,0 +1,169 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* policy.h Bus security policy + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_POLICY_H +#define BUS_POLICY_H + +#include <dbus/dbus.h> +#include <dbus/dbus-string.h> +#include <dbus/dbus-list.h> +#include <dbus/dbus-sysdeps.h> +#include "bus.h" + +typedef enum +{ + BUS_POLICY_RULE_SEND, + BUS_POLICY_RULE_RECEIVE, + BUS_POLICY_RULE_OWN, + BUS_POLICY_RULE_USER, + BUS_POLICY_RULE_GROUP +} BusPolicyRuleType; + +/** determines whether the rule affects a connection, or some global item */ +#define BUS_POLICY_RULE_IS_PER_CLIENT(rule) (!((rule)->type == BUS_POLICY_RULE_USER || \ + (rule)->type == BUS_POLICY_RULE_GROUP)) + +struct BusPolicyRule +{ + int refcount; + + BusPolicyRuleType type; + + unsigned int allow : 1; /**< #TRUE if this allows, #FALSE if it denies */ + + union + { + struct + { + /* message type can be DBUS_MESSAGE_TYPE_INVALID meaning "any" */ + int message_type; + /* any of these can be NULL meaning "any" */ + char *path; + char *interface; + char *member; + char *error; + char *destination; + unsigned int eavesdrop : 1; + unsigned int requested_reply : 1; + unsigned int log : 1; + } send; + + struct + { + /* message type can be DBUS_MESSAGE_TYPE_INVALID meaning "any" */ + int message_type; + /* any of these can be NULL meaning "any" */ + char *path; + char *interface; + char *member; + char *error; + char *origin; + unsigned int eavesdrop : 1; + unsigned int requested_reply : 1; + } receive; + + struct + { + /* can be NULL meaning "any" */ + char *service_name; + /* if prefix is set, any name starting with service_name can be owned */ + unsigned int prefix : 1; + } own; + + struct + { + /* can be DBUS_UID_UNSET meaning "any" */ + dbus_uid_t uid; + } user; + + struct + { + /* can be DBUS_GID_UNSET meaning "any" */ + dbus_gid_t gid; + } group; + + } d; +}; + +BusPolicyRule* bus_policy_rule_new (BusPolicyRuleType type, + dbus_bool_t allow); +BusPolicyRule* bus_policy_rule_ref (BusPolicyRule *rule); +void bus_policy_rule_unref (BusPolicyRule *rule); + +BusPolicy* bus_policy_new (void); +BusPolicy* bus_policy_ref (BusPolicy *policy); +void bus_policy_unref (BusPolicy *policy); +BusClientPolicy* bus_policy_create_client_policy (BusPolicy *policy, + DBusConnection *connection, + DBusError *error); +dbus_bool_t bus_policy_allow_unix_user (BusPolicy *policy, + unsigned long uid); +dbus_bool_t bus_policy_allow_windows_user (BusPolicy *policy, + const char *windows_sid); +dbus_bool_t bus_policy_append_default_rule (BusPolicy *policy, + BusPolicyRule *rule); +dbus_bool_t bus_policy_append_mandatory_rule (BusPolicy *policy, + BusPolicyRule *rule); +dbus_bool_t bus_policy_append_user_rule (BusPolicy *policy, + dbus_uid_t uid, + BusPolicyRule *rule); +dbus_bool_t bus_policy_append_group_rule (BusPolicy *policy, + dbus_gid_t gid, + BusPolicyRule *rule); +dbus_bool_t bus_policy_append_console_rule (BusPolicy *policy, + dbus_bool_t at_console, + BusPolicyRule *rule); + +dbus_bool_t bus_policy_merge (BusPolicy *policy, + BusPolicy *to_absorb); + +BusClientPolicy* bus_client_policy_new (void); +BusClientPolicy* bus_client_policy_ref (BusClientPolicy *policy); +void bus_client_policy_unref (BusClientPolicy *policy); +dbus_bool_t bus_client_policy_check_can_send (BusClientPolicy *policy, + BusRegistry *registry, + dbus_bool_t requested_reply, + DBusConnection *receiver, + DBusMessage *message, + dbus_int32_t *toggles, + dbus_bool_t *log); +dbus_bool_t bus_client_policy_check_can_receive (BusClientPolicy *policy, + BusRegistry *registry, + dbus_bool_t requested_reply, + DBusConnection *sender, + DBusConnection *addressed_recipient, + DBusConnection *proposed_recipient, + DBusMessage *message, + dbus_int32_t *toggles); +dbus_bool_t bus_client_policy_check_can_own (BusClientPolicy *policy, + const DBusString *service_name); +dbus_bool_t bus_client_policy_append_rule (BusClientPolicy *policy, + BusPolicyRule *rule); +void bus_client_policy_optimize (BusClientPolicy *policy); + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS +dbus_bool_t bus_policy_check_can_own (BusPolicy *policy, + const DBusString *service_name); +#endif + +#endif /* BUS_POLICY_H */
diff --git a/bus/rc.messagebus.in b/bus/rc.messagebus.in new file mode 100644 index 0000000..c52ca77 --- /dev/null +++ b/bus/rc.messagebus.in
@@ -0,0 +1,79 @@ +#!/bin/sh +# +# messagebus: The D-BUS systemwide message bus +# +# chkconfig: 345 97 03 +# description: This is a daemon which broadcasts notifications of system events \ +# and other messages. See http://www.freedesktop.org/software/dbus/ +# +# processname: dbus-daemon +# pidfile: @DBUS_SYSTEM_PID_FILE@ +# + +# Sanity checks. +#[ -x @EXPANDED_BINDIR@/dbus-daemon ] || exit 0 + +# Source function library. +#. @EXPANDED_SYSCONFDIR@/rc.d/init.d/functions + +# so we can rearrange this easily +#processname=dbus-daemon +#servicename=messagebus + +#RETVAL=0 + +start() { + echo "Starting system message bus" + if [ -x @EXPANDED_BINDIR@/dbus-uuidgen ] ; then + @EXPANDED_BINDIR@/dbus-uuidgen --ensure + fi + + if [ -x @EXPANDED_BINDIR@/dbus-daemon ];then + @EXPANDED_BINDIR@/dbus-daemon --system + fi + #daemon --check $servicename $processname --system + #RETVAL=$? + #echo + #[ $RETVAL -eq 0 ] && touch @EXPANDED_LOCALSTATEDIR@/lock/subsys/$servicename +} + +stop() { + echo "Stopping system message bus" + + ## we don't want to kill all the per-user $processname, we want + ## to use the pid file *only*; because we use the fake nonexistent + ## program name "$servicename" that should be safe-ish + killall dbus-daemon + #RETVAL=$? + #echo + #if [ $RETVAL -eq 0 ]; then + # rm -f @EXPANDED_LOCALSTATEDIR@/lock/subsys/$servicename + # rm -f @DBUS_SYSTEM_PID_FILE@ + #fi +} + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status $servicename + RETVAL=$? + ;; + restart) + stop + start + ;; + reload) + echo "Message bus can't reload its configuration, you have to restart it" + RETVAL=$? + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|reload}" + ;; +esac +exit $RETVAL
diff --git a/bus/selinux.c b/bus/selinux.c new file mode 100644 index 0000000..ca884ef --- /dev/null +++ b/bus/selinux.c
@@ -0,0 +1,1020 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * selinux.c SELinux security checks for D-Bus + * + * Author: Matthew Rickard <mjricka@epoch.ncsc.mil> + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include <dbus/dbus-internals.h> +#include <dbus/dbus-string.h> +#ifndef DBUS_WIN +#include <dbus/dbus-userdb.h> +#endif +#include "selinux.h" +#include "audit.h" +#include "services.h" +#include "policy.h" +#include "utils.h" +#include "config-parser.h" + +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif +#ifdef HAVE_SELINUX +#include <sys/types.h> +#include <unistd.h> +#include <limits.h> +#include <pthread.h> +#include <syslog.h> +#include <selinux/selinux.h> +#include <selinux/avc.h> +#include <signal.h> +#include <stdarg.h> +#include <stdio.h> +#include <grp.h> +#endif /* HAVE_SELINUX */ +#ifdef HAVE_LIBAUDIT +#include <libaudit.h> +#endif /* HAVE_LIBAUDIT */ + +#define BUS_SID_FROM_SELINUX(sid) ((BusSELinuxID*) (sid)) +#define SELINUX_SID_FROM_BUS(sid) ((security_id_t) (sid)) + +#ifdef HAVE_SELINUX +/* Store the value telling us if SELinux is enabled in the kernel. */ +static dbus_bool_t selinux_enabled = FALSE; + +/* Store an avc_entry_ref to speed AVC decisions. */ +static struct avc_entry_ref aeref; + +/* Store the SID of the bus itself to use as the default. */ +static security_id_t bus_sid = SECSID_WILD; + +/* Thread to listen for SELinux status changes via netlink. */ +static pthread_t avc_notify_thread; + +/* Prototypes for AVC callback functions. */ +static void log_callback (const char *fmt, ...); +static void log_audit_callback (void *data, security_class_t class, char *buf, size_t bufleft); +static void *avc_create_thread (void (*run) (void)); +static void avc_stop_thread (void *thread); +static void *avc_alloc_lock (void); +static void avc_get_lock (void *lock); +static void avc_release_lock (void *lock); +static void avc_free_lock (void *lock); + +/* AVC callback structures for use in avc_init. */ +static const struct avc_memory_callback mem_cb = +{ + .func_malloc = dbus_malloc, + .func_free = dbus_free +}; +static const struct avc_log_callback log_cb = +{ + .func_log = log_callback, + .func_audit = log_audit_callback +}; +static const struct avc_thread_callback thread_cb = +{ + .func_create_thread = avc_create_thread, + .func_stop_thread = avc_stop_thread +}; +static const struct avc_lock_callback lock_cb = +{ + .func_alloc_lock = avc_alloc_lock, + .func_get_lock = avc_get_lock, + .func_release_lock = avc_release_lock, + .func_free_lock = avc_free_lock +}; +#endif /* HAVE_SELINUX */ + +/** + * Log callback to log denial messages from the AVC. + * This is used in avc_init. Logs to both standard + * error and syslogd. + * + * @param fmt the format string + * @param variable argument list + */ +#ifdef HAVE_SELINUX + +static void +log_callback (const char *fmt, ...) +{ + va_list ap; +#ifdef HAVE_LIBAUDIT + int audit_fd; +#endif + + va_start(ap, fmt); + +#ifdef HAVE_LIBAUDIT + audit_fd = bus_audit_get_fd (); + + if (audit_fd >= 0) + { + /* This should really be a DBusString, but DBusString allocates + * memory dynamically; before switching it, we need to check with + * SELinux people that it would be OK for this to fall back to + * syslog if OOM, like the equivalent AppArmor code does. */ + char buf[PATH_MAX*2]; + + /* FIXME: need to change this to show real user */ + vsnprintf(buf, sizeof(buf), fmt, ap); + audit_log_user_avc_message(audit_fd, AUDIT_USER_AVC, buf, NULL, NULL, + NULL, getuid()); + goto out; + } +#endif /* HAVE_LIBAUDIT */ + + vsyslog (LOG_USER | LOG_INFO, fmt, ap); + +#ifdef HAVE_LIBAUDIT +out: +#endif + va_end(ap); +} + +/** + * On a policy reload we need to reparse the SELinux configuration file, since + * this could have changed. Send a SIGHUP to reload all configs. + */ +static int +policy_reload_callback (u_int32_t event, security_id_t ssid, + security_id_t tsid, security_class_t tclass, + access_vector_t perms, access_vector_t *out_retained) +{ + if (event == AVC_CALLBACK_RESET) + return raise (SIGHUP); + + return 0; +} + +/** + * Log any auxiliary data + */ +static void +log_audit_callback (void *data, security_class_t class, char *buf, size_t bufleft) +{ + DBusString *audmsg = data; + + if (bufleft > (size_t) _dbus_string_get_length(audmsg)) + { + _dbus_string_copy_to_buffer_with_nul (audmsg, buf, bufleft); + } + else + { + DBusString s; + + _dbus_string_init_const(&s, "Buffer too small for audit message"); + + if (bufleft > (size_t) _dbus_string_get_length(&s)) + _dbus_string_copy_to_buffer_with_nul (&s, buf, bufleft); + } +} + +/** + * Create thread to notify the AVC of enforcing and policy reload + * changes via netlink. + * + * @param run the thread run function + * @return pointer to the thread + */ +static void * +avc_create_thread (void (*run) (void)) +{ + int rc; + + rc = pthread_create (&avc_notify_thread, NULL, (void *(*) (void *)) run, NULL); + if (rc != 0) + { + _dbus_warn ("Failed to start AVC thread: %s\n", _dbus_strerror (rc)); + exit (1); + } + return &avc_notify_thread; +} + +/* Stop AVC netlink thread. */ +static void +avc_stop_thread (void *thread) +{ + pthread_cancel (*(pthread_t *) thread); +} + +/* Allocate a new AVC lock. */ +static void * +avc_alloc_lock (void) +{ + pthread_mutex_t *avc_mutex; + + avc_mutex = dbus_new (pthread_mutex_t, 1); + if (avc_mutex == NULL) + { + _dbus_warn ("Could not create mutex: %s\n", _dbus_strerror (errno)); + exit (1); + } + pthread_mutex_init (avc_mutex, NULL); + + return avc_mutex; +} + +/* Acquire an AVC lock. */ +static void +avc_get_lock (void *lock) +{ + pthread_mutex_lock (lock); +} + +/* Release an AVC lock. */ +static void +avc_release_lock (void *lock) +{ + pthread_mutex_unlock (lock); +} + +/* Free an AVC lock. */ +static void +avc_free_lock (void *lock) +{ + pthread_mutex_destroy (lock); + dbus_free (lock); +} +#endif /* HAVE_SELINUX */ + +/** + * Return whether or not SELinux is enabled; must be + * called after bus_selinux_init. + */ +dbus_bool_t +bus_selinux_enabled (void) +{ +#ifdef HAVE_SELINUX + return selinux_enabled; +#else + return FALSE; +#endif /* HAVE_SELINUX */ +} + +/** + * Do early initialization; determine whether SELinux is enabled. + */ +dbus_bool_t +bus_selinux_pre_init (void) +{ +#ifdef HAVE_SELINUX + int r; + _dbus_assert (bus_sid == SECSID_WILD); + + /* Determine if we are running an SELinux kernel. */ + r = is_selinux_enabled (); + if (r < 0) + { + _dbus_warn ("Could not tell if SELinux is enabled: %s\n", + _dbus_strerror (errno)); + return FALSE; + } + + selinux_enabled = r != 0; + return TRUE; +#else + return TRUE; +#endif +} + +/* + * Private Flask definitions; the order of these constants must + * exactly match that of the structure array below! + */ +/* security dbus class constants */ +#define SECCLASS_DBUS 1 + +/* dbus's per access vector constants */ +#define DBUS__ACQUIRE_SVC 1 +#define DBUS__SEND_MSG 2 + +#ifdef HAVE_SELINUX +static struct security_class_mapping dbus_map[] = { + { "dbus", { "acquire_svc", "send_msg", NULL } }, + { NULL } +}; +#endif /* HAVE_SELINUX */ + +/** + * Establish dynamic object class and permission mapping and + * initialize the user space access vector cache (AVC) for D-Bus and set up + * logging callbacks. + */ +dbus_bool_t +bus_selinux_full_init (void) +{ +#ifdef HAVE_SELINUX + char *bus_context; + + _dbus_assert (bus_sid == SECSID_WILD); + + if (!selinux_enabled) + { + _dbus_verbose ("SELinux not enabled in this kernel.\n"); + return TRUE; + } + + _dbus_verbose ("SELinux is enabled in this kernel.\n"); + + if (selinux_set_mapping (dbus_map) < 0) + { + _dbus_warn ("Failed to set up security class mapping (selinux_set_mapping():%s).\n", + strerror (errno)); + return FALSE; + } + + avc_entry_ref_init (&aeref); + if (avc_init ("avc", &mem_cb, &log_cb, &thread_cb, &lock_cb) < 0) + { + _dbus_warn ("Failed to start Access Vector Cache (AVC).\n"); + return FALSE; + } + else + { + _dbus_verbose ("Access Vector Cache (AVC) started.\n"); + } + + if (avc_add_callback (policy_reload_callback, AVC_CALLBACK_RESET, + NULL, NULL, 0, 0) < 0) + { + _dbus_warn ("Failed to add policy reload callback: %s\n", + _dbus_strerror (errno)); + avc_destroy (); + return FALSE; + } + + bus_context = NULL; + bus_sid = SECSID_WILD; + + if (getcon (&bus_context) < 0) + { + _dbus_verbose ("Error getting context of bus: %s\n", + _dbus_strerror (errno)); + return FALSE; + } + + if (avc_context_to_sid (bus_context, &bus_sid) < 0) + { + _dbus_verbose ("Error getting SID from bus context: %s\n", + _dbus_strerror (errno)); + freecon (bus_context); + return FALSE; + } + + freecon (bus_context); + +#endif /* HAVE_SELINUX */ + return TRUE; +} + +/** + * Decrement SID reference count. + * + * @param sid the SID to decrement + */ +void +bus_selinux_id_unref (BusSELinuxID *sid) +{ +#ifdef HAVE_SELINUX + if (!selinux_enabled) + return; + + _dbus_assert (sid != NULL); + + sidput (SELINUX_SID_FROM_BUS (sid)); +#endif /* HAVE_SELINUX */ +} + +void +bus_selinux_id_ref (BusSELinuxID *sid) +{ +#ifdef HAVE_SELINUX + if (!selinux_enabled) + return; + + _dbus_assert (sid != NULL); + + sidget (SELINUX_SID_FROM_BUS (sid)); +#endif /* HAVE_SELINUX */ +} + +/** + * Determine if the SELinux security policy allows the given sender + * security context to go to the given recipient security context. + * This function determines if the requested permissions are to be + * granted from the connection to the message bus or to another + * optionally supplied security identifier (e.g. for a service + * context). Currently these permissions are either send_msg or + * acquire_svc in the dbus class. + * + * @param sender_sid source security context + * @param override_sid is the target security context. If SECSID_WILD this will + * use the context of the bus itself (e.g. the default). + * @param target_class is the target security class. + * @param requested is the requested permissions. + * @returns #TRUE if security policy allows the send. + */ +#ifdef HAVE_SELINUX +static dbus_bool_t +bus_selinux_check (BusSELinuxID *sender_sid, + BusSELinuxID *override_sid, + security_class_t target_class, + access_vector_t requested, + DBusString *auxdata) +{ + if (!selinux_enabled) + return TRUE; + + /* Make the security check. AVC checks enforcing mode here as well. */ + if (avc_has_perm (SELINUX_SID_FROM_BUS (sender_sid), + override_sid ? + SELINUX_SID_FROM_BUS (override_sid) : + SELINUX_SID_FROM_BUS (bus_sid), + target_class, requested, &aeref, auxdata) < 0) + { + switch (errno) + { + case EACCES: + _dbus_verbose ("SELinux denying due to security policy.\n"); + return FALSE; + case EINVAL: + _dbus_verbose ("SELinux denying due to invalid security context.\n"); + return FALSE; + default: + _dbus_verbose ("SELinux denying due to: %s\n", _dbus_strerror (errno)); + return FALSE; + } + } + else + return TRUE; +} +#endif /* HAVE_SELINUX */ + +/** + * Returns true if the given connection can acquire a service, + * assuming the given security ID is needed for that service. + * + * @param connection connection that wants to own the service + * @param service_sid the SID of the service from the table + * @returns #TRUE if acquire is permitted. + */ +dbus_bool_t +bus_selinux_allows_acquire_service (DBusConnection *connection, + BusSELinuxID *service_sid, + const char *service_name, + DBusError *error) +{ +#ifdef HAVE_SELINUX + BusSELinuxID *connection_sid; + unsigned long spid; + DBusString auxdata; + dbus_bool_t ret; + + if (!selinux_enabled) + return TRUE; + + connection_sid = bus_connection_get_selinux_id (connection); + if (!dbus_connection_get_unix_process_id (connection, &spid)) + spid = 0; + + if (!_dbus_string_init (&auxdata)) + goto oom; + + if (!_dbus_string_append (&auxdata, "service=")) + goto oom; + + if (!_dbus_string_append (&auxdata, service_name)) + goto oom; + + if (spid) + { + if (!_dbus_string_append (&auxdata, " spid=")) + goto oom; + + if (!_dbus_string_append_uint (&auxdata, spid)) + goto oom; + } + + ret = bus_selinux_check (connection_sid, + service_sid, + SECCLASS_DBUS, + DBUS__ACQUIRE_SVC, + &auxdata); + + _dbus_string_free (&auxdata); + return ret; + + oom: + _dbus_string_free (&auxdata); + BUS_SET_OOM (error); + return FALSE; + +#else + return TRUE; +#endif /* HAVE_SELINUX */ +} + +/** + * Check if SELinux security controls allow the message to be sent to a + * particular connection based on the security context of the sender and + * that of the receiver. The destination connection need not be the + * addressed recipient, it could be an "eavesdropper" + * + * @param sender the sender of the message. + * @param proposed_recipient the connection the message is to be sent to. + * @returns whether to allow the send + */ +dbus_bool_t +bus_selinux_allows_send (DBusConnection *sender, + DBusConnection *proposed_recipient, + const char *msgtype, + const char *interface, + const char *member, + const char *error_name, + const char *destination, + DBusError *error) +{ +#ifdef HAVE_SELINUX + BusSELinuxID *recipient_sid; + BusSELinuxID *sender_sid; + unsigned long spid, tpid; + DBusString auxdata; + dbus_bool_t ret; + dbus_bool_t string_alloced; + + if (!selinux_enabled) + return TRUE; + + if (!sender || !dbus_connection_get_unix_process_id (sender, &spid)) + spid = 0; + if (!proposed_recipient || !dbus_connection_get_unix_process_id (proposed_recipient, &tpid)) + tpid = 0; + + string_alloced = FALSE; + if (!_dbus_string_init (&auxdata)) + goto oom; + string_alloced = TRUE; + + if (!_dbus_string_append (&auxdata, "msgtype=")) + goto oom; + + if (!_dbus_string_append (&auxdata, msgtype)) + goto oom; + + if (interface) + { + if (!_dbus_string_append (&auxdata, " interface=")) + goto oom; + if (!_dbus_string_append (&auxdata, interface)) + goto oom; + } + + if (member) + { + if (!_dbus_string_append (&auxdata, " member=")) + goto oom; + if (!_dbus_string_append (&auxdata, member)) + goto oom; + } + + if (error_name) + { + if (!_dbus_string_append (&auxdata, " error_name=")) + goto oom; + if (!_dbus_string_append (&auxdata, error_name)) + goto oom; + } + + if (destination) + { + if (!_dbus_string_append (&auxdata, " dest=")) + goto oom; + if (!_dbus_string_append (&auxdata, destination)) + goto oom; + } + + if (spid) + { + if (!_dbus_string_append (&auxdata, " spid=")) + goto oom; + + if (!_dbus_string_append_uint (&auxdata, spid)) + goto oom; + } + + if (tpid) + { + if (!_dbus_string_append (&auxdata, " tpid=")) + goto oom; + + if (!_dbus_string_append_uint (&auxdata, tpid)) + goto oom; + } + + sender_sid = bus_connection_get_selinux_id (sender); + /* A NULL proposed_recipient means the bus itself. */ + if (proposed_recipient) + recipient_sid = bus_connection_get_selinux_id (proposed_recipient); + else + recipient_sid = BUS_SID_FROM_SELINUX (bus_sid); + + ret = bus_selinux_check (sender_sid, + recipient_sid, + SECCLASS_DBUS, + DBUS__SEND_MSG, + &auxdata); + + _dbus_string_free (&auxdata); + + return ret; + + oom: + if (string_alloced) + _dbus_string_free (&auxdata); + BUS_SET_OOM (error); + return FALSE; + +#else + return TRUE; +#endif /* HAVE_SELINUX */ +} + +dbus_bool_t +bus_selinux_append_context (DBusMessage *message, + BusSELinuxID *sid, + DBusError *error) +{ +#ifdef HAVE_SELINUX + char *context; + + if (avc_sid_to_context (SELINUX_SID_FROM_BUS (sid), &context) < 0) + { + if (errno == ENOMEM) + BUS_SET_OOM (error); + else + dbus_set_error (error, DBUS_ERROR_FAILED, + "Error getting context from SID: %s\n", + _dbus_strerror (errno)); + return FALSE; + } + if (!dbus_message_append_args (message, + DBUS_TYPE_ARRAY, + DBUS_TYPE_BYTE, + &context, + strlen (context), + DBUS_TYPE_INVALID)) + { + _DBUS_SET_OOM (error); + return FALSE; + } + freecon (context); + return TRUE; +#else + return TRUE; +#endif +} + +/** + * Gets the security context of a connection to the bus. It is up to + * the caller to freecon() when they are done. + * + * @param connection the connection to get the context of. + * @param con the location to store the security context. + * @returns #TRUE if context is successfully obtained. + */ +#ifdef HAVE_SELINUX +static dbus_bool_t +bus_connection_read_selinux_context (DBusConnection *connection, + char **con) +{ + int fd; + + if (!selinux_enabled) + return FALSE; + + _dbus_assert (connection != NULL); + + if (!dbus_connection_get_unix_fd (connection, &fd)) + { + _dbus_verbose ("Failed to get file descriptor of socket.\n"); + return FALSE; + } + + if (getpeercon (fd, con) < 0) + { + _dbus_verbose ("Error getting context of socket peer: %s\n", + _dbus_strerror (errno)); + return FALSE; + } + + _dbus_verbose ("Successfully read connection context.\n"); + return TRUE; +} +#endif /* HAVE_SELINUX */ + +/** + * Read the SELinux ID from the connection. + * + * @param connection the connection to read from + * @returns the SID if successfully determined, #NULL otherwise. + */ +BusSELinuxID* +bus_selinux_init_connection_id (DBusConnection *connection, + DBusError *error) +{ +#ifdef HAVE_SELINUX + char *con; + security_id_t sid; + + if (!selinux_enabled) + return NULL; + + if (!bus_connection_read_selinux_context (connection, &con)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Failed to read an SELinux context from connection"); + _dbus_verbose ("Error getting peer context.\n"); + return NULL; + } + + _dbus_verbose ("Converting context to SID to store on connection\n"); + + if (avc_context_to_sid (con, &sid) < 0) + { + if (errno == ENOMEM) + BUS_SET_OOM (error); + else + dbus_set_error (error, DBUS_ERROR_FAILED, + "Error getting SID from context \"%s\": %s\n", + con, _dbus_strerror (errno)); + + _dbus_warn ("Error getting SID from context \"%s\": %s\n", + con, _dbus_strerror (errno)); + + freecon (con); + return NULL; + } + + freecon (con); + return BUS_SID_FROM_SELINUX (sid); +#else + return NULL; +#endif /* HAVE_SELINUX */ +} + + +/** + * Function for freeing hash table data. These SIDs + * should no longer be referenced. + */ +static void +bus_selinux_id_table_free_value (BusSELinuxID *sid) +{ +#ifdef HAVE_SELINUX + /* NULL sometimes due to how DBusHashTable works */ + if (sid) + bus_selinux_id_unref (sid); +#endif /* HAVE_SELINUX */ +} + +/** + * Creates a new table mapping service names to security ID. + * A security ID is a "compiled" security context, a security + * context is just a string. + * + * @returns the new table or #NULL if no memory + */ +DBusHashTable* +bus_selinux_id_table_new (void) +{ + return _dbus_hash_table_new (DBUS_HASH_STRING, + (DBusFreeFunction) dbus_free, + (DBusFreeFunction) bus_selinux_id_table_free_value); +} + +/** + * Hashes a service name and service context into the service SID + * table as a string and a SID. + * + * @param service_name is the name of the service. + * @param service_context is the context of the service. + * @param service_table is the table to hash them into. + * @return #FALSE if not enough memory + */ +dbus_bool_t +bus_selinux_id_table_insert (DBusHashTable *service_table, + const char *service_name, + const char *service_context) +{ +#ifdef HAVE_SELINUX + dbus_bool_t retval; + security_id_t sid; + char *key; + + if (!selinux_enabled) + return TRUE; + + sid = SECSID_WILD; + retval = FALSE; + + key = _dbus_strdup (service_name); + if (key == NULL) + return retval; + + if (avc_context_to_sid ((char *) service_context, &sid) < 0) + { + if (errno == ENOMEM) + { + dbus_free (key); + return FALSE; + } + + _dbus_warn ("Error getting SID from context \"%s\": %s\n", + (char *) service_context, + _dbus_strerror (errno)); + goto out; + } + + if (!_dbus_hash_table_insert_string (service_table, + key, + BUS_SID_FROM_SELINUX (sid))) + goto out; + + _dbus_verbose ("Parsed \tservice: %s \n\t\tcontext: %s\n", + key, + sid->ctx); + + /* These are owned by the hash, so clear them to avoid unref */ + key = NULL; + sid = SECSID_WILD; + + retval = TRUE; + + out: + if (sid != SECSID_WILD) + sidput (sid); + + if (key) + dbus_free (key); + + return retval; +#else + return TRUE; +#endif /* HAVE_SELINUX */ +} + + +/** + * Find the security identifier associated with a particular service + * name. Return a pointer to this SID, or #NULL/SECSID_WILD if the + * service is not found in the hash table. This should be nearly a + * constant time operation. If SELinux support is not available, + * always return NULL. + * + * @param service_table the hash table to check for service name. + * @param service_name the name of the service to look for. + * @returns the SELinux ID associated with the service + */ +BusSELinuxID* +bus_selinux_id_table_lookup (DBusHashTable *service_table, + const DBusString *service_name) +{ +#ifdef HAVE_SELINUX + security_id_t sid; + + sid = SECSID_WILD; /* default context */ + + if (!selinux_enabled) + return NULL; + + _dbus_verbose ("Looking up service SID for %s\n", + _dbus_string_get_const_data (service_name)); + + sid = _dbus_hash_table_lookup_string (service_table, + _dbus_string_get_const_data (service_name)); + + if (sid == SECSID_WILD) + _dbus_verbose ("Service %s not found\n", + _dbus_string_get_const_data (service_name)); + else + _dbus_verbose ("Service %s found\n", + _dbus_string_get_const_data (service_name)); + + return BUS_SID_FROM_SELINUX (sid); +#endif /* HAVE_SELINUX */ + return NULL; +} + +/** + * Get the SELinux policy root. This is used to find the D-Bus + * specific config file within the policy. + */ +const char * +bus_selinux_get_policy_root (void) +{ +#ifdef HAVE_SELINUX + return selinux_policy_root (); +#else + return NULL; +#endif /* HAVE_SELINUX */ +} + +/** + * For debugging: Print out the current hash table of service SIDs. + */ +void +bus_selinux_id_table_print (DBusHashTable *service_table) +{ +#if defined (DBUS_ENABLE_VERBOSE_MODE) && defined (HAVE_SELINUX) + DBusHashIter iter; + + if (!selinux_enabled) + return; + + _dbus_verbose ("Service SID Table:\n"); + _dbus_hash_iter_init (service_table, &iter); + while (_dbus_hash_iter_next (&iter)) + { + const char *key = _dbus_hash_iter_get_string_key (&iter); + security_id_t sid = _dbus_hash_iter_get_value (&iter); + _dbus_verbose ("The key is %s\n", key); + _dbus_verbose ("The context is %s\n", sid->ctx); + _dbus_verbose ("The refcount is %d\n", sid->refcnt); + } +#endif /* DBUS_ENABLE_VERBOSE_MODE && HAVE_SELINUX */ +} + + +/** + * Print out some AVC statistics. + */ +#ifdef HAVE_SELINUX +static void +bus_avc_print_stats (void) +{ +#ifdef DBUS_ENABLE_VERBOSE_MODE + struct avc_cache_stats cstats; + + if (!selinux_enabled) + return; + + _dbus_verbose ("AVC Statistics:\n"); + avc_cache_stats (&cstats); + avc_av_stats (); + _dbus_verbose ("AVC Cache Statistics:\n"); + _dbus_verbose ("Entry lookups: %d\n", cstats.entry_lookups); + _dbus_verbose ("Entry hits: %d\n", cstats.entry_hits); + _dbus_verbose ("Entry misses %d\n", cstats.entry_misses); + _dbus_verbose ("Entry discards: %d\n", cstats.entry_discards); + _dbus_verbose ("CAV lookups: %d\n", cstats.cav_lookups); + _dbus_verbose ("CAV hits: %d\n", cstats.cav_hits); + _dbus_verbose ("CAV probes: %d\n", cstats.cav_probes); + _dbus_verbose ("CAV misses: %d\n", cstats.cav_misses); +#endif /* DBUS_ENABLE_VERBOSE_MODE */ +} +#endif /* HAVE_SELINUX */ + +/** + * Destroy the AVC before we terminate. + */ +void +bus_selinux_shutdown (void) +{ +#ifdef HAVE_SELINUX + if (!selinux_enabled) + return; + + _dbus_verbose ("AVC shutdown\n"); + + if (bus_sid != SECSID_WILD) + { + sidput (bus_sid); + bus_sid = SECSID_WILD; + + bus_avc_print_stats (); + + avc_destroy (); + } +#endif /* HAVE_SELINUX */ +}
diff --git a/bus/selinux.h b/bus/selinux.h new file mode 100644 index 0000000..e44c97e --- /dev/null +++ b/bus/selinux.h
@@ -0,0 +1,69 @@ +/* selinux.h SELinux security check headers for D-BUS + * + * Author: Matthew Rickard <mjricka@epoch.ncsc.mil> + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_SELINUX_H +#define BUS_SELINUX_H + +#include <dbus/dbus-hash.h> +#include <dbus/dbus-connection.h> +#include "services.h" + +dbus_bool_t bus_selinux_pre_init (void); +dbus_bool_t bus_selinux_full_init(void); +void bus_selinux_shutdown (void); + +dbus_bool_t bus_selinux_enabled (void); + +void bus_selinux_id_ref (BusSELinuxID *sid); +void bus_selinux_id_unref (BusSELinuxID *sid); + +DBusHashTable* bus_selinux_id_table_new (void); +BusSELinuxID* bus_selinux_id_table_lookup (DBusHashTable *service_table, + const DBusString *service_name); +dbus_bool_t bus_selinux_id_table_insert (DBusHashTable *service_table, + const char *service_name, + const char *service_context); +void bus_selinux_id_table_print (DBusHashTable *service_table); +const char* bus_selinux_get_policy_root (void); + +dbus_bool_t bus_selinux_append_context (DBusMessage *message, + BusSELinuxID *context, + DBusError *error); + +dbus_bool_t bus_selinux_allows_acquire_service (DBusConnection *connection, + BusSELinuxID *service_sid, + const char *service_name, + DBusError *error); + +dbus_bool_t bus_selinux_allows_send (DBusConnection *sender, + DBusConnection *proposed_recipient, + const char *msgtype, /* Supplementary audit data */ + const char *interface, + const char *member, + const char *error_name, + const char *destination, + DBusError *error); + +BusSELinuxID* bus_selinux_init_connection_id (DBusConnection *connection, + DBusError *error); + +#endif /* BUS_SELINUX_H */
diff --git a/bus/services.c b/bus/services.c new file mode 100644 index 0000000..6a4c884 --- /dev/null +++ b/bus/services.c
@@ -0,0 +1,1312 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* services.c Service management + * + * Copyright (C) 2003 Red Hat, Inc. + * Copyright (C) 2003 CodeFactory AB + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include <dbus/dbus-hash.h> +#include <dbus/dbus-list.h> +#include <dbus/dbus-mempool.h> +#include <dbus/dbus-marshal-validate.h> + +#include "driver.h" +#include "services.h" +#include "connection.h" +#include "utils.h" +#include "activation.h" +#include "policy.h" +#include "bus.h" +#include "selinux.h" +#include "apparmor.h" + +struct BusService +{ + int refcount; + + BusRegistry *registry; + char *name; + DBusList *owners; +}; + +struct BusOwner +{ + int refcount; + + BusService *service; + DBusConnection *conn; + + unsigned int allow_replacement : 1; + unsigned int do_not_queue : 1; +}; + +struct BusRegistry +{ + int refcount; + + BusContext *context; + + DBusHashTable *service_hash; + DBusMemPool *service_pool; + DBusMemPool *owner_pool; + + DBusHashTable *service_sid_table; +}; + +BusRegistry* +bus_registry_new (BusContext *context) +{ + BusRegistry *registry; + + _dbus_assert (context); + registry = dbus_new0 (BusRegistry, 1); + if (registry == NULL) + return NULL; + + registry->refcount = 1; + registry->context = context; + + registry->service_hash = _dbus_hash_table_new (DBUS_HASH_STRING, + NULL, NULL); + if (registry->service_hash == NULL) + goto failed; + + registry->service_pool = _dbus_mem_pool_new (sizeof (BusService), + TRUE); + + if (registry->service_pool == NULL) + goto failed; + + registry->owner_pool = _dbus_mem_pool_new (sizeof (BusOwner), + TRUE); + + if (registry->owner_pool == NULL) + goto failed; + + registry->service_sid_table = NULL; + + return registry; + + failed: + bus_registry_unref (registry); + return NULL; +} + +BusRegistry * +bus_registry_ref (BusRegistry *registry) +{ + _dbus_assert (registry->refcount > 0); + registry->refcount += 1; + + return registry; +} + +void +bus_registry_unref (BusRegistry *registry) +{ + _dbus_assert (registry->refcount > 0); + registry->refcount -= 1; + + if (registry->refcount == 0) + { + if (registry->service_hash) + _dbus_hash_table_unref (registry->service_hash); + if (registry->service_pool) + _dbus_mem_pool_free (registry->service_pool); + if (registry->owner_pool) + _dbus_mem_pool_free (registry->owner_pool); + if (registry->service_sid_table) + _dbus_hash_table_unref (registry->service_sid_table); + + dbus_free (registry); + } +} + +BusService* +bus_registry_lookup (BusRegistry *registry, + const DBusString *service_name) +{ + BusService *service; + + service = _dbus_hash_table_lookup_string (registry->service_hash, + _dbus_string_get_const_data (service_name)); + + return service; +} + +static DBusList * +_bus_service_find_owner_link (BusService *service, + DBusConnection *connection) +{ + DBusList *link; + + link = _dbus_list_get_first_link (&service->owners); + + while (link != NULL) + { + BusOwner *bus_owner; + + bus_owner = (BusOwner *) link->data; + if (bus_owner->conn == connection) + break; + + link = _dbus_list_get_next_link (&service->owners, link); + } + + return link; +} + +static void +bus_owner_set_flags (BusOwner *owner, + dbus_uint32_t flags) +{ + owner->allow_replacement = + (flags & DBUS_NAME_FLAG_ALLOW_REPLACEMENT) != FALSE; + + owner->do_not_queue = + (flags & DBUS_NAME_FLAG_DO_NOT_QUEUE) != FALSE; +} + +static BusOwner * +bus_owner_new (BusService *service, + DBusConnection *conn, + dbus_uint32_t flags) +{ + BusOwner *result; + + result = _dbus_mem_pool_alloc (service->registry->owner_pool); + if (result != NULL) + { + result->refcount = 1; + /* don't ref the connection because we don't want + to block the connection from going away. + transactions take care of reffing the connection + but we need to use refcounting on the owner + so that the owner does not get freed before + we can deref the connection in the transaction + */ + result->conn = conn; + result->service = service; + + if (!bus_connection_add_owned_service (conn, service)) + { + _dbus_mem_pool_dealloc (service->registry->owner_pool, result); + return NULL; + } + + bus_owner_set_flags (result, flags); + } + return result; +} + +static BusOwner * +bus_owner_ref (BusOwner *owner) +{ + _dbus_assert (owner->refcount > 0); + owner->refcount += 1; + + return owner; +} + +static void +bus_owner_unref (BusOwner *owner) +{ + _dbus_assert (owner->refcount > 0); + owner->refcount -= 1; + + if (owner->refcount == 0) + { + bus_connection_remove_owned_service (owner->conn, owner->service); + _dbus_mem_pool_dealloc (owner->service->registry->owner_pool, owner); + } +} + +BusService* +bus_registry_ensure (BusRegistry *registry, + const DBusString *service_name, + DBusConnection *owner_connection_if_created, + dbus_uint32_t flags, + BusTransaction *transaction, + DBusError *error) +{ + BusService *service; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + _dbus_assert (owner_connection_if_created != NULL); + _dbus_assert (transaction != NULL); + + service = _dbus_hash_table_lookup_string (registry->service_hash, + _dbus_string_get_const_data (service_name)); + if (service != NULL) + return service; + + service = _dbus_mem_pool_alloc (registry->service_pool); + if (service == NULL) + { + BUS_SET_OOM (error); + return NULL; + } + + service->registry = registry; + service->refcount = 1; + + _dbus_verbose ("copying string %p '%s' to service->name\n", + service_name, _dbus_string_get_const_data (service_name)); + if (!_dbus_string_copy_data (service_name, &service->name)) + { + _dbus_mem_pool_dealloc (registry->service_pool, service); + BUS_SET_OOM (error); + return NULL; + } + _dbus_verbose ("copied string %p '%s' to '%s'\n", + service_name, _dbus_string_get_const_data (service_name), + service->name); + + if (!bus_driver_send_service_owner_changed (service->name, + NULL, + bus_connection_get_name (owner_connection_if_created), + transaction, error)) + { + bus_service_unref (service); + return NULL; + } + + if (!bus_activation_service_created (bus_context_get_activation (registry->context), + service->name, transaction, error)) + { + bus_service_unref (service); + return NULL; + } + + if (!bus_service_add_owner (service, owner_connection_if_created, flags, + transaction, error)) + { + bus_service_unref (service); + return NULL; + } + + if (!_dbus_hash_table_insert_string (registry->service_hash, + service->name, + service)) + { + /* The add_owner gets reverted on transaction cancel */ + BUS_SET_OOM (error); + return NULL; + } + + return service; +} + +void +bus_registry_foreach (BusRegistry *registry, + BusServiceForeachFunction function, + void *data) +{ + DBusHashIter iter; + + _dbus_hash_iter_init (registry->service_hash, &iter); + while (_dbus_hash_iter_next (&iter)) + { + BusService *service = _dbus_hash_iter_get_value (&iter); + + (* function) (service, data); + } +} + +dbus_bool_t +bus_registry_list_services (BusRegistry *registry, + char ***listp, + int *array_len) +{ + int i, j, len; + char **retval; + DBusHashIter iter; + + len = _dbus_hash_table_get_n_entries (registry->service_hash); + retval = dbus_new (char *, len + 1); + + if (retval == NULL) + return FALSE; + + _dbus_hash_iter_init (registry->service_hash, &iter); + i = 0; + while (_dbus_hash_iter_next (&iter)) + { + BusService *service = _dbus_hash_iter_get_value (&iter); + + retval[i] = _dbus_strdup (service->name); + if (retval[i] == NULL) + goto error; + + i++; + } + + retval[i] = NULL; + + if (array_len) + *array_len = len; + + *listp = retval; + return TRUE; + + error: + for (j = 0; j < i; j++) + dbus_free (retval[j]); + dbus_free (retval); + + return FALSE; +} + +dbus_bool_t +bus_registry_acquire_service (BusRegistry *registry, + DBusConnection *connection, + const DBusString *service_name, + dbus_uint32_t flags, + dbus_uint32_t *result, + BusTransaction *transaction, + DBusError *error) +{ + dbus_bool_t retval; + DBusConnection *old_owner_conn; + BusClientPolicy *policy; + BusService *service; + BusActivation *activation; + BusSELinuxID *sid; + BusOwner *primary_owner; + + retval = FALSE; + + if (!_dbus_validate_bus_name (service_name, 0, + _dbus_string_get_length (service_name))) + { + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "Requested bus name \"%s\" is not valid", + _dbus_string_get_const_data (service_name)); + + _dbus_verbose ("Attempt to acquire invalid service name\n"); + + goto out; + } + + if (_dbus_string_get_byte (service_name, 0) == ':') + { + /* Not allowed; only base services can start with ':' */ + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "Cannot acquire a service starting with ':' such as \"%s\"", + _dbus_string_get_const_data (service_name)); + + _dbus_verbose ("Attempt to acquire invalid base service name \"%s\"", + _dbus_string_get_const_data (service_name)); + + goto out; + } + + if (_dbus_string_equal_c_str (service_name, DBUS_SERVICE_DBUS)) + { + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "Connection \"%s\" is not allowed to own the service \"%s\"because " + "it is reserved for D-Bus' use only", + bus_connection_is_active (connection) ? + bus_connection_get_name (connection) : + "(inactive)", + DBUS_SERVICE_DBUS); + goto out; + } + + policy = bus_connection_get_policy (connection); + _dbus_assert (policy != NULL); + + /* Note that if sid is #NULL then the bus's own context gets used + * in bus_connection_selinux_allows_acquire_service() + */ + sid = bus_selinux_id_table_lookup (registry->service_sid_table, + service_name); + + if (!bus_selinux_allows_acquire_service (connection, sid, + _dbus_string_get_const_data (service_name), error)) + { + + if (dbus_error_is_set (error) && + dbus_error_has_name (error, DBUS_ERROR_NO_MEMORY)) + { + goto out; + } + + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "Connection \"%s\" is not allowed to own the service \"%s\" due " + "to SELinux policy", + bus_connection_is_active (connection) ? + bus_connection_get_name (connection) : + "(inactive)", + _dbus_string_get_const_data (service_name)); + goto out; + } + + if (!bus_apparmor_allows_acquire_service (connection, + bus_context_get_type (registry->context), + _dbus_string_get_const_data (service_name), error)) + goto out; + + if (!bus_client_policy_check_can_own (policy, service_name)) + { + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "Connection \"%s\" is not allowed to own the service \"%s\" due " + "to security policies in the configuration file", + bus_connection_is_active (connection) ? + bus_connection_get_name (connection) : + "(inactive)", + _dbus_string_get_const_data (service_name)); + goto out; + } + + if (bus_connection_get_n_services_owned (connection) >= + bus_context_get_max_services_per_connection (registry->context)) + { + dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED, + "Connection \"%s\" is not allowed to own more services " + "(increase limits in configuration file if required)", + bus_connection_is_active (connection) ? + bus_connection_get_name (connection) : + "(inactive)"); + goto out; + } + + service = bus_registry_lookup (registry, service_name); + + if (service != NULL) + { + primary_owner = bus_service_get_primary_owner (service); + if (primary_owner != NULL) + old_owner_conn = primary_owner->conn; + else + old_owner_conn = NULL; + } + else + old_owner_conn = NULL; + + if (service == NULL) + { + service = bus_registry_ensure (registry, + service_name, connection, flags, + transaction, error); + if (service == NULL) + goto out; + } + + primary_owner = bus_service_get_primary_owner (service); + if (primary_owner == NULL) + goto out; + + if (old_owner_conn == NULL) + { + _dbus_assert (primary_owner->conn == connection); + + *result = DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER; + } + else if (old_owner_conn == connection) + { + bus_owner_set_flags (primary_owner, flags); + *result = DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER; + } + else if (((flags & DBUS_NAME_FLAG_DO_NOT_QUEUE) && + !(bus_service_get_allow_replacement (service))) || + ((flags & DBUS_NAME_FLAG_DO_NOT_QUEUE) && + !(flags & DBUS_NAME_FLAG_REPLACE_EXISTING))) + { + DBusList *link; + BusOwner *temp_owner; + /* Since we can't be queued if we are already in the queue + remove us */ + + link = _bus_service_find_owner_link (service, connection); + if (link != NULL) + { + _dbus_list_unlink (&service->owners, link); + temp_owner = (BusOwner *)link->data; + bus_owner_unref (temp_owner); + _dbus_list_free_link (link); + } + + *result = DBUS_REQUEST_NAME_REPLY_EXISTS; + } + else if (!(flags & DBUS_NAME_FLAG_DO_NOT_QUEUE) && + (!(flags & DBUS_NAME_FLAG_REPLACE_EXISTING) || + !(bus_service_get_allow_replacement (service)))) + { + /* Queue the connection */ + if (!bus_service_add_owner (service, connection, + flags, + transaction, error)) + goto out; + + *result = DBUS_REQUEST_NAME_REPLY_IN_QUEUE; + } + else + { + /* Replace the current owner */ + + /* We enqueue the new owner and remove the first one because + * that will cause NameAcquired and NameLost messages to + * be sent. + */ + + if (!bus_service_add_owner (service, connection, + flags, + transaction, error)) + goto out; + + if (primary_owner->do_not_queue) + { + if (!bus_service_remove_owner (service, old_owner_conn, + transaction, error)) + goto out; + } + else + { + if (!bus_service_swap_owner (service, old_owner_conn, + transaction, error)) + goto out; + } + + + _dbus_assert (connection == bus_service_get_primary_owner (service)->conn); + *result = DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER; + } + + activation = bus_context_get_activation (registry->context); + retval = bus_activation_send_pending_auto_activation_messages (activation, + service, + transaction); + if (!retval) + BUS_SET_OOM (error); + + out: + return retval; +} + +dbus_bool_t +bus_registry_release_service (BusRegistry *registry, + DBusConnection *connection, + const DBusString *service_name, + dbus_uint32_t *result, + BusTransaction *transaction, + DBusError *error) +{ + dbus_bool_t retval; + BusService *service; + + retval = FALSE; + + if (!_dbus_validate_bus_name (service_name, 0, + _dbus_string_get_length (service_name))) + { + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "Given bus name \"%s\" is not valid", + _dbus_string_get_const_data (service_name)); + + _dbus_verbose ("Attempt to release invalid service name\n"); + + goto out; + } + + if (_dbus_string_get_byte (service_name, 0) == ':') + { + /* Not allowed; the base service name cannot be created or released */ + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "Cannot release a service starting with ':' such as \"%s\"", + _dbus_string_get_const_data (service_name)); + + _dbus_verbose ("Attempt to release invalid base service name \"%s\"", + _dbus_string_get_const_data (service_name)); + + goto out; + } + + if (_dbus_string_equal_c_str (service_name, DBUS_SERVICE_DBUS)) + { + /* Not allowed; the base service name cannot be created or released */ + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "Cannot release the %s service because it is owned by the bus", + DBUS_SERVICE_DBUS); + + _dbus_verbose ("Attempt to release service name \"%s\"", + DBUS_SERVICE_DBUS); + + goto out; + } + + service = bus_registry_lookup (registry, service_name); + + if (service == NULL) + { + *result = DBUS_RELEASE_NAME_REPLY_NON_EXISTENT; + } + else if (!bus_service_has_owner (service, connection)) + { + *result = DBUS_RELEASE_NAME_REPLY_NOT_OWNER; + } + else + { + if (!bus_service_remove_owner (service, connection, + transaction, error)) + goto out; + + _dbus_assert (!bus_service_has_owner (service, connection)); + *result = DBUS_RELEASE_NAME_REPLY_RELEASED; + } + + retval = TRUE; + + out: + return retval; +} + +dbus_bool_t +bus_registry_set_service_context_table (BusRegistry *registry, + DBusHashTable *table) +{ + DBusHashTable *new_table; + DBusHashIter iter; + + new_table = bus_selinux_id_table_new (); + if (!new_table) + return FALSE; + + _dbus_hash_iter_init (table, &iter); + while (_dbus_hash_iter_next (&iter)) + { + const char *service = _dbus_hash_iter_get_string_key (&iter); + const char *context = _dbus_hash_iter_get_value (&iter); + + if (!bus_selinux_id_table_insert (new_table, + service, + context)) + return FALSE; + } + + if (registry->service_sid_table) + _dbus_hash_table_unref (registry->service_sid_table); + registry->service_sid_table = new_table; + return TRUE; +} + +static void +bus_service_unlink_owner (BusService *service, + BusOwner *owner) +{ + _dbus_list_remove_last (&service->owners, owner); + bus_owner_unref (owner); +} + +static void +bus_service_unlink (BusService *service) +{ + _dbus_assert (service->owners == NULL); + + /* the service may not be in the hash, if + * the failure causing transaction cancel + * was in the right place, but that's OK + */ + _dbus_hash_table_remove_string (service->registry->service_hash, + service->name); + + bus_service_unref (service); +} + +static void +bus_service_relink (BusService *service, + DBusPreallocatedHash *preallocated) +{ + _dbus_assert (service->owners == NULL); + _dbus_assert (preallocated != NULL); + + _dbus_hash_table_insert_string_preallocated (service->registry->service_hash, + preallocated, + service->name, + service); + + bus_service_ref (service); +} + +/** + * Data used to represent an ownership cancellation in + * a bus transaction. + */ +typedef struct +{ + BusOwner *owner; /**< the owner */ + BusService *service; /**< service to cancel ownership of */ +} OwnershipCancelData; + +static void +cancel_ownership (void *data) +{ + OwnershipCancelData *d = data; + + /* We don't need to send messages notifying of these + * changes, since we're reverting something that was + * cancelled (effectively never really happened) + */ + bus_service_unlink_owner (d->service, d->owner); + + if (d->service->owners == NULL) + bus_service_unlink (d->service); +} + +static void +free_ownership_cancel_data (void *data) +{ + OwnershipCancelData *d = data; + + dbus_connection_unref (d->owner->conn); + bus_owner_unref (d->owner); + bus_service_unref (d->service); + + dbus_free (d); +} + +static dbus_bool_t +add_cancel_ownership_to_transaction (BusTransaction *transaction, + BusService *service, + BusOwner *owner) +{ + OwnershipCancelData *d; + + d = dbus_new (OwnershipCancelData, 1); + if (d == NULL) + return FALSE; + + d->service = service; + d->owner = owner; + + if (!bus_transaction_add_cancel_hook (transaction, cancel_ownership, d, + free_ownership_cancel_data)) + { + dbus_free (d); + return FALSE; + } + + bus_service_ref (d->service); + bus_owner_ref (owner); + dbus_connection_ref (d->owner->conn); + + return TRUE; +} + +/* this function is self-cancelling if you cancel the transaction */ +dbus_bool_t +bus_service_add_owner (BusService *service, + DBusConnection *connection, + dbus_uint32_t flags, + BusTransaction *transaction, + DBusError *error) +{ + BusOwner *bus_owner; + DBusList *bus_owner_link; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + /* Send service acquired message first, OOM will result + * in cancelling the transaction + */ + if (service->owners == NULL) + { + if (!bus_driver_send_service_acquired (connection, service->name, transaction, error)) + return FALSE; + } + + bus_owner_link = _bus_service_find_owner_link (service, connection); + + if (bus_owner_link == NULL) + { + bus_owner = bus_owner_new (service, connection, flags); + if (bus_owner == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + bus_owner_set_flags (bus_owner, flags); + if (!(flags & DBUS_NAME_FLAG_REPLACE_EXISTING) || service->owners == NULL) + { + if (!_dbus_list_append (&service->owners, + bus_owner)) + { + bus_owner_unref (bus_owner); + BUS_SET_OOM (error); + return FALSE; + } + } + else + { + if (!_dbus_list_insert_after (&service->owners, + _dbus_list_get_first_link (&service->owners), + bus_owner)) + { + bus_owner_unref (bus_owner); + BUS_SET_OOM (error); + return FALSE; + } + } + } + else + { + /* Update the link since we are already in the queue + * No need for operations that can produce OOM + */ + + bus_owner = (BusOwner *) bus_owner_link->data; + if (flags & DBUS_NAME_FLAG_REPLACE_EXISTING) + { + DBusList *link; + _dbus_list_unlink (&service->owners, bus_owner_link); + link = _dbus_list_get_first_link (&service->owners); + _dbus_assert (link != NULL); + + _dbus_list_insert_after_link (&service->owners, link, bus_owner_link); + } + + bus_owner_set_flags (bus_owner, flags); + return TRUE; + } + + if (!add_cancel_ownership_to_transaction (transaction, + service, + bus_owner)) + { + bus_service_unlink_owner (service, bus_owner); + BUS_SET_OOM (error); + return FALSE; + } + + return TRUE; +} + +typedef struct +{ + BusOwner *owner; + BusService *service; + BusOwner *before_owner; /* restore to position before this connection in owners list */ + DBusList *owner_link; + DBusList *service_link; + DBusPreallocatedHash *hash_entry; +} OwnershipRestoreData; + +static void +restore_ownership (void *data) +{ + OwnershipRestoreData *d = data; + DBusList *link; + + _dbus_assert (d->service_link != NULL); + _dbus_assert (d->owner_link != NULL); + + if (d->service->owners == NULL) + { + _dbus_assert (d->hash_entry != NULL); + bus_service_relink (d->service, d->hash_entry); + } + else + { + _dbus_assert (d->hash_entry == NULL); + } + + /* We don't need to send messages notifying of these + * changes, since we're reverting something that was + * cancelled (effectively never really happened) + */ + link = _dbus_list_get_first_link (&d->service->owners); + while (link != NULL) + { + if (link->data == d->before_owner) + break; + + link = _dbus_list_get_next_link (&d->service->owners, link); + } + + _dbus_list_insert_before_link (&d->service->owners, link, d->owner_link); + + /* Note that removing then restoring this changes the order in which + * ServiceDeleted messages are sent on destruction of the + * connection. This should be OK as the only guarantee there is + * that the base service is destroyed last, and we never even + * tentatively remove the base service. + */ + bus_connection_add_owned_service_link (d->owner->conn, d->service_link); + + d->hash_entry = NULL; + d->service_link = NULL; + d->owner_link = NULL; +} + +static void +free_ownership_restore_data (void *data) +{ + OwnershipRestoreData *d = data; + + if (d->service_link) + _dbus_list_free_link (d->service_link); + if (d->owner_link) + _dbus_list_free_link (d->owner_link); + if (d->hash_entry) + _dbus_hash_table_free_preallocated_entry (d->service->registry->service_hash, + d->hash_entry); + + dbus_connection_unref (d->owner->conn); + bus_owner_unref (d->owner); + bus_service_unref (d->service); + + dbus_free (d); +} + +static dbus_bool_t +add_restore_ownership_to_transaction (BusTransaction *transaction, + BusService *service, + BusOwner *owner) +{ + OwnershipRestoreData *d; + DBusList *link; + + d = dbus_new (OwnershipRestoreData, 1); + if (d == NULL) + return FALSE; + + d->service = service; + d->owner = owner; + d->service_link = _dbus_list_alloc_link (service); + d->owner_link = _dbus_list_alloc_link (owner); + d->hash_entry = _dbus_hash_table_preallocate_entry (service->registry->service_hash); + + bus_service_ref (d->service); + bus_owner_ref (d->owner); + dbus_connection_ref (d->owner->conn); + + d->before_owner = NULL; + link = _dbus_list_get_first_link (&service->owners); + while (link != NULL) + { + if (link->data == owner) + { + link = _dbus_list_get_next_link (&service->owners, link); + + if (link) + d->before_owner = link->data; + + break; + } + + link = _dbus_list_get_next_link (&service->owners, link); + } + + if (d->service_link == NULL || + d->owner_link == NULL || + d->hash_entry == NULL || + !bus_transaction_add_cancel_hook (transaction, restore_ownership, d, + free_ownership_restore_data)) + { + free_ownership_restore_data (d); + return FALSE; + } + + return TRUE; +} + +dbus_bool_t +bus_service_swap_owner (BusService *service, + DBusConnection *connection, + BusTransaction *transaction, + DBusError *error) +{ + DBusList *swap_link; + BusOwner *primary_owner; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + /* We send out notifications before we do any work we + * might have to undo if the notification-sending failed + */ + + /* Send service lost message */ + primary_owner = bus_service_get_primary_owner (service); + if (primary_owner == NULL || primary_owner->conn != connection) + _dbus_assert_not_reached ("Tried to swap a non primary owner"); + + + if (!bus_driver_send_service_lost (connection, service->name, + transaction, error)) + return FALSE; + + if (service->owners == NULL) + { + _dbus_assert_not_reached ("Tried to swap owner of a service that has no owners"); + } + else if (_dbus_list_length_is_one (&service->owners)) + { + _dbus_assert_not_reached ("Tried to swap owner of a service that has no other owners in the queue"); + } + else + { + DBusList *link; + BusOwner *new_owner; + DBusConnection *new_owner_conn; + link = _dbus_list_get_first_link (&service->owners); + _dbus_assert (link != NULL); + link = _dbus_list_get_next_link (&service->owners, link); + _dbus_assert (link != NULL); + + new_owner = (BusOwner *)link->data; + new_owner_conn = new_owner->conn; + + if (!bus_driver_send_service_owner_changed (service->name, + bus_connection_get_name (connection), + bus_connection_get_name (new_owner_conn), + transaction, error)) + return FALSE; + + /* This will be our new owner */ + if (!bus_driver_send_service_acquired (new_owner_conn, + service->name, + transaction, + error)) + return FALSE; + } + + if (!add_restore_ownership_to_transaction (transaction, service, primary_owner)) + { + BUS_SET_OOM (error); + return FALSE; + } + + /* unlink the primary and make it the second link */ + swap_link = _dbus_list_get_first_link (&service->owners); + _dbus_list_unlink (&service->owners, swap_link); + + _dbus_list_insert_after_link (&service->owners, + _dbus_list_get_first_link (&service->owners), + swap_link); + + return TRUE; +} + +/* this function is self-cancelling if you cancel the transaction */ +dbus_bool_t +bus_service_remove_owner (BusService *service, + DBusConnection *connection, + BusTransaction *transaction, + DBusError *error) +{ + BusOwner *primary_owner; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + /* We send out notifications before we do any work we + * might have to undo if the notification-sending failed + */ + + /* Send service lost message */ + primary_owner = bus_service_get_primary_owner (service); + if (primary_owner != NULL && primary_owner->conn == connection) + { + if (!bus_driver_send_service_lost (connection, service->name, + transaction, error)) + return FALSE; + } + else + { + /* if we are not the primary owner then just remove us from the queue */ + DBusList *link; + BusOwner *temp_owner; + + link = _bus_service_find_owner_link (service, connection); + _dbus_list_unlink (&service->owners, link); + temp_owner = (BusOwner *)link->data; + bus_owner_unref (temp_owner); + _dbus_list_free_link (link); + + return TRUE; + } + + if (service->owners == NULL) + { + _dbus_assert_not_reached ("Tried to remove owner of a service that has no owners"); + } + else if (_dbus_list_length_is_one (&service->owners)) + { + if (!bus_driver_send_service_owner_changed (service->name, + bus_connection_get_name (connection), + NULL, + transaction, error)) + return FALSE; + } + else + { + DBusList *link; + BusOwner *new_owner; + DBusConnection *new_owner_conn; + link = _dbus_list_get_first_link (&service->owners); + _dbus_assert (link != NULL); + link = _dbus_list_get_next_link (&service->owners, link); + _dbus_assert (link != NULL); + + new_owner = (BusOwner *)link->data; + new_owner_conn = new_owner->conn; + + if (!bus_driver_send_service_owner_changed (service->name, + bus_connection_get_name (connection), + bus_connection_get_name (new_owner_conn), + transaction, error)) + return FALSE; + + /* This will be our new owner */ + if (!bus_driver_send_service_acquired (new_owner_conn, + service->name, + transaction, + error)) + return FALSE; + } + + if (!add_restore_ownership_to_transaction (transaction, service, primary_owner)) + { + BUS_SET_OOM (error); + return FALSE; + } + + bus_service_unlink_owner (service, primary_owner); + + if (service->owners == NULL) + bus_service_unlink (service); + + return TRUE; +} + +BusService * +bus_service_ref (BusService *service) +{ + _dbus_assert (service->refcount > 0); + + service->refcount += 1; + + return service; +} + +void +bus_service_unref (BusService *service) +{ + _dbus_assert (service->refcount > 0); + + service->refcount -= 1; + + if (service->refcount == 0) + { + _dbus_assert (service->owners == NULL); + + dbus_free (service->name); + _dbus_mem_pool_dealloc (service->registry->service_pool, service); + } +} + +DBusConnection * +bus_service_get_primary_owners_connection (BusService *service) +{ + BusOwner *owner; + + owner = bus_service_get_primary_owner (service); + + if (owner != NULL) + return owner->conn; + else + return NULL; +} + +BusOwner* +bus_service_get_primary_owner (BusService *service) +{ + return _dbus_list_get_first (&service->owners); +} + +const char* +bus_service_get_name (BusService *service) +{ + return service->name; +} + +dbus_bool_t +bus_service_get_allow_replacement (BusService *service) +{ + BusOwner *owner; + DBusList *link; + + _dbus_assert (service->owners != NULL); + + link = _dbus_list_get_first_link (&service->owners); + owner = (BusOwner *) link->data; + + return owner->allow_replacement; +} + +dbus_bool_t +bus_service_has_owner (BusService *service, + DBusConnection *connection) +{ + DBusList *link; + + link = _bus_service_find_owner_link (service, connection); + + if (link == NULL) + return FALSE; + else + return TRUE; +} + +dbus_bool_t +bus_service_list_queued_owners (BusService *service, + DBusList **return_list, + DBusError *error) +{ + DBusList *link; + + _dbus_assert (*return_list == NULL); + + link = _dbus_list_get_first_link (&service->owners); + _dbus_assert (link != NULL); + + while (link != NULL) + { + BusOwner *owner; + const char *uname; + + owner = (BusOwner *) link->data; + uname = bus_connection_get_name (owner->conn); + + if (!_dbus_list_append (return_list, (char *)uname)) + goto oom; + + link = _dbus_list_get_next_link (&service->owners, link); + } + + return TRUE; + + oom: + _dbus_list_clear (return_list); + BUS_SET_OOM (error); + return FALSE; +}
diff --git a/bus/services.h b/bus/services.h new file mode 100644 index 0000000..056dd9f --- /dev/null +++ b/bus/services.h
@@ -0,0 +1,94 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* services.h Service management + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_SERVICES_H +#define BUS_SERVICES_H + +#include <dbus/dbus.h> +#include <dbus/dbus-string.h> +#include <dbus/dbus-hash.h> +#include "connection.h" +#include "bus.h" + +typedef void (* BusServiceForeachFunction) (BusService *service, + void *data); + +BusRegistry* bus_registry_new (BusContext *context); +BusRegistry* bus_registry_ref (BusRegistry *registry); +void bus_registry_unref (BusRegistry *registry); +BusService* bus_registry_lookup (BusRegistry *registry, + const DBusString *service_name); +BusService* bus_registry_ensure (BusRegistry *registry, + const DBusString *service_name, + DBusConnection *owner_connection_if_created, + dbus_uint32_t flags, + BusTransaction *transaction, + DBusError *error); +void bus_registry_foreach (BusRegistry *registry, + BusServiceForeachFunction function, + void *data); +dbus_bool_t bus_registry_list_services (BusRegistry *registry, + char ***listp, + int *array_len); +dbus_bool_t bus_registry_acquire_service (BusRegistry *registry, + DBusConnection *connection, + const DBusString *service_name, + dbus_uint32_t flags, + dbus_uint32_t *result, + BusTransaction *transaction, + DBusError *error); +dbus_bool_t bus_registry_release_service (BusRegistry *registry, + DBusConnection *connection, + const DBusString *service_name, + dbus_uint32_t *result, + BusTransaction *transaction, + DBusError *error); +dbus_bool_t bus_registry_set_service_context_table (BusRegistry *registry, + DBusHashTable *table); + +BusService* bus_service_ref (BusService *service); +void bus_service_unref (BusService *service); +dbus_bool_t bus_service_add_owner (BusService *service, + DBusConnection *connection, + dbus_uint32_t flags, + BusTransaction *transaction, + DBusError *error); +dbus_bool_t bus_service_swap_owner (BusService *service, + DBusConnection *connection, + BusTransaction *transaction, + DBusError *error); +dbus_bool_t bus_service_remove_owner (BusService *service, + DBusConnection *connection, + BusTransaction *transaction, + DBusError *error); +dbus_bool_t bus_service_has_owner (BusService *service, + DBusConnection *connection); +BusOwner* bus_service_get_primary_owner (BusService *service); +dbus_bool_t bus_service_get_allow_replacement (BusService *service); +const char* bus_service_get_name (BusService *service); +dbus_bool_t bus_service_list_queued_owners (BusService *service, + DBusList **return_list, + DBusError *error); + +DBusConnection* bus_service_get_primary_owners_connection (BusService *service); +#endif /* BUS_SERVICES_H */
diff --git a/bus/session.conf.in b/bus/session.conf.in new file mode 100644 index 0000000..affa7f1 --- /dev/null +++ b/bus/session.conf.in
@@ -0,0 +1,80 @@ +<!-- This configuration file controls the per-user-login-session message bus. + Add a session-local.conf and edit that rather than changing this + file directly. --> + +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> +<busconfig> + <!-- Our well-known bus type, don't change this --> + <type>session</type> + + <!-- If we fork, keep the user's original umask to avoid affecting + the behavior of child processes. --> + <keep_umask/> + + <listen>@DBUS_SESSION_BUS_LISTEN_ADDRESS@</listen> + + <!-- On Unix systems, the most secure authentication mechanism is + EXTERNAL, which uses credential-passing over Unix sockets. + + This authentication mechanism is not available on Windows, + is not suitable for use with the tcp: or nonce-tcp: transports, + and will not work on obscure flavours of Unix that do not have + a supported credentials-passing mechanism. On those platforms/transports, + comment out the <auth> element to allow fallback to DBUS_COOKIE_SHA1. --> + @DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL@ + + <standard_session_servicedirs /> + + <policy context="default"> + <!-- Allow everything to be sent --> + <allow send_destination="*" eavesdrop="true"/> + <!-- Allow everything to be received --> + <allow eavesdrop="true"/> + <!-- Allow anyone to own anything --> + <allow own="*"/> + </policy> + + <!-- Include legacy configuration location --> + <include ignore_missing="yes">@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/session.conf</include> + + <!-- Config files are placed here that among other things, + further restrict the above policy for specific services. --> + <includedir>session.d</includedir> + + <includedir>@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/session.d</includedir> + + <!-- This is included last so local configuration can override what's + in this standard file --> + <include ignore_missing="yes">@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/session-local.conf</include> + + <include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include> + + <!-- For the session bus, override the default relatively-low limits + with essentially infinite limits, since the bus is just running + as the user anyway, using up bus resources is not something we need + to worry about. In some cases, we do set the limits lower than + "all available memory" if exceeding the limit is almost certainly a bug, + having the bus enforce a limit is nicer than a huge memory leak. But the + intent is that these limits should never be hit. --> + + <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max --> + <limit name="max_incoming_bytes">1000000000</limit> + <limit name="max_incoming_unix_fds">250000000</limit> + <limit name="max_outgoing_bytes">1000000000</limit> + <limit name="max_outgoing_unix_fds">250000000</limit> + <limit name="max_message_size">1000000000</limit> + <!-- We do not override max_message_unix_fds here since the in-kernel + limit is also relatively low --> + <limit name="service_start_timeout">120000</limit> + <limit name="auth_timeout">240000</limit> + <limit name="pending_fd_timeout">150000</limit> + <limit name="max_completed_connections">100000</limit> + <limit name="max_incomplete_connections">10000</limit> + <limit name="max_connections_per_user">100000</limit> + <limit name="max_pending_service_starts">10000</limit> + <limit name="max_names_per_connection">50000</limit> + <limit name="max_match_rules_per_connection">50000</limit> + <limit name="max_replies_per_connection">50000</limit> + +</busconfig>
diff --git a/bus/signals.c b/bus/signals.c new file mode 100644 index 0000000..e8def9f --- /dev/null +++ b/bus/signals.c
@@ -0,0 +1,2973 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* signals.c Bus signal connection implementation + * + * Copyright (C) 2003, 2005 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> + +#include <string.h> + +#include "signals.h" +#include "services.h" +#include "utils.h" +#include <dbus/dbus-marshal-validate.h> + +struct BusMatchRule +{ + int refcount; /**< reference count */ + + DBusConnection *matches_go_to; /**< Owner of the rule */ + + unsigned int flags; /**< BusMatchFlags */ + + int message_type; + char *interface; + char *member; + char *sender; + char *destination; + char *path; + + unsigned int *arg_lens; + char **args; + int args_len; +}; + +#define BUS_MATCH_ARG_NAMESPACE 0x4000000u +#define BUS_MATCH_ARG_IS_PATH 0x8000000u + +#define BUS_MATCH_ARG_FLAGS (BUS_MATCH_ARG_NAMESPACE | BUS_MATCH_ARG_IS_PATH) + +BusMatchRule* +bus_match_rule_new (DBusConnection *matches_go_to) +{ + BusMatchRule *rule; + + rule = dbus_new0 (BusMatchRule, 1); + if (rule == NULL) + return NULL; + + rule->refcount = 1; + rule->matches_go_to = matches_go_to; + +#ifndef DBUS_ENABLE_EMBEDDED_TESTS + _dbus_assert (rule->matches_go_to != NULL); +#endif + + return rule; +} + +BusMatchRule * +bus_match_rule_ref (BusMatchRule *rule) +{ + _dbus_assert (rule->refcount > 0); + + rule->refcount += 1; + + return rule; +} + +void +bus_match_rule_unref (BusMatchRule *rule) +{ + _dbus_assert (rule->refcount > 0); + + rule->refcount -= 1; + if (rule->refcount == 0) + { + dbus_free (rule->interface); + dbus_free (rule->member); + dbus_free (rule->sender); + dbus_free (rule->destination); + dbus_free (rule->path); + dbus_free (rule->arg_lens); + + /* can't use dbus_free_string_array() since there + * are embedded NULL + */ + if (rule->args) + { + int i; + + i = 0; + while (i < rule->args_len) + { + if (rule->args[i]) + dbus_free (rule->args[i]); + ++i; + } + + dbus_free (rule->args); + } + + dbus_free (rule); + } +} + +#if defined(DBUS_ENABLE_VERBOSE_MODE) || defined(DBUS_ENABLE_STATS) +static dbus_bool_t +append_key_and_escaped_value (DBusString *str, const char *token, const char *value) +{ + const char *p = value; + + if (!_dbus_string_append_printf (str, "%s='", token)) + return FALSE; + + while (*p != '\0') + { + const char *next = strchr (p, '\''); + + if (next) + { + if (!_dbus_string_append_printf (str, "%.*s", (int) (next - p), p)) + return FALSE; + /* Horrible escape sequence: single quote cannot be escaped inside + * a single quoted string. So we close the single quote, escape the + * single quote, and reopen a single quote. + */ + if (!_dbus_string_append_printf (str, "'\\''")) + return FALSE; + p = next + 1; + } + else + { + if (!_dbus_string_append_printf (str, "%s", p)) + return FALSE; + break; + } + } + + if (!_dbus_string_append_byte (str, '\'')) + return FALSE; + + return TRUE; +} + +/* returns NULL if no memory */ +static char* +match_rule_to_string (BusMatchRule *rule) +{ + DBusString str; + char *ret; + + if (!_dbus_string_init (&str)) + { + return NULL; + } + + if (rule->flags & BUS_MATCH_MESSAGE_TYPE) + { + if (!append_key_and_escaped_value (&str, "type", + dbus_message_type_to_string (rule->message_type))) + goto nomem; + } + + if (rule->flags & BUS_MATCH_INTERFACE) + { + if (_dbus_string_get_length (&str) > 0) + { + if (!_dbus_string_append (&str, ",")) + goto nomem; + } + + if (!append_key_and_escaped_value (&str, "interface", rule->interface)) + goto nomem; + } + + if (rule->flags & BUS_MATCH_MEMBER) + { + if (_dbus_string_get_length (&str) > 0) + { + if (!_dbus_string_append (&str, ",")) + goto nomem; + } + + if (!append_key_and_escaped_value (&str, "member", rule->member)) + goto nomem; + } + + if (rule->flags & BUS_MATCH_PATH) + { + if (_dbus_string_get_length (&str) > 0) + { + if (!_dbus_string_append (&str, ",")) + goto nomem; + } + + if (!append_key_and_escaped_value (&str, "path", rule->path)) + goto nomem; + } + + if (rule->flags & BUS_MATCH_PATH_NAMESPACE) + { + if (_dbus_string_get_length (&str) > 0) + { + if (!_dbus_string_append (&str, ",")) + goto nomem; + } + + if (!append_key_and_escaped_value (&str, "path_namespace", rule->path)) + goto nomem; + } + + if (rule->flags & BUS_MATCH_SENDER) + { + if (_dbus_string_get_length (&str) > 0) + { + if (!_dbus_string_append (&str, ",")) + goto nomem; + } + + if (!append_key_and_escaped_value (&str, "sender", rule->sender)) + goto nomem; + } + + if (rule->flags & BUS_MATCH_DESTINATION) + { + if (_dbus_string_get_length (&str) > 0) + { + if (!_dbus_string_append (&str, ",")) + goto nomem; + } + + if (!append_key_and_escaped_value (&str, "destination", rule->destination)) + goto nomem; + } + + if (rule->flags & BUS_MATCH_CLIENT_IS_EAVESDROPPING) + { + if (_dbus_string_get_length (&str) > 0) + { + if (!_dbus_string_append (&str, ",")) + goto nomem; + } + + if (!append_key_and_escaped_value (&str, "eavesdrop", + (rule->flags & BUS_MATCH_CLIENT_IS_EAVESDROPPING) ? + "true" : "false")) + goto nomem; + } + + if (rule->flags & BUS_MATCH_ARGS) + { + int i; + + _dbus_assert (rule->args != NULL); + + i = 0; + while (i < rule->args_len) + { + if (rule->args[i] != NULL) + { + dbus_bool_t is_path, is_namespace; + + if (_dbus_string_get_length (&str) > 0) + { + if (!_dbus_string_append (&str, ",")) + goto nomem; + } + + is_path = (rule->arg_lens[i] & BUS_MATCH_ARG_IS_PATH) != 0; + is_namespace = (rule->arg_lens[i] & BUS_MATCH_ARG_NAMESPACE) != 0; + + if (!_dbus_string_append_printf (&str, + "arg%d%s", + i, + is_path ? "path" : + is_namespace ? "namespace" : "")) + goto nomem; + if (!append_key_and_escaped_value (&str, "", rule->args[i])) + goto nomem; + } + + ++i; + } + } + + if (!_dbus_string_steal_data (&str, &ret)) + goto nomem; + + _dbus_string_free (&str); + return ret; + + nomem: + _dbus_string_free (&str); + return NULL; +} +#endif /* defined(DBUS_ENABLE_VERBOSE_MODE) || defined(DBUS_ENABLE_STATS) */ + +dbus_bool_t +bus_match_rule_set_message_type (BusMatchRule *rule, + int type) +{ + rule->flags |= BUS_MATCH_MESSAGE_TYPE; + + rule->message_type = type; + + return TRUE; +} + +dbus_bool_t +bus_match_rule_set_interface (BusMatchRule *rule, + const char *interface) +{ + char *new; + + _dbus_assert (interface != NULL); + + new = _dbus_strdup (interface); + if (new == NULL) + return FALSE; + + rule->flags |= BUS_MATCH_INTERFACE; + dbus_free (rule->interface); + rule->interface = new; + + return TRUE; +} + +dbus_bool_t +bus_match_rule_set_member (BusMatchRule *rule, + const char *member) +{ + char *new; + + _dbus_assert (member != NULL); + + new = _dbus_strdup (member); + if (new == NULL) + return FALSE; + + rule->flags |= BUS_MATCH_MEMBER; + dbus_free (rule->member); + rule->member = new; + + return TRUE; +} + +dbus_bool_t +bus_match_rule_set_sender (BusMatchRule *rule, + const char *sender) +{ + char *new; + + _dbus_assert (sender != NULL); + + new = _dbus_strdup (sender); + if (new == NULL) + return FALSE; + + rule->flags |= BUS_MATCH_SENDER; + dbus_free (rule->sender); + rule->sender = new; + + return TRUE; +} + +dbus_bool_t +bus_match_rule_set_destination (BusMatchRule *rule, + const char *destination) +{ + char *new; + + _dbus_assert (destination != NULL); + + new = _dbus_strdup (destination); + if (new == NULL) + return FALSE; + + rule->flags |= BUS_MATCH_DESTINATION; + dbus_free (rule->destination); + rule->destination = new; + + return TRUE; +} + +void +bus_match_rule_set_client_is_eavesdropping (BusMatchRule *rule, + dbus_bool_t is_eavesdropping) +{ + if (is_eavesdropping) + rule->flags |= BUS_MATCH_CLIENT_IS_EAVESDROPPING; + else + rule->flags &= ~(BUS_MATCH_CLIENT_IS_EAVESDROPPING); +} + +dbus_bool_t +bus_match_rule_get_client_is_eavesdropping (BusMatchRule *rule) +{ + if (rule->flags & BUS_MATCH_CLIENT_IS_EAVESDROPPING) + return TRUE; + else + return FALSE; +} + +dbus_bool_t +bus_match_rule_set_path (BusMatchRule *rule, + const char *path, + dbus_bool_t is_namespace) +{ + char *new; + + _dbus_assert (path != NULL); + + new = _dbus_strdup (path); + if (new == NULL) + return FALSE; + + rule->flags &= ~(BUS_MATCH_PATH|BUS_MATCH_PATH_NAMESPACE); + + if (is_namespace) + rule->flags |= BUS_MATCH_PATH_NAMESPACE; + else + rule->flags |= BUS_MATCH_PATH; + + dbus_free (rule->path); + rule->path = new; + + return TRUE; +} + +dbus_bool_t +bus_match_rule_set_arg (BusMatchRule *rule, + int arg, + const DBusString *value, + dbus_bool_t is_path, + dbus_bool_t is_namespace) +{ + int length; + char *new; + + _dbus_assert (value != NULL); + + /* args_len is the number of args not including null termination + * in the char** + */ + if (arg >= rule->args_len) + { + unsigned int *new_arg_lens; + char **new_args; + int new_args_len; + int i; + + new_args_len = arg + 1; + + /* add another + 1 here for null termination */ + new_args = dbus_realloc (rule->args, + sizeof (char *) * (new_args_len + 1)); + if (new_args == NULL) + return FALSE; + + /* NULL the new slots */ + i = rule->args_len; + while (i <= new_args_len) /* <= for null termination */ + { + new_args[i] = NULL; + ++i; + } + + rule->args = new_args; + + /* and now add to the lengths */ + new_arg_lens = dbus_realloc (rule->arg_lens, + sizeof (int) * (new_args_len + 1)); + + if (new_arg_lens == NULL) + return FALSE; + + /* zero the new slots */ + i = rule->args_len; + while (i <= new_args_len) /* <= for null termination */ + { + new_arg_lens[i] = 0; + ++i; + } + + rule->arg_lens = new_arg_lens; + rule->args_len = new_args_len; + } + + length = _dbus_string_get_length (value); + if (!_dbus_string_copy_data (value, &new)) + return FALSE; + + rule->flags |= BUS_MATCH_ARGS; + + dbus_free (rule->args[arg]); + rule->arg_lens[arg] = length; + rule->args[arg] = new; + + if (is_path) + rule->arg_lens[arg] |= BUS_MATCH_ARG_IS_PATH; + + if (is_namespace) + rule->arg_lens[arg] |= BUS_MATCH_ARG_NAMESPACE; + + /* NULL termination didn't get busted */ + _dbus_assert (rule->args[rule->args_len] == NULL); + _dbus_assert (rule->arg_lens[rule->args_len] == 0); + + return TRUE; +} + +#define ISWHITE(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\n') || ((c) == '\r')) + +static dbus_bool_t +find_key (const DBusString *str, + int start, + DBusString *key, + int *value_pos, + DBusError *error) +{ + const char *p; + const char *s; + const char *key_start; + const char *key_end; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + s = _dbus_string_get_const_data (str); + + p = s + start; + + while (*p && ISWHITE (*p)) + ++p; + + key_start = p; + + while (*p && *p != '=' && !ISWHITE (*p)) + ++p; + + key_end = p; + + while (*p && ISWHITE (*p)) + ++p; + + if (key_start == key_end) + { + /* Empty match rules or trailing whitespace are OK */ + *value_pos = p - s; + return TRUE; + } + + if (*p != '=') + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Match rule has a key with no subsequent '=' character"); + return FALSE; + } + ++p; + + if (!_dbus_string_append_len (key, key_start, key_end - key_start)) + { + BUS_SET_OOM (error); + return FALSE; + } + + *value_pos = p - s; + + return TRUE; +} + +static dbus_bool_t +find_value (const DBusString *str, + int start, + const char *key, + DBusString *value, + int *value_end, + DBusError *error) +{ + const char *p; + const char *s; + char quote_char; + int orig_len; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + orig_len = _dbus_string_get_length (value); + + s = _dbus_string_get_const_data (str); + + p = s + start; + + quote_char = '\0'; + + while (*p) + { + if (quote_char == '\0') + { + switch (*p) + { + case '\0': + goto done; + + case '\'': + quote_char = '\''; + goto next; + + case ',': + ++p; + goto done; + + case '\\': + quote_char = '\\'; + goto next; + + default: + if (!_dbus_string_append_byte (value, *p)) + { + BUS_SET_OOM (error); + goto failed; + } + } + } + else if (quote_char == '\\') + { + /* \ only counts as an escape if escaping a quote mark */ + if (*p != '\'') + { + if (!_dbus_string_append_byte (value, '\\')) + { + BUS_SET_OOM (error); + goto failed; + } + } + + if (!_dbus_string_append_byte (value, *p)) + { + BUS_SET_OOM (error); + goto failed; + } + + quote_char = '\0'; + } + else + { + _dbus_assert (quote_char == '\''); + + if (*p == '\'') + { + quote_char = '\0'; + } + else + { + if (!_dbus_string_append_byte (value, *p)) + { + BUS_SET_OOM (error); + goto failed; + } + } + } + + next: + ++p; + } + + done: + + if (quote_char == '\\') + { + if (!_dbus_string_append_byte (value, '\\')) + { + BUS_SET_OOM (error); + goto failed; + } + } + else if (quote_char == '\'') + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Unbalanced quotation marks in match rule"); + goto failed; + } + else + _dbus_assert (quote_char == '\0'); + + /* Zero-length values are allowed */ + + *value_end = p - s; + + return TRUE; + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_string_set_length (value, orig_len); + return FALSE; +} + +/* duplicates aren't allowed so the real legitimate max is only 6 or + * so. Leaving extra so we don't have to bother to update it. + * FIXME this is sort of busted now with arg matching, but we let + * you match on up to 10 args for now + */ +#define MAX_RULE_TOKENS 16 + +/* this is slightly too high level to be termed a "token" + * but let's not be pedantic. + */ +typedef struct +{ + char *key; + char *value; +} RuleToken; + +static dbus_bool_t +tokenize_rule (const DBusString *rule_text, + RuleToken tokens[MAX_RULE_TOKENS], + DBusError *error) +{ + int i; + int pos; + DBusString key; + DBusString value; + dbus_bool_t retval; + + retval = FALSE; + + if (!_dbus_string_init (&key)) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!_dbus_string_init (&value)) + { + _dbus_string_free (&key); + BUS_SET_OOM (error); + return FALSE; + } + + i = 0; + pos = 0; + while (i < MAX_RULE_TOKENS && + pos < _dbus_string_get_length (rule_text)) + { + _dbus_assert (tokens[i].key == NULL); + _dbus_assert (tokens[i].value == NULL); + + if (!find_key (rule_text, pos, &key, &pos, error)) + goto out; + + if (_dbus_string_get_length (&key) == 0) + goto next; + + if (!_dbus_string_steal_data (&key, &tokens[i].key)) + { + BUS_SET_OOM (error); + goto out; + } + + if (!find_value (rule_text, pos, tokens[i].key, &value, &pos, error)) + goto out; + + if (!_dbus_string_steal_data (&value, &tokens[i].value)) + { + BUS_SET_OOM (error); + goto out; + } + + next: + ++i; + } + + retval = TRUE; + + out: + if (!retval) + { + i = 0; + while (tokens[i].key || tokens[i].value) + { + dbus_free (tokens[i].key); + dbus_free (tokens[i].value); + tokens[i].key = NULL; + tokens[i].value = NULL; + ++i; + } + } + + _dbus_string_free (&key); + _dbus_string_free (&value); + + return retval; +} + +static dbus_bool_t +bus_match_rule_parse_arg_match (BusMatchRule *rule, + const char *key, + const DBusString *value, + DBusError *error) +{ + dbus_bool_t is_path = FALSE; + dbus_bool_t is_namespace = FALSE; + DBusString key_str; + unsigned long arg; + int length; + int end; + + /* For now, arg0='foo' always implies that 'foo' is a + * DBUS_TYPE_STRING. Someday we could add an arg0type='int32' thing + * if we wanted, which would specify another type, in which case + * arg0='5' would have the 5 parsed as an int rather than string. + */ + + /* First we need to parse arg0 = 0, arg27 = 27 */ + + _dbus_string_init_const (&key_str, key); + length = _dbus_string_get_length (&key_str); + + if (_dbus_string_get_length (&key_str) < 4) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Key '%s' in match rule starts with 'arg' but lacks an arg number. Should be 'arg0' or 'arg7' for example.\n", key); + goto failed; + } + + if (!_dbus_string_parse_uint (&key_str, 3, &arg, &end)) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Key '%s' in match rule starts with 'arg' but could not parse arg number. Should be 'arg0' or 'arg7' for example.\n", key); + goto failed; + } + + if (end != length) + { + int len1 = strlen ("path"); + if ((end + len1) == length && + _dbus_string_ends_with_c_str (&key_str, "path")) + { + is_path = TRUE; + } + else if (_dbus_string_equal_c_str (&key_str, "arg0namespace")) + { + int value_len = _dbus_string_get_length (value); + + is_namespace = TRUE; + + if (!_dbus_validate_bus_namespace (value, 0, value_len)) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "arg0namespace='%s' is not a valid prefix of a bus name", + _dbus_string_get_const_data (value)); + goto failed; + } + } + else + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Key '%s' in match rule contains junk after argument number (%u). Only 'arg%upath' (for example) or 'arg0namespace' are valid", key, arg, arg); + goto failed; + } + } + + /* If we didn't check this we could allocate a huge amount of RAM */ + if (arg > DBUS_MAXIMUM_MATCH_RULE_ARG_NUMBER) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Key '%s' in match rule has arg number %lu but the maximum is %d.\n", key, (unsigned long) arg, DBUS_MAXIMUM_MATCH_RULE_ARG_NUMBER); + goto failed; + } + + if ((rule->flags & BUS_MATCH_ARGS) && + rule->args_len > (int) arg && + rule->args[arg] != NULL) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Argument %d matched more than once in match rule\n", key); + goto failed; + } + + if (!bus_match_rule_set_arg (rule, arg, value, is_path, is_namespace)) + { + BUS_SET_OOM (error); + goto failed; + } + + return TRUE; + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + return FALSE; +} + +/* + * The format is comma-separated with strings quoted with single quotes + * as for the shell (to escape a literal single quote, use '\''). + * + * type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='Foo', + * path='/bar/foo',destination=':452345.34' + * + */ +BusMatchRule* +bus_match_rule_parse (DBusConnection *matches_go_to, + const DBusString *rule_text, + DBusError *error) +{ + BusMatchRule *rule; + RuleToken tokens[MAX_RULE_TOKENS+1]; /* NULL termination + 1 */ + int i; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (_dbus_string_get_length (rule_text) > DBUS_MAXIMUM_MATCH_RULE_LENGTH) + { + dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED, + "Match rule text is %d bytes, maximum is %d", + _dbus_string_get_length (rule_text), + DBUS_MAXIMUM_MATCH_RULE_LENGTH); + return NULL; + } + + memset (tokens, '\0', sizeof (tokens)); + + rule = bus_match_rule_new (matches_go_to); + if (rule == NULL) + { + BUS_SET_OOM (error); + goto failed; + } + + if (!tokenize_rule (rule_text, tokens, error)) + goto failed; + + i = 0; + while (tokens[i].key != NULL) + { + DBusString tmp_str; + int len; + const char *key = tokens[i].key; + const char *value = tokens[i].value; + + _dbus_string_init_const (&tmp_str, value); + len = _dbus_string_get_length (&tmp_str); + + if (strcmp (key, "type") == 0) + { + int t; + + if (rule->flags & BUS_MATCH_MESSAGE_TYPE) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Key %s specified twice in match rule\n", key); + goto failed; + } + + t = dbus_message_type_from_string (value); + + if (t == DBUS_MESSAGE_TYPE_INVALID) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Invalid message type (%s) in match rule\n", value); + goto failed; + } + + if (!bus_match_rule_set_message_type (rule, t)) + { + BUS_SET_OOM (error); + goto failed; + } + } + else if (strcmp (key, "sender") == 0) + { + if (rule->flags & BUS_MATCH_SENDER) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Key %s specified twice in match rule\n", key); + goto failed; + } + + if (!_dbus_validate_bus_name (&tmp_str, 0, len)) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Sender name '%s' is invalid\n", value); + goto failed; + } + + if (!bus_match_rule_set_sender (rule, value)) + { + BUS_SET_OOM (error); + goto failed; + } + } + else if (strcmp (key, "interface") == 0) + { + if (rule->flags & BUS_MATCH_INTERFACE) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Key %s specified twice in match rule\n", key); + goto failed; + } + + if (!_dbus_validate_interface (&tmp_str, 0, len)) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Interface name '%s' is invalid\n", value); + goto failed; + } + + if (!bus_match_rule_set_interface (rule, value)) + { + BUS_SET_OOM (error); + goto failed; + } + } + else if (strcmp (key, "member") == 0) + { + if (rule->flags & BUS_MATCH_MEMBER) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Key %s specified twice in match rule\n", key); + goto failed; + } + + if (!_dbus_validate_member (&tmp_str, 0, len)) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Member name '%s' is invalid\n", value); + goto failed; + } + + if (!bus_match_rule_set_member (rule, value)) + { + BUS_SET_OOM (error); + goto failed; + } + } + else if (strcmp (key, "path") == 0 || + strcmp (key, "path_namespace") == 0) + { + dbus_bool_t is_namespace = (strcmp (key, "path_namespace") == 0); + + if (rule->flags & (BUS_MATCH_PATH | BUS_MATCH_PATH_NAMESPACE)) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "path or path_namespace specified twice in match rule\n"); + goto failed; + } + + if (!_dbus_validate_path (&tmp_str, 0, len)) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Path '%s' is invalid\n", value); + goto failed; + } + + if (!bus_match_rule_set_path (rule, value, is_namespace)) + { + BUS_SET_OOM (error); + goto failed; + } + } + else if (strcmp (key, "destination") == 0) + { + if (rule->flags & BUS_MATCH_DESTINATION) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Key %s specified twice in match rule\n", key); + goto failed; + } + + if (!_dbus_validate_bus_name (&tmp_str, 0, len)) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Destination name '%s' is invalid\n", value); + goto failed; + } + + if (!bus_match_rule_set_destination (rule, value)) + { + BUS_SET_OOM (error); + goto failed; + } + } + else if (strcmp (key, "eavesdrop") == 0) + { + /* do not detect "eavesdrop" being used more than once in rule: + * 1) it's not possible, it's only in the flags + * 2) it might be used twice to disable eavesdropping when it's + * automatically added (eg dbus-monitor/bustle) */ + + /* we accept only "true|false" as possible values */ + if ((strcmp (value, "true") == 0)) + { + bus_match_rule_set_client_is_eavesdropping (rule, TRUE); + } + else if (strcmp (value, "false") == 0) + { + bus_match_rule_set_client_is_eavesdropping (rule, FALSE); + } + else + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "eavesdrop='%s' is invalid, " + "it should be 'true' or 'false'\n", + value); + goto failed; + } + } + else if (strncmp (key, "arg", 3) == 0) + { + if (!bus_match_rule_parse_arg_match (rule, key, &tmp_str, error)) + goto failed; + } + else + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID, + "Unknown key \"%s\" in match rule", + key); + goto failed; + } + + ++i; + } + + + goto out; + + failed: + _DBUS_ASSERT_ERROR_IS_SET (error); + if (rule) + { + bus_match_rule_unref (rule); + rule = NULL; + } + + out: + + i = 0; + while (tokens[i].key || tokens[i].value) + { + _dbus_assert (i < MAX_RULE_TOKENS); + dbus_free (tokens[i].key); + dbus_free (tokens[i].value); + ++i; + } + + return rule; +} + +typedef struct RulePool RulePool; +struct RulePool +{ + /* Maps non-NULL interface names to non-NULL (DBusList **)s */ + DBusHashTable *rules_by_iface; + + /* List of BusMatchRules which don't specify an interface */ + DBusList *rules_without_iface; +}; + +struct BusMatchmaker +{ + int refcount; + + /* Pools of rules, grouped by the type of message they match. 0 + * (DBUS_MESSAGE_TYPE_INVALID) represents rules that do not specify a message + * type. + */ + RulePool rules_by_type[DBUS_NUM_MESSAGE_TYPES]; +}; + +#ifdef DBUS_ENABLE_STATS +dbus_bool_t +bus_match_rule_dump (BusMatchmaker *matchmaker, + DBusConnection *conn_filter, + DBusMessageIter *arr_iter) +{ + int i; + + for (i = 0 ; i < DBUS_NUM_MESSAGE_TYPES ; i++) + { + DBusHashIter iter; + DBusList **list; + DBusList *link; + + _dbus_hash_iter_init (matchmaker->rules_by_type[i].rules_by_iface, &iter); + while (_dbus_hash_iter_next (&iter)) + { + list = _dbus_hash_iter_get_value (&iter); + for (link = _dbus_list_get_first_link (list); + link != NULL; + link = _dbus_list_get_next_link (list, link)) + { + BusMatchRule *rule = link->data; + + if (rule->matches_go_to == conn_filter) + { + char *s = match_rule_to_string (rule); + + if (s == NULL) + return FALSE; + + if (!dbus_message_iter_append_basic (arr_iter, DBUS_TYPE_STRING, &s)) + { + dbus_free (s); + return FALSE; + } + dbus_free (s); + } + } + } + list = &matchmaker->rules_by_type[i].rules_without_iface; + for (link = _dbus_list_get_first_link (list); + link != NULL; + link = _dbus_list_get_next_link (list, link)) + { + BusMatchRule *rule = link->data; + + if (rule->matches_go_to == conn_filter) + { + char *s = match_rule_to_string (rule); + + if (s == NULL) + return FALSE; + + if (!dbus_message_iter_append_basic (arr_iter, DBUS_TYPE_STRING, &s)) + { + dbus_free (s); + return FALSE; + } + dbus_free (s); + } + } + } + + return TRUE; +} +#endif + +static void +rule_list_free (DBusList **rules) +{ + while (*rules != NULL) + { + BusMatchRule *rule; + + rule = (*rules)->data; + bus_match_rule_unref (rule); + _dbus_list_remove_link (rules, *rules); + } +} + +static void +rule_list_ptr_free (DBusList **list) +{ + /* We have to cope with NULL because the hash table frees the "existing" + * value (which is NULL) when creating a new table entry... + */ + if (list != NULL) + { + rule_list_free (list); + dbus_free (list); + } +} + +BusMatchmaker* +bus_matchmaker_new (void) +{ + BusMatchmaker *matchmaker; + int i; + + matchmaker = dbus_new0 (BusMatchmaker, 1); + if (matchmaker == NULL) + return NULL; + + matchmaker->refcount = 1; + + for (i = DBUS_MESSAGE_TYPE_INVALID; i < DBUS_NUM_MESSAGE_TYPES; i++) + { + RulePool *p = matchmaker->rules_by_type + i; + + p->rules_by_iface = _dbus_hash_table_new (DBUS_HASH_STRING, + dbus_free, (DBusFreeFunction) rule_list_ptr_free); + + if (p->rules_by_iface == NULL) + goto nomem; + } + + return matchmaker; + + nomem: + for (i = DBUS_MESSAGE_TYPE_INVALID; i < DBUS_NUM_MESSAGE_TYPES; i++) + { + RulePool *p = matchmaker->rules_by_type + i; + + if (p->rules_by_iface == NULL) + break; + else + _dbus_hash_table_unref (p->rules_by_iface); + } + dbus_free (matchmaker); + + return NULL; +} + +static DBusList ** +bus_matchmaker_get_rules (BusMatchmaker *matchmaker, + int message_type, + const char *interface, + dbus_bool_t create) +{ + RulePool *p; + + _dbus_assert (message_type >= 0); + _dbus_assert (message_type < DBUS_NUM_MESSAGE_TYPES); + + _dbus_verbose ("Looking up rules for message_type %d, interface %s\n", + message_type, + interface != NULL ? interface : "<null>"); + + p = matchmaker->rules_by_type + message_type; + + if (interface == NULL) + { + return &p->rules_without_iface; + } + else + { + DBusList **list; + + list = _dbus_hash_table_lookup_string (p->rules_by_iface, interface); + + if (list == NULL && create) + { + char *dupped_interface; + + list = dbus_new0 (DBusList *, 1); + if (list == NULL) + return NULL; + + dupped_interface = _dbus_strdup (interface); + if (dupped_interface == NULL) + { + dbus_free (list); + return NULL; + } + + _dbus_verbose ("Adding list for type %d, iface %s\n", message_type, + interface); + + if (!_dbus_hash_table_insert_string (p->rules_by_iface, + dupped_interface, list)) + { + dbus_free (list); + dbus_free (dupped_interface); + return NULL; + } + } + + return list; + } +} + +static void +bus_matchmaker_gc_rules (BusMatchmaker *matchmaker, + int message_type, + const char *interface, + DBusList **rules) +{ + RulePool *p; + + if (interface == NULL) + return; + + if (*rules != NULL) + return; + + _dbus_verbose ("GCing HT entry for message_type %u, interface %s\n", + message_type, interface); + + p = matchmaker->rules_by_type + message_type; + + _dbus_assert (_dbus_hash_table_lookup_string (p->rules_by_iface, interface) + == rules); + + _dbus_hash_table_remove_string (p->rules_by_iface, interface); +} + +BusMatchmaker * +bus_matchmaker_ref (BusMatchmaker *matchmaker) +{ + _dbus_assert (matchmaker->refcount > 0); + + matchmaker->refcount += 1; + + return matchmaker; +} + +void +bus_matchmaker_unref (BusMatchmaker *matchmaker) +{ + _dbus_assert (matchmaker->refcount > 0); + + matchmaker->refcount -= 1; + if (matchmaker->refcount == 0) + { + int i; + + for (i = DBUS_MESSAGE_TYPE_INVALID; i < DBUS_NUM_MESSAGE_TYPES; i++) + { + RulePool *p = matchmaker->rules_by_type + i; + + _dbus_hash_table_unref (p->rules_by_iface); + rule_list_free (&p->rules_without_iface); + } + + dbus_free (matchmaker); + } +} + +/* The rule can't be modified after it's added. */ +dbus_bool_t +bus_matchmaker_add_rule (BusMatchmaker *matchmaker, + BusMatchRule *rule) +{ + DBusList **rules; + + _dbus_assert (bus_connection_is_active (rule->matches_go_to)); + + _dbus_verbose ("Adding rule with message_type %d, interface %s\n", + rule->message_type, + rule->interface != NULL ? rule->interface : "<null>"); + + rules = bus_matchmaker_get_rules (matchmaker, rule->message_type, + rule->interface, TRUE); + + if (rules == NULL) + return FALSE; + + if (!_dbus_list_append (rules, rule)) + return FALSE; + + if (!bus_connection_add_match_rule (rule->matches_go_to, rule)) + { + _dbus_list_remove_last (rules, rule); + bus_matchmaker_gc_rules (matchmaker, rule->message_type, + rule->interface, rules); + return FALSE; + } + + bus_match_rule_ref (rule); + +#ifdef DBUS_ENABLE_VERBOSE_MODE + { + char *s = match_rule_to_string (rule); + + _dbus_verbose ("Added match rule %s to connection %p\n", + s ? s : "nomem", rule->matches_go_to); + dbus_free (s); + } +#endif + + return TRUE; +} + +static dbus_bool_t +match_rule_equal (BusMatchRule *a, + BusMatchRule *b) +{ + if (a->flags != b->flags) + return FALSE; + + if (a->matches_go_to != b->matches_go_to) + return FALSE; + + if ((a->flags & BUS_MATCH_MESSAGE_TYPE) && + a->message_type != b->message_type) + return FALSE; + + if ((a->flags & BUS_MATCH_MEMBER) && + strcmp (a->member, b->member) != 0) + return FALSE; + + if ((a->flags & BUS_MATCH_PATH) && + strcmp (a->path, b->path) != 0) + return FALSE; + + if ((a->flags & BUS_MATCH_INTERFACE) && + strcmp (a->interface, b->interface) != 0) + return FALSE; + + if ((a->flags & BUS_MATCH_SENDER) && + strcmp (a->sender, b->sender) != 0) + return FALSE; + + if ((a->flags & BUS_MATCH_DESTINATION) && + strcmp (a->destination, b->destination) != 0) + return FALSE; + + /* we already compared the value of flags, and + * BUS_MATCH_CLIENT_IS_EAVESDROPPING does not have another struct member */ + + if (a->flags & BUS_MATCH_ARGS) + { + int i; + + if (a->args_len != b->args_len) + return FALSE; + + i = 0; + while (i < a->args_len) + { + int length; + + if ((a->args[i] != NULL) != (b->args[i] != NULL)) + return FALSE; + + if (a->arg_lens[i] != b->arg_lens[i]) + return FALSE; + + length = a->arg_lens[i] & ~BUS_MATCH_ARG_FLAGS; + + if (a->args[i] != NULL) + { + _dbus_assert (b->args[i] != NULL); + if (memcmp (a->args[i], b->args[i], length) != 0) + return FALSE; + } + + ++i; + } + } + + return TRUE; +} + +static void +bus_matchmaker_remove_rule_link (DBusList **rules, + DBusList *link) +{ + BusMatchRule *rule = link->data; + + bus_connection_remove_match_rule (rule->matches_go_to, rule); + _dbus_list_remove_link (rules, link); + +#ifdef DBUS_ENABLE_VERBOSE_MODE + { + char *s = match_rule_to_string (rule); + + _dbus_verbose ("Removed match rule %s for connection %p\n", + s ? s : "nomem", rule->matches_go_to); + dbus_free (s); + } +#endif + + bus_match_rule_unref (rule); +} + +void +bus_matchmaker_remove_rule (BusMatchmaker *matchmaker, + BusMatchRule *rule) +{ + DBusList **rules; + + _dbus_verbose ("Removing rule with message_type %d, interface %s\n", + rule->message_type, + rule->interface != NULL ? rule->interface : "<null>"); + + bus_connection_remove_match_rule (rule->matches_go_to, rule); + + rules = bus_matchmaker_get_rules (matchmaker, rule->message_type, + rule->interface, FALSE); + + /* We should only be asked to remove a rule by identity right after it was + * added, so there should be a list for it. + */ + _dbus_assert (rules != NULL); + + _dbus_list_remove (rules, rule); + bus_matchmaker_gc_rules (matchmaker, rule->message_type, rule->interface, + rules); + +#ifdef DBUS_ENABLE_VERBOSE_MODE + { + char *s = match_rule_to_string (rule); + + _dbus_verbose ("Removed match rule %s for connection %p\n", + s ? s : "nomem", rule->matches_go_to); + dbus_free (s); + } +#endif + + bus_match_rule_unref (rule); +} + +/* Remove a single rule which is equal to the given rule by value */ +dbus_bool_t +bus_matchmaker_remove_rule_by_value (BusMatchmaker *matchmaker, + BusMatchRule *value, + DBusError *error) +{ + DBusList **rules; + DBusList *link = NULL; + + _dbus_verbose ("Removing rule by value with message_type %d, interface %s\n", + value->message_type, + value->interface != NULL ? value->interface : "<null>"); + + rules = bus_matchmaker_get_rules (matchmaker, value->message_type, + value->interface, FALSE); + + if (rules != NULL) + { + /* we traverse backward because bus_connection_remove_match_rule() + * removes the most-recently-added rule + */ + link = _dbus_list_get_last_link (rules); + while (link != NULL) + { + BusMatchRule *rule; + DBusList *prev; + + rule = link->data; + prev = _dbus_list_get_prev_link (rules, link); + + if (match_rule_equal (rule, value)) + { + bus_matchmaker_remove_rule_link (rules, link); + break; + } + + link = prev; + } + } + + if (link == NULL) + { + dbus_set_error (error, DBUS_ERROR_MATCH_RULE_NOT_FOUND, + "The given match rule wasn't found and can't be removed"); + return FALSE; + } + + bus_matchmaker_gc_rules (matchmaker, value->message_type, value->interface, + rules); + + return TRUE; +} + +static void +rule_list_remove_by_connection (DBusList **rules, + DBusConnection *connection) +{ + DBusList *link; + + link = _dbus_list_get_first_link (rules); + while (link != NULL) + { + BusMatchRule *rule; + DBusList *next; + + rule = link->data; + next = _dbus_list_get_next_link (rules, link); + + if (rule->matches_go_to == connection) + { + bus_matchmaker_remove_rule_link (rules, link); + } + else if (((rule->flags & BUS_MATCH_SENDER) && *rule->sender == ':') || + ((rule->flags & BUS_MATCH_DESTINATION) && *rule->destination == ':')) + { + /* The rule matches to/from a base service, see if it's the + * one being disconnected, since we know this service name + * will never be recycled. + */ + const char *name; + + name = bus_connection_get_name (connection); + _dbus_assert (name != NULL); /* because we're an active connection */ + + if (((rule->flags & BUS_MATCH_SENDER) && + strcmp (rule->sender, name) == 0) || + ((rule->flags & BUS_MATCH_DESTINATION) && + strcmp (rule->destination, name) == 0)) + { + bus_matchmaker_remove_rule_link (rules, link); + } + } + + link = next; + } +} + +void +bus_matchmaker_disconnected (BusMatchmaker *matchmaker, + DBusConnection *connection) +{ + int i; + + /* FIXME + * + * This scans all match rules on the bus. We could avoid that + * for the rules belonging to the connection, since we keep + * a list of those; but for the rules that just refer to + * the connection we'd need to do something more elaborate. + */ + + _dbus_assert (bus_connection_is_active (connection)); + + _dbus_verbose ("Removing all rules for connection %p\n", connection); + + for (i = DBUS_MESSAGE_TYPE_INVALID; i < DBUS_NUM_MESSAGE_TYPES; i++) + { + RulePool *p = matchmaker->rules_by_type + i; + DBusHashIter iter; + + rule_list_remove_by_connection (&p->rules_without_iface, connection); + + _dbus_hash_iter_init (p->rules_by_iface, &iter); + while (_dbus_hash_iter_next (&iter)) + { + DBusList **items = _dbus_hash_iter_get_value (&iter); + + rule_list_remove_by_connection (items, connection); + + if (*items == NULL) + _dbus_hash_iter_remove_entry (&iter); + } + } +} + +static dbus_bool_t +connection_is_primary_owner (DBusConnection *connection, + const char *service_name) +{ + BusService *service; + DBusString str; + BusRegistry *registry; + + _dbus_assert (connection != NULL); + + registry = bus_connection_get_registry (connection); + + _dbus_string_init_const (&str, service_name); + service = bus_registry_lookup (registry, &str); + + if (service == NULL) + return FALSE; /* Service doesn't exist so connection can't own it. */ + + return bus_service_get_primary_owners_connection (service) == connection; +} + +static dbus_bool_t +str_has_prefix (const char *str, const char *prefix) +{ + size_t prefix_len; + prefix_len = strlen (prefix); + if (strncmp (str, prefix, prefix_len) == 0) + return TRUE; + else + return FALSE; +} + +static dbus_bool_t +match_rule_matches (BusMatchRule *rule, + DBusConnection *sender, + DBusConnection *addressed_recipient, + DBusMessage *message, + BusMatchFlags already_matched) +{ + dbus_bool_t wants_to_eavesdrop = FALSE; + int flags; + + /* All features of the match rule are AND'd together, + * so FALSE if any of them don't match. + */ + + /* sender/addressed_recipient of #NULL may mean bus driver, + * or for addressed_recipient may mean a message with no + * specific recipient (i.e. a signal) + */ + + /* Don't bother re-matching features we've already checked implicitly. */ + flags = rule->flags & (~already_matched); + + if (flags & BUS_MATCH_CLIENT_IS_EAVESDROPPING) + wants_to_eavesdrop = TRUE; + + if (flags & BUS_MATCH_MESSAGE_TYPE) + { + _dbus_assert (rule->message_type != DBUS_MESSAGE_TYPE_INVALID); + + if (rule->message_type != dbus_message_get_type (message)) + return FALSE; + } + + if (flags & BUS_MATCH_INTERFACE) + { + const char *iface; + + _dbus_assert (rule->interface != NULL); + + iface = dbus_message_get_interface (message); + if (iface == NULL) + return FALSE; + + if (strcmp (iface, rule->interface) != 0) + return FALSE; + } + + if (flags & BUS_MATCH_MEMBER) + { + const char *member; + + _dbus_assert (rule->member != NULL); + + member = dbus_message_get_member (message); + if (member == NULL) + return FALSE; + + if (strcmp (member, rule->member) != 0) + return FALSE; + } + + if (flags & BUS_MATCH_SENDER) + { + _dbus_assert (rule->sender != NULL); + + if (sender == NULL) + { + if (strcmp (rule->sender, + DBUS_SERVICE_DBUS) != 0) + return FALSE; + } + else + { + if (!connection_is_primary_owner (sender, rule->sender)) + return FALSE; + } + } + + /* Note: this part is relevant for eavesdropper rules: + * Two cases: + * 1) rule has a destination to be matched + * (flag BUS_MATCH_DESTINATION present). Rule will match if: + * - rule->destination matches the addressed_recipient + * AND + * - wants_to_eavesdrop=TRUE + * + * Note: (the case in which addressed_recipient is the actual rule owner + * is handled elsewere in dispatch.c:bus_dispatch_matches(). + * + * 2) rule has no destination. Rule will match if: + * - message has no specified destination (ie broadcasts) + * (Note: this will rule out unicast method calls and unicast signals, + * fixing FDO#269748) + * OR + * - wants_to_eavesdrop=TRUE (destination-catch-all situation) + */ + if (flags & BUS_MATCH_DESTINATION) + { + const char *destination; + + _dbus_assert (rule->destination != NULL); + + destination = dbus_message_get_destination (message); + if (destination == NULL) + /* broadcast, but this rule specified a destination: no match */ + return FALSE; + + /* rule owner does not intend to eavesdrop: we'll deliver only msgs + * directed to it, NOT MATCHING */ + if (!wants_to_eavesdrop) + return FALSE; + + if (addressed_recipient == NULL) + { + if (strcmp (rule->destination, + DBUS_SERVICE_DBUS) != 0) + return FALSE; + } + else + { + if (!connection_is_primary_owner (addressed_recipient, rule->destination)) + return FALSE; + } + } else { /* no destination in rule */ + dbus_bool_t msg_is_broadcast; + + _dbus_assert (rule->destination == NULL); + + msg_is_broadcast = (dbus_message_get_destination (message) == NULL); + + if (!wants_to_eavesdrop && !msg_is_broadcast) + return FALSE; + + /* if we are here rule owner intends to eavesdrop + * OR + * message is being broadcasted */ + } + + if (flags & BUS_MATCH_PATH) + { + const char *path; + + _dbus_assert (rule->path != NULL); + + path = dbus_message_get_path (message); + if (path == NULL) + return FALSE; + + if (strcmp (path, rule->path) != 0) + return FALSE; + } + + if (flags & BUS_MATCH_PATH_NAMESPACE) + { + const char *path; + int len; + + _dbus_assert (rule->path != NULL); + + path = dbus_message_get_path (message); + if (path == NULL) + return FALSE; + + if (!str_has_prefix (path, rule->path)) + return FALSE; + + len = strlen (rule->path); + + /* Check that the actual argument is within the expected + * namespace, rather than just starting with that string, + * by checking that the matched prefix is followed by a '/' + * or the end of the path. + * + * Special case: the only valid path of length 1, "/", + * matches everything. + */ + if (len > 1 && path[len] != '\0' && path[len] != '/') + return FALSE; + } + + if (flags & BUS_MATCH_ARGS) + { + int i; + DBusMessageIter iter; + + _dbus_assert (rule->args != NULL); + + dbus_message_iter_init (message, &iter); + + i = 0; + while (i < rule->args_len) + { + int current_type; + const char *expected_arg; + int expected_length; + dbus_bool_t is_path, is_namespace; + + expected_arg = rule->args[i]; + expected_length = rule->arg_lens[i] & ~BUS_MATCH_ARG_FLAGS; + is_path = (rule->arg_lens[i] & BUS_MATCH_ARG_IS_PATH) != 0; + is_namespace = (rule->arg_lens[i] & BUS_MATCH_ARG_NAMESPACE) != 0; + + current_type = dbus_message_iter_get_arg_type (&iter); + + if (expected_arg != NULL) + { + const char *actual_arg; + int actual_length; + + if (current_type != DBUS_TYPE_STRING && + (!is_path || current_type != DBUS_TYPE_OBJECT_PATH)) + return FALSE; + + actual_arg = NULL; + dbus_message_iter_get_basic (&iter, &actual_arg); + _dbus_assert (actual_arg != NULL); + + actual_length = strlen (actual_arg); + + if (is_path) + { + if (actual_length < expected_length && + actual_arg[actual_length - 1] != '/') + return FALSE; + + if (expected_length < actual_length && + expected_arg[expected_length - 1] != '/') + return FALSE; + + if (memcmp (actual_arg, expected_arg, + MIN (actual_length, expected_length)) != 0) + return FALSE; + } + else if (is_namespace) + { + if (expected_length > actual_length) + return FALSE; + + /* If the actual argument doesn't start with the expected + * namespace, then we don't match. + */ + if (memcmp (expected_arg, actual_arg, expected_length) != 0) + return FALSE; + + if (expected_length < actual_length) + { + /* Check that the actual argument is within the expected + * namespace, rather than just starting with that string, + * by checking that the matched prefix ends in a '.'. + * + * This doesn't stop "foo.bar." matching "foo.bar..baz" + * which is an invalid namespace, but at some point the + * daemon can't cover up for broken services. + */ + if (actual_arg[expected_length] != '.') + return FALSE; + } + /* otherwise we had an exact match. */ + } + else + { + if (expected_length != actual_length || + memcmp (expected_arg, actual_arg, expected_length) != 0) + return FALSE; + } + + } + + if (current_type != DBUS_TYPE_INVALID) + dbus_message_iter_next (&iter); + + ++i; + } + } + + return TRUE; +} + +static dbus_bool_t +get_recipients_from_list (DBusList **rules, + DBusConnection *sender, + DBusConnection *addressed_recipient, + DBusMessage *message, + DBusList **recipients_p) +{ + DBusList *link; + + if (rules == NULL) + return TRUE; + + link = _dbus_list_get_first_link (rules); + while (link != NULL) + { + BusMatchRule *rule; + + rule = link->data; + +#ifdef DBUS_ENABLE_VERBOSE_MODE + { + char *s = match_rule_to_string (rule); + + _dbus_verbose ("Checking whether message matches rule %s for connection %p\n", + s ? s : "nomem", rule->matches_go_to); + dbus_free (s); + } +#endif + + if (match_rule_matches (rule, + sender, addressed_recipient, message, + BUS_MATCH_MESSAGE_TYPE | BUS_MATCH_INTERFACE)) + { + _dbus_verbose ("Rule matched\n"); + + /* Append to the list if we haven't already */ + if (bus_connection_mark_stamp (rule->matches_go_to)) + { + if (!_dbus_list_append (recipients_p, rule->matches_go_to)) + return FALSE; + } + else + { + _dbus_verbose ("Connection already receiving this message, so not adding again\n"); + } + } + + link = _dbus_list_get_next_link (rules, link); + } + + return TRUE; +} + +dbus_bool_t +bus_matchmaker_get_recipients (BusMatchmaker *matchmaker, + BusConnections *connections, + DBusConnection *sender, + DBusConnection *addressed_recipient, + DBusMessage *message, + DBusList **recipients_p) +{ + int type; + const char *interface; + DBusList **neither, **just_type, **just_iface, **both; + + _dbus_assert (*recipients_p == NULL); + + /* This avoids sending same message to the same connection twice. + * Purpose of the stamp instead of a bool is to avoid iterating over + * all connections resetting the bool each time. + */ + bus_connections_increment_stamp (connections); + + /* addressed_recipient is already receiving the message, don't add to list. + * NULL addressed_recipient means either bus driver, or this is a signal + * and thus lacks a specific addressed_recipient. + */ + if (addressed_recipient != NULL) + bus_connection_mark_stamp (addressed_recipient); + + type = dbus_message_get_type (message); + interface = dbus_message_get_interface (message); + + neither = bus_matchmaker_get_rules (matchmaker, DBUS_MESSAGE_TYPE_INVALID, + NULL, FALSE); + just_type = just_iface = both = NULL; + + if (interface != NULL) + just_iface = bus_matchmaker_get_rules (matchmaker, + DBUS_MESSAGE_TYPE_INVALID, interface, FALSE); + + if (type > DBUS_MESSAGE_TYPE_INVALID && type < DBUS_NUM_MESSAGE_TYPES) + { + just_type = bus_matchmaker_get_rules (matchmaker, type, NULL, FALSE); + + if (interface != NULL) + both = bus_matchmaker_get_rules (matchmaker, type, interface, FALSE); + } + + if (!(get_recipients_from_list (neither, sender, addressed_recipient, + message, recipients_p) && + get_recipients_from_list (just_iface, sender, addressed_recipient, + message, recipients_p) && + get_recipients_from_list (just_type, sender, addressed_recipient, + message, recipients_p) && + get_recipients_from_list (both, sender, addressed_recipient, + message, recipients_p))) + { + _dbus_list_clear (recipients_p); + return FALSE; + } + + return TRUE; +} + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS +#include "test.h" +#include <stdlib.h> + +static BusMatchRule* +check_parse (dbus_bool_t should_succeed, + const char *text) +{ + BusMatchRule *rule; + DBusString str; + DBusError error; + + dbus_error_init (&error); + + _dbus_string_init_const (&str, text); + + rule = bus_match_rule_parse (NULL, &str, &error); + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + dbus_error_free (&error); + return NULL; + } + + if (should_succeed && rule == NULL) + { + _dbus_warn ("Failed to parse: %s: %s: \"%s\"\n", + error.name, error.message, + _dbus_string_get_const_data (&str)); + exit (1); + } + + if (!should_succeed && rule != NULL) + { + _dbus_warn ("Failed to fail to parse: \"%s\"\n", + _dbus_string_get_const_data (&str)); + exit (1); + } + + dbus_error_free (&error); + + return rule; +} + +static void +assert_large_rule (BusMatchRule *rule) +{ + _dbus_assert (rule->flags & BUS_MATCH_MESSAGE_TYPE); + _dbus_assert (rule->flags & BUS_MATCH_SENDER); + _dbus_assert (rule->flags & BUS_MATCH_INTERFACE); + _dbus_assert (rule->flags & BUS_MATCH_MEMBER); + _dbus_assert (rule->flags & BUS_MATCH_DESTINATION); + _dbus_assert (rule->flags & BUS_MATCH_PATH); + + _dbus_assert (rule->message_type == DBUS_MESSAGE_TYPE_SIGNAL); + _dbus_assert (rule->interface != NULL); + _dbus_assert (rule->member != NULL); + _dbus_assert (rule->sender != NULL); + _dbus_assert (rule->destination != NULL); + _dbus_assert (rule->path != NULL); + + _dbus_assert (strcmp (rule->interface, "org.freedesktop.DBusInterface") == 0); + _dbus_assert (strcmp (rule->sender, "org.freedesktop.DBusSender") == 0); + _dbus_assert (strcmp (rule->member, "Foo") == 0); + _dbus_assert (strcmp (rule->path, "/bar/foo") == 0); + _dbus_assert (strcmp (rule->destination, ":452345.34") == 0); +} + +static dbus_bool_t +test_parsing (void *data) +{ + BusMatchRule *rule; + + rule = check_parse (TRUE, "type='signal',sender='org.freedesktop.DBusSender',interface='org.freedesktop.DBusInterface',member='Foo',path='/bar/foo',destination=':452345.34'"); + if (rule != NULL) + { + assert_large_rule (rule); + bus_match_rule_unref (rule); + } + + /* With extra whitespace and useless quotes */ + rule = check_parse (TRUE, " type='signal', \tsender='org.freedes''ktop.DBusSender', interface='org.freedesktop.DBusInterface''''', \tmember='Foo',path='/bar/foo',destination=':452345.34'''''"); + if (rule != NULL) + { + assert_large_rule (rule); + bus_match_rule_unref (rule); + } + + + /* A simple signal connection */ + rule = check_parse (TRUE, "type='signal',path='/foo',interface='org.Bar'"); + if (rule != NULL) + { + _dbus_assert (rule->flags & BUS_MATCH_MESSAGE_TYPE); + _dbus_assert (rule->flags & BUS_MATCH_INTERFACE); + _dbus_assert (rule->flags & BUS_MATCH_PATH); + + _dbus_assert (rule->message_type == DBUS_MESSAGE_TYPE_SIGNAL); + _dbus_assert (rule->interface != NULL); + _dbus_assert (rule->path != NULL); + + _dbus_assert (strcmp (rule->interface, "org.Bar") == 0); + _dbus_assert (strcmp (rule->path, "/foo") == 0); + + bus_match_rule_unref (rule); + } + + /* argN */ + rule = check_parse (TRUE, "arg0='foo'"); + if (rule != NULL) + { + _dbus_assert (rule->flags == BUS_MATCH_ARGS); + _dbus_assert (rule->args != NULL); + _dbus_assert (rule->args_len == 1); + _dbus_assert (rule->args[0] != NULL); + _dbus_assert (rule->args[1] == NULL); + _dbus_assert (strcmp (rule->args[0], "foo") == 0); + + bus_match_rule_unref (rule); + } + + rule = check_parse (TRUE, "arg1='foo'"); + if (rule != NULL) + { + _dbus_assert (rule->flags == BUS_MATCH_ARGS); + _dbus_assert (rule->args != NULL); + _dbus_assert (rule->args_len == 2); + _dbus_assert (rule->args[0] == NULL); + _dbus_assert (rule->args[1] != NULL); + _dbus_assert (rule->args[2] == NULL); + _dbus_assert (strcmp (rule->args[1], "foo") == 0); + + bus_match_rule_unref (rule); + } + + rule = check_parse (TRUE, "arg2='foo'"); + if (rule != NULL) + { + _dbus_assert (rule->flags == BUS_MATCH_ARGS); + _dbus_assert (rule->args != NULL); + _dbus_assert (rule->args_len == 3); + _dbus_assert (rule->args[0] == NULL); + _dbus_assert (rule->args[1] == NULL); + _dbus_assert (rule->args[2] != NULL); + _dbus_assert (rule->args[3] == NULL); + _dbus_assert (strcmp (rule->args[2], "foo") == 0); + + bus_match_rule_unref (rule); + } + + rule = check_parse (TRUE, "arg40='foo'"); + if (rule != NULL) + { + _dbus_assert (rule->flags == BUS_MATCH_ARGS); + _dbus_assert (rule->args != NULL); + _dbus_assert (rule->args_len == 41); + _dbus_assert (rule->args[0] == NULL); + _dbus_assert (rule->args[1] == NULL); + _dbus_assert (rule->args[40] != NULL); + _dbus_assert (rule->args[41] == NULL); + _dbus_assert (strcmp (rule->args[40], "foo") == 0); + + bus_match_rule_unref (rule); + } + + rule = check_parse (TRUE, "arg63='foo'"); + if (rule != NULL) + { + _dbus_assert (rule->flags == BUS_MATCH_ARGS); + _dbus_assert (rule->args != NULL); + _dbus_assert (rule->args_len == 64); + _dbus_assert (rule->args[0] == NULL); + _dbus_assert (rule->args[1] == NULL); + _dbus_assert (rule->args[63] != NULL); + _dbus_assert (rule->args[64] == NULL); + _dbus_assert (strcmp (rule->args[63], "foo") == 0); + + bus_match_rule_unref (rule); + } + + rule = check_parse (TRUE, "arg7path='/foo'"); + if (rule != NULL) + { + _dbus_assert (rule->flags == BUS_MATCH_ARGS); + _dbus_assert (rule->args != NULL); + _dbus_assert (rule->args_len == 8); + _dbus_assert (rule->args[7] != NULL); + _dbus_assert (rule->args[8] == NULL); + _dbus_assert (strcmp (rule->args[7], "/foo") == 0); + _dbus_assert ((rule->arg_lens[7] & BUS_MATCH_ARG_IS_PATH) + == BUS_MATCH_ARG_IS_PATH); + + bus_match_rule_unref (rule); + } + + /* Arg 0 namespace matches */ + rule = check_parse (TRUE, "arg0namespace='foo'"); + if (rule != NULL) + { + _dbus_assert (rule->flags == BUS_MATCH_ARGS); + _dbus_assert (rule->args != NULL); + _dbus_assert (rule->args_len == 1); + _dbus_assert (strcmp (rule->args[0], "foo") == 0); + _dbus_assert ((rule->arg_lens[0] & BUS_MATCH_ARG_NAMESPACE) + == BUS_MATCH_ARG_NAMESPACE); + + bus_match_rule_unref (rule); + } + + rule = check_parse (TRUE, "arg0namespace='foo.bar'"); + if (rule != NULL) + { + _dbus_assert (rule->flags == BUS_MATCH_ARGS); + _dbus_assert (rule->args != NULL); + _dbus_assert (rule->args_len == 1); + _dbus_assert (strcmp (rule->args[0], "foo.bar") == 0); + _dbus_assert ((rule->arg_lens[0] & BUS_MATCH_ARG_NAMESPACE) + == BUS_MATCH_ARG_NAMESPACE); + + bus_match_rule_unref (rule); + } + + /* Only arg0namespace is supported. */ + rule = check_parse (FALSE, "arg1namespace='foo'"); + _dbus_assert (rule == NULL); + + /* An empty string isn't a valid namespace prefix (you should just not + * specify this key at all). + */ + rule = check_parse (FALSE, "arg0namespace=''"); + _dbus_assert (rule == NULL); + + /* Trailing periods aren't allowed (earlier versions of the arg0namespace + * spec allowed a single trailing period, which altered the semantics) */ + rule = check_parse (FALSE, "arg0namespace='foo.'"); + _dbus_assert (rule == NULL); + + rule = check_parse (FALSE, "arg0namespace='foo.bar.'"); + _dbus_assert (rule == NULL); + + rule = check_parse (FALSE, "arg0namespace='foo..'"); + _dbus_assert (rule == NULL); + + rule = check_parse (FALSE, "arg0namespace='foo.bar..'"); + _dbus_assert (rule == NULL); + + /* Too-large argN */ + rule = check_parse (FALSE, "arg300='foo'"); + _dbus_assert (rule == NULL); + rule = check_parse (FALSE, "arg64='foo'"); + _dbus_assert (rule == NULL); + + /* No N in argN */ + rule = check_parse (FALSE, "arg='foo'"); + _dbus_assert (rule == NULL); + rule = check_parse (FALSE, "argv='foo'"); + _dbus_assert (rule == NULL); + rule = check_parse (FALSE, "arg3junk='foo'"); + _dbus_assert (rule == NULL); + rule = check_parse (FALSE, "argument='foo'"); + _dbus_assert (rule == NULL); + + /* Reject duplicates */ + rule = check_parse (FALSE, "type='signal',type='method_call'"); + _dbus_assert (rule == NULL); + + rule = check_parse (TRUE, "path_namespace='/foo/bar'"); + if (rule != NULL) + { + _dbus_assert (rule->flags == BUS_MATCH_PATH_NAMESPACE); + _dbus_assert (rule->path != NULL); + _dbus_assert (strcmp (rule->path, "/foo/bar") == 0); + + bus_match_rule_unref (rule); + } + + /* Almost a duplicate */ + rule = check_parse (FALSE, "path='/foo',path_namespace='/foo'"); + _dbus_assert (rule == NULL); + + /* Trailing / was supported in the initial proposal, but now isn't */ + rule = check_parse (FALSE, "path_namespace='/foo/'"); + _dbus_assert (rule == NULL); + + /* Duplicates with the argN code */ + rule = check_parse (FALSE, "arg0='foo',arg0='bar'"); + _dbus_assert (rule == NULL); + rule = check_parse (FALSE, "arg3='foo',arg3='bar'"); + _dbus_assert (rule == NULL); + rule = check_parse (FALSE, "arg30='foo',arg30='bar'"); + _dbus_assert (rule == NULL); + + /* Reject broken keys */ + rule = check_parse (FALSE, "blah='signal'"); + _dbus_assert (rule == NULL); + + /* Reject broken values */ + rule = check_parse (FALSE, "type='chouin'"); + _dbus_assert (rule == NULL); + rule = check_parse (FALSE, "interface='abc@def++'"); + _dbus_assert (rule == NULL); + rule = check_parse (FALSE, "service='youpi'"); + _dbus_assert (rule == NULL); + + /* Allow empty rule */ + rule = check_parse (TRUE, ""); + if (rule != NULL) + { + _dbus_assert (rule->flags == 0); + + bus_match_rule_unref (rule); + } + + /* All-whitespace rule is the same as empty */ + rule = check_parse (TRUE, " \t"); + if (rule != NULL) + { + _dbus_assert (rule->flags == 0); + + bus_match_rule_unref (rule); + } + + /* But with non-whitespace chars and no =value, it's not OK */ + rule = check_parse (FALSE, "type"); + _dbus_assert (rule == NULL); + + return TRUE; +} + +static struct { + const char *first; + const char *second; +} equality_tests[] = { + { "type='signal'", "type='signal'" }, + { "type='signal',interface='foo.bar'", "interface='foo.bar',type='signal'" }, + { "type='signal',member='bar'", "member='bar',type='signal'" }, + { "type='method_call',sender=':1.0'", "sender=':1.0',type='method_call'" }, + { "type='method_call',destination=':1.0'", "destination=':1.0',type='method_call'" }, + { "type='method_call',path='/foo/bar'", "path='/foo/bar',type='method_call'" }, + { "type='method_call',arg0='blah'", "arg0='blah',type='method_call'" }, + { "type='method_call',arg0='boo'", "arg0='boo',type='method_call'" }, + { "type='method_call',arg0='blah',arg1='baz'", "arg0='blah',arg1='baz',type='method_call'" }, + { "type='method_call',arg3='foosh'", "arg3='foosh',type='method_call'" }, + { "arg3='fool'", "arg3='fool'" }, + { "arg0namespace='fool'", "arg0namespace='fool'" }, + { "member='food'", "member='food'" }, + { "member=escape", "member='escape'" }, + { "member=icecream", "member=ice'cream'" }, + { "arg0='comma,type=comma',type=signal", "type=signal,arg0='comma,type=comma'" }, + { "arg0=escap\\e", "arg0='escap\\e'" }, + { "arg0=Time: 8 o\\'clock", "arg0='Time: 8 o'\\''clock'" }, +}; + +static void +test_equality (void) +{ + int i; + + i = 0; + while (i < _DBUS_N_ELEMENTS (equality_tests)) + { + BusMatchRule *first; + BusMatchRule *second; + char *first_str, *second_str; + BusMatchRule *first_reparsed, *second_reparsed; + int j; + + first = check_parse (TRUE, equality_tests[i].first); + _dbus_assert (first != NULL); + second = check_parse (TRUE, equality_tests[i].second); + _dbus_assert (second != NULL); + + if (!match_rule_equal (first, second)) + { + _dbus_warn ("rule %s and %s should have been equal\n", + equality_tests[i].first, + equality_tests[i].second); + exit (1); + } + + /* Check match_rule_to_string */ + first_str = match_rule_to_string (first); + _dbus_assert (first_str != NULL); + second_str = match_rule_to_string (second); + _dbus_assert (second_str != NULL); + _dbus_assert (strcmp (first_str, second_str) == 0); + first_reparsed = check_parse (TRUE, first_str); + second_reparsed = check_parse (TRUE, second_str); + _dbus_assert (match_rule_equal (first, first_reparsed)); + _dbus_assert (match_rule_equal (second, second_reparsed)); + bus_match_rule_unref (first_reparsed); + bus_match_rule_unref (second_reparsed); + dbus_free (first_str); + dbus_free (second_str); + + bus_match_rule_unref (second); + + /* Check that the rule is not equal to any of the + * others besides its pair match + */ + j = 0; + while (j < _DBUS_N_ELEMENTS (equality_tests)) + { + if (i != j) + { + second = check_parse (TRUE, equality_tests[j].second); + + if (match_rule_equal (first, second)) + { + _dbus_warn ("rule %s and %s should not have been equal\n", + equality_tests[i].first, + equality_tests[j].second); + exit (1); + } + + bus_match_rule_unref (second); + } + + ++j; + } + + bus_match_rule_unref (first); + + ++i; + } +} + +static const char* +should_match_message_1[] = { + "type='signal'", + "member='Frobated'", + "arg0='foobar'", + "type='signal',member='Frobated'", + "type='signal',member='Frobated',arg0='foobar'", + "member='Frobated',arg0='foobar'", + "type='signal',arg0='foobar'", + /* The definition of argXpath matches says: "As with normal argument matches, + * if the argument is exactly equal to the string given in the match rule + * then the rule is satisfied." So this should match (even though the + * argument is not a valid path)! + */ + "arg0path='foobar'", + "arg0namespace='foobar'", + NULL +}; + +static const char* +should_not_match_message_1[] = { + "type='method_call'", + "type='error'", + "type='method_return'", + "type='signal',member='Oopsed'", + "arg0='blah'", + "arg1='foobar'", + "arg2='foobar'", + "arg3='foobar'", + "arg0='3'", + "arg1='3'", + "arg0='foobar',arg1='abcdef'", + "arg0='foobar',arg1='abcdef',arg2='abcdefghi',arg3='abcdefghi',arg4='abcdefghi'", + "arg0='foobar',arg1='abcdef',arg4='abcdefghi',arg3='abcdefghi',arg2='abcdefghi'", + "arg0path='foo'", + "arg0path='foobar/'", + "arg1path='3'", + "arg0namespace='foo'", + "arg0namespace='foo',arg1='abcdef'", + "arg0namespace='moo'", + NULL +}; + +#define EXAMPLE_NAME "com.example.backend.foo" + +static const char * +should_match_message_2[] = { + /* EXAMPLE_NAME is in all of these namespaces */ + "arg0namespace='com.example.backend'", + "arg0namespace='com.example'", + "arg0namespace='com'", + + /* If the client specifies the name exactly, with no trailing period, then + * it should match. + */ + "arg0namespace='com.example.backend.foo'", + + NULL +}; + +static const char * +should_not_match_message_2[] = { + /* These are not even prefixes */ + "arg0namespace='com.example.backend.foo.bar'", + "arg0namespace='com.example.backend.foobar'", + + /* These are prefixes, but they're not parent namespaces. */ + "arg0namespace='com.example.backend.fo'", + "arg0namespace='com.example.backen'", + "arg0namespace='com.exampl'", + "arg0namespace='co'", + + NULL +}; + +static void +check_matches (dbus_bool_t expected_to_match, + int number, + DBusMessage *message, + const char *rule_text) +{ + BusMatchRule *rule; + dbus_bool_t matched; + + rule = check_parse (TRUE, rule_text); + _dbus_assert (rule != NULL); + + /* We can't test sender/destination rules since we pass NULL here */ + matched = match_rule_matches (rule, NULL, NULL, message, 0); + + if (matched != expected_to_match) + { + _dbus_warn ("Expected rule %s to %s message %d, failed\n", + rule_text, expected_to_match ? + "match" : "not match", number); + exit (1); + } + + bus_match_rule_unref (rule); +} + +static void +check_matching (DBusMessage *message, + int number, + const char **should_match, + const char **should_not_match) +{ + int i; + + i = 0; + while (should_match[i] != NULL) + { + check_matches (TRUE, number, message, should_match[i]); + ++i; + } + + i = 0; + while (should_not_match[i] != NULL) + { + check_matches (FALSE, number, message, should_not_match[i]); + ++i; + } +} + +static void +test_matching (void) +{ + DBusMessage *message1, *message2; + const char *v_STRING; + dbus_int32_t v_INT32; + + message1 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL); + _dbus_assert (message1 != NULL); + if (!dbus_message_set_member (message1, "Frobated")) + _dbus_assert_not_reached ("oom"); + + v_STRING = "foobar"; + v_INT32 = 3; + if (!dbus_message_append_args (message1, + DBUS_TYPE_STRING, &v_STRING, + DBUS_TYPE_INT32, &v_INT32, + NULL)) + _dbus_assert_not_reached ("oom"); + + check_matching (message1, 1, + should_match_message_1, + should_not_match_message_1); + + dbus_message_unref (message1); + + message2 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL); + _dbus_assert (message2 != NULL); + if (!dbus_message_set_member (message2, "NameOwnerChanged")) + _dbus_assert_not_reached ("oom"); + + /* Obviously this isn't really a NameOwnerChanged signal. */ + v_STRING = EXAMPLE_NAME; + if (!dbus_message_append_args (message2, + DBUS_TYPE_STRING, &v_STRING, + NULL)) + _dbus_assert_not_reached ("oom"); + + check_matching (message2, 2, + should_match_message_2, + should_not_match_message_2); + + dbus_message_unref (message2); +} + +#define PATH_MATCH_RULE "arg0path='/aa/bb/'" + +/* This is a list of paths that should be matched by PATH_MATCH_RULE, taken + * from the specification. Notice that not all of them are actually legal D-Bus + * paths. + * + * The author of this test takes no responsibility for the semantics of + * this match rule key. + */ +static const char *paths_that_should_be_matched[] = { + "/aa/", + "/aa/bb/", + "/aa/bb/cc/", +#define FIRST_VALID_PATH_WHICH_SHOULD_MATCH 3 + "/", + "/aa/bb/cc", + NULL +}; + +/* These paths should not be matched by PATH_MATCH_RULE. */ +static const char *paths_that_should_not_be_matched[] = { + "/aa/b", + "/aa", + /* or even... */ + "/aa/bb", + NULL +}; + +static void +test_path_match (int type, + const char *path, + const char *rule_text, + BusMatchRule *rule, + dbus_bool_t should_match) +{ + DBusMessage *message = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL); + dbus_bool_t matched; + + _dbus_assert (message != NULL); + if (!dbus_message_set_member (message, "Foo")) + _dbus_assert_not_reached ("oom"); + + if (!dbus_message_append_args (message, + type, &path, + NULL)) + _dbus_assert_not_reached ("oom"); + + matched = match_rule_matches (rule, NULL, NULL, message, 0); + + if (matched != should_match) + { + _dbus_warn ("Expected rule %s to %s message " + "with first arg %s of type '%c', failed\n", + rule_text, + should_match ? "match" : "not match", + path, + (char) type); + exit (1); + } + + dbus_message_unref (message); +} + +static void +test_path_matching (void) +{ + BusMatchRule *rule; + const char **s; + + rule = check_parse (TRUE, PATH_MATCH_RULE); + _dbus_assert (rule != NULL); + + for (s = paths_that_should_be_matched; *s != NULL; s++) + test_path_match (DBUS_TYPE_STRING, *s, PATH_MATCH_RULE, rule, TRUE); + + for (s = paths_that_should_be_matched + FIRST_VALID_PATH_WHICH_SHOULD_MATCH; + *s != NULL; s++) + test_path_match (DBUS_TYPE_OBJECT_PATH, *s, PATH_MATCH_RULE, rule, TRUE); + + for (s = paths_that_should_not_be_matched; *s != NULL; s++) + { + test_path_match (DBUS_TYPE_STRING, *s, PATH_MATCH_RULE, rule, FALSE); + test_path_match (DBUS_TYPE_OBJECT_PATH, *s, PATH_MATCH_RULE, rule, FALSE); + } + + bus_match_rule_unref (rule); +} + +static const char* +path_namespace_should_match_message_1[] = { + "type='signal',path_namespace='/'", + "type='signal',path_namespace='/foo'", + "type='signal',path_namespace='/foo/TheObjectManager'", + NULL +}; + +static const char* +path_namespace_should_not_match_message_1[] = { + "type='signal',path_namespace='/bar'", + "type='signal',path_namespace='/bar/TheObjectManager'", + NULL +}; + +static const char* +path_namespace_should_match_message_2[] = { + "type='signal',path_namespace='/'", + "type='signal',path_namespace='/foo/TheObjectManager'", + NULL +}; + +static const char* +path_namespace_should_not_match_message_2[] = { + NULL +}; + +static const char* +path_namespace_should_match_message_3[] = { + "type='signal',path_namespace='/'", + NULL +}; + +static const char* +path_namespace_should_not_match_message_3[] = { + "type='signal',path_namespace='/foo/TheObjectManager'", + NULL +}; + +static const char* +path_namespace_should_match_message_4[] = { + "type='signal',path_namespace='/'", + NULL +}; + +static const char* +path_namespace_should_not_match_message_4[] = { + "type='signal',path_namespace='/foo/TheObjectManager'", + NULL +}; + +static void +test_matching_path_namespace (void) +{ + DBusMessage *message1; + DBusMessage *message2; + DBusMessage *message3; + DBusMessage *message4; + + message1 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL); + _dbus_assert (message1 != NULL); + if (!dbus_message_set_path (message1, "/foo/TheObjectManager")) + _dbus_assert_not_reached ("oom"); + + message2 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL); + _dbus_assert (message2 != NULL); + if (!dbus_message_set_path (message2, "/foo/TheObjectManager/child_object")) + _dbus_assert_not_reached ("oom"); + + message3 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL); + _dbus_assert (message3 != NULL); + if (!dbus_message_set_path (message3, "/foo/TheObjectManagerOther")) + _dbus_assert_not_reached ("oom"); + + message4 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL); + _dbus_assert (message4 != NULL); + if (!dbus_message_set_path (message4, "/")) + _dbus_assert_not_reached ("oom"); + + check_matching (message1, 1, + path_namespace_should_match_message_1, + path_namespace_should_not_match_message_1); + check_matching (message2, 2, + path_namespace_should_match_message_2, + path_namespace_should_not_match_message_2); + check_matching (message3, 3, + path_namespace_should_match_message_3, + path_namespace_should_not_match_message_3); + check_matching (message4, 4, + path_namespace_should_match_message_4, + path_namespace_should_not_match_message_4); + + dbus_message_unref (message4); + dbus_message_unref (message3); + dbus_message_unref (message2); + dbus_message_unref (message1); +} + +dbus_bool_t +bus_signals_test (const DBusString *test_data_dir) +{ + BusMatchmaker *matchmaker; + + matchmaker = bus_matchmaker_new (); + bus_matchmaker_ref (matchmaker); + bus_matchmaker_unref (matchmaker); + bus_matchmaker_unref (matchmaker); + + if (!_dbus_test_oom_handling ("parsing match rules", test_parsing, NULL)) + _dbus_assert_not_reached ("Parsing match rules test failed"); + + test_equality (); + test_matching (); + test_path_matching (); + test_matching_path_namespace (); + + return TRUE; +} + +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */ +
diff --git a/bus/signals.h b/bus/signals.h new file mode 100644 index 0000000..0edfb07 --- /dev/null +++ b/bus/signals.h
@@ -0,0 +1,108 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* signals.h Bus signal connection implementation + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_SIGNALS_H +#define BUS_SIGNALS_H + +#include <dbus/dbus.h> +#include <dbus/dbus-string.h> +#include <dbus/dbus-sysdeps.h> +#include "connection.h" + +typedef enum +{ + BUS_MATCH_MESSAGE_TYPE = 1 << 0, + BUS_MATCH_INTERFACE = 1 << 1, + BUS_MATCH_MEMBER = 1 << 2, + BUS_MATCH_SENDER = 1 << 3, + BUS_MATCH_DESTINATION = 1 << 4, + BUS_MATCH_PATH = 1 << 5, + BUS_MATCH_ARGS = 1 << 6, + BUS_MATCH_PATH_NAMESPACE = 1 << 7, + BUS_MATCH_CLIENT_IS_EAVESDROPPING = 1 << 8 +} BusMatchFlags; + +BusMatchRule* bus_match_rule_new (DBusConnection *matches_go_to); +BusMatchRule* bus_match_rule_ref (BusMatchRule *rule); +void bus_match_rule_unref (BusMatchRule *rule); + +dbus_bool_t bus_match_rule_set_message_type (BusMatchRule *rule, + int type); +dbus_bool_t bus_match_rule_set_interface (BusMatchRule *rule, + const char *interface); +dbus_bool_t bus_match_rule_set_member (BusMatchRule *rule, + const char *member); +dbus_bool_t bus_match_rule_set_sender (BusMatchRule *rule, + const char *sender); +dbus_bool_t bus_match_rule_set_destination (BusMatchRule *rule, + const char *destination); +dbus_bool_t bus_match_rule_set_path (BusMatchRule *rule, + const char *path, + dbus_bool_t is_namespace); +dbus_bool_t bus_match_rule_set_arg (BusMatchRule *rule, + int arg, + const DBusString *value, + dbus_bool_t is_path, + dbus_bool_t is_namespace); + +/* Calling this methods a client declares that it is creating a rule which + * needs to eavesdrop (e.g., dbus-monitor), any other created rules not + * setting themselves as eavesdropping won't receive any message not addressed + * to them, when eavedrop is enabled in the policy. On the other hand, when + * eavedrop is not enabled in policy, this method won't have any effect */ +void bus_match_rule_set_client_is_eavesdropping (BusMatchRule *rule, + dbus_bool_t is_eavesdropping); + +dbus_bool_t bus_match_rule_get_client_is_eavesdropping (BusMatchRule *rule); + +BusMatchRule* bus_match_rule_parse (DBusConnection *matches_go_to, + const DBusString *rule_text, + DBusError *error); + +#ifdef DBUS_ENABLE_STATS +dbus_bool_t bus_match_rule_dump (BusMatchmaker *matchmaker, + DBusConnection *conn_filter, + DBusMessageIter *arr_iter); +#endif + +BusMatchmaker* bus_matchmaker_new (void); +BusMatchmaker* bus_matchmaker_ref (BusMatchmaker *matchmaker); +void bus_matchmaker_unref (BusMatchmaker *matchmaker); + +dbus_bool_t bus_matchmaker_add_rule (BusMatchmaker *matchmaker, + BusMatchRule *rule); +dbus_bool_t bus_matchmaker_remove_rule_by_value (BusMatchmaker *matchmaker, + BusMatchRule *value, + DBusError *error); +void bus_matchmaker_remove_rule (BusMatchmaker *matchmaker, + BusMatchRule *rule); +void bus_matchmaker_disconnected (BusMatchmaker *matchmaker, + DBusConnection *connection); +dbus_bool_t bus_matchmaker_get_recipients (BusMatchmaker *matchmaker, + BusConnections *connections, + DBusConnection *sender, + DBusConnection *addressed_recipient, + DBusMessage *message, + DBusList **recipients_p); + +#endif /* BUS_SIGNALS_H */
diff --git a/bus/stats.c b/bus/stats.c new file mode 100644 index 0000000..dace0e2 --- /dev/null +++ b/bus/stats.c
@@ -0,0 +1,344 @@ +/* stats.c - statistics from the bus driver + * + * Copyright © 2011-2012 Nokia Corporation + * Copyright © 2012-2013 Collabora Ltd. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <config.h> +#include "stats.h" + +#include <dbus/dbus-asv-util.h> +#include <dbus/dbus-internals.h> +#include <dbus/dbus-connection-internal.h> + +#include "connection.h" +#include "driver.h" +#include "services.h" +#include "signals.h" +#include "utils.h" + +#ifdef DBUS_ENABLE_STATS + +dbus_bool_t +bus_stats_handle_get_stats (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + BusContext *context; + BusConnections *connections; + DBusMessage *reply = NULL; + DBusMessageIter iter, arr_iter; + static dbus_uint32_t stats_serial = 0; + dbus_uint32_t in_use, in_free_list, allocated; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!bus_driver_check_message_is_for_us (message, error)) + return FALSE; + + context = bus_transaction_get_context (transaction); + connections = bus_context_get_connections (context); + + reply = _dbus_asv_new_method_return (message, &iter, &arr_iter); + + if (reply == NULL) + goto oom; + + /* Globals */ + + _dbus_list_get_stats (&in_use, &in_free_list, &allocated); + + if (!_dbus_asv_add_uint32 (&arr_iter, "Serial", stats_serial++) || + !_dbus_asv_add_uint32 (&arr_iter, "ListMemPoolUsedBytes", in_use) || + !_dbus_asv_add_uint32 (&arr_iter, "ListMemPoolCachedBytes", in_free_list) || + !_dbus_asv_add_uint32 (&arr_iter, "ListMemPoolAllocatedBytes", allocated)) + { + _dbus_asv_abandon (&iter, &arr_iter); + goto oom; + } + + /* Connections */ + + if (!_dbus_asv_add_uint32 (&arr_iter, "ActiveConnections", + bus_connections_get_n_active (connections)) || + !_dbus_asv_add_uint32 (&arr_iter, "IncompleteConnections", + bus_connections_get_n_incomplete (connections)) || + !_dbus_asv_add_uint32 (&arr_iter, "MatchRules", + bus_connections_get_total_match_rules (connections)) || + !_dbus_asv_add_uint32 (&arr_iter, "PeakMatchRules", + bus_connections_get_peak_match_rules (connections)) || + !_dbus_asv_add_uint32 (&arr_iter, "PeakMatchRulesPerConnection", + bus_connections_get_peak_match_rules_per_conn (connections)) || + !_dbus_asv_add_uint32 (&arr_iter, "BusNames", + bus_connections_get_total_bus_names (connections)) || + !_dbus_asv_add_uint32 (&arr_iter, "PeakBusNames", + bus_connections_get_peak_bus_names (connections)) || + !_dbus_asv_add_uint32 (&arr_iter, "PeakBusNamesPerConnection", + bus_connections_get_peak_bus_names_per_conn (connections))) + { + _dbus_asv_abandon (&iter, &arr_iter); + goto oom; + } + + /* end */ + + if (!_dbus_asv_close (&iter, &arr_iter)) + goto oom; + + if (!bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + dbus_message_unref (reply); + return TRUE; + +oom: + if (reply != NULL) + dbus_message_unref (reply); + + BUS_SET_OOM (error); + return FALSE; +} + +dbus_bool_t +bus_stats_handle_get_connection_stats (DBusConnection *caller_connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + const char *bus_name = NULL; + DBusString bus_name_str; + DBusMessage *reply = NULL; + DBusMessageIter iter, arr_iter; + static dbus_uint32_t stats_serial = 0; + dbus_uint32_t in_messages, in_bytes, in_fds, in_peak_bytes, in_peak_fds; + dbus_uint32_t out_messages, out_bytes, out_fds, out_peak_bytes, out_peak_fds; + BusRegistry *registry; + BusService *service; + DBusConnection *stats_connection; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!bus_driver_check_message_is_for_us (message, error)) + return FALSE; + + registry = bus_connection_get_registry (caller_connection); + + if (! dbus_message_get_args (message, error, + DBUS_TYPE_STRING, &bus_name, + DBUS_TYPE_INVALID)) + return FALSE; + + _dbus_string_init_const (&bus_name_str, bus_name); + service = bus_registry_lookup (registry, &bus_name_str); + + if (service == NULL) + { + dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER, + "Bus name '%s' has no owner", bus_name); + return FALSE; + } + + stats_connection = bus_service_get_primary_owners_connection (service); + _dbus_assert (stats_connection != NULL); + + reply = _dbus_asv_new_method_return (message, &iter, &arr_iter); + + if (reply == NULL) + goto oom; + + /* Bus daemon per-connection stats */ + + if (!_dbus_asv_add_uint32 (&arr_iter, "Serial", stats_serial++) || + !_dbus_asv_add_uint32 (&arr_iter, "MatchRules", + bus_connection_get_n_match_rules (stats_connection)) || + !_dbus_asv_add_uint32 (&arr_iter, "PeakMatchRules", + bus_connection_get_peak_match_rules (stats_connection)) || + !_dbus_asv_add_uint32 (&arr_iter, "BusNames", + bus_connection_get_n_services_owned (stats_connection)) || + !_dbus_asv_add_uint32 (&arr_iter, "PeakBusNames", + bus_connection_get_peak_bus_names (stats_connection)) || + !_dbus_asv_add_string (&arr_iter, "UniqueName", + bus_connection_get_name (stats_connection))) + { + _dbus_asv_abandon (&iter, &arr_iter); + goto oom; + } + + /* DBusConnection per-connection stats */ + + _dbus_connection_get_stats (stats_connection, + &in_messages, &in_bytes, &in_fds, + &in_peak_bytes, &in_peak_fds, + &out_messages, &out_bytes, &out_fds, + &out_peak_bytes, &out_peak_fds); + + if (!_dbus_asv_add_uint32 (&arr_iter, "IncomingMessages", in_messages) || + !_dbus_asv_add_uint32 (&arr_iter, "IncomingBytes", in_bytes) || + !_dbus_asv_add_uint32 (&arr_iter, "IncomingFDs", in_fds) || + !_dbus_asv_add_uint32 (&arr_iter, "PeakIncomingBytes", in_peak_bytes) || + !_dbus_asv_add_uint32 (&arr_iter, "PeakIncomingFDs", in_peak_fds) || + !_dbus_asv_add_uint32 (&arr_iter, "OutgoingMessages", out_messages) || + !_dbus_asv_add_uint32 (&arr_iter, "OutgoingBytes", out_bytes) || + !_dbus_asv_add_uint32 (&arr_iter, "OutgoingFDs", out_fds) || + !_dbus_asv_add_uint32 (&arr_iter, "PeakOutgoingBytes", out_peak_bytes) || + !_dbus_asv_add_uint32 (&arr_iter, "PeakOutgoingFDs", out_peak_fds)) + { + _dbus_asv_abandon (&iter, &arr_iter); + goto oom; + } + + /* end */ + + if (!_dbus_asv_close (&iter, &arr_iter)) + goto oom; + + if (!bus_transaction_send_from_driver (transaction, caller_connection, + reply)) + goto oom; + + dbus_message_unref (reply); + return TRUE; + +oom: + if (reply != NULL) + dbus_message_unref (reply); + + BUS_SET_OOM (error); + return FALSE; +} + + +dbus_bool_t +bus_stats_handle_get_all_match_rules (DBusConnection *caller_connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + BusContext *context; + DBusString bus_name_str; + DBusMessage *reply = NULL; + DBusMessageIter iter, hash_iter, entry_iter, arr_iter; + BusRegistry *registry; + char **services = NULL; + int services_len; + DBusConnection *conn_filter = NULL; + BusMatchmaker *matchmaker; + int i; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + registry = bus_connection_get_registry (caller_connection); + context = bus_transaction_get_context (transaction); + matchmaker = bus_context_get_matchmaker (context); + + if (!bus_registry_list_services (registry, &services, &services_len)) + return FALSE; + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + dbus_message_iter_init_append (reply, &iter); + + if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{sas}", + &hash_iter)) + goto oom; + + for (i = 0 ; i < services_len ; i++) + { + BusService *service; + + /* To avoid duplicate entries, only look for unique names */ + if (services[i][0] != ':') + continue; + + _dbus_string_init_const (&bus_name_str, services[i]); + service = bus_registry_lookup (registry, &bus_name_str); + _dbus_assert (service != NULL); + + conn_filter = bus_service_get_primary_owners_connection (service); + _dbus_assert (conn_filter != NULL); + + if (!dbus_message_iter_open_container (&hash_iter, DBUS_TYPE_DICT_ENTRY, NULL, + &entry_iter)) + { + dbus_message_iter_abandon_container (&iter, &hash_iter); + goto oom; + } + + if (!dbus_message_iter_append_basic (&entry_iter, DBUS_TYPE_STRING, &services[i])) + { + dbus_message_iter_abandon_container (&hash_iter, &entry_iter); + dbus_message_iter_abandon_container (&iter, &hash_iter); + goto oom; + } + + if (!dbus_message_iter_open_container (&entry_iter, DBUS_TYPE_ARRAY, "s", + &arr_iter)) + { + dbus_message_iter_abandon_container (&hash_iter, &entry_iter); + dbus_message_iter_abandon_container (&iter, &hash_iter); + goto oom; + } + + if (!bus_match_rule_dump (matchmaker, conn_filter, &arr_iter)) + { + dbus_message_iter_abandon_container (&entry_iter, &arr_iter); + dbus_message_iter_abandon_container (&hash_iter, &entry_iter); + dbus_message_iter_abandon_container (&iter, &hash_iter); + goto oom; + } + + if (!dbus_message_iter_close_container (&entry_iter, &arr_iter)) + { + dbus_message_iter_abandon_container (&hash_iter, &entry_iter); + dbus_message_iter_abandon_container (&iter, &hash_iter); + goto oom; + } + if (!dbus_message_iter_close_container (&hash_iter, &entry_iter)) + { + dbus_message_iter_abandon_container (&iter, &hash_iter); + goto oom; + } + } + + if (!dbus_message_iter_close_container (&iter, &hash_iter)) + goto oom; + + if (!bus_transaction_send_from_driver (transaction, caller_connection, + reply)) + goto oom; + + dbus_message_unref (reply); + dbus_free_string_array (services); + return TRUE; + +oom: + if (reply != NULL) + dbus_message_unref (reply); + + dbus_free_string_array (services); + + BUS_SET_OOM (error); + return FALSE; +} + +#endif
diff --git a/bus/stats.h b/bus/stats.h new file mode 100644 index 0000000..dcb022c --- /dev/null +++ b/bus/stats.h
@@ -0,0 +1,43 @@ +/* stats.h - statistics from the bus driver + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef BUS_STATS_H +#define BUS_STATS_H + +#include "bus.h" + +#define BUS_INTERFACE_STATS "org.freedesktop.DBus.Debug.Stats" + +dbus_bool_t bus_stats_handle_get_stats (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error); + +dbus_bool_t bus_stats_handle_get_connection_stats (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error); + +dbus_bool_t bus_stats_handle_get_all_match_rules (DBusConnection *caller_connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error); + +#endif /* multiple-inclusion guard */
diff --git a/bus/system.conf.in b/bus/system.conf.in new file mode 100644 index 0000000..9f9bf45 --- /dev/null +++ b/bus/system.conf.in
@@ -0,0 +1,118 @@ +<!-- This configuration file controls the systemwide message bus. + Add a system-local.conf and edit that rather than changing this + file directly. --> + +<!-- Note that there are any number of ways you can hose yourself + security-wise by screwing up this file; in particular, you + probably don't want to listen on any more addresses, add any more + auth mechanisms, run as a different user, etc. --> + +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> +<busconfig> + + <!-- Our well-known bus type, do not change this --> + <type>system</type> + + <!-- Run as special user --> + <user>@DBUS_USER@</user> + + <!-- Fork into daemon mode --> + <fork/> + + <!-- We use system service launching using a helper --> + <standard_system_servicedirs/> + + <!-- This is a setuid helper that is used to launch system services --> + <servicehelper>@DBUS_LIBEXECDIR@/dbus-daemon-launch-helper</servicehelper> + + <!-- Write a pid file --> + <pidfile>@DBUS_SYSTEM_PID_FILE@</pidfile> + + <!-- Enable logging to syslog --> + <syslog/> + + <!-- Only allow socket-credentials-based authentication --> + <auth>EXTERNAL</auth> + + <!-- Only listen on a local socket. (abstract=/path/to/socket + means use abstract namespace, don't really create filesystem + file; only Linux supports this. Use path=/whatever on other + systems.) --> + <listen>@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@</listen> + + <policy context="default"> + <!-- All users can connect to system bus --> + <allow user="*"/> + + <!-- Holes must be punched in service configuration files for + name ownership and sending method calls --> + <deny own="*"/> + <deny send_type="method_call"/> + + <!-- Signals and reply messages (method returns, errors) are allowed + by default --> + <allow send_type="signal"/> + <allow send_requested_reply="true" send_type="method_return"/> + <allow send_requested_reply="true" send_type="error"/> + + <!-- All messages may be received by default --> + <allow receive_type="method_call"/> + <allow receive_type="method_return"/> + <allow receive_type="error"/> + <allow receive_type="signal"/> + + <!-- Allow anyone to talk to the message bus --> + <allow send_destination="org.freedesktop.DBus" + send_interface="org.freedesktop.DBus" /> + <allow send_destination="org.freedesktop.DBus" + send_interface="org.freedesktop.DBus.Introspectable"/> + <!-- But disallow some specific bus services --> + <deny send_destination="org.freedesktop.DBus" + send_interface="org.freedesktop.DBus" + send_member="UpdateActivationEnvironment"/> + <deny send_destination="org.freedesktop.DBus" + send_interface="org.freedesktop.DBus.Debug.Stats"/> + <deny send_destination="org.freedesktop.DBus" + send_interface="org.freedesktop.systemd1.Activator"/> + </policy> + + <!-- Only systemd, which runs as root, may report activation failures. --> + <policy user="root"> + <allow send_destination="org.freedesktop.DBus" + send_interface="org.freedesktop.systemd1.Activator"/> + </policy> + + <!-- root may monitor the system bus. --> + <policy user="root"> + <allow send_destination="org.freedesktop.DBus" + send_interface="org.freedesktop.DBus.Monitoring"/> + </policy> + + <!-- If the Stats interface was enabled at compile-time, root may use it. + Copy this into system.local.conf or system.d/*.conf if you want to + enable other privileged users to view statistics and debug info --> + <policy user="root"> + <allow send_destination="org.freedesktop.DBus" + send_interface="org.freedesktop.DBus.Debug.Stats"/> + </policy> + + <!-- Include legacy configuration location --> + <include ignore_missing="yes">@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/system.conf</include> + + <!-- Config files are placed here that among other things, punch + holes in the above policy for specific services. --> + <includedir>system.d</includedir> + + <includedir>@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/system.d</includedir> + + <!-- This is included last so local configuration can override what's + in this standard file --> + <include ignore_missing="yes">@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/system-local.conf</include> + + <include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include> + + <!-- Chromium talks to most services on the bus so needs a relatively + large number of match rules. --> + <limit name="max_match_rules_per_connection">4096</limit> +</busconfig>
diff --git a/bus/systemd-user/dbus.service.in b/bus/systemd-user/dbus.service.in new file mode 100644 index 0000000..b41f522 --- /dev/null +++ b/bus/systemd-user/dbus.service.in
@@ -0,0 +1,11 @@ +[Unit] +Description=D-Bus User Message Bus +Documentation=man:dbus-daemon(1) +Requires=dbus.socket + +[Service] +ExecStart=@EXPANDED_BINDIR@/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation +ExecReload=@EXPANDED_BINDIR@/dbus-send --print-reply --session --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig + +[Install] +Also=dbus.socket
diff --git a/bus/systemd-user/dbus.socket.in b/bus/systemd-user/dbus.socket.in new file mode 100644 index 0000000..4793d1d --- /dev/null +++ b/bus/systemd-user/dbus.socket.in
@@ -0,0 +1,10 @@ +[Unit] +Description=D-Bus User Message Bus Socket + +[Socket] +ListenStream=%t/bus +ExecStartPost=-@SYSTEMCTL@ --user set-environment DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus + +[Install] +WantedBy=sockets.target +Also=dbus.service
diff --git a/bus/test-launch-helper.c b/bus/test-launch-helper.c new file mode 100644 index 0000000..c58d06e --- /dev/null +++ b/bus/test-launch-helper.c
@@ -0,0 +1,148 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* test-main.c main() for the OOM check of the launch helper + * + * Copyright (C) 2007 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "test.h" +#include "activation-helper.h" + +#include <stdio.h> +#include <stdlib.h> +#include <dbus/dbus-internals.h> +#include <dbus/dbus-misc.h> + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS +static void +die (const char *failure) +{ + fprintf (stderr, "Unit test failed: %s\n", failure); + exit (1); +} + +static void +check_memleaks (const char *name) +{ + dbus_shutdown (); + + printf ("%s: checking for memleaks\n", name); + if (_dbus_get_malloc_blocks_outstanding () != 0) + { + _dbus_warn ("%d dbus_malloc blocks were not freed\n", + _dbus_get_malloc_blocks_outstanding ()); + die ("memleaks"); + } +} + +static void +test_post_hook (const char *name) +{ + check_memleaks (name); +} +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */ + + +#ifdef ACTIVATION_LAUNCHER_DO_OOM + +/* returns true if good things happen, or if we get OOM */ +static dbus_bool_t +bus_activation_helper_oom_test (void *data) +{ + const char *service; + DBusError error; + dbus_bool_t retval; + + service = (const char *) data; + retval = TRUE; + + dbus_error_init (&error); + if (!run_launch_helper (service, &error)) + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + /* we failed, but a OOM is good */ + if (!dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + _dbus_warn ("FAILED SELF TEST: Error: %s\n", error.message); + retval = FALSE; + } + dbus_error_free (&error); + } + else + { + /* we succeeded, yay! */ + _DBUS_ASSERT_ERROR_IS_CLEAR (&error); + } + return retval; +} + +#endif + +int +main (int argc, char **argv) +{ +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + const char *dir; + DBusString config_file; + + if (argc > 1 && strcmp (argv[1], "--tap") != 0) + dir = argv[1]; + else + dir = _dbus_getenv ("DBUS_TEST_DATA"); + + if (dir == NULL) + { + fprintf (stderr, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n"); + return 1; + } + + printf ("%s: Running launch helper OOM checks\n", argv[0]); + + if (!_dbus_string_init (&config_file)) + return 1; + if (!_dbus_string_append (&config_file, dir)) + return 1; + if (!_dbus_string_append (&config_file, "/valid-config-files-system/debug-allow-all-pass.conf")) + return 1; + + /* use a config file that will actually work... */ + dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG", + _dbus_string_get_const_data (&config_file)); + + _dbus_string_free (&config_file); + + if (!_dbus_test_oom_handling ("dbus-daemon-launch-helper", + bus_activation_helper_oom_test, + "org.freedesktop.DBus.TestSuiteEchoService")) + die ("OOM failed"); + + test_post_hook (argv[0]); + + printf ("%s: Success\n", argv[0]); + + return 0; +#else /* DBUS_ENABLE_EMBEDDED_TESTS */ + + printf ("Not compiled with test support\n"); + + return 0; +#endif +} +
diff --git a/bus/test-main.c b/bus/test-main.c new file mode 100644 index 0000000..faa6395 --- /dev/null +++ b/bus/test-main.c
@@ -0,0 +1,199 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* test-main.c main() for make check + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "test.h" +#include <stdio.h> +#include <stdlib.h> +#include <dbus/dbus-string.h> +#include <dbus/dbus-sysdeps.h> +#include <dbus/dbus-internals.h> +#include <dbus/dbus-message-internal.h> +#include "selinux.h" + +#ifdef DBUS_UNIX +# include <dbus/dbus-sysdeps-unix.h> +#endif + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS +static void +die (const char *failure) +{ + fprintf (stderr, "Unit test failed: %s\n", failure); + exit (1); +} + +static void +check_memleaks (const char *name) +{ + dbus_shutdown (); + + printf ("%s: checking for memleaks\n", name); + if (_dbus_get_malloc_blocks_outstanding () != 0) + { + _dbus_warn ("%d dbus_malloc blocks were not freed\n", + _dbus_get_malloc_blocks_outstanding ()); + die ("memleaks"); + } +} +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */ + +static DBusInitialFDs *initial_fds = NULL; + +static void +test_pre_hook (void) +{ + + if (_dbus_getenv ("DBUS_TEST_SELINUX") + && (!bus_selinux_pre_init () + || !bus_selinux_full_init ())) + die ("could not init selinux support"); + + initial_fds = _dbus_check_fdleaks_enter (); +} + +static char *progname = ""; + +static void +test_post_hook (void) +{ + if (_dbus_getenv ("DBUS_TEST_SELINUX")) + bus_selinux_shutdown (); + check_memleaks (progname); + + _dbus_check_fdleaks_leave (initial_fds); + initial_fds = NULL; +} + +int +main (int argc, char **argv) +{ +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + const char *dir; + const char *only; + DBusString test_data_dir; + + progname = argv[0]; + + if (argc > 1 && strcmp (argv[1], "--tap") != 0) + dir = argv[1]; + else + dir = _dbus_getenv ("DBUS_TEST_DATA"); + + if (argc > 2) + only = argv[2]; + else + only = NULL; + + if (dir == NULL) + { + fprintf (stderr, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n"); + return 1; + } + + _dbus_string_init_const (&test_data_dir, dir); + +#ifdef DBUS_UNIX + /* close any inherited fds so dbus-spawn's check for close-on-exec works */ + _dbus_close_all (); +#endif + + if (!_dbus_threads_init_debug ()) + die ("initializing debug threads"); + + if (only == NULL || strcmp (only, "expire-list") == 0) + { + test_pre_hook (); + printf ("%s: Running expire list test\n", argv[0]); + if (!bus_expire_list_test (&test_data_dir)) + die ("expire list"); + test_post_hook (); + } + + if (only == NULL || strcmp (only, "config-parser") == 0) + { + test_pre_hook (); + printf ("%s: Running config file parser test\n", argv[0]); + if (!bus_config_parser_test (&test_data_dir)) + die ("parser"); + test_post_hook (); + } + + if (only == NULL || strcmp (only, "signals") == 0) + { + test_pre_hook (); + printf ("%s: Running signals test\n", argv[0]); + if (!bus_signals_test (&test_data_dir)) + die ("signals"); + test_post_hook (); + } + + if (only == NULL || strcmp (only, "dispatch-sha1") == 0) + { + test_pre_hook (); + printf ("%s: Running SHA1 connection test\n", argv[0]); + if (!bus_dispatch_sha1_test (&test_data_dir)) + die ("sha1"); + test_post_hook (); + } + + if (only == NULL || strcmp (only, "dispatch") == 0) + { + test_pre_hook (); + printf ("%s: Running message dispatch test\n", argv[0]); + if (!bus_dispatch_test (&test_data_dir)) + die ("dispatch"); + test_post_hook (); + } + + if (only == NULL || strcmp (only, "activation-service-reload") == 0) + { + test_pre_hook (); + printf ("%s: Running service files reloading test\n", argv[0]); + if (!bus_activation_service_reload_test (&test_data_dir)) + die ("service reload"); + test_post_hook (); + } + +#ifdef HAVE_UNIX_FD_PASSING + if (only == NULL || strcmp (only, "unix-fds-passing") == 0) + { + test_pre_hook (); + printf ("%s: Running unix fd passing test\n", argv[0]); + if (!bus_unix_fds_passing_test (&test_data_dir)) + die ("unix fd passing"); + test_post_hook (); + } +#endif + + printf ("%s: Success\n", argv[0]); + + + return 0; +#else /* DBUS_ENABLE_EMBEDDED_TESTS */ + + printf ("Not compiled with test support\n"); + + return 0; +#endif +}
diff --git a/bus/test-system.c b/bus/test-system.c new file mode 100644 index 0000000..2d7848c --- /dev/null +++ b/bus/test-system.c
@@ -0,0 +1,107 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* test-main.c main() for make check + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "test.h" +#include <stdio.h> +#include <stdlib.h> +#include <dbus/dbus-string.h> +#include <dbus/dbus-sysdeps.h> +#include <dbus/dbus-internals.h> + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS +static void +die (const char *failure) +{ + fprintf (stderr, "Unit test failed: %s\n", failure); + exit (1); +} + +static void +check_memleaks (const char *name) +{ + dbus_shutdown (); + + printf ("%s: checking for memleaks\n", name); + if (_dbus_get_malloc_blocks_outstanding () != 0) + { + _dbus_warn ("%d dbus_malloc blocks were not freed\n", + _dbus_get_malloc_blocks_outstanding ()); + die ("memleaks"); + } +} +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */ + +static void +test_pre_hook (void) +{ +} + +static char *progname = ""; +static void +test_post_hook (void) +{ + check_memleaks (progname); +} + +int +main (int argc, char **argv) +{ +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + const char *dir; + DBusString test_data_dir; + + progname = argv[0]; + + if (argc > 1 && strcmp (argv[1], "--tap") != 0) + dir = argv[1]; + else + dir = _dbus_getenv ("DBUS_TEST_DATA"); + + if (dir == NULL) + { + fprintf (stderr, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n"); + return 1; + } + + _dbus_string_init_const (&test_data_dir, dir); + + if (!_dbus_threads_init_debug ()) + die ("initializing debug threads"); + + test_pre_hook (); + printf ("%s: Running config file parser (trivial) test\n", argv[0]); + if (!bus_config_parser_trivial_test (&test_data_dir)) + die ("parser"); + test_post_hook (); + + printf ("%s: Success\n", argv[0]); + + return 0; +#else /* DBUS_ENABLE_EMBEDDED_TESTS */ + + printf ("Not compiled with test support\n"); + + return 0; +#endif +}
diff --git a/bus/test.c b/bus/test.c new file mode 100644 index 0000000..31ef4c8 --- /dev/null +++ b/bus/test.c
@@ -0,0 +1,315 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* test.c unit test routines + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS +#include "test.h" +#include <dbus/dbus-internals.h> +#include <dbus/dbus-list.h> +#include <dbus/dbus-sysdeps.h> + +/* The "debug client" watch/timeout handlers don't dispatch messages, + * as we manually pull them in order to verify them. This is why they + * are different from the real handlers in connection.c + */ +static DBusList *clients = NULL; +static DBusLoop *client_loop = NULL; + +static dbus_bool_t +add_client_watch (DBusWatch *watch, + void *data) +{ + return _dbus_loop_add_watch (client_loop, watch); +} + +static void +remove_client_watch (DBusWatch *watch, + void *data) +{ + _dbus_loop_remove_watch (client_loop, watch); +} + +static void +toggle_client_watch (DBusWatch *watch, + void *data) +{ + _dbus_loop_toggle_watch (client_loop, watch); +} + +static dbus_bool_t +add_client_timeout (DBusTimeout *timeout, + void *data) +{ + return _dbus_loop_add_timeout (client_loop, timeout); +} + +static void +remove_client_timeout (DBusTimeout *timeout, + void *data) +{ + _dbus_loop_remove_timeout (client_loop, timeout); +} + +static DBusHandlerResult +client_disconnect_filter (DBusConnection *connection, + DBusMessage *message, + void *user_data) +{ + if (!dbus_message_is_signal (message, + DBUS_INTERFACE_LOCAL, + "Disconnected")) + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + _dbus_verbose ("Removing client %p in disconnect handler\n", + connection); + + _dbus_list_remove (&clients, connection); + + dbus_connection_unref (connection); + + if (clients == NULL) + { + _dbus_loop_unref (client_loop); + client_loop = NULL; + } + + return DBUS_HANDLER_RESULT_HANDLED; +} + +dbus_bool_t +bus_setup_debug_client (DBusConnection *connection) +{ + dbus_bool_t retval; + + if (!dbus_connection_add_filter (connection, + client_disconnect_filter, + NULL, NULL)) + return FALSE; + + retval = FALSE; + + if (client_loop == NULL) + { + client_loop = _dbus_loop_new (); + if (client_loop == NULL) + goto out; + } + + if (!dbus_connection_set_watch_functions (connection, + add_client_watch, + remove_client_watch, + toggle_client_watch, + connection, + NULL)) + goto out; + + if (!dbus_connection_set_timeout_functions (connection, + add_client_timeout, + remove_client_timeout, + NULL, + connection, NULL)) + goto out; + + if (!_dbus_list_append (&clients, connection)) + goto out; + + retval = TRUE; + + out: + if (!retval) + { + dbus_connection_remove_filter (connection, + client_disconnect_filter, + NULL); + + dbus_connection_set_watch_functions (connection, + NULL, NULL, NULL, NULL, NULL); + dbus_connection_set_timeout_functions (connection, + NULL, NULL, NULL, NULL, NULL); + + _dbus_list_remove_last (&clients, connection); + + if (clients == NULL) + { + _dbus_loop_unref (client_loop); + client_loop = NULL; + } + } + + return retval; +} + +void +bus_test_clients_foreach (BusConnectionForeachFunction function, + void *data) +{ + DBusList *link; + + link = _dbus_list_get_first_link (&clients); + while (link != NULL) + { + DBusConnection *connection = link->data; + DBusList *next = _dbus_list_get_next_link (&clients, link); + + if (!(* function) (connection, data)) + break; + + link = next; + } +} + +dbus_bool_t +bus_test_client_listed (DBusConnection *connection) +{ + DBusList *link; + + link = _dbus_list_get_first_link (&clients); + while (link != NULL) + { + DBusConnection *c = link->data; + DBusList *next = _dbus_list_get_next_link (&clients, link); + + if (c == connection) + return TRUE; + + link = next; + } + + return FALSE; +} + +void +bus_test_run_clients_loop (dbus_bool_t block_once) +{ + if (client_loop == NULL) + return; + + _dbus_verbose ("---> Dispatching on \"client side\"\n"); + + /* dispatch before we block so pending dispatches + * won't make our block return early + */ + _dbus_loop_dispatch (client_loop); + + /* Do one blocking wait, since we're expecting data */ + if (block_once) + { + _dbus_verbose ("---> blocking on \"client side\"\n"); + _dbus_loop_iterate (client_loop, TRUE); + } + + /* Then mop everything up */ + while (_dbus_loop_iterate (client_loop, FALSE)) + ; + + _dbus_verbose ("---> Done dispatching on \"client side\"\n"); +} + +void +bus_test_run_bus_loop (BusContext *context, + dbus_bool_t block_once) +{ + _dbus_verbose ("---> Dispatching on \"server side\"\n"); + + /* dispatch before we block so pending dispatches + * won't make our block return early + */ + _dbus_loop_dispatch (bus_context_get_loop (context)); + + /* Do one blocking wait, since we're expecting data */ + if (block_once) + { + _dbus_verbose ("---> blocking on \"server side\"\n"); + _dbus_loop_iterate (bus_context_get_loop (context), TRUE); + } + + /* Then mop everything up */ + while (_dbus_loop_iterate (bus_context_get_loop (context), FALSE)) + ; + + _dbus_verbose ("---> Done dispatching on \"server side\"\n"); +} + +void +bus_test_run_everything (BusContext *context) +{ + while (_dbus_loop_iterate (bus_context_get_loop (context), FALSE) || + (client_loop == NULL || _dbus_loop_iterate (client_loop, FALSE))) + ; +} + +BusContext* +bus_context_new_test (const DBusString *test_data_dir, + const char *filename) +{ + DBusError error; + DBusString config_file; + DBusString relative; + BusContext *context; + + if (!_dbus_string_init (&config_file)) + { + _dbus_warn ("No memory\n"); + return NULL; + } + + if (!_dbus_string_copy (test_data_dir, 0, + &config_file, 0)) + { + _dbus_warn ("No memory\n"); + _dbus_string_free (&config_file); + return NULL; + } + + _dbus_string_init_const (&relative, filename); + + if (!_dbus_concat_dir_and_file (&config_file, &relative)) + { + _dbus_warn ("No memory\n"); + _dbus_string_free (&config_file); + return NULL; + } + + dbus_error_init (&error); + context = bus_context_new (&config_file, BUS_CONTEXT_FLAG_NONE, NULL, NULL, NULL, &error); + if (context == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + + _dbus_warn ("Failed to create debug bus context from configuration file %s: %s\n", + filename, error.message); + + dbus_error_free (&error); + + _dbus_string_free (&config_file); + + return NULL; + } + + _dbus_string_free (&config_file); + + return context; +} + +#endif
diff --git a/bus/test.h b/bus/test.h new file mode 100644 index 0000000..38b74e8 --- /dev/null +++ b/bus/test.h
@@ -0,0 +1,57 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* test.h unit test routines + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_TEST_H +#define BUS_TEST_H + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + +#include <dbus/dbus.h> +#include <dbus/dbus-string.h> +#include "connection.h" + +dbus_bool_t bus_dispatch_test (const DBusString *test_data_dir); +dbus_bool_t bus_dispatch_sha1_test (const DBusString *test_data_dir); +dbus_bool_t bus_config_parser_test (const DBusString *test_data_dir); +dbus_bool_t bus_config_parser_trivial_test (const DBusString *test_data_dir); +dbus_bool_t bus_signals_test (const DBusString *test_data_dir); +dbus_bool_t bus_expire_list_test (const DBusString *test_data_dir); +dbus_bool_t bus_activation_service_reload_test (const DBusString *test_data_dir); +dbus_bool_t bus_setup_debug_client (DBusConnection *connection); +void bus_test_clients_foreach (BusConnectionForeachFunction function, + void *data); +dbus_bool_t bus_test_client_listed (DBusConnection *connection); +void bus_test_run_bus_loop (BusContext *context, + dbus_bool_t block); +void bus_test_run_clients_loop (dbus_bool_t block); +void bus_test_run_everything (BusContext *context); +BusContext* bus_context_new_test (const DBusString *test_data_dir, + const char *filename); + +#ifdef HAVE_UNIX_FD_PASSING +dbus_bool_t bus_unix_fds_passing_test (const DBusString *test_data_dir); +#endif + +#endif + +#endif /* BUS_TEST_H */
diff --git a/bus/utils.c b/bus/utils.c new file mode 100644 index 0000000..7d24872 --- /dev/null +++ b/bus/utils.c
@@ -0,0 +1,48 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* utils.c General utility functions + * + * Copyright (C) 2003 CodeFactory AB + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "utils.h" +#include <dbus/dbus-sysdeps.h> +#include <dbus/dbus-mainloop.h> + +const char bus_no_memory_message[] = "Memory allocation failure in message bus"; + +void +bus_connection_dispatch_all_messages (DBusConnection *connection) +{ + while (bus_connection_dispatch_one_message (connection)) + ; +} + +dbus_bool_t +bus_connection_dispatch_one_message (DBusConnection *connection) +{ + DBusDispatchStatus status; + + while ((status = dbus_connection_dispatch (connection)) == DBUS_DISPATCH_NEED_MEMORY) + _dbus_wait_for_memory (); + + return status == DBUS_DISPATCH_DATA_REMAINS; +}
diff --git a/bus/utils.h b/bus/utils.h new file mode 100644 index 0000000..f533895 --- /dev/null +++ b/bus/utils.h
@@ -0,0 +1,36 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* utils.h General utility functions + * + * Copyright (C) 2003 CodeFactory AB + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BUS_UTILS_H +#define BUS_UTILS_H + +#include <dbus/dbus.h> + +extern const char bus_no_memory_message[]; +#define BUS_SET_OOM(error) dbus_set_error_const ((error), DBUS_ERROR_NO_MEMORY, bus_no_memory_message) + +void bus_connection_dispatch_all_messages (DBusConnection *connection); +dbus_bool_t bus_connection_dispatch_one_message (DBusConnection *connection); + +#endif /* BUS_UTILS_H */
diff --git a/cleanup-man-pages.sh b/cleanup-man-pages.sh new file mode 100644 index 0000000..23e98a6 --- /dev/null +++ b/cleanup-man-pages.sh
@@ -0,0 +1,86 @@ +#! /bin/sh + +## This script cleans up private/internal API from the man pages +## generated by Doxygen. This brings the man pages down from 7 megs +## to 2 megs and avoids namespace-polluting man pages. It's probably +## pretty specific to GNU utilities. Patches gladly accepted to make +## it work without them. + +## You would run this after building dbus and after running "doxygen +## Doxyfile" + +die() { + echo "$*" 1>&2 + exit 1 +} + +MANDIR=$1 +if test x"$MANDIR" = x ; then + MANDIR=doc/api/man/man3dbus +fi + +cd "$MANDIR" || die "Could not cd to $MANDIR" + +test -d keep || mkdir keep || die "Could not create $MANDIR/keep directory" +test -d nuke || mkdir nuke || die "Could not create $MANDIR/nuke directory" + +## blacklist +(find . -maxdepth 1 -name "_*" | xargs -I ITEMS /bin/mv ITEMS nuke) || die "could not move all underscore-prefixed items" +(find . -maxdepth 1 -name "DBus*Internal*" | xargs -I ITEMS /bin/mv ITEMS nuke) || die "could not move all internal-containing items" +(find . -maxdepth 1 -name "dbus_*_internal_*" | xargs -I ITEMS /bin/mv ITEMS nuke) || die "could not move all internal-containing items" + +## this is kind of unmaintainable, but I guess it's no huge disaster if we miss something. +## this list should only contain man pages with >1 line, i.e. with real content; the +## one-line cross-references get cleaned up next. +for I in DBusCounter.* DBusCredentials.* DBusDataSlot.* DBusDataSlotAllocator.* DBusDataSlotList.* \ + DBusDirIter.* DBusFakeMutex.* DBusFreedElement.* DBusGroupInfo.* DBusGUID.* DBusHashEntry.* \ + DBusHashIter.* DBusHashTable.* DBusHeader.* DBusHeaderField.* DBusKey.* DBusKeyring.* DBusList.* \ + DBusMarshal.* DBusMD5* DBusMemBlock.* DBusMemPool.* DBusMessageGenerator.* DBusMessageLoader.* \ + DBusMessageRealIter.* DBusObjectSubtree.* DBusObjectTree.* DBusPollFD.* DBusReal* \ + DBusResources.* DBusServerDebugPipe.* DBusServerSocket.* DBusServerUnix.* \ + DBusServerVTable.* DBusSHA.* DBusSHAContext.* DBusSignatureRealIter.* DBusStat.* DBusString.* \ + DBusSysdeps.* DBusSysdepsUnix.* DBusTimeoutList.* DBusTransport* DBusTypeReader* DBusTypeWriter* \ + DBusUserInfo.* DBusWatchList.* ; do + if test -f "$I" ; then + /bin/mv "$I" nuke || die "could not move $I to $MANDIR/nuke" + fi +done + +## many files just contain ".so man3dbus/DBusStringInternals.3dbus" or the like, +## if these point to something we nuked, we want to also nuke the pointer. +for I in * ; do + if test -f "$I" ; then + LINES=`wc -l "$I" | cut -d ' ' -f 1` + if test x"$LINES" = x1 ; then + REF_TO=`cat "$I" | sed -e 's/\.so man3dbus\///g'` + ## echo "$I points to $REF_TO" + if ! test -f "$REF_TO" ; then + /bin/mv "$I" nuke || die "could not move $I to $MANDIR/nuke" + fi + fi + fi +done + +## whitelist +(find . -maxdepth 1 -name "dbus_*" | xargs -I ITEMS /bin/mv ITEMS keep) || die "could not move all dbus-prefixed items" +(find . -maxdepth 1 -name "DBUS_*" | xargs -I ITEMS /bin/mv ITEMS keep) || die "could not move all DBUS_-prefixed items" +(find . -maxdepth 1 -name "DBus*" | xargs -I ITEMS /bin/mv ITEMS keep) || die "could not move all DBus-prefixed items" + +## everything else is assumed irrelevant, this is mostly struct fields +## from the public headers +(find . -maxdepth 1 -type f | xargs -I ITEMS /bin/mv ITEMS nuke) || die "could not move remaining items" + +NUKE_COUNT=`find nuke -type f -name "*" | wc -l` +KEEP_COUNT=`find keep -type f -name "*" | wc -l` +MISSING_COUNT=`find . -maxdepth 1 -type f -name "*" | wc -l` + +echo "$KEEP_COUNT man pages kept and $NUKE_COUNT man pages to remove" +echo "$MISSING_COUNT not handled" + +(find keep -type f -name "*" | xargs -I ITEMS /bin/mv ITEMS .) || die "could not move kept items back" + +rmdir keep || die "could not remove $MANDIR/keep" + +echo "Man pages to be installed are in $MANDIR and man pages to ignore are in $MANDIR/nuke" + +exit 0
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt new file mode 100644 index 0000000..4db9c67 --- /dev/null +++ b/cmake/CMakeLists.txt
@@ -0,0 +1,649 @@ +# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules") + +# we do not need to have WIN32 defined +set(CMAKE_LEGACY_CYGWIN_WIN32 0) + +project(dbus) + +# we need to be up to date +CMAKE_MINIMUM_REQUIRED(VERSION 2.4.4 FATAL_ERROR) +if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +if(CMAKE_MAJOR_VERSION GREATER 2) + cmake_policy(SET CMP0026 NEW) + if (CMAKE_MAJOR_VERSION GREATER 4 OR CMAKE_MINOR_VERSION GREATER 1) + cmake_policy(SET CMP0053 NEW) + cmake_policy(SET CMP0054 NEW) + endif() +endif() + +# detect version +include(MacrosAutotools) +autoinit(../configure.ac) +autoversion(dbus) + +if(EXISTS ../config.h.in) + autoheaderchecks(../config.h.in ConfigureChecks.cmake config.h.cmake) +else() + message(STATUS "Generate config.h.in with autogen.sh to enable cmake header difference check.") +endif() + +# used by file version info +set (DBUS_PATCH_VERSION "0") + +# set PACKAGE_... variables +autopackage( + dbus + ${DBUS_VERSION_STRING} + "http://dbus.freedesktop.org" + "https://bugs.freedesktop.org/enter_bug.cgi?product=dbus" +) + +include(Macros) +TIMESTAMP(DBUS_BUILD_TIMESTAMP) + +########### basic vars ############### + + +if (DBUSDIR) + set(DBUS_INSTALL_DIR "${DBUSDIR}") +endif (DBUSDIR) +if ($ENV{DBUSDIR}) + set(DBUS_INSTALL_DIR "$ENV{DBUSDIR}") +endif ($ENV{DBUSDIR}) + +if (DBUS_INSTALL_DIR) + set(CMAKE_INSTALL_PREFIX "${DBUS_INSTALL_DIR}" CACHE PATH "install prefix" FORCE) +else (DBUS_INSTALL_DIR) + set(DBUS_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}") +endif (DBUS_INSTALL_DIR) + +# autotools style +if (NOT DATAROOTDIR) + set (DATAROOTDIR share) +endif() + +if (NOT DATADIR) + set (DATADIR ${DATAROOTDIR}) +endif() + +if (NOT DOCDIR) + SET(DOCDIR ${DATAROOTDIR}/doc/dbus) +endif() + +if (NOT DBUS_DATADIR) + SET(DBUS_DATADIR ${DATADIR}) +endif() + +set(DBUS_PREFIX ${DBUS_INSTALL_DIR}) + +set(prefix ${DBUS_INSTALL_DIR}) +set(exec_prefix ${prefix}) +set(EXPANDED_LIBDIR ${DBUS_INSTALL_DIR}/lib) +set(EXPANDED_INCLUDEDIR ${DBUS_INSTALL_DIR}/include) +set(EXPANDED_BINDIR ${DBUS_INSTALL_DIR}/bin) +set(EXPANDED_SYSCONFDIR ${DBUS_INSTALL_DIR}/etc) +set(EXPANDED_LOCALSTATEDIR ${DBUS_INSTALL_DIR}/var) +set(EXPANDED_DATADIR ${DBUS_INSTALL_DIR}/${DBUS_DATADIR}) +set(DBUS_MACHINE_UUID_FILE ${DBUS_INSTALL_DIR}/lib/dbus/machine-id) +set(DBUS_BINDIR ${EXPANDED_BINDIR}) +set(DBUS_DAEMONDIR ${EXPANDED_BINDIR}) +set(DBUS_LOCALSTATEDIR ${EXPANDED_LOCALSTATEDIR}) + +# On Windows this is relative to where we put the bus setup, in +# ${datadir}/dbus-1. For simplicity, we only do this if +# ${sysconfdir} = ${prefix}/etc and ${datadir} = ${prefix}/share. +# +# On Unix, or on Windows with weird install layouts, it's the absolute path. +if(WIN32 AND ${EXPANDED_SYSCONFDIR} STREQUAL ${prefix}/etc AND ${EXPANDED_DATADIR} STREQUAL ${prefix}/share) +set(SYSCONFDIR_FROM_PKGDATADIR ../../etc) +set(DATADIR_FROM_PKGSYSCONFDIR ../../share) +else() +set(SYSCONFDIR_FROM_PKGDATADIR ${EXPANDED_SYSCONFDIR}) +set(DATADIR_FROM_PKGSYSCONFDIR ${EXPANDED_DATADIR}) +endif() + +set(DBUS_LIBEXECDIR ${EXPANDED_LIBDIR}) +set(DBUS_DATADIR ${EXPANDED_DATADIR}) + +#enable building of shared library +SET(BUILD_SHARED_LIBS ON) + +if(WIN32) + set(INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "bin" LIBRARY DESTINATION "lib" ARCHIVE DESTINATION "lib") +else() + set(INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "${EXPANDED_LIBDIR}" LIBRARY DESTINATION "${EXPANDED_LIBDIR}" ARCHIVE DESTINATION "${EXPANDED_LIBDIR}") +endif() + +if (CYGWIN) + set (WIN32) +endif (CYGWIN) + +# search for required packages +if (WIN32) + # include local header first to avoid using old installed header + set (CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/..) + find_package(LibIconv) + include(Win32Macros) + addExplorerWrapper(${CMAKE_PROJECT_NAME}) +endif (WIN32) + +if(NOT WIN32) + option (DBUS_ENABLE_ABSTRACT_SOCKETS "enable support for abstract sockets" ON) + set (CMAKE_THREAD_PREFER_PTHREAD ON) + include (FindThreads) +endif(NOT WIN32) + +option (DBUS_DISABLE_ASSERT "Disable assertion checking" OFF) + +option (DBUS_ENABLE_STATS "enable bus daemon usage statistics" OFF) + +if(WIN32) + set(FD_SETSIZE "8192" CACHE STRING "The maximum number of connections that can be handled at once") +endif() + +find_package(EXPAT) +find_package(X11) +find_package(GLib2) +find_package(GObject) +if(GLIB2_FOUND AND GOBJECT_FOUND) + option (DBUS_WITH_GLIB "build with glib" ON) +endif() + +# analogous to AC_USE_SYSTEM_EXTENSIONS in configure.ac +add_definitions(-D_GNU_SOURCE) + +# do config checks +INCLUDE(ConfigureChecks.cmake) + +# @TODO: how to remove last dir from ${CMAKE_SOURCE_DIR} ? +SET(DBUS_SOURCE_DIR ${CMAKE_SOURCE_DIR}/..) + +# make some more macros available +include (MacroLibrary) + +if(VCS) + set(DBUS_VERBOSE_C_S 1 CACHE STRING "verbose mode" FORCE) +endif(VCS) + +if(WIN32) + if(MSVC) + # controll folders in msvc projects + include(ProjectSourceGroup) + if(NOT GROUP_CODE) + #set(GROUP_CODE split) #cmake default + set(GROUP_CODE flat) + endif(NOT GROUP_CODE) + ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) + + + # Use the highest warning level + if (WALL) + set(WALL 1 CACHE STRING "all warnings" FORCE) + set(CMAKE_CXX_WARNING_LEVEL 4 CACHE STRING "warning level" FORCE) + + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + + if(CMAKE_C_FLAGS MATCHES "/W[0-4]") + STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + else(CMAKE_C_FLAGS MATCHES "/W[0-4]") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") + endif(CMAKE_C_FLAGS MATCHES "/W[0-4]") + else (WALL) + set(CMAKE_CXX_WARNING_LEVEL 3 CACHE STRING "warning level" FORCE) + endif (WALL) + + SET(MSVC_W_ERROR " /we4028 /we4013 /we4133 /we4047 /we4031 /we4002 /we4003 /we4114") + SET(MSVC_W_DISABLE " /wd4127 /wd4090 /wd4101 /wd4244") + + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /FIconfig.h ${MSVC_W_ERROR} ${MSVC_W_DISABLE}") + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /FIconfig.h ${MSVC_W_ERROR} ${MSVC_W_DISABLE}") + endif(MSVC) +endif(WIN32) + +if (UNIX AND NOT DBUS_DISABLE_ASSERT) + # required for backtrace + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wl,--export-dynamic") + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wl,--export-dynamic") + add_definitions(-DDBUS_BUILT_R_DYNAMIC) +endif (UNIX AND NOT DBUS_DISABLE_ASSERT) + +if(DBUS_WITH_GLIB) + autodefine(GLIB_VERSION_MIN_REQUIRED) + autodefine(GLIB_VERSION_MAX_ALLOWED) +endif() + +SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") +if(MSVC) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /w14018") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w14018") +else() + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare") +endif() + +######################################################################### +# Windows CE (>= 5.0.0) +# +# WinCE support now relies on the presence of platform files, found in cmake/modules/platform +# Cmake 2.8.0 doesn't include WinCE platform files by default, but working ones can be found +# on CMake's bugtracker : +# http://public.kitware.com/Bug/view.php?id=7919 +# +# for cmake 2.8.0 get the following patch only : +# http://public.kitware.com/Bug/file_download.php?file_id=2944&type=bug +# +# after applying the patch, you can enable the WinCE build by specifying : +# cmake [...] -DCMAKE_SYSTEM_NAME=WinCE -DCMAKE_SYSTEM_VERSION=X.XX +# (where X.XX is your actual WinCE version, e.g. 5.02 for Windows Mobile 6) +# +# Note that you should have a proper cross-compilation environment set up prior to running +# cmake, ie. the PATH, INCLUDE and LIB env vars pointing to your CE SDK/toolchain. +# +if(WINCE) + +MESSAGE("Building for WinCE (${CMAKE_SYSTEM_VERSION})") + +endif(WINCE) +######################################################################### + + +ENABLE_TESTING() + +######################################################################### +# Disallow in-source build +#macro_ensure_out_of_source_build("dbus requires an out of source build. Please create a separate build directory and run 'cmake path_to_dbus [options]' there.") + +# ... and warn in case of an earlier in-source build +#set(generatedFileInSourceDir EXISTS ${dbus_SOURCE_DIR}/config.h) +#if(${generatedFileInSourceDir}) +# message(STATUS "config.h exists in your source directory.") +#endif(${generatedFileInSourceDir}) +######################################################################### + +if (WIN32 OR CYGWIN) + set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) +else (WIN32 OR CYGWIN) + set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) +endif (WIN32 OR CYGWIN) + +set (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) + +# for including config.h and for includes like <dir/foo.h> +include_directories( ${CMAKE_SOURCE_DIR}/.. ${CMAKE_BINARY_DIR} ${CMAKE_INCLUDE_PATH} ) + +# linker search directories +link_directories(${DBUS_LIB_DIR} ${LIBRARY_OUTPUT_PATH} ) +include_directories( ${CMAKE_LIBRARY_PATH} ) + +set(DBUS_INCLUDES) + +ENABLE_TESTING() + +########### command line options ############### +# TODO: take check from configure.in + +option (DBUS_BUILD_TESTS "enable unit test code" ON) + +if(DBUS_BUILD_TESTS) + set (DBUS_ENABLE_EMBEDDED_TESTS ON) + set (DBUS_ENABLE_MODULAR_TESTS ON) + add_definitions(-DDBUS_ENABLE_EMBEDDED_TESTS -DDBUS_ENABLE_MODULAR_TESTS) +endif(DBUS_BUILD_TESTS) + +option (DBUS_USE_OUTPUT_DEBUG_STRING "enable win32 debug port for message output" OFF) +if(DBUS_USE_OUTPUT_DEBUG_STRING) + add_definitions(-DDBUS_USE_OUTPUT_DEBUG_STRING) +endif(DBUS_USE_OUTPUT_DEBUG_STRING) + +if(WIN32) + # win32 dbus service support - this support is not complete + option (DBUS_SERVICE "enable dbus service installer" OFF) +endif(WIN32) + +option (DBUS_ENABLE_ANSI "enable -ansi -pedantic gcc flags" OFF) +if(DBUS_ENABLE_ANSI) + if(NOT MSVC) + add_definitions(-ansi -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -pedantic) + else(NOT MSVC) + add_definitions(-Za -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -W4) + endif(NOT MSVC) +endif(DBUS_ENABLE_ANSI) + +option (DBUS_ENABLE_VERBOSE_MODE "support verbose debug mode" ON) + +option (DBUS_DISABLE_CHECKS "Disable public API sanity checking" OFF) + +if(NOT MSVC) + option (DBUS_GCOV_ENABLED "compile with coverage profiling instrumentation (gcc only)" OFF) + if(DBUS_GCOV_ENABLED) + add_definitions(-fprofile-arcs -ftest-coverage) + # FIXME!!!! + ## remove optimization + # CFLAGS=`echo "$CFLAGS" | sed -e 's/-O[0-9]*//g'` + endif(DBUS_GCOV_ENABLED) +endif(NOT MSVC) + +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + option (DBUS_BUS_ENABLE_INOTIFY "build with inotify support (linux only)" ON) + if(DBUS_BUS_ENABLE_INOTIFY) + if(NOT HAVE_SYS_INOTIFY_H) + message(FATAL_ERROR "sys/inotify.h not found!") + endif(NOT HAVE_SYS_INOTIFY_H) + endif(DBUS_BUS_ENABLE_INOTIFY) +elseif("${CMAKE_SYSTEM_NAME}" MATCHES ".*BSD") + option (DBUS_BUS_ENABLE_KQUEUE "build with kqueue support (FreeBSD only)" ON) + if(DBUS_BUS_ENABLE_KQUEUE) + if(NOT HAVE_SYS_EVENT_H) + message(FATAL_ERROR "sys/event.h not found!") + endif(NOT HAVE_SYS_EVENT_H) + endif(DBUS_BUS_ENABLE_KQUEUE) +endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + +STRING(TOUPPER ${CMAKE_SYSTEM_NAME} sysname) +if("${sysname}" MATCHES ".*SOLARIS.*") + option (HAVE_CONSOLE_OWNER_FILE "enable console owner file (solaris only)" ON) + if(HAVE_CONSOLE_OWNER_FILE) + set (DBUS_CONSOLE_OWNER_FILE "/dev/console" CACHE STRING "Directory to check for console ownerhip") + endif(HAVE_CONSOLE_OWNER_FILE) +endif("${sysname}" MATCHES ".*SOLARIS.*") + +if(NOT EXPAT_FOUND) + message(FATAL_ERROR "expat not found!") +endif(NOT EXPAT_FOUND) + +SET(XML_LIB "Expat") +SET(XML_LIBRARY ${EXPAT_LIBRARIES}) +SET(XML_INCLUDE_DIR ${EXPAT_INCLUDE_DIR}) + +# all missing or hardcoded for now + +# 'hidden' ones +set(atomic_int OFF) +set(atomic_int486 OFF) +if(CMAKE_COMPILER_IS_GNUCC AND NOT DBUS_ENABLE_ANSI) + FIND_PROGRAM(UNAME_EXECUTABLE + NAMES uname + PATHS /bin /usr/bin /usr/local/bin c:/Programme/MSys/bin d:/Programme/MSys/bin) + + if(UNAME_EXECUTABLE) + EXECUTE_PROCESS(COMMAND ${UNAME_EXECUTABLE} "-m" + OUTPUT_VARIABLE UNAME_OUTPUT) + + if("UNAME_OUTPUT" MATCHES "^.*i[0123]86.*$") + set(atomic_int ON) + else("UNAME_OUTPUT" MATCHES "^.*i[0123]86.*$") + if("UNAME_OUTPUT" MATCHES "^.*i?86.*$") + set(atomic_int ON) + set(atomic_int_486 ON) + endif("UNAME_OUTPUT" MATCHES "^.*i?86.*$") + endif("UNAME_OUTPUT" MATCHES "^.*i[0123]86.*$") + endif(UNAME_EXECUTABLE) +endif(CMAKE_COMPILER_IS_GNUCC AND NOT DBUS_ENABLE_ANSI) + +set (DBUS_HAVE_ATOMIC_INT ${atomic_int} CACHE STRING "Some atomic integer implementation present") +set (DBUS_USE_ATOMIC_INT_486 ${atomic_int_486} CACHE STRING "Use atomic integer implementation for 486") + +if(X11_FOUND) + option (DBUS_BUILD_X11 "Build with X11 autolaunch support " ON) +endif(X11_FOUND) + +# test binary names +if (WIN32) + # follow Automake's naming convention so we can share .in files + set (EXEEXT ${CMAKE_EXECUTABLE_SUFFIX}) +endif(WIN32) + +if (MSVC_IDE) + if(CMAKE_BUILD_TYPE MATCHES Debug) + set(IDE_BIN /Debug ) + message(STATUS) + message(STATUS "Visual Studio: test programs will only work with 'Debug' configuration!") + message(STATUS "To run tests with 'Release' configuration use -DCMAKE_BUILD_TYPE=Release") + message(STATUS "Add '..\\..\\test\\data' to the command line option of the test programs") + message(STATUS) + else(CMAKE_BUILD_TYPE MATCHES Debug) + set(IDE_BIN /Release) + message(STATUS) + message(STATUS "Visual Studio: test programs will only work with 'Release' configuration!") + message(STATUS "To run tests with 'Debug' configuration use -DCMAKE_BUILD_TYPE=Debug") + message(STATUS "Add '..\\..\\test\\data' to the command line option of the test programs") + message(STATUS) + endif(CMAKE_BUILD_TYPE MATCHES Debug) + set (TEST_PATH_FORCE FORCE) + FILE(REMOVE ${CMAKE_BINARY_DIR}/data/dbus-1/services) +endif (MSVC_IDE) + +#### Find socket directories + if (NOT $ENV{TMPDIR} STREQUAL "") + set (DBUS_SESSION_SOCKET_DIR $ENV{TMPDIR}) + else (NOT $ENV{TMPDIR} STREQUAL "") + if (NOT $ENV{TEMP} STREQUAL "") + set (DBUS_SESSION_SOCKET_DIR $ENV{TEMP}) + else (NOT $ENV{TEMP} STREQUAL "") + if (NOT $ENV{TMP} STREQUAL "") + set (DBUS_SESSION_SOCKET_DIR $ENV{TMP}) + else (NOT $ENV{TMP} STREQUAL "") + if (WIN32) + #Should never happen, both TMP and TEMP seem always set on Windows + message(FATAL_ERROR "Could not determine a usable temporary directory") + else(WIN32) + set (DBUS_SESSION_SOCKET_DIR /tmp) + endif(WIN32) + endif (NOT $ENV{TMP} STREQUAL "") + endif (NOT $ENV{TEMP} STREQUAL "") + endif (NOT $ENV{TMPDIR} STREQUAL "") + + # Not used on Windows, where there is no system bus +set (DBUS_SYSTEM_PID_FILE ${DBUS_LOCALSTATEDIR}/run/dbus/pid) + +if (WIN32) + set (DBUS_CONSOLE_AUTH_DIR "") +else (WIN32) + set (DBUS_CONSOLE_AUTH_DIR "/var/run/console/") +endif (WIN32) + +# This won't work on Windows. It's not meant to - the system bus is +# meaningless on Windows anyway. +# +# This has to be suitable for hard-coding in client libraries as well as +# in the dbus-daemon's configuration, so it has to be valid to listen on +# and also to connect to. If this ever changes, it'll need to be split into +# two variables, one for the listening address and one for the connecting +# address. +set (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "unix:path=${DBUS_LOCALSTATEDIR}/run/dbus/system_bus_socket" CACHE STRING "system bus default address") + +if (WIN32) + set (DBUS_SESSION_BUS_LISTEN_ADDRESS "autolaunch:" CACHE STRING "session bus default listening address") + set (DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" CACHE STRING "session bus fallback address for clients") + + set (DBUS_SYSTEM_CONFIG_FILE "share/dbus-1/system.conf") + set (DBUS_SESSION_CONFIG_FILE "share/dbus-1/session.conf") + # bus-test expects a non empty string + set (DBUS_USER "Administrator") + set (DBUS_TEST_USER "guest") + set (DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL "<!--<auth>EXTERNAL</auth>-->") +else (WIN32) + set (DBUS_SESSION_BUS_LISTEN_ADDRESS "unix:tmpdir=${DBUS_SESSION_SOCKET_DIR}" CACHE STRING "session bus default listening address") + set (DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" CACHE STRING "session bus fallback address for clients") + set (sysconfdir "") + set (configdir ${sysconfdir}/dbus-1 ) + set (DBUS_SYSTEM_CONFIG_FILE ${configdir}/system.conf) + set (DBUS_SESSION_CONFIG_FILE ${configdir}/session.conf) + set (DBUS_USER "messagebus") + set (DBUS_TEST_USER "nobody") + # For best security, assume that all non-Windows platforms can do + # credentials-passing. + set (DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL "<auth>EXTERNAL</auth>") +endif (WIN32) + +set (DBUS_DAEMON_NAME "dbus-daemon" CACHE STRING "The name of the dbus daemon executable") + +########### create config.h ############### + +#include(ConfigureChecks.cmake) + +# better use flags for gcc +if (MINGW) + set (HAVE_GNUC_VARARGS 1) +endif(MINGW) + +# compiler definitions +add_definitions(-DHAVE_CONFIG_H=1) +add_definitions(${DBUS_BUS_CFLAGS}) + + +if (DBUS_BUILD_TESTS) + # set variables used for the .in files (substituted by configure_file) in test/data: + set(DBUS_TEST_EXEC ${EXECUTABLE_OUTPUT_PATH}${IDE_BIN}) + set(DBUS_TEST_DATA ${CMAKE_BINARY_DIR}/test/data) + set(TEST_SOCKET_DIR ${DBUS_SESSION_SOCKET_DIR} ) + set(TEST_LAUNCH_HELPER_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-daemon-launch-helper-test) + set(TEST_BUS_LAUNCH_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-launch${EXEEXT}) + if (UNIX) + set (TEST_LISTEN "unix:tmpdir=${TEST_SOCKET_DIR}") + endif (UNIX) + if (WIN32) + set (TEST_LISTEN "tcp:host=localhost") + endif (WIN32) +endif (DBUS_BUILD_TESTS) + +set(DBUS_LIBRARIES dbus-1) +set(DBUS_INTERNAL_LIBRARIES dbus-internal) + +set (DBUS_INTERNAL_ADD_LIBRARY_OPTIONS STATIC) +set (DBUS_INTERNAL_CLIENT_DEFINITIONS "-DDBUS_COMPILATION") + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h ) + +if (WIN32) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dbus-env.bat.cmake ${CMAKE_BINARY_DIR}/bin/dbus-env.bat ) +install_files(/bin FILES ${CMAKE_BINARY_DIR}/bin/dbus-env.bat) +endif() + +add_definitions(-DHAVE_CONFIG_H=1) + +########### subdirs ############### + +add_subdirectory( dbus ) +add_subdirectory( bus ) +if (DBUS_BUILD_TESTS) + add_subdirectory( test ) + add_custom_target(check + COMMAND ctest -R ^test-.* + ) +endif (DBUS_BUILD_TESTS) +add_subdirectory( tools ) +add_subdirectory( doc ) + + +OPTION(DBUS_INSTALL_SYSTEM_LIBS "install required system libraries" OFF) +MESSAGE(" ") +MESSAGE("set -DDBUS_INSTALL_SYSTEM_LIBS=1 to install runtime libraries too") +MESSAGE("set DBUSDIR (environment or cmake option) to overwrite the default install directory ") +MESSAGE(" ") +MESSAGE(" ") +GET_FILENAME_COMPONENT(C_COMPILER ${CMAKE_C_COMPILER} NAME) +GET_FILENAME_COMPONENT(CXX_COMPILER ${CMAKE_CXX_COMPILER} NAME) + +message(" D-BUS ${DBUS_VERSION} ") +message(" ============ ") +message(" ") +message(" install prefix: ${prefix} ") +message(" install exec_prefix: ${exec_prefix} ") +message(" install libdir: ${EXPANDED_LIBDIR} ") +message(" install bindir: ${EXPANDED_BINDIR} ") +message(" install sysconfdir: ${EXPANDED_SYSCONFDIR} ") +message(" install datadir: ${EXPANDED_DATADIR} ") +message(" source code location: ${DBUS_SOURCE_DIR} ") +message(" build dir: ${CMAKE_BINARY_DIR} ") +message(" c compiler: ${C_COMPILER} ") +message(" cflags: ${CMAKE_C_FLAGS} ") +message(" cflags debug: ${CMAKE_C_FLAGS_DEBUG} ") +message(" cflags release: ${CMAKE_C_FLAGS_RELEASE} ") +message(" cxx compiler: ${CXX_COMPILER} ") +message(" cxxflags: ${CMAKE_CXX_FLAGS} ") +message(" cxxflags debug: ${CMAKE_CXX_FLAGS_DEBUG} ") +message(" cxxflags release: ${CMAKE_CXX_FLAGS_RELEASE} ") +message(" 64-bit int: ${DBUS_INT64_TYPE} ") +message(" 32-bit int: ${DBUS_INT32_TYPE} ") +message(" 16-bit int: ${DBUS_INT16_TYPE} ") +message(" Doxygen: ${DOXYGEN} ") +message(" Docbook Generator: ${DOCBOOK_GENERATOR_NAME} ") + + +message(" gcc coverage profiling: ${DBUS_GCOV_ENABLED} ") +message(" Building unit tests: ${DBUS_BUILD_TESTS} ") +message(" Building with GLib: ${DBUS_WITH_GLIB} ") +message(" Building verbose mode: ${DBUS_ENABLE_VERBOSE_MODE} ") +message(" Building w/o assertions: ${DBUS_DISABLE_ASSERT} ") +message(" Building w/o checks: ${DBUS_DISABLE_CHECKS} ") +message(" Building bus stats API: ${DBUS_ENABLE_STATS} ") +message(" installing system libs: ${DBUS_INSTALL_SYSTEM_LIBS} ") +message(" Building inotify support: ${DBUS_BUS_ENABLE_INOTIFY} ") +message(" Building kqueue support: ${DBUS_BUS_ENABLE_KQUEUE} ") +message(" Building Doxygen docs: ${DBUS_ENABLE_DOXYGEN_DOCS} ") +message(" Building XML docs: ${DBUS_ENABLE_XML_DOCS} ") +message(" Daemon executable name: ${DBUS_DAEMON_NAME}") +if (WIN32) +message(" System bus address: ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS} ") +message(" Session bus listens on: ${DBUS_SESSION_BUS_LISTEN_ADDRESS} ") +message(" Session clients connect to: ${DBUS_SESSION_BUS_CONNECT_ADDRESS} ") +else (WIN32) +message(" System bus socket: ${DBUS_SYSTEM_SOCKET} ") +message(" System bus address: ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS} ") +message(" System bus PID file: ${DBUS_SYSTEM_PID_FILE} ") +message(" Session bus socket dir: ${DBUS_SESSION_SOCKET_DIR} ") +message(" Console auth dir: ${DBUS_CONSOLE_AUTH_DIR} ") +message(" System bus user: ${DBUS_USER} ") +message(" 'make check' socket dir: ${TEST_SOCKET_DIR} ") +endif (WIN32) +message(" Test listen address: ${TEST_LISTEN} ") +if (MSVC) +message(" build timestamp: ${DBUS_BUILD_TIMESTAMP} ") +endif (MSVC) + +MESSAGE(" ") +if (DBUS_BUILD_TESTS) + message("NOTE: building with unit tests increases the size of the installed library and renders it insecure.") +endif(DBUS_BUILD_TESTS) + +if (DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERT) + message("NOTE: building with unit tests but without assertions means tests may not properly report failures (this configuration is only useful when doing something like profiling the tests)") +endif(DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERT) + +if (DBUS_GCOV_ENABLED) + message("NOTE: building with coverage profiling is definitely for developers only.") +endif(DBUS_GCOV_ENABLED) + +if (DBUS_ENABLE_VERBOSE_MODE) + message("NOTE: building with verbose mode increases library size, may slightly increase security risk, and decreases performance.") +endif(DBUS_ENABLE_VERBOSE_MODE) + +if(NOT DBUS_DISABLE_ASSERT) + message("NOTE: building with assertions increases library size and decreases performance.") +endif(NOT DBUS_DISABLE_ASSERT) + +if (DBUS_DISABLE_CHECKS) + message("NOTE: building without checks for arguments passed to public API makes it harder to debug apps using D-BUS, but will slightly decrease D-BUS library size and _very_ slightly improve performance.") +endif(DBUS_DISABLE_CHECKS) + +foreach(_note ${FOOTNOTES}) + message(${_note}) +endforeach() + +MESSAGE(" ") + +INCLUDE(modules/CPackInstallConfig.cmake) + +add_custom_target(help-options + cmake -LH + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +)
diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake new file mode 100644 index 0000000..119b83e --- /dev/null +++ b/cmake/ConfigureChecks.cmake
@@ -0,0 +1,186 @@ +include(CheckIncludeFile) +include(CheckIncludeFiles) +include(CheckSymbolExists) +include(CheckStructMember) +include(CheckTypeSize) + +check_include_file(alloca.h HAVE_ALLOCA_H) +check_include_file(byteswap.h HAVE_BYTESWAP_H) +check_include_file(crt/externs.h HAVE_CRT_EXTERNS_H) +check_include_file(dirent.h HAVE_DIRENT_H) # dbus-sysdeps-util.c +check_include_file(dlfcn.h HAVE_DLFCN_H) +check_include_file(execinfo.h HAVE_EXECINFO_H) +check_include_file(errno.h HAVE_ERRNO_H) # dbus-sysdeps.c +check_include_file(expat.h HAVE_EXPAT_H) +check_include_file(grp.h HAVE_GRP_H) # dbus-sysdeps-util-win.c +check_include_file(inttypes.h HAVE_INTTYPES_H) # dbus-pipe.h +check_include_file(io.h HAVE_IO_H) # internal +check_include_file(locale.h HAVE_LOCALE_H) +check_include_file(memory.h HAVE_MEMORY_H) +check_include_file(signal.h HAVE_SIGNAL_H) +check_include_file(stdint.h HAVE_STDINT_H) # dbus-pipe.h +check_include_file(stdlib.h HAVE_STDLIB_H) +check_include_file(stdio.h HAVE_STDIO_H) # dbus-sysdeps.h +check_include_file(string.h HAVE_STRING_H) +check_include_file(strings.h HAVE_STRINGS_H) +check_include_file(syslog.h HAVE_SYSLOG_H) +check_include_files("stdint.h;sys/types.h;sys/event.h" HAVE_SYS_EVENT_H) +check_include_file(sys/inotify.h HAVE_SYS_INOTIFY_H) +check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) +check_include_file(sys/stat.h HAVE_SYS_STAT_H) +check_include_file(sys/types.h HAVE_SYS_TYPES_H) +check_include_file(sys/uio.h HAVE_SYS_UIO_H) +check_include_file(sys/poll.h HAVE_POLL) # dbus-sysdeps.c, dbus-sysdeps-win.c +check_include_file(sys/prctl.h HAVE_SYS_PRCTL_H) +check_include_file(sys/syslimits.h HAVE_SYS_SYSLIMITS_H) # dbus-sysdeps-unix.c +check_include_file(sys/time.h HAVE_SYS_TIME_H)# dbus-sysdeps-win.c +check_include_file(sys/wait.h HAVE_SYS_WAIT_H)# dbus-sysdeps-win.c +check_include_file(time.h HAVE_TIME_H) # dbus-sysdeps-win.c +check_include_file(ws2tcpip.h HAVE_WS2TCPIP_H)# dbus-sysdeps-win.c +check_include_file(unistd.h HAVE_UNISTD_H) # dbus-sysdeps-util-win.c + +check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE) # dbus-sysdeps.c, dbus-sysdeps-win.c +check_symbol_exists(getgrouplist "grp.h" HAVE_GETGROUPLIST) # dbus-sysdeps.c +check_symbol_exists(getpeerucred "ucred.h" HAVE_GETPEERUCRED) # dbus-sysdeps.c, dbus-sysdeps-win.c +check_symbol_exists(nanosleep "time.h" HAVE_NANOSLEEP) # dbus-sysdeps.c +check_symbol_exists(getpwnam_r "errno.h pwd.h" HAVE_POSIX_GETPWNAM_R) # dbus-sysdeps-util-unix.c +check_symbol_exists(setenv "stdlib.h" HAVE_SETENV) # dbus-sysdeps.c +check_symbol_exists(unsetenv "stdlib.h" HAVE_UNSETENV) # dbus-sysdeps.c +check_symbol_exists(clearenv "stdlib.h" HAVE_CLEARENV) # dbus-sysdeps.c +check_symbol_exists(writev "sys/uio.h" HAVE_WRITEV) # dbus-sysdeps.c, dbus-sysdeps-win.c +check_symbol_exists(setrlimit "sys/resource.h" HAVE_SETRLIMIT) # dbus-sysdeps.c, dbus-sysdeps-win.c, test/test-segfault.c +check_symbol_exists(socketpair "sys/socket.h" HAVE_SOCKETPAIR) # dbus-sysdeps.c +check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE) # dbus-test-main.c +check_symbol_exists(localeconv "locale.h" HAVE_LOCALECONV) # dbus-sysdeps.c +check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL) # dbus-send.c +check_symbol_exists(strtoull "stdlib.h" HAVE_STRTOULL) # dbus-send.c +set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) +check_symbol_exists(pipe2 "fcntl.h;unistd.h" HAVE_PIPE2) +check_symbol_exists(accept4 "sys/socket.h" HAVE_ACCEPT4) +check_symbol_exists(dirfd "dirent.h" HAVE_DIRFD) +check_symbol_exists(inotify_init1 "sys/inotify.h" HAVE_INOTIFY_INIT1) +check_symbol_exists(SCM_RIGHTS "sys/types.h;sys/socket.h;sys/un.h" HAVE_UNIX_FD_PASSING) +check_symbol_exists(prctl "sys/prctl.h" HAVE_PRCTL) +check_symbol_exists(raise "signal.h" HAVE_RAISE) + +check_struct_member(cmsgcred cmcred_pid "sys/types.h sys/socket.h" HAVE_CMSGCRED) # dbus-sysdeps.c + +# missing: +# HAVE_ABSTRACT_SOCKETS +# DBUS_HAVE_GCC33_GCOV + +check_type_size("short" SIZEOF_SHORT) +check_type_size("int" SIZEOF_INT) +check_type_size("long" SIZEOF_LONG) +check_type_size("long long" SIZEOF_LONG_LONG) +check_type_size("__int64" SIZEOF___INT64) +set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h") +check_type_size("socklen_t" SOCKLEN_T) # dbus-sysdeps-unix.c +set(CMAKE_EXTRA_INCLUDE_FILES) + +# DBUS_INT64_TYPE +if(SIZEOF_INT EQUAL 8) + set (DBUS_INT64_TYPE "int") + set (DBUS_INT64_CONSTANT "(val)") + set (DBUS_UINT64_CONSTANT "(val##U)") +elseif(SIZEOF_LONG EQUAL 8) + set (DBUS_INT64_TYPE "long") + set (DBUS_INT64_CONSTANT "(val##L)") + set (DBUS_UINT64_CONSTANT "(val##UL)") +elseif(SIZEOF_LONG_LONG EQUAL 8) + set (DBUS_INT64_TYPE "long long") + set (DBUS_INT64_CONSTANT "(val##LL)") + set (DBUS_UINT64_CONSTANT "(val##ULL)") +elseif(SIZEOF___INT64 EQUAL 8) + set (DBUS_INT64_TYPE "__int64") + set (DBUS_INT64_CONSTANT "(val##i64)") + set (DBUS_UINT64_CONSTANT "(val##ui64)") +else(SIZEOF_INT EQUAL 8) + message (FATAL_ERROR "Could not find a 64-bit integer type") +endif(SIZEOF_INT EQUAL 8) + +# DBUS_INT32_TYPE +if(SIZEOF_INT EQUAL 4) + set (DBUS_INT32_TYPE "int") +elseif(SIZEOF_LONG EQUAL 4) + set (DBUS_INT32_TYPE "long") +elseif(SIZEOF_LONG_LONG EQUAL 4) + set (DBUS_INT32_TYPE "long long") +endif(SIZEOF_INT EQUAL 4) + +# DBUS_INT16_TYPE +if(SIZEOF_INT EQUAL 2) + set (DBUS_INT16_TYPE "int") +elseif(SIZEOF_SHORT EQUAL 2) + set (DBUS_INT16_TYPE "short") +endif(SIZEOF_INT EQUAL 2) + +find_program(DOXYGEN doxygen) +find_program(XMLTO xmlto) + +if(MSVC) + SET(DBUS_VA_COPY_FUNC "_DBUS_VA_COPY_ASSIGN") +else(MSVC) +write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include <stdarg.h> + #include <stdlib.h> + static void f (int i, ...) { + va_list args1, args2; + va_start (args1, i); + va_copy (args2, args1); + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + va_end (args1); va_end (args2); + } + int main() { + f (0, 42); + return 0; + } +") +try_compile(DBUS_HAVE_VA_COPY + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c) + +if(DBUS_HAVE_VA_COPY) + SET(DBUS_VA_COPY_FUNC va_copy CACHE STRING "va_copy function") +else(DBUS_HAVE_VA_COPY) + write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include <stdarg.h> + #include <stdlib.h> + static void f (int i, ...) { + va_list args1, args2; + va_start (args1, i); + __va_copy (args2, args1); + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + va_end (args1); va_end (args2); + } + int main() { + f (0, 42); + return 0; + } + ") + try_compile(DBUS_HAVE___VA_COPY + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c) + if(DBUS_HAVE___VA_COPY) + SET(DBUS_VA_COPY_FUNC __va_copy CACHE STRING "va_copy function") + else(DBUS_HAVE___VA_COPY) + SET(DBUS_VA_COPY_AS_ARRAY "1" CACHE STRING "'va_lists' cannot be copies as values") + endif(DBUS_HAVE___VA_COPY) +endif(DBUS_HAVE_VA_COPY) +endif(MSVC) # _not_ MSVC +#### Abstract sockets + +if (DBUS_ENABLE_ABSTRACT_SOCKETS) + + try_compile(HAVE_ABSTRACT_SOCKETS + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/modules/CheckForAbstractSockets.c) + +endif(DBUS_ENABLE_ABSTRACT_SOCKETS) + +if(HAVE_ABSTRACT_SOCKETS) + set(DBUS_PATH_OR_ABSTRACT_VALUE abstract) +else(HAVE_ABSTRACT_SOCKETS) + set(DBUS_PATH_OR_ABSTRACT_VALUE path) +endif(HAVE_ABSTRACT_SOCKETS) +
diff --git a/cmake/bus-test.bat.cmake b/cmake/bus-test.bat.cmake new file mode 100644 index 0000000..0168871 --- /dev/null +++ b/cmake/bus-test.bat.cmake
@@ -0,0 +1,14 @@ +:: bus-test wrapper +@echo off + +:: session bus address +set DBUS_STARTER_BUS=tcp:host=localhost,port=1234 + +if NOT "%1" == "" ( + SET DATADIR=%1 +) else ( + SET DATADIR=test\data +) + +bin\bus-test.exe test\data +
diff --git a/cmake/bus/CMakeLists.txt b/cmake/bus/CMakeLists.txt new file mode 100644 index 0000000..0dcae65 --- /dev/null +++ b/cmake/bus/CMakeLists.txt
@@ -0,0 +1,212 @@ +add_definitions(-DDBUS_COMPILATION) + +SET(EFENCE "") +SET(BUS_DIR ${CMAKE_SOURCE_DIR}/../bus) + +# config files for installation +CONFIGURE_FILE( "${BUS_DIR}/session.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/session.conf" IMMEDIATE @ONLY) +CONFIGURE_FILE( "${BUS_DIR}/legacy-config/session.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/legacy-config/session.conf" IMMEDIATE @ONLY) +FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/session.d) + +if(NOT WIN32) + CONFIGURE_FILE( "${BUS_DIR}/system.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/system.conf" IMMEDIATE @ONLY) + CONFIGURE_FILE( "${BUS_DIR}/legacy-config/system.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/legacy-config/system.conf" IMMEDIATE @ONLY) + FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/system.d) +endif() + +# copy services for local daemon start to local service dir data/dbus-1/services +SET (SERVICE_FILES test/data/valid-service-files) +FILE(GLOB FILES "${CMAKE_SOURCE_DIR}/../${SERVICE_FILES}/*.service.in" ) +FOREACH(FILE ${FILES}) + GET_FILENAME_COMPONENT(FILENAME ${FILE} NAME_WE) + SET (TARGET ${CMAKE_BINARY_DIR}/data/dbus-1/services/${FILENAME}.service) + IF (CONFIG_VERBOSE) + MESSAGE("FROM: ${FILE}\nTO: ${TARGET}\n") + ENDIF (CONFIG_VERBOSE) + configure_file(${FILE} ${TARGET} ) +ENDFOREACH(FILE) + +SET (XML_SOURCES ${BUS_DIR}/config-loader-expat.c) + +if (DBUS_BUS_ENABLE_INOTIFY) + set (DIR_WATCH_SOURCE ${BUS_DIR}/dir-watch-inotify.c) +elseif (DBUS_BUS_ENABLE_KQUEUE) + set (DIR_WATCH_SOURCE ${BUS_DIR}/dir-watch-kqueue.c) +else (DBUS_BUS_ENABLE_INOTIFY) + set (DIR_WATCH_SOURCE ${BUS_DIR}/dir-watch-default.c) +endif (DBUS_BUS_ENABLE_INOTIFY) + +set (BUS_SOURCES + ${BUS_DIR}/activation.c + ${BUS_DIR}/activation.h + ${BUS_DIR}/apparmor.c + ${BUS_DIR}/apparmor.h + ${BUS_DIR}/audit.c + ${BUS_DIR}/audit.h + ${BUS_DIR}/bus.c + ${BUS_DIR}/bus.h + ${BUS_DIR}/config-parser.c + ${BUS_DIR}/config-parser.h + ${BUS_DIR}/config-parser-common.c + ${BUS_DIR}/config-parser-common.h +# ${BUS_DIR}/config-parser-trivial.c + ${BUS_DIR}/connection.c + ${BUS_DIR}/connection.h + ${BUS_DIR}/desktop-file.c + ${BUS_DIR}/desktop-file.h + ${BUS_DIR}/dir-watch.h + ${BUS_DIR}/dispatch.c + ${BUS_DIR}/dispatch.h + ${BUS_DIR}/driver.c + ${BUS_DIR}/driver.h + ${BUS_DIR}/expirelist.c + ${BUS_DIR}/expirelist.h + ${BUS_DIR}/policy.c + ${BUS_DIR}/policy.h + ${BUS_DIR}/selinux.h + ${BUS_DIR}/selinux.c + ${BUS_DIR}/services.c + ${BUS_DIR}/services.h + ${BUS_DIR}/signals.c + ${BUS_DIR}/signals.h + ${BUS_DIR}/test.c + ${BUS_DIR}/test.h + ${BUS_DIR}/utils.c + ${BUS_DIR}/utils.h + ${XML_SOURCES} + ${DIR_WATCH_SOURCE} +) +if(DBUS_ENABLE_STATS) + list(APPEND BUS_SOURCES + ${BUS_DIR}/stats.c + ${BUS_DIR}/stats.h + ) +endif(DBUS_ENABLE_STATS) + +include_directories( + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/.. + ${XML_INCLUDE_DIR} +) + +add_executable(dbus-daemon ${BUS_SOURCES} ${BUS_DIR}/main.c) +target_link_libraries(dbus-daemon ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY}) +set_target_properties(dbus-daemon PROPERTIES OUTPUT_NAME ${DBUS_DAEMON_NAME}) +set_target_properties(dbus-daemon PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) + +install_targets(/bin dbus-daemon) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/session.conf DESTINATION share/dbus-1) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/legacy-config/session.conf DESTINATION etc/dbus-1) +install(DIRECTORY DESTINATION share/dbus-1/session.d) +install(DIRECTORY DESTINATION share/dbus-1/services) + +if(NOT WIN32) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/system.conf DESTINATION share/dbus-1) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/legacy-config/system.conf DESTINATION etc/dbus-1) + install(DIRECTORY DESTINATION share/dbus-1/system.d) + install(DIRECTORY DESTINATION share/dbus-1/system-services) + install(DIRECTORY DESTINATION var/run/dbus) +endif() + +if (DBUS_SERVICE) + set (dbus_service_SOURCES + ${BUS_DIR}/bus-service-win.c + # TODO: add additional files + # ${BUS_DIR}/service-main.c + # ${BUS_SOURCES} + ) + + add_executable(dbus-service ${dbus_service_SOURCES} ) + target_link_libraries(dbus-service ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY}) + set_target_properties(dbus-service PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) + install_targets(/bin dbus-service ) +endif (DBUS_SERVICE) + +if (DBUS_ENABLE_EMBEDDED_TESTS) + set(SOURCES ${BUS_SOURCES} ${BUS_DIR}/test-main.c) + add_test_executable(test-bus "${SOURCES}" ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY}) + set_target_properties(test-bus PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) + if (NOT WIN32) + set(test_bus_system_SOURCES + ${XML_SOURCES} + ${BUS_DIR}/config-parser-common.c + ${BUS_DIR}/config-parser-trivial.c + ${BUS_DIR}/utils.c + ${BUS_DIR}/test-system.c + ) + add_test_executable(test-bus-system "${test_bus_system_SOURCES}" ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY} ${DBUS_BUS_LIBS}) + endif() +endif (DBUS_ENABLE_EMBEDDED_TESTS) + +if(MSVC) + project_source_group(${GROUP_CODE} bus_test_SOURCES dummy) +endif(MSVC) + +## mop up the gcov files +#clean-local: +# /bin/rm *.bb *.bbg *.da *.gcov || true + +#install-data-hook: +# $(mkinstalldirs) $(DESTDIR)/$(localstatedir)/run/dbus +# $(mkinstalldirs) $(DESTDIR)/$(configdir)/system.d +# $(mkinstalldirs) $(DESTDIR)/$(datadir)/dbus-1/services + +##install_file(${configdir}/system.d FILE + + +set(LAUNCH_HELPER_SOURCES ${XML_SOURCES} + ${BUS_DIR}/config-parser-common.c + ${BUS_DIR}/config-parser-trivial.c + ${BUS_DIR}/desktop-file.c + ${BUS_DIR}/utils.c + ${BUS_DIR}/activation-helper.c + +) + +if(NOT WIN32) +# TODO PENDING(kdab) fix build on windows (activation-helper.c) + add_executable(dbus-daemon-launch-helper ${LAUNCH_HELPER_SOURCES} ${BUS_DIR}/activation-helper-bin.c ) + target_link_libraries(dbus-daemon-launch-helper ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY} ) + + add_executable(dbus-daemon-launch-helper-test ${LAUNCH_HELPER_SOURCES} ${BUS_DIR}/activation-helper-bin.c) + set_target_properties(dbus-daemon-launch-helper-test PROPERTIES COMPILE_FLAGS "-DACTIVATION_LAUNCHER_TEST") + target_link_libraries(dbus-daemon-launch-helper-test ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY} ) + + set (SOURCES ${LAUNCH_HELPER_SOURCES} ${BUS_DIR}/test-launch-helper.c) + add_test_executable(test-bus-launch-helper "${SOURCES}" ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY}) + set_target_properties(test-bus-launch-helper PROPERTIES COMPILE_FLAGS "-DACTIVATION_LAUNCHER_TEST -DACTIVATION_LAUNCHER_DO_OOM") + install_targets(/lib dbus-daemon-launch-helper) +endif(NOT WIN32) + +#### Init scripts fun +#SCRIPT_IN_FILES=messagebus.in +# rc.messagebus.in + +## Red Hat start +#if DBUS_INIT_SCRIPTS_RED_HAT + +#initddir=$(sysconfdir)/rc.d/init.d + +#initd_SCRIPTS= +# messagebus + +#endif +# ## Red Hat end + +## Slackware start +#if DBUS_INIT_SCRIPTS_SLACKWARE + +#initddir=$(sysconfdir)/rc.d/ + +#initd_SCRIPTS= +# rc.messagebus + +#endif +## Slackware end + +#MAN_IN_FILES=dbus-daemon.1.in +#man_MANS = dbus-daemon.1 + +#### Extra dist + +#EXTRA_DIST=$(CONFIG_IN_FILES) $(SCRIPT_IN_FILES) $(man_MANS) $(MAN_IN_FILES)
diff --git a/cmake/bus/service.cmake b/cmake/bus/service.cmake new file mode 100644 index 0000000..25d17ff --- /dev/null +++ b/cmake/bus/service.cmake
@@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.freedektop.DBus.ServiceName +Exec=notepad
diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake new file mode 100644 index 0000000..d2af3c9 --- /dev/null +++ b/cmake/config.h.cmake
@@ -0,0 +1,297 @@ +/* config.h. Generated by cmake from config.h.cmake */ + +#ifndef _DBUS_CONFIG_H +#define _DBUS_CONFIG_H +/****************************/ +/* indicate that we are building with cmake */ +#define DBUS_CMAKE 1 + +@AUTOPACKAGE_CONFIG_H_TEMPLATE@ + +/* + * Variables defined by AC_DEFINE in ../configure.ac + * should be placed in this file +*/ +#cmakedefine HAVE_GNUC_VARARGS 1 + +#cmakedefine DBUS_CONSOLE_AUTH_DIR "@DBUS_CONSOLE_AUTH_DIR@" +#cmakedefine DBUS_DATADIR "@DBUS_DATADIR@" +#cmakedefine DBUS_BINDIR "@DBUS_BINDIR@" +#cmakedefine DBUS_PREFIX "@DBUS_PREFIX@" +#cmakedefine DBUS_SYSTEM_CONFIG_FILE "@DBUS_SYSTEM_CONFIG_FILE@" +#cmakedefine DBUS_SESSION_CONFIG_FILE "@DBUS_SESSION_CONFIG_FILE@" +#cmakedefine DBUS_DAEMON_NAME "@DBUS_DAEMON_NAME@" +#cmakedefine DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@" +#cmakedefine DBUS_SESSION_BUS_CONNECT_ADDRESS "@DBUS_SESSION_BUS_CONNECT_ADDRESS@" +#cmakedefine DBUS_MACHINE_UUID_FILE "@DBUS_MACHINE_UUID_FILE@" +#cmakedefine DBUS_DAEMONDIR "@DBUS_DAEMONDIR@" + +#cmakedefine DBUS_ENABLE_STATS + +#define TEST_LISTEN "@TEST_LISTEN@" + +// test binaries +#define DBUS_TEST_EXEC "@DBUS_TEST_EXEC@" +#define DBUS_EXEEXT "@EXEEXT@" +#cmakedefine TEST_BUS_LAUNCH_BINARY "@TEST_BUS_LAUNCH_BINARY@" + +/* Some dbus features */ +#cmakedefine DBUS_ENABLE_ANSI 1 +#cmakedefine DBUS_ENABLE_VERBOSE_MODE 1 +#cmakedefine DBUS_DISABLE_ASSERT 1 +#ifndef DBUS_DISABLE_ASSERT +# define DBUS_ENABLE_ASSERT 1 +#endif +#cmakedefine DBUS_DISABLE_CHECKS 1 +#ifndef DBUS_DISABLE_CHECKS +# define DBUS_ENABLE_CHECKS 1 +#endif +/* xmldocs */ +/* doxygen */ +#cmakedefine DBUS_GCOV_ENABLED 1 + +/* abstract-sockets */ + +#cmakedefine HAVE_ABSTRACT_SOCKETS 1 + +#cmakedefine DBUS_PATH_OR_ABSTRACT_VALUE 1 + +#if (defined DBUS_PATH_OR_ABSTRACT_VALUE) +#define DBUS_PATH_OR_ABSTRACT @DBUS_PATH_OR_ABSTRACT_VALUE@ +#endif + +#ifdef DBUS_PATH_OR_ABSTRACT_VALUE +#undef DBUS_PATH_OR_ABSTRACT_VALUE +#endif + +/* selinux */ +/* kqueue */ +#cmakedefine HAVE_CONSOLE_OWNER_FILE 1 +#define DBUS_CONSOLE_OWNER_FILE "@DBUS_CONSOLE_OWNER_FILE@" + +#cmakedefine DBUS_HAVE_ATOMIC_INT 1 +#cmakedefine DBUS_USE_ATOMIC_INT_486 1 +#if (defined(__i386__) || defined(__x86_64__)) +# define DBUS_HAVE_ATOMIC_INT 1 +# define DBUS_USE_ATOMIC_INT_486 1 +#endif + +#cmakedefine DBUS_BUILD_X11 1 +/* For the moment, the cmake build system doesn't have an equivalent of + * the autoconf build system's --disable-x11-autolaunch */ +#ifdef DBUS_BUILD_X11 +# define DBUS_ENABLE_X11_AUTOLAUNCH 1 +#endif + +#define _DBUS_VA_COPY_ASSIGN(a1,a2) { a1 = a2; } + +#cmakedefine DBUS_VA_COPY_FUNC +#if (defined DBUS_VA_COPY_FUNC) +# define DBUS_VA_COPY @DBUS_VA_COPY_FUNC@ +#endif + +#ifdef DBUS_VA_COPY_FUNC +#undef DBUS_VA_COPY_FUNC +#endif + +#cmakedefine DBUS_VA_COPY_AS_ARRAY @DBUS_VA_COPY_AS_ARRAY@ + +#cmakedefine DBUS_WITH_GLIB 1 +#cmakedefine GLIB_VERSION_MIN_REQUIRED @GLIB_VERSION_MIN_REQUIRED@ +#cmakedefine GLIB_VERSION_MAX_ALLOWED @GLIB_VERSION_MAX_ALLOWED@ + +// headers +#cmakedefine HAVE_ALLOCA_H +#cmakedefine HAVE_BYTESWAP_H +#cmakedefine HAVE_CRT_EXTERNS_H + +/* Define to 1 if you have dirent.h */ +#cmakedefine HAVE_DIRENT_H 1 + +#cmakedefine HAVE_DLFCN_H + +/* Define to 1 if you have errno.h */ +#cmakedefine HAVE_ERRNO_H 1 + +#cmakedefine HAVE_EXECINFO_H +#cmakedefine HAVE_EXPAT_H + +/* Define to 1 if you have grp.h */ +#cmakedefine HAVE_GRP_H 1 + +/* Define to 1 if you have inttypes.h */ +#cmakedefine HAVE_INTTYPES_H 1 + +/* Define to 1 if you have io.h */ +#cmakedefine HAVE_IO_H 1 + +/* Define to 1 if you have locale.h */ +#cmakedefine HAVE_LOCALE_H 1 + +#cmakedefine HAVE_MEMORY_H + +/* Define to 1 if you have sys/poll.h */ +#cmakedefine HAVE_POLL 1 + +/* Define to 1 if you have signal.h */ +#cmakedefine HAVE_SIGNAL_H 1 + +/* Define to 1 if you have stdint.h */ +#cmakedefine HAVE_STDINT_H 1 + +#cmakedefine HAVE_STDLIB_H + +/* Define to 1 if you have stdio.h */ +#cmakedefine HAVE_STDIO_H 1 + +#cmakedefine HAVE_STRINGS_H +#cmakedefine HAVE_STRING_H +#cmakedefine HAVE_SYSLOG_H +#cmakedefine HAVE_SYS_EVENTS_H +#cmakedefine HAVE_SYS_INOTIFY_H +#cmakedefine HAVE_SYS_PRCTL_H +#cmakedefine HAVE_SYS_RESOURCE_H +#cmakedefine HAVE_SYS_STAT_H + +/* Define to 1 if you have sys/syslimits.h */ +#cmakedefine HAVE_SYS_SYSLIMITS_H 1 + +/* Define to 1 if you have sys/time.h */ +#cmakedefine HAVE_SYS_TIME_H 1 + +#cmakedefine HAVE_SYS_TYPES_H + +#cmakedefine HAVE_SYS_UIO_H + +/* Define to 1 if you have sys/wait.h */ +#cmakedefine HAVE_SYS_WAIT_H 1 + +/* Define to 1 if you have time.h */ +#cmakedefine HAVE_TIME_H 1 + +/* Define to 1 if you have unistd.h */ +#cmakedefine HAVE_UNISTD_H 1 + +/* Define to 1 if you have ws2tcpip.h */ +#cmakedefine HAVE_WS2TCPIP_H + +// symbols +/* Define to 1 if you have backtrace */ +#cmakedefine HAVE_BACKTRACE 1 + +/* Define to 1 if you have getgrouplist */ +#cmakedefine HAVE_GETGROUPLIST 1 + +/* Define to 1 if you have getpeerucred */ +#cmakedefine HAVE_GETPEERUCRED 1 + +/* Define to 1 if you have nanosleep */ +#cmakedefine HAVE_NANOSLEEP 1 + +/* Define to 1 if you have getpwnam_r */ +#cmakedefine HAVE_POSIX_GETPWNAM_R 1 + +/* Define to 1 if you have socketpair */ +#cmakedefine HAVE_SOCKETPAIR 1 + +/* Define to 1 if you have setenv */ +#cmakedefine HAVE_SETENV 1 + +/* Define to 1 if you have unsetenv */ +#cmakedefine HAVE_UNSETENV 1 + +/* Define to 1 if you have clearenv */ +#cmakedefine HAVE_CLEARENV 1 + +/* Define to 1 if you have writev */ +#cmakedefine HAVE_WRITEV 1 + +/* Define to 1 if you have socklen_t */ +#cmakedefine HAVE_SOCKLEN_T 1 + +/* Define to 1 if you have setlocale */ +#cmakedefine HAVE_SETLOCALE 1 + +/* Define to 1 if you have localeconv */ +#cmakedefine HAVE_LOCALECONV 1 + +/* Define to 1 if you have strtoll */ +#cmakedefine HAVE_STRTOLL 1 + +/* Define to 1 if you have strtoull */ +#cmakedefine HAVE_STRTOULL 1 + +/* Define to 1 if you have pip2 */ +#cmakedefine HAVE_PIPE2 + +#cmakedefine HAVE_ACCEPT4 1 +#cmakedefine HAVE_DIRFD 1 +#cmakedefine HAVE_INOTIFY_INIT1 1 +#cmakedefine HAVE_UNIX_FD_PASSING 1 + +// structs +/* Define to 1 if you have struct cmsgred */ +#cmakedefine HAVE_CMSGCRED 1 + +#cmakedefine FD_SETSIZE @FD_SETSIZE@ + +#cmakedefine DBUS_USER "@DBUS_USER@" +#cmakedefine DBUS_TEST_USER "@DBUS_TEST_USER@" + +// system type defines +#if defined(_WIN32) || defined(_WIN64) || defined (_WIN32_WCE) +# define DBUS_WIN +# define DBUS_WIN_FIXME 1 +# ifdef _WIN32_WCE +# define DBUS_WINCE +# else +# define DBUS_WIN32 +# endif +#else +# define DBUS_UNIX +#endif + +#if defined(_WIN32) || defined(_WIN64) +// mingw mode_t +# ifdef HAVE_STDIO_H +# include <stdio.h> +# endif +# ifndef _MSC_VER +# define uid_t int +# define gid_t int +# else +# define snprintf _snprintf + typedef int mode_t; +# if !defined(_WIN32_WCE) +# define strtoll _strtoi64 +# define strtoull _strtoui64 +# define HAVE_STRTOLL 1 +# define HAVE_STRTOULL 1 +# endif +# endif +#endif // defined(_WIN32) || defined(_WIN64) + +#ifdef interface +#undef interface +#endif + +#ifndef SIGHUP +#define SIGHUP 1 +#endif + +#cmakedefine DBUS_VERBOSE_C_S 1 +#ifdef DBUS_VERBOSE_C_S +#define _dbus_verbose_C_S printf +#else +#define _dbus_verbose_C_S _dbus_verbose +#endif + +# if defined(_MSC_VER) && !defined(inline) +#define inline __inline +#endif + +#ifdef DBUS_WIN +#define FD_SETSIZE @FD_SETSIZE@ +#endif + +#endif // _DBUS_CONFIG_H
diff --git a/cmake/dbus-env.bat.cmake b/cmake/dbus-env.bat.cmake new file mode 100644 index 0000000..d859ce0 --- /dev/null +++ b/cmake/dbus-env.bat.cmake
@@ -0,0 +1,8 @@ +:: environment setting for dbus clients +@echo off + +:: session bus address +set DBUS_SESSION_BUS_ADDRESS=@DBUS_SESSION_BUS_CONNECT_ADDRESS@ + +:: system bus address +set DBUS_SYSTEM_BUS_DEFAULT_ADDRESS=@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@
diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt new file mode 100644 index 0000000..1701408 --- /dev/null +++ b/cmake/dbus/CMakeLists.txt
@@ -0,0 +1,326 @@ +SET(DBUS_DIR ${CMAKE_SOURCE_DIR}/../dbus) + +configure_file(${DBUS_DIR}/dbus-arch-deps.h.in ${CMAKE_CURRENT_BINARY_DIR}/dbus-arch-deps.h ) + +add_definitions(-DDBUS_COMPILATION) + +set (dbusinclude_HEADERS + ${DBUS_DIR}/dbus.h + ${DBUS_DIR}/dbus-address.h + ${DBUS_DIR}/dbus-bus.h + ${DBUS_DIR}/dbus-connection.h + ${DBUS_DIR}/dbus-errors.h + ${DBUS_DIR}/dbus-macros.h + ${DBUS_DIR}/dbus-memory.h + ${DBUS_DIR}/dbus-message.h + ${DBUS_DIR}/dbus-misc.h + ${DBUS_DIR}/dbus-pending-call.h + ${DBUS_DIR}/dbus-protocol.h + ${DBUS_DIR}/dbus-server.h + ${DBUS_DIR}/dbus-shared.h + ${DBUS_DIR}/dbus-signature.h + ${DBUS_DIR}/dbus-syntax.h + ${DBUS_DIR}/dbus-threads.h + ${DBUS_DIR}/dbus-types.h + dbus-arch-deps.h +) + +### source code that goes in the installed client library +### and is specific to library functionality +set (DBUS_LIB_SOURCES + ${DBUS_DIR}/dbus-address.c + ${DBUS_DIR}/dbus-auth.c + ${DBUS_DIR}/dbus-bus.c + ${DBUS_DIR}/dbus-connection.c + ${DBUS_DIR}/dbus-credentials.c + ${DBUS_DIR}/dbus-errors.c + ${DBUS_DIR}/dbus-keyring.c + ${DBUS_DIR}/dbus-marshal-header.c + ${DBUS_DIR}/dbus-marshal-byteswap.c + ${DBUS_DIR}/dbus-marshal-recursive.c + ${DBUS_DIR}/dbus-marshal-validate.c + ${DBUS_DIR}/dbus-message.c + ${DBUS_DIR}/dbus-misc.c + ${DBUS_DIR}/dbus-nonce.c + ${DBUS_DIR}/dbus-object-tree.c + ${DBUS_DIR}/dbus-pending-call.c + ${DBUS_DIR}/dbus-resources.c + ${DBUS_DIR}/dbus-server.c + ${DBUS_DIR}/dbus-server-socket.c + ${DBUS_DIR}/dbus-server-debug-pipe.c + ${DBUS_DIR}/dbus-sha.c + ${DBUS_DIR}/dbus-signature.c + ${DBUS_DIR}/dbus-syntax.c + ${DBUS_DIR}/dbus-timeout.c + ${DBUS_DIR}/dbus-threads.c + ${DBUS_DIR}/dbus-transport.c + ${DBUS_DIR}/dbus-transport-socket.c + ${DBUS_DIR}/dbus-watch.c +) + + +if(UNIX) + set (DBUS_LIB_SOURCES ${DBUS_LIB_SOURCES} + ${DBUS_DIR}/dbus-transport-unix.c + ${DBUS_DIR}/dbus-server-unix.c + ) +else(UNIX) + set (DBUS_LIB_SOURCES ${DBUS_LIB_SOURCES} + ${DBUS_DIR}/dbus-transport-win.c + ${DBUS_DIR}/dbus-server-win.c + ) +endif(UNIX) + +set (DBUS_LIB_HEADERS + ${DBUS_DIR}/dbus-auth.h + ${DBUS_DIR}/dbus-connection-internal.h + ${DBUS_DIR}/dbus-credentials.h + ${DBUS_DIR}/dbus-keyring.h + ${DBUS_DIR}/dbus-marshal-header.h + ${DBUS_DIR}/dbus-marshal-byteswap.h + ${DBUS_DIR}/dbus-marshal-recursive.h + ${DBUS_DIR}/dbus-marshal-validate.h + ${DBUS_DIR}/dbus-message-internal.h + ${DBUS_DIR}/dbus-message-private.h + ${DBUS_DIR}/dbus-misc.h + ${DBUS_DIR}/dbus-object-tree.h + ${DBUS_DIR}/dbus-protocol.h + ${DBUS_DIR}/dbus-resources.h + ${DBUS_DIR}/dbus-server-debug-pipe.h + ${DBUS_DIR}/dbus-server-protected.h + ${DBUS_DIR}/dbus-server-unix.h + ${DBUS_DIR}/dbus-sha.h + ${DBUS_DIR}/dbus-timeout.h + ${DBUS_DIR}/dbus-threads.h + ${DBUS_DIR}/dbus-threads-internal.h + ${DBUS_DIR}/dbus-transport.h + ${DBUS_DIR}/dbus-transport-protected.h + ${DBUS_DIR}/dbus-watch.h + ${CMAKE_BINARY_DIR}/config.h +) +if(UNIX) + set (DBUS_LIB_HEADERS ${DBUS_LIB_HEADERS} + ${DBUS_DIR}/dbus-transport-unix.h + ) +else(UNIX) + set (DBUS_LIB_HEADERS ${DBUS_LIB_HEADERS} + ${DBUS_DIR}/dbus-transport-win.h + ) +endif(UNIX) + + +### source code that goes in the installed client library +### AND is generic utility functionality used by the +### daemon or test programs (all symbols in here should +### be underscore-prefixed) +set (DBUS_SHARED_SOURCES + ${DBUS_DIR}/dbus-dataslot.c + ${DBUS_DIR}/dbus-file.c + ${DBUS_DIR}/dbus-hash.c + ${DBUS_DIR}/dbus-internals.c + ${DBUS_DIR}/dbus-list.c + ${DBUS_DIR}/dbus-marshal-basic.c + ${DBUS_DIR}/dbus-memory.c + ${DBUS_DIR}/dbus-mempool.c + ${DBUS_DIR}/dbus-string.c + ${DBUS_DIR}/dbus-sysdeps.c + ${DBUS_DIR}/dbus-pipe.c +) + +set (DBUS_SHARED_HEADERS + ${DBUS_DIR}/dbus-dataslot.h + ${DBUS_DIR}/dbus-file.h + ${DBUS_DIR}/dbus-hash.h + ${DBUS_DIR}/dbus-internals.h + ${DBUS_DIR}/dbus-list.h + ${DBUS_DIR}/dbus-marshal-basic.h + ${DBUS_DIR}/dbus-mempool.h + ${DBUS_DIR}/dbus-string.h + ${DBUS_DIR}/dbus-string-private.h + ${DBUS_DIR}/dbus-pipe.h + ${DBUS_DIR}/dbus-sysdeps.h +) + +### source code that is generic utility functionality used +### by the bus daemon or test apps, but is NOT included +### in the D-BUS client library (all symbols in here +### should be underscore-prefixed but don't really need +### to be unless they move to DBUS_SHARED_SOURCES later) +set (DBUS_UTIL_SOURCES + ${DBUS_DIR}/dbus-asv-util.c + ${DBUS_DIR}/dbus-auth-script.c + ${DBUS_DIR}/dbus-auth-util.c + ${DBUS_DIR}/dbus-credentials-util.c + ${DBUS_DIR}/dbus-mainloop.c + ${DBUS_DIR}/dbus-marshal-byteswap-util.c + ${DBUS_DIR}/dbus-marshal-recursive-util.c + ${DBUS_DIR}/dbus-marshal-validate-util.c + ${DBUS_DIR}/dbus-message-factory.c + ${DBUS_DIR}/dbus-message-util.c + ${DBUS_DIR}/dbus-shell.c + ${DBUS_DIR}/dbus-socket-set.c + ${DBUS_DIR}/dbus-socket-set-poll.c + ${DBUS_DIR}/dbus-string-util.c + ${DBUS_DIR}/dbus-sysdeps-util.c +) + +if (DBUS_ENABLE_EMBEDDED_TESTS) + set (DBUS_UTIL_SOURCES + ${DBUS_UTIL_SOURCES} + ${DBUS_DIR}/dbus-test.c + ) +endif (DBUS_ENABLE_EMBEDDED_TESTS) + +set (DBUS_UTIL_HEADERS + ${DBUS_DIR}/dbus-asv-util.h + ${DBUS_DIR}/dbus-auth-script.h + ${DBUS_DIR}/dbus-mainloop.h + ${DBUS_DIR}/dbus-message-factory.h + ${DBUS_DIR}/dbus-shell.h + ${DBUS_DIR}/dbus-socket-set.h + ${DBUS_DIR}/dbus-spawn.h + ${DBUS_DIR}/dbus-test.h +) + +### platform specific settings +if (WIN32) + set (DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES} + ${DBUS_DIR}/dbus-file-win.c + ${DBUS_DIR}/dbus-init-win.cpp + ${DBUS_DIR}/dbus-sysdeps-win.c + ${DBUS_DIR}/dbus-pipe-win.c + ${DBUS_DIR}/dbus-sysdeps-thread-win.c + ) + set (DBUS_SHARED_HEADERS ${DBUS_SHARED_HEADERS} + ${DBUS_DIR}/dbus-sockets-win.h + ${DBUS_DIR}/dbus-sysdeps-win.h + ) + set (DBUS_UTIL_SOURCES ${DBUS_UTIL_SOURCES} + ${DBUS_DIR}/dbus-spawn-win.c + ${DBUS_DIR}/dbus-sysdeps-util-win.c + ) + if(WINCE) + set (DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES} + ${DBUS_DIR}/dbus-sysdeps-wince-glue.c + ) + set (DBUS_SHARED_HEADERS ${DBUS_SHARED_HEADERS} + ${DBUS_DIR}/dbus-sysdeps-wince-glue.h + ) + endif(WINCE) +else (WIN32) + set (DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES} + ${DBUS_DIR}/dbus-file-unix.c + ${DBUS_DIR}/dbus-pipe-unix.c + ${DBUS_DIR}/dbus-sysdeps-unix.c + ${DBUS_DIR}/dbus-sysdeps-pthread.c + ${DBUS_DIR}/dbus-userdb.c + ) + set (DBUS_SHARED_HEADERS ${DBUS_SHARED_HEADERS} + ${DBUS_DIR}/dbus-server-unix.h + ${DBUS_DIR}/dbus-transport-unix.h + ${DBUS_DIR}/dbus-sysdeps-unix.h + ${DBUS_DIR}/dbus-userdb.h + ) + set (DBUS_UTIL_SOURCES ${DBUS_UTIL_SOURCES} + ${DBUS_DIR}/dbus-spawn.c + ${DBUS_DIR}/dbus-userdb-util.c + ${DBUS_DIR}/dbus-sysdeps-util-unix.c + ) +endif (WIN32) + +set(libdbus_SOURCES + ${DBUS_LIB_SOURCES} + ${DBUS_SHARED_SOURCES} +) + +set(libdbus_HEADERS + ${DBUS_LIB_HEADERS} + ${DBUS_SHARED_HEADERS} +) +if (MSVC) + set (BUILD_FILEVERSION ${DBUS_MAJOR_VERSION},${DBUS_MINOR_VERSION},${DBUS_MICRO_VERSION},${DBUS_PATCH_VERSION}) + set (BUILD_TIMESTAMP ${DBUS_BUILD_TIMESTAMP}) + + configure_file(${DBUS_DIR}/versioninfo.rc.in ${CMAKE_CURRENT_BINARY_DIR}/versioninfo.rc) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/afxres.h "") + list(APPEND libdbus_SOURCES versioninfo.rc) + set_source_files_properties(versioninfo.rc COMPILE_FLAGS "-D__LINE__=1") +endif (MSVC) + +if(MSVC_IDE) + project_source_group(${GROUP_CODE} DBUS_LIB_SOURCES DBUS_LIB_HEADERS) + project_source_group(${GROUP_CODE} DBUS_SHARED_SOURCES DBUS_SHARED_HEADERS) + project_source_group(${GROUP_CODE} DBUS_UTIL_SOURCES DBUS_UTIL_SOURCES) +endif(MSVC_IDE) + +### Client library + +add_library(dbus-1 SHARED + ${libdbus_SOURCES} + ${libdbus_HEADERS} +) +if(DEFINED DBUS_LIBRARY_REVISION) + math(EXPR DBUS_LIBRARY_MAJOR "${DBUS_LIBRARY_CURRENT} - ${DBUS_LIBRARY_AGE}") +endif() + +if(WIN32) + if(DEFINED DBUS_LIBRARY_REVISION) + set_target_properties(dbus-1 PROPERTIES SUFFIX "-${DBUS_LIBRARY_MAJOR}${CMAKE_SHARED_LIBRARY_SUFFIX}") + add_custom_command(TARGET dbus-1 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:dbus-1>" "$<TARGET_FILE_DIR:dbus-1>/${CMAKE_SHARED_LIBRARY_PREFIX}dbus-1${CMAKE_SHARED_LIBRARY_SUFFIX}" + COMMENT "Create non versioned dbus-1 library for legacy applications" + ) + install(FILES ${LEGACY_FILE_NAME} DESTINATION bin) + endif() + if(WINCE) + target_link_libraries(dbus-1 ws2) + else(WINCE) + target_link_libraries(dbus-1 ws2_32 advapi32 netapi32 iphlpapi) + endif(WINCE) +else(WIN32) + if(DEFINED DBUS_LIBRARY_REVISION) + set_target_properties(dbus-1 PROPERTIES VERSION ${DBUS_LIBRARY_MAJOR}.${DBUS_LIBRARY_AGE}.${DBUS_LIBRARY_REVISION} SOVERSION ${DBUS_LIBRARY_MAJOR}) + endif() + target_link_libraries(dbus-1 ${CMAKE_THREAD_LIBS_INIT} rt) +endif(WIN32) + +# Assume that Linux has -Wl,--version-script and other platforms do not +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + set(SOVERSION ${DBUS_LIBRARY_MAJOR}) + configure_file(${DBUS_DIR}/Version.in ${CMAKE_CURRENT_BINARY_DIR}/Version) + set_target_properties(dbus-1 PROPERTIES LINK_FLAGS -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/Version) +endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + +install(TARGETS dbus-1 ${INSTALL_TARGETS_DEFAULT_ARGS}) +install_files(/include/dbus FILES ${dbusinclude_HEADERS}) + +### Internal library, used for the daemon, tools and tests, compiled statically. + +add_library(dbus-internal ${DBUS_INTERNAL_ADD_LIBRARY_OPTIONS} + ${DBUS_UTIL_SOURCES} + ${DBUS_UTIL_HEADERS} +) +target_link_libraries(dbus-internal dbus-1) +if(WIN32) + if(WINCE) + target_link_libraries(dbus-internal ws2) + else(WINCE) + target_link_libraries(dbus-internal ws2_32 advapi32 netapi32 iphlpapi) + endif(WINCE) +else(WIN32) + target_link_libraries(dbus-internal ${CMAKE_THREAD_LIBS_INIT} rt) +endif(WIN32) + +if (DBUS_ENABLE_EMBEDDED_TESTS) + add_test_executable(test-dbus ${CMAKE_SOURCE_DIR}/../dbus/dbus-test-main.c ${DBUS_INTERNAL_LIBRARIES}) + set_target_properties(test-dbus PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) +ENDIF (DBUS_ENABLE_EMBEDDED_TESTS) + +if (UNIX) +# set version info +ENDIF (UNIX) + + +## mop up the gcov files +#clean-local: +#/bin/rm *.bb *.bbg *.da *.gcov .libs/*.da .libs/*.bbg || true
diff --git a/cmake/doc/CMakeLists.txt b/cmake/doc/CMakeLists.txt new file mode 100644 index 0000000..f21e84e --- /dev/null +++ b/cmake/doc/CMakeLists.txt
@@ -0,0 +1,175 @@ +find_package(Doxygen) + +if(DOXYGEN_EXECUTABLE) + OPTION(DBUS_ENABLE_DOXYGEN_DOCS "build DOXYGEN documentation (requires Doxygen)" ON) +endif(DOXYGEN_EXECUTABLE) + +if (DBUS_ENABLE_DOXYGEN_DOCS) + set (top_srcdir ${CMAKE_SOURCE_DIR}/..) + configure_file(${CMAKE_SOURCE_DIR}/../Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile ) + add_custom_target(doc + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) +endif (DBUS_ENABLE_DOXYGEN_DOCS) + +# +# find docbook generator +# +find_program(MEINPROC4_EXECUTABLE meinproc4) + +find_program(XMLTO_EXECUTABLE xmlto) + +find_program(CYGPATH_EXECUTABLE cygpath) + +if (MEINPROC4_EXECUTABLE OR XMLTO_EXECUTABLE) + OPTION(DBUS_ENABLE_XML_DOCS "build XML documentation (requires xmlto or meinproc4)" ON) + ADD_CUSTOM_TARGET(xmldoc ALL) +endif (MEINPROC4_EXECUTABLE OR XMLTO_EXECUTABLE) + +if (XMLTO_EXECUTABLE) + set (DOCBOOK_GENERATOR_NAME "xmlto" PARENT_SCOPE) + set(DBUS_XML_DOCS_ENABLED 1) + set(MEINPROC4_EXECUTABLE 0) + MESSAGE(STATUS "xmlto docbook generator found") + set(STYLESHEET_MAN "${DOCBOOKXSL_DIR}/manpages/docbook.xsl") + set(STYLESHEET_HTML "${DOCBOOKXSL_DIR}/html/docbook.xsl") + +elseif (MEINPROC4_EXECUTABLE) + set(DOCBOOK_GENERATOR_NAME "meinproc4" PARENT_SCOPE) + set(DBUS_XML_DOCS_ENABLED 1) + if(WIN32) + get_filename_component(_a ${MEINPROC4_EXECUTABLE} PATH) + get_filename_component(_meinproc_install_path ${_a} PATH) + set(STYLESHEET_HTML "${_meinproc_install_path}/share/apps/ksgmltools2/docbook/xsl/html/docbook.xsl") + else(WIN32) + set(STYLESHEET_HTML file:///usr/share/kde4/apps/ksgmltools2/customization/kde-nochunk.xsl) + endif(WIN32) +endif () + +if (DBUS_ENABLE_XML_DOCS) + +macro (DOCBOOK _sources _format) + get_filename_component(_infile ${_sources} ABSOLUTE) + get_filename_component(_name ${_infile} NAME) + set(_deps ${CMAKE_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt) + + if (${_format} STREQUAL "man") + string(REPLACE ".xml" "" _outname ${_name}) + set(STYLESHEET ${STYLESHEET_MAN}) + else() + string(REPLACE ".xml" ".html" _outname ${_name}) + set(STYLESHEET ${STYLESHEET_HTML}) + endif () + + set(_outfile ${CMAKE_CURRENT_BINARY_DIR}/${_outname}) + if (EXISTS ${_sources}) + if (MEINPROC4_EXECUTABLE) + ADD_CUSTOM_COMMAND( + OUTPUT ${_outfile} + COMMAND ${MEINPROC4_EXECUTABLE} --stylesheet ${STYLESHEET} -o ${_outfile} ${_infile} + DEPENDS ${_infile} ${STYLESHEET} ${_deps} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + endif () + if (XMLTO_EXECUTABLE) + if (MSYS) + if (CYGPATH_EXECUTABLE) + execute_process( + COMMAND cygpath ${_infile} + OUTPUT_VARIABLE _infile) + else () + execute_process(COMMAND dirname ${_infile} OUTPUT_VARIABLE _path) + string(STRIP ${_path} _path) + execute_process(COMMAND sh -c "cd ${_path}; pwd -W" OUTPUT_VARIABLE _path) + string(STRIP ${_path} _path) + set(_infile "${_path}/${_name}") + endif(CYGPATH_EXECUTABLE) + endif (MSYS) + ADD_CUSTOM_COMMAND( + OUTPUT ${_outfile} + COMMAND ${XMLTO_EXECUTABLE} -vv ${_format} ${_infile} + DEPENDS ${_infile} ${_deps} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + endif () + if (${_format} STREQUAL "man") + install(FILES ${_outfile} DESTINATION share/man/man1) + else () + install(FILES ${_outfile} DESTINATION share/doc/dbus) + endif () + else () + MESSAGE(STATUS "skipping xml doc generating for ${_infile}, file not found") + endif () + ADD_CUSTOM_TARGET(${_outname} DEPENDS ${_outfile}) + ADD_DEPENDENCIES(xmldoc ${_outname}) +endmacro (DOCBOOK) + +### copy tests to builddir so that generated tests and static tests +### are all in one place. +### todo how to add more filetypes +MACRO (COPYDIR _src _type) + FOREACH(FILE_TYPE ${_type}) + FOREACH(DIR ${_src}) + FILE(GLOB FILES "${CMAKE_SOURCE_DIR}/../${DIR}/${FILE_TYPE}" ) + FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DIR}) + FOREACH(FILE ${FILES}) + GET_FILENAME_COMPONENT(FILENAME ${FILE} NAME) + SET (TARGET ${CMAKE_BINARY_DIR}/${DIR}/${FILENAME}) + configure_file(${FILE} ${TARGET} COPYONLY) + IF (CONFIG_VERBOSE) + MESSAGE("FROM: ${FILE}\nTO: ${TARGET}\n") + ENDIF (CONFIG_VERBOSE) + ENDFOREACH(FILE) + ENDFOREACH(DIR) + ENDFOREACH(FILE_TYPE) +ENDMACRO (COPYDIR) + +COPYDIR(doc *.png) +COPYDIR(doc *.svg) + +DOCBOOK(${CMAKE_SOURCE_DIR}/../doc/dbus-test-plan.xml html-nochunks) +DOCBOOK(${CMAKE_SOURCE_DIR}/../doc/dbus-tutorial.xml html-nochunks) +DOCBOOK(${CMAKE_SOURCE_DIR}/../doc/dbus-specification.xml html-nochunks) +DOCBOOK(${CMAKE_SOURCE_DIR}/../doc/dbus-faq.xml html-nochunks) +configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-cleanup-sockets.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-cleanup-sockets.1.xml) +configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-daemon.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-daemon.1.xml) +configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-launch.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-launch.1.xml) +configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-monitor.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-monitor.1.xml) +configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-send.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-send.1.xml) +configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-test-tool.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-test-tool.1.xml) +configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-update-activation-environment.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-update-activation-environment.1.xml) +configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-uuidgen.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-uuidgen.1.xml) +DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-cleanup-sockets.1.xml html-nochunks) +DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-daemon.1.xml html-nochunks) +DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-launch.1.xml html-nochunks) +DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-monitor.1.xml html-nochunks) +DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-send.1.xml html-nochunks) +DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-test-tool.1.xml html-nochunks) +DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-uuidgen.1.xml html-nochunks) +DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-update-activation-environment.1.xml html-nochunks) +if (UNIX) + DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-daemon.1.xml man) + DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-monitor.1.xml man) + DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-send.1.xml man) + DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-test-tool.1.xml man) + DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-launch.1.xml man) + DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-uuidgen.1.xml man) + DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-cleanup-sockets.1.xml man) + DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-update-activation-environment.1.xml man) +endif() +# +# handle html index file +# +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/index.html.cmake ${CMAKE_CURRENT_BINARY_DIR}/index.html ) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/index.html DESTINATION share/doc/dbus) + +set (EXTRA_DIST + ${CMAKE_SOURCE_DIR}/../doc/busconfig.dtd + ${CMAKE_SOURCE_DIR}/../doc/introspect.dtd + ${CMAKE_SOURCE_DIR}/../doc/introspect.xsl +) + +install(FILES ${EXTRA_DIST} DESTINATION share/doc/dbus) + +endif(DBUS_ENABLE_XML_DOCS)
diff --git a/cmake/doc/index.html.cmake b/cmake/doc/index.html.cmake new file mode 100644 index 0000000..77dd661 --- /dev/null +++ b/cmake/doc/index.html.cmake
@@ -0,0 +1,55 @@ +<html> +<head> +<title>D-Bus Documentation Index</title> +</head> +<body> +<h1>D-Bus Documentation Index</h1> +<p>Version @DBUS_VERSION_STRING@</p> + +<table> + <tr> + <th width=10%> + </th> + <th width=30% align=left> + generic documentation + </th> + <th width=30% align=left> +application manuals + </th> + </tr> + <tr> + <td valign=top> + </td> + <td valign=top> +<a href="http://dbus.freedesktop.org">D-Bus Website</a> + <br> + <br> +<a href="dbus-tutorial.html">D-Bus Tutorial</a> + <br> + <br> +<a href="dbus-specification.html">D-Bus Specification</a> + <br> + <br> +<a href="dbus-faq.html">D-Bus FAQ</a> + <br> + <br> +<a href="dbus-test-plan.html">D-Bus Test Plan</a> + <br> + <br> + </td> + <td valign=top> +<a href="dbus-daemon.html">D-Bus Daemon manual</a> + <br> + <br> +<a href="dbus-launch.html">D-Bus launch manual</a> + <br> + <br> +<a href="dbus-send.html">D-Bus send tool manual</a> + <br> + <br> +<a href="dbus-monitor.html">D-Bus monitor manual</a> + </td> + </tr> +</table> +</body> +</html>
diff --git a/cmake/i686-w64-mingw32.cmake b/cmake/i686-w64-mingw32.cmake new file mode 100644 index 0000000..1be4e78 --- /dev/null +++ b/cmake/i686-w64-mingw32.cmake
@@ -0,0 +1,20 @@ +# Toolchain for mingw-w64 32-bit compilers, as shipped in Debian/Ubuntu. + +set(GNU_HOST i686-w64-mingw32) +set(CMAKE_SYSTEM_PROCESSOR "i686") + +set(COMPILER_PREFIX "${GNU_HOST}-") + +set(CMAKE_SYSTEM_NAME "Windows") +set(CMAKE_CROSSCOMPILING TRUE) +set(WIN32 TRUE) +set(MINGW TRUE) + +include(CMakeForceCompiler) +cmake_force_c_compiler(${COMPILER_PREFIX}gcc GNU) +cmake_force_cxx_compiler(${COMPILER_PREFIX}g++ GNU) +set(CMAKE_RC_COMPILER ${COMPILER_PREFIX}windres) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
diff --git a/cmake/modules/COPYING-CMAKE-SCRIPTS b/cmake/modules/COPYING-CMAKE-SCRIPTS new file mode 100644 index 0000000..53b6b71 --- /dev/null +++ b/cmake/modules/COPYING-CMAKE-SCRIPTS
@@ -0,0 +1,22 @@ +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/cmake/modules/CPackInstallConfig.cmake b/cmake/modules/CPackInstallConfig.cmake new file mode 100644 index 0000000..74b6689 --- /dev/null +++ b/cmake/modules/CPackInstallConfig.cmake
@@ -0,0 +1,37 @@ + +if (DBUS_INSTALL_SYSTEM_LIBS) + if (MINGW) + install_files(/bin FILES ${LIBEXPAT_LIBRARIES}) + else (MINGW) + INCLUDE(InstallRequiredSystemLibraries) + endif (MINGW) +endif (DBUS_INSTALL_SYSTEM_LIBS) + +SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "D-BUS For Windows") +SET(CPACK_PACKAGE_VENDOR "D-BUS Windows Team") +SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/../README") +SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/../COPYING") +# duplicated from VERSION +SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) +SET(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}) +SET(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH}) +#SET(CPACK_PACKAGE_INSTALL_DIRECTORY "dbus ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") +SET(CPACK_PACKAGE_INSTALL_DIRECTORY "dbus") +IF(WIN32 AND NOT UNIX) + SET(CPACK_GENERATOR NSIS ZIP) # can be NSIS, STGZ, TBZ2, TGZ, TZ and ZIP + SET(CPACK_NSIS_COMPRESSOR "/SOLID lzma") + # There is a bug in NSI that does not handle full unix paths properly. Make + # sure there is at least one set of four (4) backlasshes. +# SET(CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/Utilities/Release\\\\InstallIcon.bmp") + SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\dbus-launch.bat") + SET(CPACK_NSIS_DISPLAY_NAME "D-Bus for Windows") + SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\sourceforge.net/projects/windbus") + SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\sourceforge.net/projects/windbus") + SET(CPACK_NSIS_CONTACT "me@my-personal-home-page.com") + SET(CPACK_NSIS_MODIFY_PATH ON) +ELSE(WIN32 AND NOT UNIX) + SET(CPACK_STRIP_FILES "bin/MyExecutable") + SET(CPACK_SOURCE_STRIP_FILES "") +ENDIF(WIN32 AND NOT UNIX) +SET(CPACK_PACKAGE_EXECUTABLES "dbus-launch" "D-Bus Daemon") +INCLUDE(CPack)
diff --git a/cmake/modules/CheckForAbstractSockets.c b/cmake/modules/CheckForAbstractSockets.c new file mode 100644 index 0000000..062b846 --- /dev/null +++ b/cmake/modules/CheckForAbstractSockets.c
@@ -0,0 +1,33 @@ +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <errno.h> + +int main() { + int listen_fd; + struct sockaddr_un addr; + + listen_fd = socket (PF_UNIX, SOCK_STREAM, 0); + + if (listen_fd < 0) + { + fprintf (stderr, "socket() failed: %s\n", strerror (errno)); + exit (1); + } + + memset (&addr, '\0', sizeof (addr)); + addr.sun_family = AF_UNIX; + strcpy (addr.sun_path, "X/tmp/dbus-fake-socket-path-used-in-configure-test"); + addr.sun_path[0] = '\0'; /* this is what makes it abstract */ + + if (bind (listen_fd, (struct sockaddr*) &addr, SUN_LEN (&addr)) < 0) + { + fprintf (stderr, "Abstract socket namespace bind() failed: %s\n", + strerror (errno)); + exit (1); + } + else + exit (0); +} \ No newline at end of file
diff --git a/cmake/modules/CheckPrototypeExists.cmake b/cmake/modules/CheckPrototypeExists.cmake new file mode 100644 index 0000000..da319f1 --- /dev/null +++ b/cmake/modules/CheckPrototypeExists.cmake
@@ -0,0 +1,35 @@ +# - Check if the prototype for a function exists. +# CHECK_PROTOTYPE_EXISTS (FUNCTION HEADER VARIABLE) +# +# FUNCTION - the name of the function you are looking for +# HEADER - the header(s) where the prototype should be declared +# VARIABLE - variable to store the result +# +# The following variables may be set before calling this macro to +# modify the way the check is run: +# +# CMAKE_REQUIRED_FLAGS = string of compile command line flags +# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) +# CMAKE_REQUIRED_INCLUDES = list of include directories + +INCLUDE(CheckCXXSourceCompiles) + +MACRO (CHECK_PROTOTYPE_EXISTS _SYMBOL _HEADER _RESULT) + SET(_INCLUDE_FILES) + FOREACH (it ${_HEADER}) + SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n") + ENDFOREACH (it) + + SET(_CHECK_PROTO_EXISTS_SOURCE_CODE " +${_INCLUDE_FILES} +int main() +{ +#ifndef ${_SYMBOL} + int i = sizeof(&${_SYMBOL}); +#endif + return 0; +} +") + CHECK_CXX_SOURCE_COMPILES("${_CHECK_PROTO_EXISTS_SOURCE_CODE}" ${_RESULT}) +ENDMACRO (CHECK_PROTOTYPE_EXISTS _SYMBOL _HEADER _RESULT) +
diff --git a/cmake/modules/CheckStructMember.cmake b/cmake/modules/CheckStructMember.cmake new file mode 100644 index 0000000..fd5d346 --- /dev/null +++ b/cmake/modules/CheckStructMember.cmake
@@ -0,0 +1,36 @@ +# - Check if the given struct or class has the specified member variable +# CHECK_STRUCT_MEMBER (STRUCT MEMBER HEADER VARIABLE) +# +# STRUCT - the name of the struct or class you are interested in +# MEMBER - the member which existence you want to check +# HEADER - the header(s) where the prototype should be declared +# VARIABLE - variable to store the result +# +# The following variables may be set before calling this macro to +# modify the way the check is run: +# +# CMAKE_REQUIRED_FLAGS = string of compile command line flags +# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) +# CMAKE_REQUIRED_INCLUDES = list of include directories + +INCLUDE(CheckCXXSourceCompiles) + +MACRO (CHECK_STRUCT_MEMBER _STRUCT _MEMBER _HEADER _RESULT) + SET(_INCLUDE_FILES) + FOREACH (it ${_HEADER}) + SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n") + ENDFOREACH (it) + + SET(_CHECK_STRUCT_MEMBER_SOURCE_CODE " +${_INCLUDE_FILES} +int main() +{ + ${_STRUCT}* tmp; + tmp->${_MEMBER}; + return 0; +} +") + CHECK_CXX_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT}) + +ENDMACRO (CHECK_STRUCT_MEMBER) +
diff --git a/cmake/modules/FindDoxygen.cmake b/cmake/modules/FindDoxygen.cmake new file mode 100644 index 0000000..1767901 --- /dev/null +++ b/cmake/modules/FindDoxygen.cmake
@@ -0,0 +1,3 @@ + +find_program(DOXYGEN_EXECUTABLE NAMES doxygen DOC "doxygen executable") +mark_as_advanced(DOXYGEN_EXECUTABLE)
diff --git a/cmake/modules/FindGLib2.cmake b/cmake/modules/FindGLib2.cmake new file mode 100644 index 0000000..d72b2a0 --- /dev/null +++ b/cmake/modules/FindGLib2.cmake
@@ -0,0 +1,60 @@ +# - Try to find the GLIB2 libraries +# Once done this will define +# +# GLIB2_FOUND - system has glib2 +# GLIB2_INCLUDE_DIR - the glib2 include directory +# GLIB2_LIBRARIES - glib2 library + +# Copyright (c) 2008 Laurent Montel, <montel@kde.org> +# Copyright (c) 2013 Ralf Habacker, <ralf.habacker@freenet.de> +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +if(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES) + # Already in cache, be silent + set(GLIB2_FIND_QUIETLY TRUE) +endif(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES) + +if (NOT WIN32) + find_package(PkgConfig) + pkg_check_modules(PC_LibGLIB2 QUIET glib-2.0) +endif() + +find_path(GLIB2_MAIN_INCLUDE_DIR + NAMES glib.h + HINTS ${PC_LibGLIB2_INCLUDEDIR} + PATH_SUFFIXES glib-2.0) + +find_library(GLIB2_LIBRARY + NAMES glib-2.0 + HINTS ${PC_LibGLIB2_LIBDIR} +) + +find_library(GIO2_LIBRARY + NAMES gio-2.0 + HINTS ${PC_LibGLIB2_LIBDIR} +) + +set(GLIB2_LIBRARIES ${GLIB2_LIBRARY} ${GIO2_LIBRARY}) + +# search the glibconfig.h include dir under the same root where the library is found +get_filename_component(glib2LibDir "${GLIB2_LIBRARY}" PATH) + +find_path(GLIB2_INTERNAL_INCLUDE_DIR glibconfig.h + PATH_SUFFIXES glib-2.0/include + HINTS ${PC_LibGLIB2_INCLUDEDIR} "${glib2LibDir}" ${CMAKE_SYSTEM_LIBRARY_PATH}) + +set(GLIB2_INCLUDE_DIR "${GLIB2_MAIN_INCLUDE_DIR}") + +# not sure if this include dir is optional or required +# for now it is optional +if(GLIB2_INTERNAL_INCLUDE_DIR) + set(GLIB2_INCLUDE_DIR ${GLIB2_INCLUDE_DIR} "${GLIB2_INTERNAL_INCLUDE_DIR}") +endif(GLIB2_INTERNAL_INCLUDE_DIR) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GLIB2 DEFAULT_MSG GLIB2_LIBRARIES GLIB2_MAIN_INCLUDE_DIR) + +mark_as_advanced(GLIB2_INCLUDE_DIR GLIB2_LIBRARIES)
diff --git a/cmake/modules/FindGObject.cmake b/cmake/modules/FindGObject.cmake new file mode 100644 index 0000000..af0c9f7 --- /dev/null +++ b/cmake/modules/FindGObject.cmake
@@ -0,0 +1,52 @@ +# - Try to find GObject +# Once done this will define +# +# GOBJECT_FOUND - system has GObject +# GOBJECT_INCLUDE_DIR - the GObject include directory +# GOBJECT_LIBRARIES - the libraries needed to use GObject +# GOBJECT_DEFINITIONS - Compiler switches required for using GObject + +# Copyright (c) 2011, Raphael Kubo da Costa <kubito@gmail.com> +# Copyright (c) 2006, Tim Beaulen <tbscope@gmail.com> +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +FIND_PACKAGE(PkgConfig) +PKG_CHECK_MODULES(PC_GOBJECT gobject-2.0) +SET(GOBJECT_DEFINITIONS ${PC_GOBJECT_CFLAGS_OTHER}) + +FIND_PATH(GOBJECT_INCLUDE_DIR gobject.h + HINTS + ${PC_GOBJECT_INCLUDEDIR} + ${PC_GOBJECT_INCLUDE_DIRS} + PATH_SUFFIXES glib-2.0/gobject/ + ) + +FIND_LIBRARY(_GObjectLibs NAMES gobject-2.0 + HINTS + ${PC_GOBJECT_LIBDIR} + ${PC_GOBJECT_LIBRARY_DIRS} + ) +FIND_LIBRARY(_GModuleLibs NAMES gmodule-2.0 + HINTS + ${PC_GOBJECT_LIBDIR} + ${PC_GOBJECT_LIBRARY_DIRS} + ) +FIND_LIBRARY(_GThreadLibs NAMES gthread-2.0 + HINTS + ${PC_GOBJECT_LIBDIR} + ${PC_GOBJECT_LIBRARY_DIRS} + ) +FIND_LIBRARY(_GLibs NAMES glib-2.0 + HINTS + ${PC_GOBJECT_LIBDIR} + ${PC_GOBJECT_LIBRARY_DIRS} + ) + +SET( GOBJECT_LIBRARIES ${_GObjectLibs} ${_GModuleLibs} ${_GThreadLibs} ${_GLibs} ) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GOBJECT DEFAULT_MSG GOBJECT_LIBRARIES GOBJECT_INCLUDE_DIR) + +MARK_AS_ADVANCED(GOBJECT_INCLUDE_DIR _GObjectLibs _GModuleLibs _GThreadLibs _GLibs)
diff --git a/cmake/modules/FindLibIconv.cmake b/cmake/modules/FindLibIconv.cmake new file mode 100644 index 0000000..dac6344 --- /dev/null +++ b/cmake/modules/FindLibIconv.cmake
@@ -0,0 +1,52 @@ +# - Try to find LibIconv +# Once done this will define +# +# LIBICONV_FOUND - system has LibIconv +# LIBICONV_INCLUDE_DIR - the LibIconv include directory +# LIBICONV_LIBRARIES - the libraries needed to use LibIconv +# LIBICONV_DEFINITIONS - Compiler switches required for using LibIconv + +if (LIBICONV_INCLUDE_DIR AND LIBICONV_LIBRARIES) + + # in cache already + SET(LIBICONV_FOUND TRUE) + +else (LIBICONV_INCLUDE_DIR AND LIBICONV_LIBRARIES) + + IF (NOT WIN32) + MESSAGE(FATAL_ERROR "Please set this to the correct values!") + # use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + INCLUDE(UsePkgConfig) + PKGCONFIG(libiconv-1.9 _LibIconvIncDir _LibIconvLinkDir _LibIconvLinkFlags _LiIconvCflags) + SET(LIBICONV_DEFINITIONS ${_LibIconvCflags}) + ENDIF (NOT WIN32) + + FIND_PATH(LIBICONV_INCLUDE_DIR iconv.h + PATHS + ${_LibIconvIncDir} + PATH_SUFFIXES libiconv + ) + + FIND_LIBRARY(LIBICONV_LIBRARIES NAMES iconv libiconv + PATHS + ${_LibIconvLinkDir} + ) + + if (LIBICONV_INCLUDE_DIR AND LIBICONV_LIBRARIES) + set(LIBICONV_FOUND TRUE) + endif (LIBICONV_INCLUDE_DIR AND LIBICONV_LIBRARIES) + + if (LIBICONV_FOUND) + if (NOT LibIconv_FIND_QUIETLY) + message(STATUS "Found LibIconv: ${LIBICONV_LIBRARIES}") + endif (NOT LibIconv_FIND_QUIETLY) + else (LIBICONV_FOUND) + if (LibIconv_FIND_REQUIRED) + message(SEND_ERROR "Could NOT find LibIconv") + endif (LibIconv_FIND_REQUIRED) + endif (LIBICONV_FOUND) + + MARK_AS_ADVANCED(LIBICONV_INCLUDE_DIR LIBICONV_LIBRARIES) + +endif (LIBICONV_INCLUDE_DIR AND LIBICONV_LIBRARIES)
diff --git a/cmake/modules/MacroGetenvWinPath.cmake b/cmake/modules/MacroGetenvWinPath.cmake new file mode 100644 index 0000000..b18f7f6 --- /dev/null +++ b/cmake/modules/MacroGetenvWinPath.cmake
@@ -0,0 +1,5 @@ + +MACRO (MACRO_GETENV_WIN_PATH var name) + set(${var} $ENV{${name}}) + STRING(REGEX REPLACE "\\\\" "/" ${var} "${${var}}") +ENDMACRO (MACRO_GETENV_WIN_PATH var name)
diff --git a/cmake/modules/MacroLibrary.cmake b/cmake/modules/MacroLibrary.cmake new file mode 100644 index 0000000..6523530 --- /dev/null +++ b/cmake/modules/MacroLibrary.cmake
@@ -0,0 +1,9 @@ +# - include MacroLibrary offers a collection of macros which extend the built-in cmake commands +# OPTIONAL_FIND_PACKAGE( <name> [QUIT] ) + +INCLUDE(MacroOptionalFindPackage) +#INCLUDE(MacroAdditionalCleanFiles) +#INCLUDE(MacroAddFileDependencies) +#INCLUDE(MacroGetenvWinPath) +#INCLUDE(MacroEnsureOutOfSourceBuild) +
diff --git a/cmake/modules/MacroOptionalFindPackage.cmake b/cmake/modules/MacroOptionalFindPackage.cmake new file mode 100644 index 0000000..7068131 --- /dev/null +++ b/cmake/modules/MacroOptionalFindPackage.cmake
@@ -0,0 +1,22 @@ +# - MACRO_OPTIONAL_FIND_PACKAGE() combines FIND_PACKAGE() with an OPTION() +# MACRO_OPTIONAL_FIND_PACKAGE( <name> [QUIT] ) +# This macro is a combination of OPTION() and FIND_PACKAGE(), it +# works like FIND_PACKAGE(), but additionally it automatically creates +# an option name WITH_<name>, which can be disabled via the cmake GUI. +# or via -DWITH_<name>=OFF +# The standard <name>_FOUND variables can be used in the same way +# as when using the normal FIND_PACKAGE() + +MACRO (MACRO_OPTIONAL_FIND_PACKAGE _name ) + OPTION(WITH_${_name} "Search for ${_name} package" ON) + if (WITH_${_name}) + FIND_PACKAGE(${_name} ${ARGN}) + else (WITH_${_name}) + set(${_name}_FOUND) + set(${_name}_INCLUDE_DIR) + set(${_name}_INCLUDES) + set(${_name}_LIBRARY) + set(${_name}_LIBRARIES) + endif (WITH_${_name}) +ENDMACRO (MACRO_OPTIONAL_FIND_PACKAGE) +
diff --git a/cmake/modules/Macros.cmake b/cmake/modules/Macros.cmake new file mode 100644 index 0000000..8d6cf11 --- /dev/null +++ b/cmake/modules/Macros.cmake
@@ -0,0 +1,62 @@ +if(DBUS_BUILD_TESTS AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows") + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + find_file(WINE_EXECUTABLE + NAMES wine + PATHS /usr/bin /usr/local/bin + NO_CMAKE_FIND_ROOT_PATH + ) + find_file(HAVE_BINFMT_WINE_SUPPORT + NAMES DOSWin wine Wine windows Windows + PATHS /proc/sys/fs/binfmt_misc + NO_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH + ) + if(WINE_EXECUTABLE AND HAVE_BINFMT_WINE_SUPPORT) + list(APPEND FOOTNOTES "NOTE: The requirements to run cross compiled applications on your host system are achieved. You may run 'make check'.") + endif() + if(NOT WINE_EXECUTABLE) + list(APPEND FOOTNOTES "NOTE: You may install the Windows emulator 'wine' to be able to run cross compiled test applications.") + endif() + if(NOT HAVE_BINFMT_WINE_SUPPORT) + list(APPEND FOOTNOTES "NOTE: You may activate binfmt_misc support for wine to be able to run cross compiled test applications.") + endif() + else() + list(APPEND FOOTNOTES "NOTE: You will not be able to run cross compiled applications on your host system.") + endif() +endif() + +MACRO(TIMESTAMP RESULT) + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE DATE) + string(REGEX REPLACE "(..)[/.](..)[/.](....).*" "\\3\\2\\1" DATE ${DATE}) + EXECUTE_PROCESS(COMMAND "cmd" " /C time /T" OUTPUT_VARIABLE TIME) + string(REGEX REPLACE "(..):(..)" "\\1\\2" TIME ${TIME}) + set (${RESULT} "${DATE}${TIME}") + else () + EXECUTE_PROCESS(COMMAND "date" "+%Y%m%d%H%M" OUTPUT_VARIABLE ${RESULT}) + endif () +ENDMACRO() + +macro(add_test_executable _target _source) + add_executable(${_target} ${_source}) + target_link_libraries(${_target} ${ARGN}) + if (CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows") + # run tests with binfmt_misc + set(PREFIX "z:") + set(_env "DBUS_TEST_DAEMON=${PREFIX}${CMAKE_BINARY_DIR}/bin/dbus-daemon${EXEEXT}") + add_test(NAME ${_target} COMMAND $<TARGET_FILE:${_target}> --tap) + else() + set(PREFIX) + set(_env "DBUS_TEST_DAEMON=${CMAKE_BINARY_DIR}/bin/dbus-daemon${EXEEXT}") + add_test(NAME ${_target} COMMAND $<TARGET_FILE:${_target}> --tap) + endif() + list(APPEND _env "DBUS_SESSION_BUS_ADDRESS=") + list(APPEND _env "DBUS_FATAL_WARNINGS=1") + list(APPEND _env "DBUS_TEST_DATA=${PREFIX}${CMAKE_BINARY_DIR}/test/data") + list(APPEND _env "DBUS_TEST_HOMEDIR=${PREFIX}${CMAKE_BINARY_DIR}/dbus") + set_tests_properties(${_target} PROPERTIES ENVIRONMENT "${_env}") +endmacro(add_test_executable) + +macro(add_helper_executable _target _source) + add_executable(${_target} ${_source}) + target_link_libraries(${_target} ${ARGN}) +endmacro(add_helper_executable)
diff --git a/cmake/modules/MacrosAutotools.cmake b/cmake/modules/MacrosAutotools.cmake new file mode 100644 index 0000000..8bb83cd --- /dev/null +++ b/cmake/modules/MacrosAutotools.cmake
@@ -0,0 +1,168 @@ +# +# cmake package for autotools support +# +# @Author Ralf Habacker +# + +# +# load autotools configure file into an internal list named _configure_ac +# +macro(autoinit config) + set(_configure_ac_name ${config}) + file(READ ${config} _configure_ac_raw) + # Convert file contents into a CMake list (where each element in the list + # is one line of the file) + STRING(REGEX REPLACE ";" "\\\\;" _configure_ac "${_configure_ac_raw}") + STRING(REGEX REPLACE "\n" ";" _configure_ac "${_configure_ac}") +endmacro() + +# extracts version information from autoconf config file +# and set related cmake variables +# +# returns +# ${prefix}_VERSION +# ${prefix}_VERSION_STRING +# ${prefix}_MAJOR_VERSION +# ${prefix}_MINOR_VERSION +# ${prefix}_MICRO_VERSION +# ${prefix}_LIBRARY_AGE +# ${prefix}_LIBRARY_REVISION +# ${prefix}_LIBRARY_CURRENT +# +macro(autoversion prefix) + string(TOUPPER ${prefix} prefix_upper) + string (REGEX REPLACE ".*${prefix}_major_version], .([0-9]+).*" "\\1" ${prefix_upper}_MAJOR_VERSION ${_configure_ac_raw}) + string (REGEX REPLACE ".*${prefix}_minor_version], .([0-9]+).*" "\\1" ${prefix_upper}_MINOR_VERSION ${_configure_ac_raw}) + string (REGEX REPLACE ".*${prefix}_micro_version], .([0-9]+).*" "\\1" ${prefix_upper}_MICRO_VERSION ${_configure_ac_raw}) + set (${prefix_upper}_VERSION ${${prefix_upper}_MAJOR_VERSION}.${${prefix_upper}_MINOR_VERSION}.${${prefix_upper}_MICRO_VERSION}) + set (${prefix_upper}_VERSION_STRING "${${prefix_upper}_VERSION}") + string (REGEX REPLACE ".*LT_AGE=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_AGE ${_configure_ac_raw}) + string (REGEX REPLACE ".*LT_CURRENT=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_CURRENT ${_configure_ac_raw}) + string (REGEX REPLACE ".*LT_REVISION=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_REVISION ${_configure_ac_raw}) +endmacro() + +# +# Defines package related variables (PACKAGE_..., PACKAGE and VERSION) +# as done by autotools. +# +# Additional it defines a cmake variable named PACKAGE_CONFIG_H_TEMPLATE +# which could be placed in config.h templates to have those variables +# defined at code level like shown below: +# +# config.h.template +# ... +# @AUTOPACKAGE_CONFIG_H_TEMPLATE@ +# ... +# +macro(autopackage name version url support_url) + # Define to the full name of this package. + set(PACKAGE_NAME ${name}) + + # Define to the version of this package. + set(PACKAGE_VERSION ${version}) + + # Define to the home page for this package. + set(PACKAGE_URL ${url}) + + # Define to the address where bug reports for this package should be sent. + set(PACKAGE_BUGREPORT ${support_url}) + + # Define to the full name and version of this package. + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") + + # Define to the one symbol short name of this package. + set(PACKAGE_TARNAME ${PACKAGE_NAME}) + + set(PACKAGE ${name}) + set(VERSION ${DBUS_VERSION_STRING}) + + string(CONFIGURE "/* generated by cmake macro autopackage */\n +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT \"@PACKAGE_BUGREPORT@\" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME \"@PACKAGE_NAME@\" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING \"@PACKAGE_STRING@\" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME \"@PACKAGE_TARNAME@\" + +/* Define to the home page for this package. */ +#define PACKAGE_URL \"@PACKAGE_URL@\" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION \"@PACKAGE_VERSION@\" + +/* defined by autotools package */ +#define PACKAGE \"@PACKAGE@\" +#define VERSION \"@VERSION@\" +" AUTOPACKAGE_CONFIG_H_TEMPLATE) +endmacro(autopackage) + +# +# define a cmake variable from autotools AC_DEFINE statement +# +macro(autodefine name) + foreach(line ${_configure_ac}) + if(line MATCHES ".*AC_DEFINE(.*${name}.*).*") + string (REGEX REPLACE ".*AC_DEFINE(.*).*" "\\1" value ${line}) + string (REGEX REPLACE ".*,(.*),.*" "\\1" value2 ${value}) + string (REPLACE "[" "" value3 ${value2}) + string (REPLACE "]" "" value4 ${value3}) + set(${name} ${value4}) + endif() + endforeach() +endmacro() + +macro(autoheaderchecks config_h_in configure_checks_file config_h_cmake) + file(READ ${configure_checks_file} configure_checks_file_raw) + file(READ ${config_h_in} _config_h_in_raw) + file(READ ${config_h_cmake} _config_h_cmake_raw) + STRING(REGEX REPLACE ";" "\\\\;" _config_h_in "${_config_h_in_raw}") + STRING(REGEX REPLACE "\n" ";" _config_h_in "${_config_h_in}") + foreach(line ${_config_h_in}) + #message(STATUS ${line}) + if(line MATCHES ".*HAVE_.*_H.*") + string (REGEX REPLACE ".*HAVE_(.*)_H.*" "\\1" key ${line}) + set(full_key "HAVE_${key}_H") + if(key MATCHES ".*_.*") + string(REGEX MATCH "^[A-Z0-9]+" dir ${key}) + string(REGEX MATCH "[A-Z0-9]+$" file ${key}) + string(TOLOWER ${dir} dirname) + string(TOLOWER ${file} filename) + set(check "check_include_file(${dirname}/${filename}.h ${full_key})") + set(config_define "#cmakedefine ${full_key}") + else() + set(file ${key}) + string(TOLOWER ${file} filename) + set(check "check_include_file(${filename}.h ${full_key})") + set(config_define "#cmakedefine ${full_key}") + endif() + if(NOT configure_checks_file_raw MATCHES ".*${full_key}.*") + message("${check}") + endif() + if(NOT _config_h_cmake_raw MATCHES "${full_key}") + message("${config_define}") + endif() + endif() + endforeach() +endmacro(autoheaderchecks) + +# +# parses config.h template and create cmake equivalent +# not implemented yet +# +macro(autoconfig template output) + file(READ ${template} contents) + # Convert file contents into a CMake list (where each element in the list + # is one line of the file) + STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}") + STRING(REGEX REPLACE "\n" ";" contents "${contents}") + foreach(line contents) + message(STATUS ${line}) + # find #undef lines + # append to config.h #define <variable-name> <variable-content> + endforeach() +endmacro()
diff --git a/cmake/modules/ProjectSourceGroup.cmake b/cmake/modules/ProjectSourceGroup.cmake new file mode 100644 index 0000000..713a67a --- /dev/null +++ b/cmake/modules/ProjectSourceGroup.cmake
@@ -0,0 +1,18 @@ +# folders in the msvc projects +# mode==flat : headers and ourses in no folders +# mode==split : standard behavior of cmake, split headers and sources +# mode== <other values" : code is in this folder +macro(project_source_group mode sources headers) + #message(STATUS ${mode}) + #message(STATUS ${sources} ${headers}) + if(${mode} MATCHES "flat") + source_group("Source Files" Files) + source_group("Header Files" Files) + source_group("cmake" FILES CMakeLists.txt) + else(${mode} MATCHES "flat") + if(NOT ${mode} MATCHES "split") + source_group("${mode}" FILES ${${sources}} ${${headers}}) + endif(NOT ${mode} MATCHES "split") + endif(${mode} MATCHES "flat") +endmacro(project_source_group mode sources headers) +
diff --git a/cmake/modules/Win32Macros.cmake b/cmake/modules/Win32Macros.cmake new file mode 100644 index 0000000..4385cc9 --- /dev/null +++ b/cmake/modules/Win32Macros.cmake
@@ -0,0 +1,44 @@ +# +# win32 macros +# +# Copyright (c) 2006-2007, Ralf Habacker +# +# Redistribution and use is allowed according to the terms of the BSD license. +# + +if (WIN32) + # + # addExplorerWrapper creates batch files for fast access + # to the build environment from the win32 explorer. + # + # For mingw and nmake projects it's opens a command shell, + # for Visual Studio IDE's (at least tested with VS 8 2005) it + # opens the related .sln file with paths setting specified at + # configure time. + # + MACRO (addExplorerWrapper _projectname) + # write explorer wrappers + get_filename_component(CMAKE_BIN_PATH ${CMAKE_COMMAND} PATH) + set (ADD_PATH "${CMAKE_BIN_PATH}") + + if (QT_QMAKE_EXECUTABLE) + get_filename_component(QT_BIN_PATH ${QT_QMAKE_EXECUTABLE} PATH) + set (ADD_PATH "${ADD_PATH};${QT_BIN_PATH}") + endif (QT_QMAKE_EXECUTABLE) + + # add here more pathes + + if (MINGW) + get_filename_component(MINGW_BIN_PATH ${CMAKE_CXX_COMPILER} PATH) + set (ADD_PATH "${ADD_PATH};${MINGW_BIN_PATH}") + write_file (${CMAKE_BINARY_DIR}/${_projectname}-shell.bat "set PATH=${ADD_PATH};%PATH%\ncmd.exe") + else (MINGW) + if (CMAKE_BUILD_TOOL STREQUAL "nmake") + get_filename_component(VC_BIN_PATH ${CMAKE_CXX_COMPILER} PATH) + write_file (${CMAKE_BINARY_DIR}/${_projectname}-shell.bat "set PATH=${ADD_PATH};%PATH%\ncall \"${VC_BIN_PATH}\\vcvars32.bat\"\ncmd.exe") + else (CMAKE_BUILD_TOOL STREQUAL "nmake") + write_file (${CMAKE_BINARY_DIR}/${_projectname}-sln.bat "set PATH=${ADD_PATH};%PATH%\nstart ${_projectname}.sln") + endif (CMAKE_BUILD_TOOL STREQUAL "nmake") + endif (MINGW) + ENDMACRO (addExplorerWrapper) +endif(WIN32)
diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt new file mode 100644 index 0000000..e78af7a --- /dev/null +++ b/cmake/test/CMakeLists.txt
@@ -0,0 +1,185 @@ +include_directories(${CMAKE_SOURCE_DIR}/../test) + +add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS}) + +include_directories(${CMAKE_SOURCE_DIR}/../test) + +set(DBUS_SESSION_BUS_LISTEN_ADDRESS ${TEST_LISTEN}) + +add_library(dbus-testutils STATIC + ${CMAKE_SOURCE_DIR}/../test/test-utils.h + ${CMAKE_SOURCE_DIR}/../test/test-utils.c +) +target_link_libraries(dbus-testutils ${DBUS_INTERNAL_LIBRARIES}) + +add_subdirectory( name-test ) + +set (manual-dir-iter_SOURCES + ${CMAKE_SOURCE_DIR}/../test/manual-dir-iter.c +) + +set (test-service_SOURCES + ${CMAKE_SOURCE_DIR}/../test/test-service.c +) + +set (test-names_SOURCES + ${CMAKE_SOURCE_DIR}/../test/test-names.c +) + +set (break_loader_SOURCES + ${CMAKE_SOURCE_DIR}/../test/break-loader.c +) + +set (test-shell-service_SOURCES + ${CMAKE_SOURCE_DIR}/../test/test-shell-service.c +) + +set (test-shell_SOURCES + ${CMAKE_SOURCE_DIR}/../test/shell-test.c +) + +set (test-spawn_SOURCES + ${CMAKE_SOURCE_DIR}/../test/spawn-test.c +) + +set (test-exit_SOURCES + ${CMAKE_SOURCE_DIR}/../test/test-exit.c +) + +set (test-segfault_SOURCES + ${CMAKE_SOURCE_DIR}/../test/test-segfault.c +) + +set (test-sleep-forever_SOURCES + ${CMAKE_SOURCE_DIR}/../test/test-sleep-forever.c +) + +set (manual-tcp_SOURCES + ${CMAKE_SOURCE_DIR}/../test/manual-tcp.c +) + +set (manual-paths_SOURCES + ${CMAKE_SOURCE_DIR}/../test/manual-paths.c +) + +add_helper_executable(manual-dir-iter ${manual-dir-iter_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +add_helper_executable(test-service ${test-service_SOURCES} dbus-testutils) +add_helper_executable(test-names ${test-names_SOURCES} dbus-testutils) +add_test_executable(test-shell ${test-shell_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +add_test_executable(test-printf ${CMAKE_SOURCE_DIR}/../test/internals/printf.c dbus-testutils) +add_helper_executable(test-shell-service ${test-shell-service_SOURCES} dbus-testutils) +add_helper_executable(test-spawn ${test-spawn_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +add_helper_executable(test-exit ${test-exit_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +add_helper_executable(test-segfault ${test-segfault_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +add_helper_executable(test-sleep-forever ${test-sleep-forever_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +add_helper_executable(manual-tcp ${manual-tcp_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +if(WIN32) + add_helper_executable(manual-paths ${manual-paths_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +endif() + +if(DBUS_WITH_GLIB) + message(STATUS "with glib test apps") + + add_library(dbus-testutils-glib STATIC + ${CMAKE_SOURCE_DIR}/../test/test-utils-glib.h + ${CMAKE_SOURCE_DIR}/../test/test-utils-glib.c + ) + target_link_libraries(dbus-testutils-glib dbus-testutils ${DBUS_INTERNAL_LIBRARIES}) + + add_definitions( + ${GLIB2_DEFINITIONS} + ${GOBJECT_DEFINITIONS} + ) + include_directories( + ${GLIB2_INCLUDE_DIR} + ${GOBJECT_INCLUDE_DIR} + ) + + set(TEST_LIBRARIES ${DBUS_INTERNAL_LIBRARIES} dbus-testutils dbus-testutils-glib ${GLIB2_LIBRARIES} ${GOBJECT_LIBRARIES}) + + add_test_executable(test-corrupt ${CMAKE_SOURCE_DIR}/../test/corrupt.c ${TEST_LIBRARIES}) + add_test_executable(test-dbus-daemon ${CMAKE_SOURCE_DIR}/../test/dbus-daemon.c ${TEST_LIBRARIES}) + add_test_executable(test-dbus-daemon-eavesdrop ${CMAKE_SOURCE_DIR}/../test/dbus-daemon-eavesdrop.c ${TEST_LIBRARIES}) + add_test_executable(test-fdpass ${CMAKE_SOURCE_DIR}/../test/fdpass.c ${TEST_LIBRARIES}) + add_test_executable(test-loopback ${CMAKE_SOURCE_DIR}/../test/loopback.c ${TEST_LIBRARIES}) + add_test_executable(test-marshal ${CMAKE_SOURCE_DIR}/../test/marshal.c ${TEST_LIBRARIES}) + add_test_executable(test-monitor ${CMAKE_SOURCE_DIR}/../test/monitor.c ${TEST_LIBRARIES}) + add_test_executable(test-refs ${CMAKE_SOURCE_DIR}/../test/internals/refs.c ${TEST_LIBRARIES}) + add_test_executable(test-relay ${CMAKE_SOURCE_DIR}/../test/relay.c ${TEST_LIBRARIES}) + add_test_executable(test-syntax ${CMAKE_SOURCE_DIR}/../test/syntax.c ${TEST_LIBRARIES}) + add_test_executable(test-syslog ${CMAKE_SOURCE_DIR}/../test/internals/syslog.c ${TEST_LIBRARIES}) + add_helper_executable(manual-authz ${CMAKE_SOURCE_DIR}/../test/manual-authz.c ${TEST_LIBRARIES}) +endif() + +### keep these in creation order, i.e. uppermost dirs first +set (TESTDIRS + test/data + test/data/valid-messages + test/data/invalid-messages + test/data/incomplete-messages + test/data/auth + test/data/sha-1 + test/data/systemd-activation + test/data/valid-config-files + test/data/valid-config-files/basic.d + test/data/valid-config-files/session.d + test/data/valid-config-files-system + test/data/valid-config-files-system/system.d + test/data/valid-introspection-files + test/data/valid-messages + test/data/valid-service-files + test/data/valid-service-files-system + test/data/invalid-config-files + test/data/invalid-config-files-system + test/data/invalid-messages + test/data/invalid-service-files-system + test/data/equiv-config-files + test/data/equiv-config-files/basic + test/data/equiv-config-files/basic/basic.d + test/data/equiv-config-files/entities + test/data/equiv-config-files/entities/basic.d +) +set (CONFIG_VERBOSE 0) + +FOREACH(DIR ${TESTDIRS}) + FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DIR}) +ENDFOREACH(DIR) + +### copy tests to builddir so that generated tests and static tests +### are all in one place. +MESSAGE(STATUS "Copying test files to test directory") +FOREACH(FILE_TYPE *.message *.message-raw *.auth-script *.sha1 *.txt *.conf *.service) + FOREACH(DIR ${TESTDIRS}) + FILE(GLOB FILES "${CMAKE_SOURCE_DIR}/../${DIR}/${FILE_TYPE}" ) + FOREACH(FILE ${FILES}) + GET_FILENAME_COMPONENT(FILENAME ${FILE} NAME) + SET (TARGET ${CMAKE_BINARY_DIR}/${DIR}/${FILENAME}) + configure_file(${FILE} ${TARGET} COPYONLY) + IF (CONFIG_VERBOSE) + MESSAGE("${FILE}") + ENDIF (CONFIG_VERBOSE) + ENDFOREACH(FILE) + ENDFOREACH(DIR) +ENDFOREACH(FILE_TYPE) + +### generate test files +MESSAGE(STATUS "Generating test files from templates into test directory") + +FOREACH(FILE_TYPE *.conf.in *.service.in) + FOREACH(DIR ${TESTDIRS}) + FILE(GLOB FILES "${CMAKE_SOURCE_DIR}/../${DIR}/${FILE_TYPE}" ) + FOREACH(FILE ${FILES}) + GET_FILENAME_COMPONENT(FILENAME ${FILE} NAME) + STRING(REGEX REPLACE "\\.in$" "" FILENAME ${FILENAME}) + SET (TARGET ${CMAKE_BINARY_DIR}/${DIR}/${FILENAME}) + configure_file(${FILE} ${TARGET} @ONLY IMMEDIATE) + IF (CONFIG_VERBOSE) + MESSAGE("${FILE}") + ENDIF (CONFIG_VERBOSE) + ENDFOREACH(FILE) + ENDFOREACH(DIR) +ENDFOREACH(FILE_TYPE) + +MESSAGE(STATUS "Copying generated bus config files to test directory") +configure_file("${CMAKE_SOURCE_DIR}/../bus/session.conf.in" ${CMAKE_BINARY_DIR}/test/data/valid-config-files/session.conf @ONLY) +configure_file("${CMAKE_SOURCE_DIR}/../bus/system.conf.in" ${CMAKE_BINARY_DIR}/test/data/valid-config-files-system/system.conf @ONLY)
diff --git a/cmake/test/name-test/CMakeLists.txt b/cmake/test/name-test/CMakeLists.txt new file mode 100644 index 0000000..befb28f --- /dev/null +++ b/cmake/test/name-test/CMakeLists.txt
@@ -0,0 +1,15 @@ +if (DBUS_ENABLE_EMBEDDED_TESTS) + +set (NAMEtest-DIR ../../../test/name-test) + +add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS}) + +add_helper_executable(test-pending-call-dispatch ${NAMEtest-DIR}/test-pending-call-dispatch.c ${DBUS_INTERNAL_LIBRARIES}) +add_helper_executable(test-pending-call-timeout ${NAMEtest-DIR}/test-pending-call-timeout.c ${DBUS_INTERNAL_LIBRARIES}) +add_helper_executable(test-thread-init ${NAMEtest-DIR}/test-threads-init.c ${DBUS_INTERNAL_LIBRARIES}) +add_helper_executable(test-ids ${NAMEtest-DIR}/test-ids.c ${DBUS_INTERNAL_LIBRARIES}) +add_helper_executable(test-shutdown ${NAMEtest-DIR}/test-shutdown.c dbus-testutils) +add_helper_executable(test-privserver ${NAMEtest-DIR}/test-privserver.c dbus-testutils) +add_helper_executable(test-privserver-client ${NAMEtest-DIR}/test-privserver-client.c dbus-testutils) +add_helper_executable(test-autolaunch ${NAMEtest-DIR}/test-autolaunch.c dbus-testutils) +endif (DBUS_ENABLE_EMBEDDED_TESTS)
diff --git a/cmake/tools/CMakeLists.txt b/cmake/tools/CMakeLists.txt new file mode 100644 index 0000000..6a2e999 --- /dev/null +++ b/cmake/tools/CMakeLists.txt
@@ -0,0 +1,81 @@ +add_definitions("-DDBUS_COMPILATION") + +set (dbus_send_SOURCES + ../../tools/dbus-print-message.c + ../../tools/dbus-print-message.h + ../../tools/dbus-send.c + ../../tools/tool-common.c + ../../tools/tool-common.h +) + +set (dbus_monitor_SOURCES + ../../tools/dbus-monitor.c + ../../tools/dbus-print-message.c + ../../tools/dbus-print-message.h + ../../tools/tool-common.c + ../../tools/tool-common.h +) + +set (dbus_test_tool_SOURCES + ../../tools/dbus-echo.c + ../../tools/dbus-spam.c + ../../tools/tool-common.c + ../../tools/tool-common.h + ../../tools/test-tool.c + ../../tools/test-tool.h +) + +set (dbus_update_activation_environment_SOURCES + ../../tools/dbus-update-activation-environment.c + ../../tools/tool-common.c + ../../tools/tool-common.h +) + +if (WIN32) +set (dbus_launch_SOURCES + ../../tools/dbus-launch-win.c +) +else (WIN32) +set (dbus_launch_SOURCES + ../../tools/dbus-launch.c + ../../tools/tool-common.c + ../../tools/tool-common.h +) +endif (WIN32) + +if (DBUS_BUILD_X11) +set (dbus_launch_SOURCES + ${dbus_launch_SOURCES} + ../../tools/dbus-launch-x11.c +) +endif(DBUS_BUILD_X11) + +set (dbus_cleanup_sockets_SOURCES + ../../tools/dbus-cleanup-sockets.c +) + +add_executable(dbus-send ${dbus_send_SOURCES}) +target_link_libraries(dbus-send ${DBUS_LIBRARIES}) +install_targets(/bin dbus-send ) + +add_executable(dbus-test-tool ${dbus_test_tool_SOURCES}) +target_link_libraries(dbus-test-tool ${DBUS_LIBRARIES}) +install_targets(/bin dbus-test-tool ) + +add_executable(dbus-update-activation-environment ${dbus_update_activation_environment_SOURCES}) +target_link_libraries(dbus-update-activation-environment ${DBUS_LIBRARIES}) +install_targets(/bin dbus-update-activation-environment ) + +add_executable(dbus-launch ${dbus_launch_SOURCES}) +target_link_libraries(dbus-launch ${DBUS_LIBRARIES}) +if (DBUS_BUILD_X11) + target_link_libraries(dbus-launch ${X11_LIBRARIES} ) +endif (DBUS_BUILD_X11) +install_targets(/bin dbus-launch ) + +add_executable(dbus-monitor ${dbus_monitor_SOURCES}) +target_link_libraries(dbus-monitor ${DBUS_LIBRARIES}) +install_targets(/bin dbus-monitor ) + +# create the /var/lib/dbus directory for dbus-uuidgen +install(DIRECTORY DESTINATION var/lib/dbus)
diff --git a/config.h b/config.h new file mode 100644 index 0000000..065e11d --- /dev/null +++ b/config.h
@@ -0,0 +1,534 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* poll doesn't work on devices */ +/* #undef BROKEN_POLL */ + +/* Directory for installing the binaries */ +#define DBUS_BINDIR "/system/bin" + +/* Define to build X11 functionality */ +/* #undef DBUS_BUILD_X11 */ + +/* whether -export-dynamic was passed to libtool */ +/* #undef DBUS_BUILT_R_DYNAMIC */ + +/* Use inotify */ +#define DBUS_BUS_ENABLE_INOTIFY 1 + +/* Use kqueue */ +/* #undef DBUS_BUS_ENABLE_KQUEUE */ + +/* Directory to check for console ownerhip */ +#define DBUS_CONSOLE_AUTH_DIR "/etc" + +/* File to check for console ownerhip */ +/* #undef DBUS_CONSOLE_OWNER_FILE */ + +/* Defined if we run on a cygwin API based system */ +/* #undef DBUS_CYGWIN */ + +/* Directory for installing the DBUS daemon */ +#define DBUS_DAEMONDIR "/system/bin" + +/* Name of executable */ +#define DBUS_DAEMON_NAME "dbus-daemon" + +/* Directory for installing DBUS data files */ +#define DBUS_DATADIR "/data" + +/* Disable assertion checking */ +/* #undef DBUS_DISABLE_ASSERT */ + +/* Disable public API sanity checking */ +/* #undef DBUS_DISABLE_CHECKS */ + +/* Define to build test code into the library and binaries */ +/* #undef DBUS_ENABLE_EMBEDDED_TESTS */ + +/* Use launchd autolaunch */ +/* #undef DBUS_ENABLE_LAUNCHD */ + +/* Define to build independent test binaries */ +/* #undef DBUS_ENABLE_MODULAR_TESTS */ + +/* Define to enable bus daemon usage statistics */ +/* #undef DBUS_ENABLE_STATS */ + +/* Support a verbose mode */ +/* #undef DBUS_ENABLE_VERBOSE_MODE */ + +/* Define to enable X11 auto-launch */ +/* #undef DBUS_ENABLE_X11_AUTOLAUNCH */ + +/* Extension for executables, typically empty or .exe */ +#define DBUS_EXEEXT "" + +/* Defined if gcov is enabled to force a rebuild due to config.h changing */ +/* #undef DBUS_GCOV_ENABLED */ + +/* Define to use epoll(4) on Linux */ +#define DBUS_HAVE_LINUX_EPOLL 1 + +/* Define to printf modifier for 64 bit integer type */ +#define DBUS_INT64_PRINTF_MODIFIER "ll" + +/* Directory for installing the libexec binaries */ +#define DBUS_LIBEXECDIR "/system/bin" + +/* Prefix for installing DBUS */ +#define DBUS_PREFIX "/system" + +/* Fallback address for session bus clients */ +#define DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" + +/* Where per-session bus puts its sockets */ +#define DBUS_SESSION_SOCKET_DIR "/data" + +/* The default D-Bus address of the system bus */ +#define DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "unix:path="DBUS_SYSTEM_SOCKET + +/* The name of the socket the system bus listens on by default */ +#define DBUS_SYSTEM_SOCKET "/dev/socket/dbus" + +/* Full path to the daemon in the builddir */ +#define DBUS_TEST_EXEC "/system/bin/dbus-test" + +/* Full path to the launch helper test program in the builddir */ +#define DBUS_TEST_LAUNCH_HELPER_BINARY "/system/bin/dbus-daemon-launch-helper-test" + +/* Where to put test sockets */ +#define DBUS_TEST_SOCKET_DIR "/data" + +/* Unprivileged user used in some regression tests */ +#define DBUS_TEST_USER "nobody" + +/* Defined if we run on a Unix-based system */ +#define DBUS_UNIX 1 + +/* User for running the system BUS daemon */ +/* #undef DBUS_USER "messagebus" */ + +/* Use the gcc __sync extension */ +#define DBUS_USE_SYNC 1 + +/* A 'va_copy' style function */ +#define DBUS_VA_COPY va_copy + +/* 'va_lists' cannot be copies as values */ +/* #undef DBUS_VA_COPY_AS_ARRAY */ + +/* Defined if we run on a W32 API based system */ +/* #undef DBUS_WIN */ + +/* Defined if we run on a W32 CE API based system */ +/* #undef DBUS_WINCE */ + +/* Define if GLib, GObject, GIO are available */ +/* #undef DBUS_WITH_GLIB */ + +/* The maximum number of connections that can be handled at once */ +/* #undef FD_SETSIZE */ + +/* The name of the gettext domain */ +/* #undef GETTEXT_PACKAGE "dbus-1" */ + +/* Prevent post-2.38 APIs */ +#define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_38 + +/* Ignore post-2.36 deprecations */ +#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_36 + +/* Disable GLib public API sanity checking */ +/* #undef G_DISABLE_CHECKS */ + +/* Have abstract socket namespace */ +#define HAVE_ABSTRACT_SOCKETS 1 + +/* Define to 1 if you have the `accept4' function. */ +#define HAVE_ACCEPT4 1 + +/* Adt audit API */ +/* #undef HAVE_ADT */ + +/* Define to 1 if you have the <alloca.h> header file. */ +#define HAVE_ALLOCA_H 1 + +/* AppArmor Support */ +/* #undef HAVE_APPARMOR */ + +/* Define to 1 if you have backtrace(). */ +/* #undef HAVE_BACKTRACE */ + +/* Define to 1 if you have the <byteswap.h> header file. */ +#define HAVE_BYTESWAP_H 1 + +/* Define to 1 if you have the `clearenv' function. */ +#define HAVE_CLEARENV 1 + +/* Have cmsgcred structure */ +/* #undef HAVE_CMSGCRED */ + +/* Have console owner file */ +/* #undef HAVE_CONSOLE_OWNER_FILE */ + +/* Define to 1 if you have the <crt_externs.h> header file. */ +/* #undef HAVE_CRT_EXTERNS_H */ + +/* Have the ddfd member of DIR */ +/* #undef HAVE_DDFD */ + +/* Define to 1 if you have the declaration of `LOG_PERROR', and to 0 if you + don't. */ +#define HAVE_DECL_LOG_PERROR 1 + +/* Define to 1 if you have the declaration of `MSG_NOSIGNAL', and to 0 if you + don't. */ +#define HAVE_DECL_MSG_NOSIGNAL 1 + +/* Define to 1 if you have the <dirent.h> header file. */ +#define HAVE_DIRENT_H 1 + +/* Have dirfd function */ +/* #undef HAVE_DIRFD */ + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the <errno.h> header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the <execinfo.h> header file. */ +#define HAVE_EXECINFO_H 1 + +/* Define to 1 if you have the <expat.h> header file. */ +#define HAVE_EXPAT_H 1 + +/* Define to 1 if you have the `fpathconf' function. */ +/* #undef HAVE_FPATHCONF */ + +/* Define to 1 if you have the `getgrouplist' function. */ +#define HAVE_GETGROUPLIST 1 + +/* Define to 1 if you have the `getpeereid' function. */ +/* #undef HAVE_GETPEEREID */ + +/* Define to 1 if you have the `getpeerucred' function. */ +/* #undef HAVE_GETPEERUCRED */ + +/* Define to 1 if you have the `getresuid' function. */ +#define HAVE_GETRESUID 1 + +/* Define to 1 if you have the `getrlimit' function. */ +#define HAVE_GETRLIMIT 1 + +/* Have GNU-style varargs macros */ +/* #undef HAVE_GNUC_VARARGS */ + +/* Define to 1 if you have the `inotify_init1' function. */ +#define HAVE_INOTIFY_INIT1 1 + +/* Define to 1 if you have the <inttypes.h> header file. */ +#define HAVE_INTTYPES_H 1 + +/* Have ISO C99 varargs macros */ +#define HAVE_ISO_VARARGS 1 + +/* Define to 1 if you have the `issetugid' function. */ +/* #undef HAVE_ISSETUGID */ + +/* audit daemon SELinux support */ +/* #undef HAVE_LIBAUDIT */ + +/* Define to 1 if you have the `nsl' library (-lnsl). */ +/* #undef HAVE_LIBNSL */ + +/* Define to 1 if you have the `localeconv' function. */ +#define HAVE_LOCALECONV 1 + +/* Define to 1 if you have the <locale.h> header file. */ +#define HAVE_LOCALE_H 1 + +/* Define to 1 if you have the <memory.h> header file. */ +#define HAVE_MEMORY_H 1 + +/* Define if we have CLOCK_MONOTONIC */ +#define HAVE_MONOTONIC_CLOCK 1 + +/* Define to 1 if you have the `nanosleep' function. */ +#define HAVE_NANOSLEEP 1 + +/* Have non-POSIX function getpwnam_r */ +/* #undef HAVE_NONPOSIX_GETPWNAM_R */ + +/* Define if your system needs _NSGetEnviron to set up the environment */ +/* #undef HAVE_NSGETENVIRON */ + +/* Define to 1 if you have the `pipe2' function. */ +#define HAVE_PIPE2 1 + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Have POSIX function getpwnam_r */ +/* #undef HAVE_POSIX_GETPWNAM_R */ + +/* Define to 1 if you have the `prctl' function. */ +#define HAVE_PRCTL 1 + +/* Define to 1 if you have the `raise' function. */ +#define HAVE_RAISE 1 + +/* SELinux support */ +/* #undef HAVE_SELINUX */ + +/* Define to 1 if you have the `setenv' function. */ +#define HAVE_SETENV 1 + +/* Define to 1 if you have the `setlocale' function. */ +#define HAVE_SETLOCALE 1 + +/* Define to 1 if you have the `setresuid' function. */ +#define HAVE_SETRESUID 1 + +/* Define to 1 if you have the `setrlimit' function. */ +#define HAVE_SETRLIMIT 1 + +/* Define to 1 if you have the <signal.h> header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if you have the `socketpair' function. */ +#define HAVE_SOCKETPAIR 1 + +/* Have socklen_t type */ +#define HAVE_SOCKLEN_T 1 + +/* Define to 1 if you have the <stdint.h> header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the <stdlib.h> header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the <strings.h> header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the <string.h> header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strtoll' function. */ +#define HAVE_STRTOLL 1 + +/* Define to 1 if you have the `strtoull' function. */ +#define HAVE_STRTOULL 1 + +/* Define to 1 if you have the <syslog.h> header file. */ +#define HAVE_SYSLOG_H 1 + +/* Have systemd */ +/* #undef HAVE_SYSTEMD */ + +/* Define to 1 if you have the <sys/inotify.h> header file. */ +#define HAVE_SYS_INOTIFY_H 1 + +/* Define to 1 if you have the <sys/prctl.h> header file. */ +#define HAVE_SYS_PRCTL_H 1 + +/* Define to 1 if you have the <sys/resource.h> header file. */ +#define HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the <sys/syslimits.h> header file. */ +/* #undef HAVE_SYS_SYSLIMITS_H */ + +/* Define to 1 if you have the <sys/types.h> header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the <sys/uio.h> header file. */ +#define HAVE_SYS_UIO_H 1 + +/* Define to 1 if you have the <unistd.h> header file. */ +#define HAVE_UNISTD_H 1 + +/* Supports sending UNIX file descriptors */ +#define HAVE_UNIX_FD_PASSING 1 + +/* Have unpcbid structure */ +/* #undef HAVE_UNPCBID */ + +/* Define to 1 if you have the `unsetenv' function. */ +#define HAVE_UNSETENV 1 + +/* Define to 1 if you have the `usleep' function. */ +#define HAVE_USLEEP 1 + +/* Define to 1 if you have the `vasprintf' function. */ +#define HAVE_VASPRINTF 1 + +/* Define to 1 or 0, depending whether the compiler supports simple visibility + declarations. */ +#define HAVE_VISIBILITY 1 + +/* Define to 1 if you have the `vsnprintf' function. */ +#define HAVE_VSNPRINTF 1 + +/* Define to 1 if you have the `writev' function. */ +#define HAVE_WRITEV 1 + +/* Define to 1 if you have the <ws2tcpip.h> header file. */ +/* #undef HAVE_WS2TCPIP_H */ + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "dbus" + +/* Define to the address where bug reports for this package should be sent. */ +/* #undef PACKAGE_BUGREPORT */ + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "dbus" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "dbus-1.10.12" + +/* Define to the one symbol short name of this package. */ +/* #undef PACKAGE_TARNAME */ + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.10.12" + +/* The size of `char', as computed by sizeof. */ +#define SIZEOF_CHAR 1 + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `long long', as computed by sizeof. */ +#define SIZEOF_LONG_LONG 8 + +/* The size of `short', as computed by sizeof. */ +#define SIZEOF_SHORT 2 + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 4 + +/* The size of `__int64', as computed by sizeof. */ +#define SIZEOF___INT64 8 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Full path to the dbus-launch in the builddir */ +#define TEST_BUS_LAUNCH_BINARY "/system/bin/dbus-launch" + +/* Listening address for regression tests */ +#define TEST_LISTEN "unix:tmpdir=/data" + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif + + +/* Version number of package */ +#define VERSION "1.10.12" + +/* Define to add Valgrind instrumentation */ +/* #undef WITH_VALGRIND */ + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + + + /* Use the compiler-provided endianness defines to allow universal compiling. */ + #if defined(__BIG_ENDIAN__) + #define WORDS_BIGENDIAN 1 + #endif + + +/* Define to 1 if the X Window System is missing or not being used. */ +#define X_DISPLAY_MISSING 1 + + +#if defined(HAVE_NSGETENVIRON) && defined(HAVE_CRT_EXTERNS_H) +# include <sys/time.h> +# include <crt_externs.h> +# define environ (*_NSGetEnviron()) +#endif + + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#define _FILE_OFFSET_BITS 64 + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to 1 if on MINIX. */ +/* #undef _MINIX */ + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +/* #undef _POSIX_1_SOURCE */ + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +/* #undef _POSIX_SOURCE */ + +/* Defined to get newer W32 CE APIs */ +/* #undef _WIN32_WCE */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + + +/* explicitly define these macros to get less confusing conditions */ +#ifndef DBUS_DISABLE_ASSERT +# define DBUS_ENABLE_ASSERT 1 +#endif +#ifndef DBUS_DISABLE_CHECKS +# define DBUS_ENABLE_CHECKS 1 +#endif
diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..b75a106 --- /dev/null +++ b/configure.ac
@@ -0,0 +1,1994 @@ +dnl -*- mode: m4 -*- +AC_PREREQ([2.63]) + +m4_define([dbus_major_version], [1]) +m4_define([dbus_minor_version], [10]) +m4_define([dbus_micro_version], [12]) +m4_define([dbus_version], + [dbus_major_version.dbus_minor_version.dbus_micro_version]) +AC_INIT([dbus],[dbus_version],[https://bugs.freedesktop.org/enter_bug.cgi?product=dbus],[dbus]) +AC_CONFIG_AUX_DIR([build-aux]) + +AC_CANONICAL_HOST + +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) + +AM_INIT_AUTOMAKE([1.13 tar-ustar -Wno-portability subdir-objects]) + +GETTEXT_PACKAGE=dbus-1 +AC_SUBST(GETTEXT_PACKAGE) +AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[The name of the gettext domain]) + +# By default, rebuild autotools files on demand; only use ./missing if the +# user says --disable-maintainer-mode (some distributions like to do this) +AM_MAINTAINER_MODE([enable]) + +m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) + +AC_DEFINE_UNQUOTED(DBUS_DAEMON_NAME,"dbus-daemon",[Name of executable]) + +# libtool versioning - this applies to libdbus +# +# See http://sources.redhat.com/autobook/autobook/autobook_91.html#SEC91 for details +# + +## increment if the interface has additions, changes, removals. +LT_CURRENT=17 + +## increment any time the source changes; set to +## 0 if you increment CURRENT +LT_REVISION=8 + +## increment if any interfaces have been added; set to 0 +## if any interfaces have been changed or removed. removal has +## precedence over adding, so set to 0 if both happened. +LT_AGE=14 + +AC_SUBST(LT_CURRENT) +AC_SUBST(LT_REVISION) +AC_SUBST(LT_AGE) +SOVERSION=`expr ${LT_CURRENT} - ${LT_AGE}` +AC_SUBST([SOVERSION]) + +DBUS_MAJOR_VERSION=dbus_major_version +DBUS_MINOR_VERSION=dbus_minor_version +DBUS_MICRO_VERSION=dbus_micro_version +DBUS_VERSION=dbus_major_version.dbus_minor_version.dbus_micro_version + +AC_SUBST(DBUS_MAJOR_VERSION) +AC_SUBST(DBUS_MINOR_VERSION) +AC_SUBST(DBUS_MICRO_VERSION) +AC_SUBST(DBUS_VERSION) + +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_CXX +AC_USE_SYSTEM_EXTENSIONS +AC_SYS_LARGEFILE +AC_ISC_POSIX +AC_HEADER_STDC +AC_C_INLINE +AM_PROG_LIBTOOL +AC_PROG_MKDIR_P +COMPILER_COVERAGE +COMPILER_OPTIMISATIONS +PKG_PROG_PKG_CONFIG + +# TAP test driver support +AC_PROG_AWK +AC_REQUIRE_AUX_FILE([tap-driver.sh]) + +# This must come before we set up compiler warnings because it assumes +# non-use of -Werror=missing-prototypes +gl_VISIBILITY +AM_CONDITIONAL([HAVE_VISIBILITY], [test "x$HAVE_VISIBILITY" = x1]) + +# Initialize libtool +LT_INIT([win32-dll]) +LT_LANG([Windows Resource]) + +# Set some internal variables depending on the platform for later use. +dbus_win=no +dbus_cygwin=no +dbus_unix=no +case "${host}" in + *-mingw32ce*) + dbus_win=yes + dbus_wince=yes + ;; + *-mingw32*) + dbus_win=yes + ;; + *-cygwin*) + dbus_cygwin=yes + dbus_unix=yes + ;; + *) + dbus_unix=yes + ;; +esac + +# Special defines for certain platforms +if test "$dbus_win" = yes; then + AC_DEFINE(DBUS_WIN,1,[Defined if we run on a W32 API based system]) + # Yes, on Windows it really does work like this. + # http://support.microsoft.com/kb/111855 + AC_DEFINE(FD_SETSIZE,8192,[The maximum number of connections that can be handled at once]) + BUILD_TIMESTAMP=`date --iso-8601=minutes` + AC_SUBST(BUILD_TIMESTAMP) + # Assume DBUS_VERSION is always three numbers + BUILD_FILEVERSION=`echo "$DBUS_VERSION" | sed -e 's/\./,/g'`,0 + AC_SUBST(BUILD_FILEVERSION) + AC_CHECK_TOOL(WINDRES, windres, no) + if test "$WINDRES" = no; then + AC_MSG_ERROR([*** Could not find an implementation of windres in your PATH.]) + fi + if test "$dbus_wince" = yes; then + AC_DEFINE(DBUS_WINCE,1,[Defined if we run on a W32 CE API based system]) + AC_DEFINE(_WIN32_WCE, 0x0502, [Defined to get newer W32 CE APIs]) + fi +else + AC_DEFINE(DBUS_UNIX,1,[Defined if we run on a Unix-based system]) +fi +if test "$dbus_cygwin" = yes; then + AC_DEFINE(DBUS_CYGWIN,1,[Defined if we run on a cygwin API based system]) +fi + +# For best security, assume that all non-Windows platforms can do +# credentials-passing. +AS_IF([test "$dbus_win" = yes], + [DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL="<!--<auth>EXTERNAL</auth>-->"], + [DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL="<auth>EXTERNAL</auth>"]) +AC_SUBST([DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL]) + +AM_CONDITIONAL(DBUS_WIN, test "$dbus_win" = yes) +AM_CONDITIONAL(DBUS_WINCE, test "$dbus_wince" = yes) +AM_CONDITIONAL(DBUS_UNIX, test "$dbus_unix" = yes) +AM_CONDITIONAL(DBUS_CYGWIN, test "$dbus_cygwin" = yes) + +# this must come first: other options use this to set their defaults +AC_ARG_ENABLE([developer], + [AS_HELP_STRING([--enable-developer], + [set defaults to be appropriate for a D-Bus developer instead of a distribution/end-user])], + [], + [enable_developer=no]) + +DBUS_STATIC_BUILD_CPPFLAGS= +if test "x$enable_shared" = xno; then + # On Windows, linking against the static library requires special effort + # to turn off DLL import/export processing. We normally link some things + # against the dynamic library, but if we're not building that, we'll + # have to link everything statically. + DBUS_STATIC_BUILD_CPPFLAGS=-DDBUS_STATIC_BUILD +fi +AC_SUBST([DBUS_STATIC_BUILD_CPPFLAGS]) + +AC_ARG_ENABLE(ansi, AS_HELP_STRING([--enable-ansi],[enable -ansi -pedantic gcc flags]),enable_ansi=$enableval,enable_ansi=no) +AC_ARG_ENABLE(verbose-mode, AS_HELP_STRING([--enable-verbose-mode],[support verbose debug mode]),enable_verbose_mode=$enableval,enable_verbose_mode=$enable_developer) +AC_ARG_ENABLE(asserts, AS_HELP_STRING([--enable-asserts],[include assertion checks]),enable_asserts=$enableval,enable_asserts=$enable_developer) +AC_ARG_ENABLE(checks, AS_HELP_STRING([--enable-checks],[include sanity checks on public API]),enable_checks=$enableval,enable_checks=yes) +AC_ARG_ENABLE(xml-docs, AS_HELP_STRING([--enable-xml-docs],[build XML documentation (requires xmlto)]),enable_xml_docs=$enableval,enable_xml_docs=auto) +AC_ARG_ENABLE(doxygen-docs, AS_HELP_STRING([--enable-doxygen-docs],[build DOXYGEN documentation (requires Doxygen)]),enable_doxygen_docs=$enableval,enable_doxygen_docs=auto) +AC_ARG_ENABLE([ducktype-docs], + AS_HELP_STRING([--enable-ducktype-docs], + [build Ducktype documentation (requires Ducktype)]), + [enable_ducktype_docs=$enableval], [enable_ducktype_docs=auto]) +AC_ARG_ENABLE(abstract-sockets, AS_HELP_STRING([--enable-abstract-sockets],[use abstract socket namespace (linux only)]),enable_abstract_sockets=$enableval,enable_abstract_sockets=auto) +AC_ARG_ENABLE(selinux, AS_HELP_STRING([--enable-selinux],[build with SELinux support]),enable_selinux=$enableval,enable_selinux=auto) +AC_ARG_ENABLE([apparmor], + [AS_HELP_STRING([--enable-apparmor], [build with AppArmor support])], + [enable_apparmor=$enableval], + [enable_apparmor=auto]) +AC_ARG_ENABLE(libaudit,AS_HELP_STRING([--enable-libaudit],[build audit daemon support for SELinux]),enable_libaudit=$enableval,enable_libaudit=auto) +AC_ARG_ENABLE(inotify, AS_HELP_STRING([--enable-inotify],[build with inotify support (linux only)]),enable_inotify=$enableval,enable_inotify=auto) +AC_ARG_ENABLE(kqueue, AS_HELP_STRING([--enable-kqueue],[build with kqueue support]),enable_kqueue=$enableval,enable_kqueue=auto) +AC_ARG_ENABLE(console-owner-file, AS_HELP_STRING([--enable-console-owner-file],[enable console owner file]),enable_console_owner_file=$enableval,enable_console_owner_file=auto) +AC_ARG_ENABLE(launchd, AS_HELP_STRING([--enable-launchd],[build with launchd auto-launch support]),enable_launchd=$enableval,enable_launchd=auto) +AC_ARG_ENABLE(systemd, AS_HELP_STRING([--enable-systemd],[build with systemd at_console support]),enable_systemd=$enableval,enable_systemd=auto) + +AC_ARG_WITH(init-scripts, AS_HELP_STRING([--with-init-scripts=[redhat]],[Style of init scripts to install])) +AC_ARG_WITH(session-socket-dir, AS_HELP_STRING([--with-session-socket-dir=[dirname]],[Where to put sockets for the per-login-session message bus])) +AC_ARG_WITH(test-socket-dir, AS_HELP_STRING([--with-test-socket-dir=[dirname]],[Where to put sockets for make check])) +AC_ARG_WITH(system-pid-file, AS_HELP_STRING([--with-system-pid-file=[pidfile]],[PID file for systemwide daemon])) +AC_ARG_WITH(system-socket, AS_HELP_STRING([--with-system-socket=[filename]],[UNIX domain socket for systemwide daemon])) +AC_ARG_WITH(console-auth-dir, AS_HELP_STRING([--with-console-auth-dir=[dirname]],[directory to check for console ownerhip])) +AC_ARG_WITH(console-owner-file, AS_HELP_STRING([--with-console-owner-file=[filename]],[file whose owner determines current console owner])) +AC_ARG_WITH(launchd-agent-dir, AS_HELP_STRING([--with-launchd-agent-dir=[dirname]],[directory to put the launchd agent (default: /Library/LaunchAgents)])) +AC_ARG_WITH(dbus_user, AS_HELP_STRING([--with-dbus-user=<user>],[User for running the DBUS daemon (messagebus)])) +AC_ARG_WITH([test_user], + [AS_HELP_STRING([--with-test-user=<user>], + [Unprivileged user for regression tests, other than root and the dbus_user (default: nobody)])]) +AC_ARG_WITH(dbus_daemondir, AS_HELP_STRING([--with-dbus-daemondir=[dirname]],[Directory for installing the DBUS daemon])) + +AC_ARG_ENABLE([embedded-tests], + AS_HELP_STRING([--enable-embedded-tests], + [enable unit test code in the library and binaries]), + [], [enable_embedded_tests=$enable_developer]) +AC_ARG_ENABLE([modular-tests], + AS_HELP_STRING([--enable-modular-tests], + [enable modular regression tests (requires GLib)]), + [], [enable_modular_tests=auto]) +# --enable-tests overrides both --enable-embedded-tests and +# --enable-modular-tests +AC_ARG_ENABLE([tests], + AS_HELP_STRING([--enable-tests], + [enable/disable all tests, overriding embedded-tests/modular-tests]), + [ + if test "x$enableval" = xyes; then + AC_MSG_NOTICE([Full test coverage was requested with --enable-tests=yes]) + AC_MSG_NOTICE([This has many dependencies (GLib, Python etc.)]) + fi + enable_embedded_tests=$enableval + enable_modular_tests=$enableval + ], + []) + +# DBUS_ENABLE_EMBEDDED_TESTS controls unit tests built in to .c files +# and also some stuff in the test/ subdir. +AM_CONDITIONAL([DBUS_ENABLE_EMBEDDED_TESTS], + [test "x$enable_embedded_tests" = xyes]) +if test "x$enable_embedded_tests" = xyes; then + AC_DEFINE([DBUS_ENABLE_EMBEDDED_TESTS], [1], + [Define to build test code into the library and binaries]) +fi + +# DBUS_ENABLE_MODULAR_TESTS controls tests that work based on public API. +# These use GTest, from GLib, because life's too short. They're enabled by +# default (unless you don't have GLib), because they don't bloat the library +# or binaries. + +AC_DEFINE([GLIB_VERSION_MIN_REQUIRED], [GLIB_VERSION_2_36], [Ignore post-2.36 deprecations]) +AC_DEFINE([GLIB_VERSION_MAX_ALLOWED], [GLIB_VERSION_2_38], [Prevent post-2.38 APIs]) + +with_glib=yes + +AS_IF([test "x$enable_modular_tests" != xno], + [ + PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.36, gio-2.0 >= 2.36], + [], + [if test "x$enable_modular_tests" = xyes; then + AC_MSG_NOTICE([Full test coverage (--enable-modular-tests=yes or --enable-tests=yes) requires GLib]) + AC_MSG_ERROR([$GLIB_ERRORS]) + else # assumed to be "auto" + with_glib=no + fi]) + ], + [with_glib=no]) + +if test "x$enable_modular_tests" != xno; then + AC_DEFINE([DBUS_ENABLE_MODULAR_TESTS], [1], + [Define to build independent test binaries]) +fi +AM_CONDITIONAL([DBUS_ENABLE_MODULAR_TESTS], + [test "x$enable_modular_tests" != xno]) + +if test "x$with_glib" != xno; then + AC_DEFINE([DBUS_WITH_GLIB], [1], + [Define if GLib, GObject, GIO are available]) +fi +AM_CONDITIONAL([DBUS_WITH_GLIB], [test "x$with_glib" != xno]) + +AC_ARG_ENABLE([installed-tests], + AS_HELP_STRING([--enable-installed-tests], + [enable unit test code in the library and binaries]), + [], [enable_installed_tests=no]) +AM_CONDITIONAL([DBUS_ENABLE_INSTALLED_TESTS], + [test "x$enable_installed_tests" = xyes]) + +if test "x$enable_tests" = xyes; then + # full test coverage is required, Python is a hard dependency + AC_MSG_NOTICE([Full test coverage (--enable-tests=yes) requires Python, dbus-python, pygi]) + AM_PATH_PYTHON([2.6]) + AC_MSG_CHECKING([for Python modules for full test coverage]) + if "$PYTHON" -c "import dbus, gi.repository.GObject, dbus.mainloop.glib"; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + AC_MSG_ERROR([cannot import dbus, gi.repository.GObject, dbus.mainloop.glib Python modules]) + fi +else + # --enable-tests not given: do not abort if Python is missing + AM_PATH_PYTHON([2.6], [], [:]) +fi + +if test x$enable_verbose_mode = xyes; then + AC_DEFINE(DBUS_ENABLE_VERBOSE_MODE,1,[Support a verbose mode]) +fi + +if test x$enable_asserts = xno; then + AC_DEFINE(DBUS_DISABLE_ASSERT,1,[Disable assertion checking]) + DISABLE_UNUSED_WARNINGS="unused-label" + R_DYNAMIC_LDFLAG="" + if test x$enable_embedded_tests = xyes; then + DISABLE_UNUSED_WARNINGS="$DISABLE_UNUSED_WARNINGS \ + unused-but-set-variable unused-variable \ + unused-function" + fi +else + # -rdynamic is needed for glibc's backtrace_symbols to work. + # No clue how much overhead this adds, but it's useful + # to do this on any assertion failure, + # so for now it's enabled anytime asserts are (currently not + # in production builds). + + # To get -rdynamic you pass -export-dynamic to libtool. + AC_DEFINE(DBUS_BUILT_R_DYNAMIC,1,[whether -export-dynamic was passed to libtool]) + R_DYNAMIC_LDFLAG=-export-dynamic +fi +AC_SUBST(R_DYNAMIC_LDFLAG) + +if test x$enable_checks = xno; then + AC_DEFINE(DBUS_DISABLE_CHECKS,1,[Disable public API sanity checking]) + AC_DEFINE(G_DISABLE_CHECKS,1,[Disable GLib public API sanity checking]) + DISABLE_UNUSED_WARNINGS="unused-label" +fi + +AH_BOTTOM([ +/* explicitly define these macros to get less confusing conditions */ +#ifndef DBUS_DISABLE_ASSERT +# define DBUS_ENABLE_ASSERT 1 +#endif +#ifndef DBUS_DISABLE_CHECKS +# define DBUS_ENABLE_CHECKS 1 +#endif]) + +if test x$enable_compiler_coverage = xyes; then + ## so that config.h changes when you toggle gcov support + AC_DEFINE_UNQUOTED(DBUS_GCOV_ENABLED, 1, [Defined if gcov is enabled to force a rebuild due to config.h changing]) +fi + +# glibc21.m4 serial 3 +dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Test for the GNU C Library, version 2.1 or newer. +# From Bruno Haible. + +AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer, + ac_cv_gnu_library_2_1, + [AC_EGREP_CPP([Lucky GNU user], + [ +#include <features.h> +#ifdef __GNU_LIBRARY__ + #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2) + Lucky GNU user + #endif +#endif + ], + ac_cv_gnu_library_2_1=yes, + ac_cv_gnu_library_2_1=no) + ] +) + +#### Integer sizes + +AC_CHECK_SIZEOF(char) +AC_CHECK_SIZEOF(short) +AC_CHECK_SIZEOF(long) +AC_CHECK_SIZEOF(int) +AC_CHECK_SIZEOF(void *) +AC_CHECK_SIZEOF(long long) +AC_CHECK_SIZEOF(__int64) + +### See what our 64 bit type is called +AC_MSG_CHECKING([64-bit integer type]) + +case 8 in +$ac_cv_sizeof_int) + dbusint64=int + dbusint64_constant='(val)' + dbusuint64_constant='(val)' + dbusint64_printf_modifier='""' + ;; +$ac_cv_sizeof_long) + dbusint64=long + dbusint64_constant='(val##L)' + dbusuint64_constant='(val##UL)' + dbusint64_printf_modifier='"l"' + ;; +$ac_cv_sizeof_long_long) + dbusint64='long long' + dbusint64_constant='(val##LL)' + dbusuint64_constant='(val##ULL)' + # Ideally we discover what the format is, but this is + # only used in verbose mode, so eh... + if test x"$ac_cv_gnu_library_2_1" = xyes; then + dbusint64_printf_modifier='"ll"' + fi + ;; +$ac_cv_sizeof___int64) + dbusint64=__int64 + dbusint64_constant='(val##i64)' + dbusuint64_constant='(val##ui64)' + # See above case + if test x"$ac_cv_gnu_library_2_1" = xyes; then + dbusint64_printf_modifier='"ll"' + fi + ;; +esac + +AS_IF( + [test -z "$dbusint64"], + [AC_MSG_RESULT([not found]) + AC_MSG_ERROR([Could not find a 64-bit integer type. + +Please report a bug here with details of your platform and compiler: + + http://bugs.freedesktop.org/enter_bug.cgi?product=DBus&component=core]) + ], + dnl else + [ + DBUS_INT64_TYPE="$dbusint64" + DBUS_INT64_CONSTANT="$dbusint64_constant" + DBUS_UINT64_CONSTANT="$dbusuint64_constant" + if test x"$dbusint64_printf_modifier" != x; then + AC_DEFINE_UNQUOTED(DBUS_INT64_PRINTF_MODIFIER, [$dbusint64_printf_modifier], [Define to printf modifier for 64 bit integer type]) + fi + AC_MSG_RESULT($DBUS_INT64_TYPE) + ]) + +AC_SUBST(DBUS_INT64_TYPE) +AC_SUBST(DBUS_INT64_CONSTANT) +AC_SUBST(DBUS_UINT64_CONSTANT) + +### see what 32-bit int is called +AC_MSG_CHECKING([32-bit integer type]) + +case 4 in +$ac_cv_sizeof_short) + dbusint32=short + ;; +$ac_cv_sizeof_int) + dbusint32=int + ;; +$ac_cv_sizeof_long) + dbusint32=long + ;; +esac + +if test -z "$dbusint32" ; then + DBUS_INT32_TYPE="no_int32_type_detected" + AC_MSG_ERROR([No 32-bit integer type found]) +else + DBUS_INT32_TYPE="$dbusint32" + AC_MSG_RESULT($DBUS_INT32_TYPE) +fi + +AC_SUBST(DBUS_INT32_TYPE) + +### see what 16-bit int is called +AC_MSG_CHECKING([16-bit integer type]) + +case 2 in +$ac_cv_sizeof_short) + dbusint16=short + ;; +$ac_cv_sizeof_int) + dbusint16=int + ;; +esac + +if test -z "$dbusint16" ; then + DBUS_INT16_TYPE="no_int16_type_detected" + AC_MSG_ERROR([No 16-bit integer type found]) +else + DBUS_INT16_TYPE="$dbusint16" + AC_MSG_RESULT($DBUS_INT16_TYPE) +fi + +AC_SUBST(DBUS_INT16_TYPE) + +## byte order +case $host_os in + darwin*) + # check at compile-time, so that it is possible to build universal + # (with multiple architectures at once on the compile line) + AH_VERBATIM([WORDS_BIGENDIAN_DARWIN], [ + /* Use the compiler-provided endianness defines to allow universal compiling. */ + #if defined(__BIG_ENDIAN__) + #define WORDS_BIGENDIAN 1 + #endif + ]) + ;; + *) + AC_C_BIGENDIAN + ;; +esac + +dnl ********************************** +dnl *** va_copy checks (from GLib) *** +dnl ********************************** +dnl we currently check for all three va_copy possibilities, so we get +dnl all results in config.log for bug reports. +AC_CACHE_CHECK([for an implementation of va_copy()],dbus_cv_va_copy,[ + AC_LINK_IFELSE([AC_LANG_SOURCE([#include <stdarg.h> +#include <stdlib.h> + static void f (int i, ...) { + va_list args1, args2; + va_start (args1, i); + va_copy (args2, args1); + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + va_end (args1); va_end (args2); + } + int main() { + f (0, 42); + return 0; + }])], + [dbus_cv_va_copy=yes], + [dbus_cv_va_copy=no]) +]) +AC_CACHE_CHECK([for an implementation of __va_copy()],dbus_cv___va_copy,[ + AC_LINK_IFELSE([AC_LANG_SOURCE([#include <stdarg.h> +#include <stdlib.h> + static void f (int i, ...) { + va_list args1, args2; + va_start (args1, i); + __va_copy (args2, args1); + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + va_end (args1); va_end (args2); + } + int main() { + f (0, 42); + return 0; + }])], + [dbus_cv___va_copy=yes], + [dbus_cv___va_copy=no]) +]) + +if test "x$dbus_cv_va_copy" = "xyes"; then + dbus_va_copy_func=va_copy +else if test "x$dbus_cv___va_copy" = "xyes"; then + dbus_va_copy_func=__va_copy +fi +fi + +if test -n "$dbus_va_copy_func"; then + AC_DEFINE_UNQUOTED(DBUS_VA_COPY,$dbus_va_copy_func,[A 'va_copy' style function]) +fi + +AC_LANG_PUSH(C) +AC_CACHE_CHECK([whether va_lists can be copied by value], + dbus_cv_va_val_copy, + [AC_RUN_IFELSE([AC_LANG_PROGRAM( +[[ + #include <stdarg.h> + #include <stdlib.h> +]], +[[ + static void f (int i, ...) { + va_list args1, args2; + va_start (args1, i); + args2 = args1; + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + va_end (args1); va_end (args2); + } + int main() { + f (0, 42); + return 0; + } +]])], + [dbus_cv_va_val_copy=yes], + [dbus_cv_va_val_copy=no], + [dbus_cv_va_val_copy=yes]) +]) +AC_LANG_POP(C) + +if test "x$dbus_cv_va_val_copy" = "xno"; then + AC_DEFINE(DBUS_VA_COPY_AS_ARRAY,1, ['va_lists' cannot be copies as values]) +fi + + +#### Atomic integers + +AC_CACHE_CHECK([whether $CC knows __sync_sub_and_fetch()], + dbus_cv_sync_sub_and_fetch, + [AC_LINK_IFELSE([ + AC_LANG_PROGRAM([[]], [[int a = 4; int b = __sync_sub_and_fetch(&a, 4); exit(b); ]])], + [dbus_cv_sync_sub_and_fetch=yes], + [dbus_cv_sync_sub_and_fetch=no]) + ]) + +if test "x$dbus_cv_sync_sub_and_fetch" = "xyes" ; then + have_sync=1 +else + have_sync=0 +fi + +AC_DEFINE_UNQUOTED([DBUS_USE_SYNC], [$have_sync], [Use the gcc __sync extension]) + +#### Various functions +AC_SEARCH_LIBS(socket,[socket network]) +AC_CHECK_FUNC(gethostbyname,,[AC_CHECK_LIB(nsl,gethostbyname)]) + +AC_CHECK_FUNCS([vsnprintf vasprintf nanosleep usleep setenv clearenv unsetenv socketpair getgrouplist fpathconf setrlimit poll setlocale localeconv strtoll strtoull issetugid getresuid setresuid getrlimit]) + +AC_CHECK_HEADERS([syslog.h]) +if test "x$ac_cv_header_syslog_h" = "xyes"; then + AC_CHECK_DECLS([LOG_PERROR], [], [], [[#include <syslog.h>]]) +fi + +# For test-segfault.c +AC_CHECK_HEADERS_ONCE([sys/prctl.h]) +AC_CHECK_FUNCS_ONCE([prctl raise]) + +#### Check for broken poll; taken from Glib's configure + +AC_MSG_CHECKING([for broken poll]) +AC_RUN_IFELSE([AC_LANG_SOURCE([[ + #include <stdlib.h> + #include <fcntl.h> + #include <poll.h> + #ifdef HAVE_SYS_POLL_H + #include <sys/poll.h> + #endif + int main(void) { + struct pollfd fds[1]; + int fd; + fd = open("/dev/null", 1); + fds[0].fd = fd; + fds[0].events = POLLIN; + fds[0].revents = 0; + if (poll(fds, 1, 0) < 0 || (fds[0].revents & POLLNVAL) != 0) { + exit(1); /* Does not work for devices -- fail */ + } + exit(0); + }]])], + [broken_poll=no], + [broken_poll=yes + AC_DEFINE(BROKEN_POLL,1,[poll doesn't work on devices])], + [broken_poll="no (cross compiling)"]) +AC_MSG_RESULT($broken_poll) + +AC_MSG_CHECKING(for dirfd) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +#include <sys/types.h> +#include <dirent.h> +]], [[ +DIR *dirp; +dirp = opendir("."); +dirfd(dirp); +closedir(dirp); +]])], +[dbus_have_dirfd=yes], +[dbus_have_dirfd=no]) +AC_MSG_RESULT($dbus_have_dirfd) +if test "$dbus_have_dirfd" = yes; then + AC_DEFINE(HAVE_DIRFD,1,[Have dirfd function]) +else + AC_MSG_CHECKING(for DIR *dirp->dd_fd) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +#include <sys/types.h> +#include <dirent.h> + ]], [[ +DIR *dirp; +int fd; +dirp = opendir("."); +fd = dirp->dd_fd; +closedir(dirp); + ]])], + [dbus_have_ddfd=yes], + [dbus_have_ddfd=no]) + AC_MSG_RESULT($dbus_have_ddfd) + if test "$dbus_have_ddfd" = yes; then + AC_DEFINE(HAVE_DDFD,1,[Have the ddfd member of DIR]) + fi +fi + +AC_CHECK_HEADERS(sys/resource.h) + +AC_CHECK_HEADERS(dirent.h) + +AC_CHECK_HEADERS([execinfo.h], + [AC_SEARCH_LIBS([backtrace], [execinfo], + [AC_DEFINE([HAVE_BACKTRACE], [1], + [Define to 1 if you have backtrace().])])]) + +AC_CHECK_HEADERS(errno.h) + +AC_CHECK_HEADERS(signal.h) + +AC_CHECK_HEADERS(locale.h) + +AC_CHECK_HEADERS(byteswap.h) + +AC_CHECK_HEADERS(unistd.h) + +AC_CHECK_HEADERS([stdint.h]) + +AC_CHECK_HEADERS(ws2tcpip.h) + +AC_CHECK_HEADERS(alloca.h) + +# Add -D_POSIX_PTHREAD_SEMANTICS if on Solaris +# +case $host_os in + solaris*) + CFLAGS="$CFLAGS -D_POSIX_PTHREAD_SEMANTICS" ;; +esac + +# checking for a posix version of getpwnam_r +# if we are cross compiling and can not run the test +# assume getpwnam_r is the posix version +# it is up to the person cross compiling to change +# this behavior if desired +AC_LANG_PUSH(C) +AC_CACHE_CHECK([for posix getpwnam_r], + ac_cv_func_posix_getpwnam_r, + [AC_RUN_IFELSE([AC_LANG_PROGRAM( +[[ +#include <errno.h> +#include <pwd.h> +]], +[[ + char buffer[10000]; + struct passwd pwd, *pwptr = &pwd; + int error; + errno = 0; + error = getpwnam_r ("", &pwd, buffer, + sizeof (buffer), &pwptr); + return (error < 0 && errno == ENOSYS) + || error == ENOSYS; +]])], + [ac_cv_func_posix_getpwnam_r=yes], + [ac_cv_func_posix_getpwnam_r=no], + [ac_cv_func_posix_getpwnam_r=yes] +)]) +AC_LANG_POP(C) + +if test "$ac_cv_func_posix_getpwnam_r" = yes; then + AC_DEFINE(HAVE_POSIX_GETPWNAM_R,1, + [Have POSIX function getpwnam_r]) +else + AC_CACHE_CHECK([for nonposix getpwnam_r], + ac_cv_func_nonposix_getpwnam_r, + [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pwd.h>]], [[char buffer[10000]; + struct passwd pwd; + getpwnam_r ("", &pwd, buffer, + sizeof (buffer));]])], + [ac_cv_func_nonposix_getpwnam_r=yes], + [ac_cv_func_nonposix_getpwnam_r=no])]) + if test "$ac_cv_func_nonposix_getpwnam_r" = yes; then + AC_DEFINE(HAVE_NONPOSIX_GETPWNAM_R,1, + [Have non-POSIX function getpwnam_r]) + fi +fi + +dnl check for socklen_t +AC_MSG_CHECKING(whether socklen_t is defined) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> +]], [[ +socklen_t foo; +foo = 1; +]])], +[dbus_have_socklen_t=yes], +[dbus_have_socklen_t=no]) +AC_MSG_RESULT($dbus_have_socklen_t) + +if test "x$dbus_have_socklen_t" = "xyes"; then + AC_DEFINE(HAVE_SOCKLEN_T,1,[Have socklen_t type]) +fi + +dnl check for writev header and writev function so we're +dnl good to go if HAVE_WRITEV gets defined. +AC_CHECK_HEADERS(sys/uio.h, [AC_CHECK_FUNCS(writev)]) + +dnl needed on darwin for NAME_MAX +AC_CHECK_HEADERS(sys/syslimits.h) + +dnl Make it easy to check if we have MSG_NOSIGNAL without actually having to include sys/socket.h +AC_CHECK_DECLS([MSG_NOSIGNAL], [], [], [[ #include <sys/types.h> +#include <sys/socket.h> ]]) + +dnl check for flavours of varargs macros (test from GLib) +AC_MSG_CHECKING(for ISO C99 varargs macros in C) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ +int a(int p1, int p2, int p3); +#define call_a(...) a(1,__VA_ARGS__) +call_a(2,3); +]])], +[dbus_have_iso_c_varargs=yes], +[dbus_have_iso_c_varargs=no]) +AC_MSG_RESULT($dbus_have_iso_c_varargs) + +AC_MSG_CHECKING(for GNUC varargs macros) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ +int a(int p1, int p2, int p3); +#define call_a(params...) a(1,params) +call_a(2,3); +]])], +[dbus_have_gnuc_varargs=yes], +[dbus_have_gnuc_varargs=no]) +AC_MSG_RESULT($dbus_have_gnuc_varargs) + +dnl Output varargs tests +if test x$dbus_have_iso_c_varargs = xyes; then + AC_DEFINE(HAVE_ISO_VARARGS,1,[Have ISO C99 varargs macros]) +fi +if test x$dbus_have_gnuc_varargs = xyes; then + AC_DEFINE(HAVE_GNUC_VARARGS,1,[Have GNU-style varargs macros]) +fi + +dnl Check for various credentials. +AC_MSG_CHECKING(for struct cmsgcred) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include <sys/types.h> +#include <sys/socket.h> +]], [[ +struct cmsgcred cred; + +cred.cmcred_pid = 0; +]])], +[dbus_have_struct_cmsgcred=yes], +[dbus_have_struct_cmsgcred=no]) +AC_MSG_RESULT($dbus_have_struct_cmsgcred) + +if test x$dbus_have_struct_cmsgcred = xyes; then + AC_DEFINE(HAVE_CMSGCRED,1,[Have cmsgcred structure]) +fi + +AC_CHECK_MEMBER([struct unpcbid.unp_pid], + [AC_DEFINE([HAVE_UNPCBID], 1, [Have unpcbid structure])], + [], + [[#include <sys/un.h>]]) + +AC_CHECK_FUNCS(getpeerucred getpeereid) + +AC_CHECK_FUNCS(pipe2 accept4) + +#### Abstract sockets + +if test x$enable_abstract_sockets = xauto; then +AC_LANG_PUSH(C) +warn_on_xcompile=no +AC_CACHE_CHECK([abstract socket namespace], + ac_cv_have_abstract_sockets, + [AC_RUN_IFELSE([AC_LANG_PROGRAM( +[[ +#include <sys/types.h> +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <errno.h> +]], +[[ + size_t slen; + int listen_fd; + struct sockaddr_un addr; + + listen_fd = socket (PF_UNIX, SOCK_STREAM, 0); + + if (listen_fd < 0) + { + fprintf (stderr, "socket() failed: %s\n", strerror (errno)); + exit (1); + } + + memset (&addr, '\0', sizeof (addr)); + addr.sun_family = AF_UNIX; + strcpy (addr.sun_path, "X/tmp/dbus-fake-socket-path-used-in-configure-test"); + /* SUN_LEN uses strlen() so need to calculate it before adding \0 at the + * beginning. + */ + slen = SUN_LEN(&addr); + addr.sun_path[0] = '\0'; /* this is what makes it abstract */ + + if (bind (listen_fd, (struct sockaddr*) &addr, slen) < 0) + { + fprintf (stderr, "Abstract socket namespace bind() failed: %s\n", + strerror (errno)); + exit (1); + } + else + exit (0); +]])], + [ac_cv_have_abstract_sockets=yes], + [ac_cv_have_abstract_sockets=no], + [ + ac_cv_have_abstract_sockets=no + warn_on_xcompile=yes + ] +)]) +if test x$warn_on_xcompile = xyes ; then + AC_MSG_WARN([Cannot check for abstract sockets when cross-compiling, please use --enable-abstract-sockets]) +fi +AC_LANG_POP(C) +fi + +if test x$enable_abstract_sockets = xyes; then + if test x$ac_cv_have_abstract_sockets = xno; then + AC_MSG_ERROR([Abstract sockets explicitly required, and support not detected.]) + fi +fi + +if test x$enable_abstract_sockets = xno; then + ac_cv_have_abstract_sockets=no; +fi + +if test x$ac_cv_have_abstract_sockets = xyes ; then + DBUS_PATH_OR_ABSTRACT=abstract + AC_DEFINE(HAVE_ABSTRACT_SOCKETS,1,[Have abstract socket namespace]) +else + DBUS_PATH_OR_ABSTRACT=path +fi + +# this is used in addresses to prefer abstract, e.g. +# unix:path=/foo or unix:abstract=/foo +AC_SUBST(DBUS_PATH_OR_ABSTRACT) + +#### Sort out XML library + +AC_CHECK_LIB(expat, XML_ParserCreate_MM, + [ AC_CHECK_HEADERS(expat.h, [], + [AC_MSG_ERROR([Could not find expat.h, check config.log for failed attempts])]) ], + [ AC_MSG_ERROR([Explicitly requested expat but expat not found]) ]) + +XML_LIBS=-lexpat +XML_CFLAGS= +AC_SUBST([XML_CFLAGS]) +AC_SUBST([XML_LIBS]) + +# Thread lib detection +AC_ARG_VAR([THREAD_LIBS]) +save_libs="$LIBS" +LIBS="$LIBS $THREAD_LIBS" + +is_missing_pthread_function="is required when compiling D-Bus on Unix platforms, but is not in your libc or libpthread. Please open a bug on https://bugs.freedesktop.org/enter_bug.cgi?product=dbus with details of your platform." + +# Don't do these automatic checks if the user set THREAD_LIBS on the +# configure command-line. If they did, we assume they're right. +# +# We also don't do these checks on Windows, because you don't need magical +# linker flags to have threading support there. +AS_IF([test "x$dbus_unix" = xyes && test "x$THREAD_LIBS" = x], + [ + # Mandatory pthread functions. In principle, some of these could be made + # optional if there are platforms that don't have them. + # + # Currently, we only look in -lpthread. + # In principle we might need to look in -lpthreads, -lthreads, ... + # as well - please file a bug if your platform needs this. + AC_SEARCH_LIBS([pthread_cond_timedwait], + [pthread], + [THREAD_LIBS="$LIBS"], + [AC_MSG_ERROR([pthread_cond_timedwait $is_missing_pthread_function])], + []) + AC_SEARCH_LIBS([pthread_mutexattr_init], + [pthread], + [THREAD_LIBS="$LIBS"], + [AC_MSG_ERROR([pthread_mutexattr_init $is_missing_pthread_function])], + []) + AC_SEARCH_LIBS([pthread_mutexattr_settype], + [pthread], + [THREAD_LIBS="$LIBS"], + [AC_MSG_ERROR([pthread_mutexattr_settype $is_missing_pthread_function])], + []) + + # Optional, for monotonic clocks. Because it's optional, this check + # is non-fatal if we don't find it. + AC_SEARCH_LIBS([pthread_condattr_setclock], + [pthread], + [THREAD_LIBS="$LIBS"]) + + AS_IF([test "x$ac_cv_search_pthread_condattr_setclock" != xno], + [ + AC_SEARCH_LIBS([clock_getres], [rt], [THREAD_LIBS="$LIBS"]) + AC_MSG_CHECKING([for CLOCK_MONOTONIC]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM( +[[#include <time.h> +#include <pthread.h> +]], [[ +struct timespec monotonic_timer; +pthread_condattr_t attr; +pthread_condattr_init (&attr); +pthread_condattr_setclock (&attr, CLOCK_MONOTONIC); +clock_getres (CLOCK_MONOTONIC,&monotonic_timer); +]])], + [have_clock_monotonic=true], + [have_clock_monotonic=false]) + AS_IF([test x$have_clock_monotonic = xtrue], + [ + AC_MSG_RESULT([found]) + AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1, [Define if we have CLOCK_MONOTONIC]) + ], + [AC_MSG_RESULT([not found])]) + ]) dnl have pthread_condattr_setclock + ]) dnl on Unix + +LIBS="$save_libs" + +AC_SUBST([THREAD_LIBS]) + +# SELinux detection +if test x$enable_selinux = xno ; then + have_selinux=no; +else + # See if we have SELinux library + AC_CHECK_LIB(selinux, is_selinux_enabled, + have_selinux=yes, have_selinux=no) + + # see if we have the SELinux header with the new D-Bus stuff in it + if test x$have_selinux = xyes ; then + AC_MSG_CHECKING([for DBUS Flask permissions in selinux/av_permissions.h]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <selinux/av_permissions.h>]], + [[#ifdef DBUS__ACQUIRE_SVC return 0; + #else + #error DBUS__ACQUIRE_SVC not defined + #endif]])], + [have_selinux=yes], + [have_selinux=no]) + AC_MSG_RESULT($have_selinux) + fi + + if test x$enable_selinux = xauto ; then + if test x$have_selinux = xno ; then + AC_MSG_WARN([Sufficiently new SELinux library not found]) + fi + else + if test x$have_selinux = xno ; then + AC_MSG_ERROR([SElinux explicitly required, and SELinux library not found]) + fi + fi +fi + +AM_CONDITIONAL(HAVE_SELINUX, test x$have_selinux = xyes) + +if test x$have_selinux = xyes ; then + # the selinux code creates threads + # which requires libpthread even on linux + AC_CHECK_FUNC(pthread_create,,[AC_CHECK_LIB(pthread,pthread_create, + [SELINUX_THREAD_LIBS="-lpthread"])]) + + SELINUX_LIBS="-lselinux $SELINUX_THREAD_LIBS" + AC_DEFINE(HAVE_SELINUX,1,[SELinux support]) +else + SELINUX_LIBS= +fi + +# AppArmor detection +AS_IF([test x$enable_apparmor = xno], + [have_apparmor=no], + [ + PKG_CHECK_MODULES([APPARMOR], [libapparmor >= 2.8.95], + [have_apparmor=yes], [have_apparmor=no]) + + AS_IF([test x$enable_apparmor = xauto && test x$have_apparmor = xno], + [AC_MSG_WARN([Sufficiently new AppArmor library not found])]) + AS_IF([test x$enable_apparmor != xauto && test x$have_apparmor = xno], + [AC_MSG_ERROR([AppArmor explicitly required, and AppArmor library not found])]) + ]) + +AS_IF([test x$have_apparmor = xyes], + [AC_DEFINE([HAVE_APPARMOR], [1], [AppArmor Support])]) + +# inotify checks +if test x$enable_inotify = xno ; then + have_inotify=no; +else + AC_CHECK_HEADERS(sys/inotify.h, have_inotify=yes, have_inotify=no) +fi + +dnl check if inotify backend is enabled +if test x$have_inotify = xyes; then + AC_DEFINE(DBUS_BUS_ENABLE_INOTIFY,1,[Use inotify]) + AC_CHECK_FUNCS(inotify_init1) +fi + +AM_CONDITIONAL(DBUS_BUS_ENABLE_INOTIFY, test x$have_inotify = xyes) + +# For simplicity, we require the userland API for epoll_create1 at +# compile-time (glibc 2.9), but we'll run on kernels that turn out +# not to have it at runtime. +AC_ARG_ENABLE([epoll], + [AS_HELP_STRING([--enable-epoll],[use epoll(4) on Linux])], + [enable_epoll=$enableval], [enable_epoll=auto]) +if test x$enable_epoll = xno; then + have_linux_epoll=no +else + AC_MSG_CHECKING([for Linux epoll(4)]) + AC_LINK_IFELSE([AC_LANG_PROGRAM( + [ + #ifndef __linux__ + #error This is not Linux + #endif + #include <sys/epoll.h> + ], + [epoll_create1 (EPOLL_CLOEXEC);])], + [have_linux_epoll=yes], + [have_linux_epoll=no]) + AC_MSG_RESULT([$have_linux_epoll]) +fi +if test x$enable_epoll,$have_linux_epoll = xyes,no; then + AC_MSG_ERROR([epoll support explicitly enabled but not available]) +fi +if test x$have_linux_epoll = xyes; then + AC_DEFINE([DBUS_HAVE_LINUX_EPOLL], 1, [Define to use epoll(4) on Linux]) +fi +AM_CONDITIONAL([HAVE_LINUX_EPOLL], [test x$have_linux_epoll = xyes]) + +# kqueue checks +if test x$enable_kqueue = xno ; then + have_kqueue=no +else + have_kqueue=yes + AC_CHECK_HEADER(sys/event.h, , have_kqueue=no) + AC_CHECK_FUNC(kqueue, , have_kqueue=no) + + if test x$enable_kqueue = xyes -a x$have_kqueue = xno; then + AC_MSG_ERROR(kqueue support explicitly enabled but not available) + fi +fi + +dnl check if kqueue backend is enabled +if test x$have_kqueue = xyes; then + AC_DEFINE(DBUS_BUS_ENABLE_KQUEUE,1,[Use kqueue]) +fi + +AM_CONDITIONAL(DBUS_BUS_ENABLE_KQUEUE, test x$have_kqueue = xyes) + +# launchd checks +if test x$enable_launchd = xno ; then + have_launchd=no +else + have_launchd=yes + AC_CHECK_HEADER([launch.h], , have_launchd=no) + AC_PATH_PROG([LAUNCHCTL], [launchctl]) + if test "x$LAUNCHCTL" = "x"; then + have_launchd=no + fi + + if test x$enable_launchd = xyes && test x$have_launchd = xno ; then + AC_MSG_ERROR([launchd support explicitly enabled but not available]) + fi +fi + +dnl check if launchd is enabled +if test x$have_launchd = xyes; then + AC_DEFINE(DBUS_ENABLE_LAUNCHD,1,[Use launchd autolaunch]) +fi + +AM_CONDITIONAL(DBUS_ENABLE_LAUNCHD, test x$have_launchd = xyes) + +#### Directory to place launchd agent file +if test "x$with_launchd_agent_dir" = "x"; then + LAUNCHD_AGENT_DIR="/Library/LaunchAgents" +else + LAUNCHD_AGENT_DIR="$with_launchd_agent_dir" +fi + +AC_SUBST(LAUNCHD_AGENT_DIR) + +dnl console owner file +if test x$enable_console_owner_file = xno ; then + have_console_owner_file=no; +else + case $host_os in + solaris*) + have_console_owner_file=yes; + AC_DEFINE(HAVE_CONSOLE_OWNER_FILE,1,[Have console owner file]) + ;; + *) + have_console_owner_file=no;; + esac +fi + +AM_CONDITIONAL(HAVE_CONSOLE_OWNER_FILE, test x$have_console_owner_file = xyes) + +dnl systemd detection +if test x$enable_systemd = xno ; then + have_systemd=no; +else + PKG_CHECK_MODULES([SYSTEMD], + [libsystemd >= 209], + [have_systemd=yes], + [PKG_CHECK_MODULES([SYSTEMD], + [libsystemd-login >= 32, libsystemd-daemon >= 32, libsystemd-journal >= 32], + [have_systemd=yes], + [have_systemd=no])]) +fi + +if test x$have_systemd = xyes; then + AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd]) +fi + +if test x$enable_systemd = xyes -a x$have_systemd != xyes ; then + AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found]) +fi + +# If not found in $PATH, we might still have systemd and systemctl at runtime +# (perhaps dbus is being compiled in a minimal chroot with no systemd). +# Assume the upstream-recommended location. Distributors with split /usr +# can override this with ./configure SYSTEMCTL=/bin/systemctl +AC_PATH_PROG([SYSTEMCTL], [systemctl], [/usr/bin/systemctl]) + +# libaudit detection +if test x$enable_libaudit = xno ; then + have_libaudit=no; +else + # See if we have audit daemon & capabilities library + AC_CHECK_LIB(audit, audit_log_user_avc_message, + have_libaudit=yes, have_libaudit=no) + if test x$have_libaudit = xyes ; then + AC_CHECK_LIB(cap-ng, capng_clear, + have_libaudit=yes, have_libaudit=no) + fi +fi + +AM_CONDITIONAL(HAVE_LIBAUDIT, test x$have_libaudit = xyes) + +if test x$have_libaudit = xyes ; then + SELINUX_LIBS="$SELINUX_LIBS -laudit -lcap-ng" + AC_DEFINE(HAVE_LIBAUDIT,1,[audit daemon SELinux support]) +fi + +AC_SUBST([SELINUX_LIBS]) + +# Check for ADT API (Solaris Basic Security Mode auditing) +AC_MSG_CHECKING(for ADT API) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include <bsm/adt.h> +adt_user_context = ADT_USER; +]], [[]])], [ check_adt_audit=yes ], [ check_adt_audit=no ]) + +if test ${check_adt_audit} = yes +then + AC_DEFINE([HAVE_ADT], [], [Adt audit API]) + ADT_LIBS="-lbsm" + LIBS="-lbsm $LIBS" + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi +AC_SUBST([ADT_LIBS]) + +# Check for SCM_RIGHTS +AC_MSG_CHECKING([for SCM_RIGHTS]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +static int x = SCM_RIGHTS; +]], [[]])], +[ AC_MSG_RESULT([supported]) + AC_DEFINE([HAVE_UNIX_FD_PASSING], [1], [Supports sending UNIX file descriptors]) ], +[ AC_MSG_RESULT([not supported]) ]) + +NETWORK_libs= +if test x$dbus_win = xyes ; then + if test x$dbus_wince = xyes ; then + NETWORK_libs="-lws2" + else + NETWORK_libs="-lws2_32 -liphlpapi" + fi +fi + +AC_SUBST([NETWORK_libs]) + +AC_ARG_WITH([valgrind], + [AS_HELP_STRING([--with-valgrind], + [Add instrumentation to help valgrind to understand our allocator])], + [], + [with_valgrind=no]) + +AS_IF([test "x$with_valgrind" = xauto], + [PKG_CHECK_EXISTS([valgrind >= 3.6], + [with_valgrind=yes], [with_valgrind=no])]) + +if test x$with_valgrind != xno; then + PKG_CHECK_MODULES([VALGRIND], [valgrind >= 3.6]) + AC_DEFINE([WITH_VALGRIND], [1], [Define to add Valgrind instrumentation]) +fi + +#### Set up final flags +LIBDBUS_LIBS="$THREAD_LIBS $NETWORK_libs $SYSTEMD_LIBS" +AC_SUBST([LIBDBUS_LIBS]) + +### X11 detection +DBUS_X_LIBS= +DBUS_X_CFLAGS= + +AC_ARG_ENABLE([x11-autolaunch], + AS_HELP_STRING([--enable-x11-autolaunch], [build with X11 auto-launch support]), + [], [enable_x11_autolaunch=auto]) + +if test "x$dbus_win" = xyes; then + if test "x$enable_x11_autolaunch" = xyes; then + AC_MSG_ERROR([X11 auto-launch is not supported on Windows]) + fi + + enable_x11_autolaunch=no + have_x11=no +else + AC_PATH_XTRA + + if test "x$no_x" = xyes; then + have_x11=no + else + have_x11=yes + DBUS_X_LIBS="$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS" + DBUS_X_CFLAGS="$X_CFLAGS" + fi +fi + +if test "x$enable_x11_autolaunch,$have_x11" = xyes,no; then + AC_MSG_ERROR([X11 auto-launch requires X headers/libraries]) +else + # move from "auto" to "yes" or "no" if necessary + if test "x$enable_x11_autolaunch" != xno; then + enable_x11_autolaunch="$have_x11" + fi +fi + +if test "x$have_x11" = xyes ; then + AC_DEFINE([DBUS_BUILD_X11], [1], [Define to build X11 functionality]) +fi + +if test "x$enable_x11_autolaunch" = xyes ; then + AC_DEFINE([DBUS_ENABLE_X11_AUTOLAUNCH], [1], [Define to enable X11 auto-launch]) +fi + +AC_SUBST([DBUS_X_CFLAGS]) +AC_SUBST([DBUS_X_LIBS]) + +#### gcc warning flags + +cc_supports_flag() { + AC_MSG_CHECKING(whether $CC supports "$*") + save_CFLAGS="$CFLAGS" + CFLAGS="$*" + AC_TRY_COMPILE([], [], [rc=yes], [rc=no]) + CFLAGS="$save_CFLAGS" + AC_MSG_RESULT([$rc]) + test "x$rc" = xyes +} + +TP_COMPILER_WARNINGS([WARNING_CFLAGS], + dnl Use -Werror by default if: + dnl - we're not on Windows (too many warnings), and + dnl - we're in developer mode (a D-Bus developer, not a distro or end-user) + dnl Override with --enable-Werror or --disable-Werror + [test x$dbus_win != xyes -a x$dbus_cygwin != xyes -a x$enable_developer = xyes], + + dnl Enable these warnings if possible: + [all \ + extra \ + char-subscripts \ + missing-declarations \ + missing-prototypes \ + nested-externs \ + pointer-arith \ + cast-align \ + no-address \ + float-equal \ + declaration-after-statement \ + ], + + dnl Disable these warnings if possible, make them non-fatal if possible, + dnl and don't enable -Werror unless we succeeded. + dnl + dnl Intentional: + dnl - $DISABLE_UNUSED_WARNINGS disables unused-label warnings if not + dnl checking or not asserting + dnl - missing field initializers being 0 is a C feature, not a bug + dnl - unused-parameter is to make writing callbacks less annoying + dnl + dnl To be fixed one day: + dnl - pointer-sign is a workaround for fd.o #15522 + dnl - type-limits is probably a bug too, but having the rest of -Wextra + dnl is better than nothing + [$DISABLE_UNUSED_WARNINGS \ + deprecated-declarations \ + missing-field-initializers \ + unused-parameter \ + pointer-sign \ + type-limits \ + ]) + +if test "x$GCC" = "xyes"; then + # We're treating -fno-common like a warning: it makes the linker more + # strict, because on some systems the linker is *always* this strict + TP_ADD_COMPILER_FLAG([WARNING_CFLAGS], [-fno-common]) + + # http://bugs.freedesktop.org/show_bug.cgi?id=10599 + TP_ADD_COMPILER_FLAG([WARNING_CFLAGS], [-fno-strict-aliasing]) + + if test "x$enable_ansi" = "xyes"; then + TP_ADD_COMPILER_FLAG([WARNING_CFLAGS], + [-ansi -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -pedantic]) + fi +fi + +dnl In principle we should put WARNING_CFLAGS in each Makefile.am like +dnl telepathy-glib does, since CFLAGS is meant to be reserved for the user... +dnl but prepending to CFLAGS (so the user can override it with later CFLAGS) +dnl is the next best thing +CFLAGS="$WARNING_CFLAGS $CFLAGS" + +case $host_os in + solaris*) + # Solaris' C library apparently needs these runes to be threadsafe... + CFLAGS="$CFLAGS -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT" + # ... this opt-in to get sockaddr_in6 and sockaddr_storage... + CFLAGS="$CFLAGS -D__EXTENSIONS__" + # ... and this opt-in to get file descriptor passing support + CFLAGS="$CFLAGS -D_XOPEN_SOURCE=500" + ;; +esac + +### Detect if ld supports --version-script + +gl_LD_VERSION_SCRIPT +AM_CONDITIONAL([HAVE_LD_VERSION_SCRIPT], + [test "x$have_ld_version_script" = xyes]) +### Doxygen Documentation + +AC_PATH_PROG(DOXYGEN, doxygen, no) + +AC_MSG_CHECKING([whether to build Doxygen documentation]) + +if test x$DOXYGEN = xno ; then + have_doxygen=no +else + have_doxygen=yes +fi + +if test x$enable_doxygen_docs = xauto ; then + if test x$have_doxygen = xno ; then + enable_doxygen_docs=no + else + enable_doxygen_docs=yes + fi +fi + +if test x$enable_doxygen_docs = xyes; then + if test x$have_doxygen = xno; then + AC_MSG_ERROR([Building Doxygen docs explicitly required, but Doxygen not found]) + fi +fi + +AM_CONDITIONAL(DBUS_DOXYGEN_DOCS_ENABLED, test x$enable_doxygen_docs = xyes) +AC_MSG_RESULT($enable_doxygen_docs) + +AC_CHECK_PROGS([XSLTPROC], [xsltproc]) +AM_CONDITIONAL([DBUS_HAVE_XSLTPROC], [test "x$XSLTPROC" != "x"]) + +### Ducktype/Yelp documentation + +AC_PATH_PROG([DUCKTYPE],[ducktype],[no]) +AC_PATH_PROG([YELP_BUILD],[yelp-build],[no]) + +AC_MSG_CHECKING([whether to build Ducktype documentation]) + +AS_IF([test "$DUCKTYPE" = "no"],[have_ducktype=no],[have_ducktype=yes]) +AS_IF([test "$YELP_BUILD" = "no"],[have_yelp_build=no],[have_yelp_build=yes]) + +AS_IF([test "$enable_ducktype_docs" = "auto"],[ + AS_IF([test "$have_ducktype" = "no" || test "$have_yelp_build" = "no"],[ + enable_ducktype_docs=no + ],[ + enable_ducktype_docs=yes + ]) +]) + +AS_IF([test "$enable_ducktype_docs" = "yes"],[ + AS_IF([test "$have_ducktype" = "no"],[ + AC_MSG_ERROR([Building Ducktype docs explicitly required, but ducktype not found]) + ]) + AS_IF([test "$have_yelp_build" = "no"],[ + AC_MSG_ERROR([Building Ducktype docs explicitly required, but yelp-build not found]) + ]) +]) + +AM_CONDITIONAL([DBUS_DUCKTYPE_DOCS_ENABLED],[test "$enable_ducktype_docs" = "yes"]) +AC_MSG_RESULT([$enable_ducktype_docs]) + +### XML Documentation + +AC_PATH_PROG(XMLTO, xmlto, no) + +AC_MSG_CHECKING([whether to build XML documentation]) + +if test x$XMLTO = xno ; then + have_xmlto=no +else + have_xmlto=yes +fi + +if test x$enable_xml_docs = xauto ; then + if test x$have_xmlto = xno ; then + enable_xml_docs=no + else + enable_xml_docs=yes + fi +fi + +if test x$enable_xml_docs = xyes; then + if test x$have_xmlto = xno; then + AC_MSG_ERROR([Building XML docs explicitly required, but xmlto not found]) + fi +fi + +AM_CONDITIONAL(DBUS_XML_DOCS_ENABLED, test x$enable_xml_docs = xyes) +AC_MSG_RESULT($enable_xml_docs) + +AM_CONDITIONAL(DBUS_CAN_UPLOAD_DOCS, + [test x$enable_doxygen_docs = xyes && test x$enable_xml_docs = xyes && + test x$enable_ducktype_docs = xyes]) + +#### Have to go $localstatedir->$prefix/var->/usr/local/var + +#### find the actual value for $prefix that we'll end up with +## (I know this is broken and should be done in the Makefile, but +## that's a major pain and almost nobody actually seems to care) +AS_AC_EXPAND(EXPANDED_PREFIX, "$prefix") +AS_AC_EXPAND(EXPANDED_LOCALSTATEDIR, "$localstatedir") +AS_AC_EXPAND(EXPANDED_SYSCONFDIR, "$sysconfdir") +AS_AC_EXPAND(EXPANDED_BINDIR, "$bindir") +AS_AC_EXPAND(EXPANDED_LIBDIR, "$libdir") +AS_AC_EXPAND(EXPANDED_LIBEXECDIR, "$libexecdir") +AS_AC_EXPAND(EXPANDED_DATADIR, "$datadir") + +#### Check our operating system +operating_system=unknown +if test -f /etc/redhat-release || test -f $EXPANDED_SYSCONFDIR/redhat-release ; then + operating_system=redhat +fi + +if test -f /etc/slackware-version || test -f $EXPANDED_SYSCONFDIR/slackware-version ; then + operating_system=slackware +fi + +if test -f /usr/bin/cygwin1.dll || test -f $EXPANDED_BINDIR/cygwin1.dll ; then + operating_system=cygwin +fi + +#### Sort out init scripts + +if test x$with_init_scripts = x; then + case x$operating_system in + xredhat) with_init_scripts=redhat ;; + xslackware) with_init_scripts=slackware ;; + xcygwin) with_init_scripts=cygwin ;; + *) with_init_scripts=none ;; + esac +fi + +AM_CONDITIONAL(DBUS_INIT_SCRIPTS_RED_HAT, test x$with_init_scripts = xredhat) +AM_CONDITIONAL(DBUS_INIT_SCRIPTS_SLACKWARE, test x$with_init_scripts = xslackware) +AM_CONDITIONAL(DBUS_INIT_SCRIPTS_CYGWIN, test x$with_init_scripts = xcygwin) + +##### systemd unit files +AC_ARG_WITH([systemdsystemunitdir], +AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]), + [], + [ + PKG_CHECK_EXISTS([systemd], + [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)], + [with_systemdsystemunitdir=no]) + ]) +if test "x$with_systemdsystemunitdir" != xno; then + AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir]) +fi +AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$have_systemd" != "xno" -a -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ]) + +AC_ARG_WITH([systemduserunitdir], +AS_HELP_STRING([--with-systemduserunitdir=DIR], [Directory for systemd user service files]), + [], + [ + PKG_CHECK_EXISTS([systemd], + [with_systemduserunitdir=$($PKG_CONFIG --variable=systemduserunitdir systemd)], + [with_systemduserunitdir='${libdir}/systemd/user']) + ]) +AC_SUBST([systemduserunitdir], [$with_systemduserunitdir]) + +##### Set up location for system bus socket +if ! test -z "$with_system_socket"; then + DBUS_SYSTEM_SOCKET=$with_system_socket +else + DBUS_SYSTEM_SOCKET=${EXPANDED_LOCALSTATEDIR}/run/dbus/system_bus_socket +fi + +AC_SUBST(DBUS_SYSTEM_SOCKET) +AC_DEFINE_UNQUOTED(DBUS_SYSTEM_SOCKET,"$DBUS_SYSTEM_SOCKET",[The name of the socket the system bus listens on by default]) + +## System bus only listens on local domain sockets, and never +## on an abstract socket (so only root can create the socket). +## +## This won't work on Windows. It's not meant to - the system bus is +## meaningless on Windows anyway. +## +## This has to be suitable for hard-coding in client libraries as well as +## in the dbus-daemon's configuration, so it has to be valid to listen on +## and also to connect to. If this ever changes, it'll need to be split into +## two variables, one for the listening address and one for the connecting +## address. +DBUS_SYSTEM_BUS_DEFAULT_ADDRESS="unix:path=$DBUS_SYSTEM_SOCKET" +AC_SUBST(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS) +AC_DEFINE_UNQUOTED(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS, "$DBUS_SYSTEM_BUS_DEFAULT_ADDRESS",[The default D-Bus address of the system bus]) + +#### Set up the pid file +if ! test -z "$with_system_pid_file"; then + DBUS_SYSTEM_PID_FILE=$with_system_pid_file +elif test x$with_init_scripts = xredhat ; then + DBUS_SYSTEM_PID_FILE=${EXPANDED_LOCALSTATEDIR}/run/messagebus.pid +else + DBUS_SYSTEM_PID_FILE=${EXPANDED_LOCALSTATEDIR}/run/dbus/pid +fi + +AC_SUBST(DBUS_SYSTEM_PID_FILE) + +#### Directory to check for console ownership +if ! test -z "$with_console_auth_dir"; then + DBUS_CONSOLE_AUTH_DIR=$with_console_auth_dir +else + DBUS_CONSOLE_AUTH_DIR=/var/run/console/ +fi + +AC_SUBST(DBUS_CONSOLE_AUTH_DIR) +AC_DEFINE_UNQUOTED(DBUS_CONSOLE_AUTH_DIR, "$DBUS_CONSOLE_AUTH_DIR", [Directory to check for console ownerhip]) + +#### File to check for console ownership +if test x$have_console_owner_file = xyes; then + if ! test -z "$with_console_owner_file"; then + DBUS_CONSOLE_OWNER_FILE=$with_console_owner_file + else + DBUS_CONSOLE_OWNER_FILE=/dev/console + fi +else + DBUS_CONSOLE_OWNER_FILE= +fi + +AC_SUBST(DBUS_CONSOLE_OWNER_FILE) +AC_DEFINE_UNQUOTED(DBUS_CONSOLE_OWNER_FILE, "$DBUS_CONSOLE_OWNER_FILE", [File to check for console ownerhip]) + +#### User to start the system bus as +if test -z "$with_dbus_user" ; then + DBUS_USER=messagebus +else + DBUS_USER=$with_dbus_user +fi +AC_SUBST(DBUS_USER) +AC_DEFINE_UNQUOTED(DBUS_USER,"$DBUS_USER", [User for running the system BUS daemon]) + +#### User for regression tests +AS_IF([test -z "$with_test_user"], [with_test_user=nobody]) +DBUS_TEST_USER="$with_test_user" +AC_SUBST([DBUS_TEST_USER]) +AC_DEFINE_UNQUOTED([DBUS_TEST_USER], ["$DBUS_TEST_USER"], + [Unprivileged user used in some regression tests]) + +#### Prefix to install into +DBUS_PREFIX=$EXPANDED_PREFIX +AC_SUBST(DBUS_PREFIX) +AC_DEFINE_UNQUOTED(DBUS_PREFIX,"$DBUS_PREFIX", [Prefix for installing DBUS]) + +#### Direcotry to install data files into +DBUS_DATADIR=$EXPANDED_DATADIR +AC_SUBST(DBUS_DATADIR) +AC_DEFINE_UNQUOTED(DBUS_DATADIR,"$DBUS_DATADIR", [Directory for installing DBUS data files]) + +#### Directory to install dbus-daemon +if test -z "$with_dbus_daemondir" ; then + DBUS_DAEMONDIR=$EXPANDED_BINDIR + dbus_daemondir='$bindir' +else + DBUS_DAEMONDIR=$with_dbus_daemondir + dbus_daemondir=$with_dbus_daemondir +fi +AC_SUBST(DBUS_DAEMONDIR) +AC_SUBST(dbus_daemondir) +AC_DEFINE_UNQUOTED(DBUS_DAEMONDIR,"$DBUS_DAEMONDIR", [Directory for installing the DBUS daemon]) + +#### Directory to install the other binaries +DBUS_BINDIR="$EXPANDED_BINDIR" +AC_SUBST(DBUS_BINDIR) +AC_DEFINE_UNQUOTED(DBUS_BINDIR,"$DBUS_BINDIR", [Directory for installing the binaries]) + +#### Directory to install the libexec binaries +DBUS_LIBEXECDIR="$EXPANDED_LIBEXECDIR" +AC_SUBST(DBUS_LIBEXECDIR) +AC_DEFINE_UNQUOTED(DBUS_LIBEXECDIR,"$DBUS_LIBEXECDIR", [Directory for installing the libexec binaries]) + +#### Directory to source sysconfdir configuration from + +# On Windows this is relative to where we put the bus setup, in +# ${datadir}/dbus-1. For simplicity, we only do this if +# ${sysconfdir} = ${prefix}/etc and ${datadir} = ${prefix}/share. +# +# On Unix, or on Windows with weird install layouts, it's the absolute path. +AS_IF([test "${dbus_win}" = yes && \ + test "$EXPANDED_SYSCONFDIR" = "$EXPANDED_PREFIX/etc" && \ + test "$EXPANDED_DATADIR" = "$EXPANDED_PREFIX/share"], + [SYSCONFDIR_FROM_PKGDATADIR="../../etc" + DATADIR_FROM_PKGSYSCONFDIR="../../share"], + [SYSCONFDIR_FROM_PKGDATADIR="$EXPANDED_SYSCONFDIR" + DATADIR_FROM_PKGSYSCONFDIR="$EXPANDED_DATADIR"]) +AC_SUBST([SYSCONFDIR_FROM_PKGDATADIR]) +AC_SUBST([DATADIR_FROM_PKGSYSCONFDIR]) + +#### Tell tests where to find certain stuff in builddir + +DBUS_PWD=`pwd` +# Useful in a cross-compilation environment, where the tests are run on the host system. +AC_ARG_WITH(dbus-test-dir, AS_HELP_STRING([--with-dbus-test-dir=[dirname]],[path where the tests tools are available]), + DBUS_PWD=$withval) + +DBUS_TEST_EXEC="$DBUS_PWD/test" +DBUS_TEST_DATA="$DBUS_PWD/test/data" + +AC_SUBST([DBUS_TEST_DATA]) +AC_SUBST([DBUS_TEST_EXEC]) + +AC_DEFINE_UNQUOTED([DBUS_TEST_EXEC], ["$DBUS_TEST_EXEC"], + [Full path to the daemon in the builddir]) +AC_DEFINE_UNQUOTED([DBUS_EXEEXT], ["$EXEEXT"], + [Extension for executables, typically empty or .exe]) + +AC_DEFINE_UNQUOTED(TEST_BUS_LAUNCH_BINARY, ["$DBUS_PWD/tools/dbus-launch$EXEEXT"], + [Full path to the dbus-launch in the builddir]) + +## Export the non-setuid external helper +TEST_LAUNCH_HELPER_BINARY="$DBUS_PWD/bus/dbus-daemon-launch-helper-test$EXEEXT" +AC_SUBST(TEST_LAUNCH_HELPER_BINARY) +AC_DEFINE_UNQUOTED(DBUS_TEST_LAUNCH_HELPER_BINARY, "$TEST_LAUNCH_HELPER_BINARY", + [Full path to the launch helper test program in the builddir]) + +#### Find socket directories +if ! test -z "$TMPDIR" ; then + DEFAULT_SOCKET_DIR=$TMPDIR +elif ! test -z "$TEMP" ; then + DEFAULT_SOCKET_DIR=$TEMP +elif ! test -z "$TMP" ; then + DEFAULT_SOCKET_DIR=$TMP +else + DEFAULT_SOCKET_DIR=/tmp +fi + +DEFAULT_SOCKET_DIR=`echo $DEFAULT_SOCKET_DIR | sed 's/+/%2B/g'` + +if ! test -z "$with_test_socket_dir" ; then + TEST_SOCKET_DIR="$with_test_socket_dir" +else + TEST_SOCKET_DIR=$DEFAULT_SOCKET_DIR +fi +AC_SUBST(TEST_SOCKET_DIR) +AC_DEFINE_UNQUOTED(DBUS_TEST_SOCKET_DIR, "$TEST_SOCKET_DIR", [Where to put test sockets]) + +if test "x$dbus_unix" = xyes; then + TEST_LISTEN="unix:tmpdir=$TEST_SOCKET_DIR" +else + TEST_LISTEN="tcp:host=localhost" +fi +AC_SUBST([TEST_LISTEN]) +AC_DEFINE_UNQUOTED([TEST_LISTEN], ["$TEST_LISTEN"], + [Listening address for regression tests]) + +if ! test -z "$with_session_socket_dir" ; then + DBUS_SESSION_SOCKET_DIR="$with_session_socket_dir" +else + DBUS_SESSION_SOCKET_DIR=$DEFAULT_SOCKET_DIR +fi +AC_DEFINE_UNQUOTED(DBUS_SESSION_SOCKET_DIR, "$DBUS_SESSION_SOCKET_DIR", [Where per-session bus puts its sockets]) +AC_SUBST(DBUS_SESSION_SOCKET_DIR) + +# This must be a listening address. It doesn't necessarily need to be an +# address you can connect to - it can be something vague like +# "nonce-tcp:". +# +# The default varies by platform. +AC_ARG_WITH([dbus_session_bus_listen_address], + AS_HELP_STRING([--with-dbus-session-bus-listen-address=[ADDRESS]], + [default address for a session bus to listen on (see configure.ac)]), + [with_dbus_session_bus_listen_address=$withval], + [with_dbus_session_bus_listen_address=]) + +if test "x$with_dbus_session_bus_listen_address" != "x"; then + # the user specified something, trust them + DBUS_SESSION_BUS_LISTEN_ADDRESS="$with_dbus_session_bus_listen_address" +elif test x$dbus_win = xyes; then + # On Windows, you can (and should) listen on autolaunch addresses, + # because autolaunching is different. + # See https://bugs.freedesktop.org/show_bug.cgi?id=38201 + DBUS_SESSION_BUS_LISTEN_ADDRESS="autolaunch:" +elif test x$have_launchd = xyes; then + # Mac OS X default is to use launchd + DBUS_SESSION_BUS_LISTEN_ADDRESS="launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET" +else + # The default on all other Unix platforms (notably Linux) + # is to create a randomly named socket in /tmp or similar + DBUS_SESSION_BUS_LISTEN_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR" +fi +AC_SUBST([DBUS_SESSION_BUS_LISTEN_ADDRESS]) + +# This must be an address you can connect to. It doesn't necessarily +# need to be an address you can listen on - it can be "autolaunch:", +# even on Unix. +# +# The default varies by platform. +AC_ARG_WITH([dbus_session_bus_connect_address], + AS_HELP_STRING([--with-dbus-session-bus-connect-address=[ADDRESS]], + [fallback address for a session bus client to connect to (see configure.ac)]), + [with_dbus_session_bus_connect_address=$withval], + [with_dbus_session_bus_connect_address=]) + +if test "x$with_dbus_session_bus_connect_address" != "x"; then + # the user specified something, trust them + DBUS_SESSION_BUS_CONNECT_ADDRESS="$with_dbus_session_bus_connect_address" +elif test x$dbus_win = xyes; then + # Windows autolaunching is a bit different; leaving it in its own + # branch of the conditional because the default might conceivably + # change (see #38201) + DBUS_SESSION_BUS_CONNECT_ADDRESS="autolaunch:" +else + # The default on all other Unix platforms (notably Linux) + # is to use auto-launching - this works a bit differently on Mac OS X + # but comes out basically the same in the end + DBUS_SESSION_BUS_CONNECT_ADDRESS="autolaunch:" +fi +AC_SUBST([DBUS_SESSION_BUS_CONNECT_ADDRESS]) +AC_DEFINE_UNQUOTED([DBUS_SESSION_BUS_CONNECT_ADDRESS], + ["$DBUS_SESSION_BUS_CONNECT_ADDRESS"], + [Fallback address for session bus clients]) + +# darwin needs this to initialize the environment +AC_CHECK_HEADERS(crt_externs.h) +AC_CHECK_FUNC(_NSGetEnviron, [AC_DEFINE(HAVE_NSGETENVIRON, 1, [Define if your system needs _NSGetEnviron to set up the environment])]) +AH_VERBATIM(_DARWIN_ENVIRON, +[ +#if defined(HAVE_NSGETENVIRON) && defined(HAVE_CRT_EXTERNS_H) +# include <sys/time.h> +# include <crt_externs.h> +# define environ (*_NSGetEnviron()) +#endif +]) + +AC_ARG_ENABLE([stats], + [AS_HELP_STRING([--disable-stats], + [disable bus daemon usage statistics])], + [], [enable_stats=yes]) +if test "x$enable_stats" = xyes; then + AC_DEFINE([DBUS_ENABLE_STATS], [1], + [Define to enable bus daemon usage statistics]) +fi + +AC_ARG_ENABLE([user-session], + [AS_HELP_STRING([--enable-user-session], + [enable user-session semantics for session bus under systemd])], + [], [enable_user_session=no]) +AM_CONDITIONAL([DBUS_ENABLE_USER_SESSION], + [test "x$enable_user_session" = xyes]) + +AC_CONFIG_FILES([ +Doxyfile +dbus/Version +dbus/versioninfo.rc +dbus/dbus-arch-deps.h +bus/system.conf +bus/session.conf +bus/legacy-config/system.conf +bus/legacy-config/session.conf +bus/example-system-enable-stats.conf +bus/example-session-disable-stats.conf +bus/messagebus +bus/messagebus-config +bus/org.freedesktop.dbus-session.plist +bus/rc.messagebus +bus/dbus.service +bus/dbus.socket +bus/systemd-user/dbus.service +bus/systemd-user/dbus.socket +Makefile +dbus/Makefile +bus/Makefile +tools/Makefile +test/Makefile +test/name-test/Makefile +doc/Makefile +doc/dbus-cleanup-sockets.1.xml +doc/dbus-daemon.1.xml +doc/dbus-launch.1.xml +doc/dbus-monitor.1.xml +doc/dbus-run-session.1.xml +doc/dbus-send.1.xml +doc/dbus-test-tool.1.xml +doc/dbus-update-activation-environment.1.xml +doc/dbus-uuidgen.1.xml +dbus-1.pc +dbus-1-uninstalled.pc +]) +AC_OUTPUT + +dnl ========================================================================== +echo " + D-Bus $VERSION + ============== + + prefix: ${EXPANDED_PREFIX} + exec_prefix: ${exec_prefix} + libdir: ${EXPANDED_LIBDIR} + libexecdir: ${EXPANDED_LIBEXECDIR} + bindir: ${EXPANDED_BINDIR} + sysconfdir: ${EXPANDED_SYSCONFDIR} + localstatedir: ${EXPANDED_LOCALSTATEDIR} + datadir: ${EXPANDED_DATADIR} + source code location: ${srcdir} + compiler: ${CC} + cflags: ${CFLAGS} + cppflags: ${CPPFLAGS} + cxxflags: ${CXXFLAGS} + 64-bit int: ${DBUS_INT64_TYPE} + 32-bit int: ${DBUS_INT32_TYPE} + 16-bit int: ${DBUS_INT16_TYPE} + Doxygen: ${DOXYGEN:-not found} + xmlto: ${XMLTO:-not found} + ducktype: ${DUCKTYPE:-not found} + yelp-build: ${YELP_BUILD:-not found}" + +echo " + Rebuilding generated files: ${USE_MAINTAINER_MODE} + gcc coverage profiling: ${enable_compiler_coverage} + Building embedded tests: ${enable_embedded_tests} + Building modular tests: ${enable_modular_tests} + - with GLib: ${with_glib} + Installing tests: ${enable_installed_tests} + Building verbose mode: ${enable_verbose_mode} + Building assertions: ${enable_asserts} + Building checks: ${enable_checks} + Building bus stats API: ${enable_stats} + Building SELinux support: ${have_selinux} + Building AppArmor support: ${have_apparmor} + Building inotify support: ${have_inotify} + Building kqueue support: ${have_kqueue} + Building systemd support: ${have_systemd} + Building X11 code: ${have_x11} + Building Doxygen docs: ${enable_doxygen_docs} + Building Ducktype docs: ${enable_ducktype_docs} + Building XML docs: ${enable_xml_docs} + Building launchd support: ${have_launchd} + Init scripts style: ${with_init_scripts} + Abstract socket names: ${ac_cv_have_abstract_sockets} + System bus socket: ${DBUS_SYSTEM_SOCKET} + System bus address: ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS} + System bus PID file: ${DBUS_SYSTEM_PID_FILE} + Session bus listens on: ${DBUS_SESSION_BUS_LISTEN_ADDRESS} + Session clients connect to: ${DBUS_SESSION_BUS_CONNECT_ADDRESS} + Console auth dir: ${DBUS_CONSOLE_AUTH_DIR} + Console owner file: ${have_console_owner_file} + Console owner file path: ${DBUS_CONSOLE_OWNER_FILE} + System bus user: ${DBUS_USER} + Session bus services dir: ${EXPANDED_DATADIR}/dbus-1/services + 'make check' socket dir: ${TEST_SOCKET_DIR} +" +if test x$have_launchd = xyes; then + echo " launchd agent dir: ${LAUNCHD_AGENT_DIR}" +fi +echo + +if test x$enable_embedded_tests = xyes; then + echo "NOTE: building with unit tests increases the size of the installed library and renders it insecure." +fi +if test x$enable_embedded_tests = xyes -a x$enable_asserts = xno; then + echo "NOTE: building with embedded tests but without assertions means tests may not properly report failures (this configuration is only useful when doing something like profiling the tests)" +fi +if test x$enable_compiler_coverage = xyes; then + echo "NOTE: building with coverage profiling is definitely for developers only." +fi +if test x$enable_verbose_mode = xyes; then + echo "NOTE: building with verbose mode increases library size, may slightly increase security risk, and decreases performance." +fi +if test x$enable_asserts = xyes; then + echo "NOTE: building with assertions increases library size and decreases performance." +fi +if test x$enable_checks = xno; then + echo "NOTE: building without checks for arguments passed to public API makes it harder to debug apps using D-Bus, but will slightly decrease D-Bus library size and _very_ slightly improve performance." +fi
diff --git a/dbus-1-uninstalled.pc.in b/dbus-1-uninstalled.pc.in new file mode 100644 index 0000000..b66ad2f --- /dev/null +++ b/dbus-1-uninstalled.pc.in
@@ -0,0 +1,20 @@ +abs_top_builddir=@abs_top_builddir@ +abs_top_srcdir=@abs_top_srcdir@ +prefix= +exec_prefix= +bindir=@bindir@ +system_bus_default_address=@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@ +datarootdir=@datarootdir@ +datadir=@datadir@ +sysconfdir=@sysconfdir@ +session_bus_services_dir=${datadir}/dbus-1/services +system_bus_services_dir=${datadir}/dbus-1/system-services +interfaces_dir=${datadir}/dbus-1/interfaces +daemondir=@dbus_daemondir@ + +Name: dbus +Description: Free desktop message bus (uninstalled copy) +Version: @VERSION@ +Libs: ${abs_top_builddir}/dbus/libdbus-1.la +Libs.private: @LIBDBUS_LIBS@ +Cflags: -I${abs_top_srcdir} @DBUS_STATIC_BUILD_CPPFLAGS@
diff --git a/dbus-1.pc.in b/dbus-1.pc.in new file mode 100644 index 0000000..f93d156 --- /dev/null +++ b/dbus-1.pc.in
@@ -0,0 +1,20 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ +libdir=@libdir@ +includedir=@includedir@ +system_bus_default_address=@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@ +datarootdir=@datarootdir@ +datadir=@datadir@ +sysconfdir=@sysconfdir@ +session_bus_services_dir=${datadir}/dbus-1/services +system_bus_services_dir=${datadir}/dbus-1/system-services +interfaces_dir=${datadir}/dbus-1/interfaces +daemondir=@dbus_daemondir@ + +Name: dbus +Description: Free desktop message bus +Version: @VERSION@ +Libs: -L${libdir} -ldbus-1 +Libs.private: @LIBDBUS_LIBS@ +Cflags: -I${includedir}/dbus-1.0 -I${libdir}/dbus-1.0/include @DBUS_STATIC_BUILD_CPPFLAGS@
diff --git a/dbus/.gitignore b/dbus/.gitignore new file mode 100644 index 0000000..e495cb3 --- /dev/null +++ b/dbus/.gitignore
@@ -0,0 +1,16 @@ +.deps +.libs +Makefile +Makefile.in +*.lo +*.la +dbus-test +*.bb +*.bbg +*.gcov +*.da +.dbus-keyrings +dbus-glib-error-enum.h +*.gcno +*.gcda +versioninfo.rc
diff --git a/dbus/Android.mk b/dbus/Android.mk new file mode 100644 index 0000000..1e7ed8a --- /dev/null +++ b/dbus/Android.mk
@@ -0,0 +1,113 @@ +# Set to true to write libdbus logs to logcat instead of stderr +# See also config.h to turn on verbose logs +LOG_TO_ANDROID_LOGCAT := true + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + dbus-address.c \ + dbus-asv-util.c \ + dbus-auth.c \ + dbus-bus.c \ + dbus-connection.c \ + dbus-credentials.c \ + dbus-dataslot.c \ + dbus-errors.c \ + dbus-file.c \ + dbus-file-unix.c \ + dbus-hash.c \ + dbus-internals.c \ + dbus-keyring.c \ + dbus-list.c \ + dbus-mainloop.c \ + dbus-marshal-basic.c \ + dbus-marshal-byteswap.c \ + dbus-marshal-header.c \ + dbus-marshal-recursive.c \ + dbus-marshal-validate.c \ + dbus-memory.c \ + dbus-mempool.c \ + dbus-message.c \ + dbus-misc.c \ + dbus-nonce.c \ + dbus-object-tree.c \ + dbus-pending-call.c \ + dbus-pipe.c \ + dbus-pipe-unix.c \ + dbus-resources.c \ + dbus-server.c \ + dbus-server-debug-pipe.c \ + dbus-server-launchd.c \ + dbus-server-socket.c \ + dbus-server-unix.c \ + dbus-sha.c \ + dbus-shell.c \ + dbus-signature.c \ + dbus-socket-set.c \ + dbus-socket-set-epoll.c \ + dbus-socket-set-poll.c \ + dbus-spawn.c \ + dbus-string.c \ + dbus-string-util.c \ + dbus-syntax.c \ + dbus-sysdeps.c \ + dbus-sysdeps-pthread.c \ + dbus-sysdeps-unix.c \ + dbus-sysdeps-util.c \ + dbus-sysdeps-util-unix.c \ + dbus-threads.c \ + dbus-timeout.c \ + dbus-transport.c \ + dbus-transport-socket.c \ + dbus-transport-unix.c \ + dbus-userdb.c \ + dbus-userdb-util.c \ + dbus-uuidgen.c \ + dbus-watch.c + +LOCAL_C_INCLUDES+= $(LOCAL_PATH)/.. + +LOCAL_MODULE:=libdbus + +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/.. + +LOCAL_CFLAGS+= \ + -DDBUS_COMPILATION \ + -DHAVE_MONOTONIC_CLOCK \ + -DDBUS_MACHINE_UUID_FILE=\"/etc/machine-id\" \ + -DDBUS_SYSTEM_CONFIG_FILE=\"/etc/dbus-1/system.conf\" \ + -DDBUS_SESSION_CONFIG_FILE=\"/etc/dbus-1/session.conf\" \ + -Wno-empty-body \ + -Wno-missing-field-initializers \ + -Wno-pointer-sign \ + -Wno-sign-compare \ + -Wno-tautological-compare \ + -Wno-type-limits \ + -Wno-unused-parameter + +LOCAL_CLANG := true + +ifeq ($(LOG_TO_ANDROID_LOGCAT),true) +ifneq ($(TARGET_ARCH), x86-64) +LOCAL_CFLAGS+= \ + -DDBUS_ANDROID_LOG \ + -DANDROID_MANAGED_SOCKET + +LOCAL_SHARED_LIBRARIES+= libcutils liblog +endif +endif + +ifeq ($(TARGET_ARCH), x86-64) +LOCAL_CFLAGS+= -D_GNU_SOURCE +endif + +ifeq ($(BUILD_EUREKA),true) +# Copy the headers to the build sysroot directory. +include_dir := $(LOCAL_PATH)/.. +include_files := $(shell find $(include_dir) -type f -name '*.h') +LOCAL_TOOLCHAIN_PREBUILTS := \ + $(join $(include_files),\ + $(patsubst $(include_dir)/%,:usr/include/%,$(include_files))) +endif +include $(BUILD_SHARED_LIBRARY)
diff --git a/dbus/Makefile.am b/dbus/Makefile.am new file mode 100644 index 0000000..a7b3491 --- /dev/null +++ b/dbus/Makefile.am
@@ -0,0 +1,328 @@ + +dbusdatadir=$(datadir)/dbus-1 + +AM_CPPFLAGS = \ + -I$(top_builddir) \ + -I$(top_srcdir) \ + $(DBUS_STATIC_BUILD_CPPFLAGS) \ + $(SYSTEMD_CFLAGS) \ + $(VALGRIND_CFLAGS) \ + -DDBUS_COMPILATION \ + -DDBUS_MACHINE_UUID_FILE=\""$(localstatedir)/lib/dbus/machine-id"\" \ + -DDBUS_SYSTEM_CONFIG_FILE=\""$(dbusdatadir)/system.conf"\" \ + -DDBUS_SESSION_CONFIG_FILE=\""$(dbusdatadir)/session.conf"\" \ + $(NULL) + +AM_CFLAGS = + +if HAVE_VISIBILITY +if !DBUS_WIN +AM_CFLAGS += $(CFLAG_VISIBILITY) +AM_CPPFLAGS += \ + -DDBUS_EXPORT='__attribute__((__visibility__("default")))' \ + -DDBUS_PRIVATE_EXPORT='__attribute__((__visibility__("default")))' \ + $(NULL) +endif +endif + +# if assertions are enabled, improve backtraces +AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ + +dbusincludedir=$(includedir)/dbus-1.0/dbus +dbusarchincludedir=$(libdir)/dbus-1.0/include/dbus + +lib_LTLIBRARIES=libdbus-1.la + +# +# Deal with W32 .def and version-info.rc stuff +# +if DBUS_WIN + +SUFFIXES = rc + +.rc.o: + $(WINDRES) $< -o $@ + +dbus_res = versioninfo.o +dbus_res_ldflag = -Wl,$(dbus_res) +no_undefined = -no-undefined +export_symbols = + +EXTRA_libdbus_1_la_DEPENDENCIES = $(dbus_res) +intllibs = + +else +dbus_res = +dbus_res_ldflag = +no_undefined = + +intllibs = @LTLIBINTL@ + +endif + + +# +# Platform-dependent sources: +# +if DBUS_WIN +DBUS_LIB_arch_sources = \ + dbus-server-win.c \ + dbus-server-win.h + +if DBUS_WINCE +wince_source = dbus-sysdeps-wince-glue.h dbus-sysdeps-wince-glue.c +else +wince_source = +endif + +DBUS_SHARED_arch_sources = \ + $(wince_source) \ + dbus-file-win.c \ + dbus-pipe-win.c \ + dbus-sockets-win.h \ + dbus-sysdeps-win.c \ + dbus-sysdeps-win.h \ + dbus-sysdeps-thread-win.c \ + dbus-transport-win.c \ + dbus-transport-win.h + +DBUS_UTIL_arch_sources = \ + dbus-sysdeps-util-win.c \ + dbus-spawn-win.c +else + +if DBUS_ENABLE_LAUNCHD +launchd_source = dbus-server-launchd.h dbus-server-launchd.c +else +launchd_source = +endif + +DBUS_LIB_arch_sources = \ + dbus-uuidgen.c \ + dbus-uuidgen.h \ + dbus-server-unix.c \ + dbus-server-unix.h + +DBUS_SHARED_arch_sources = \ + $(launchd_source) \ + dbus-file-unix.c \ + dbus-pipe-unix.c \ + dbus-sysdeps-unix.c \ + dbus-sysdeps-unix.h \ + dbus-sysdeps-pthread.c \ + dbus-transport-unix.c \ + dbus-transport-unix.h \ + dbus-userdb.c \ + dbus-userdb.h \ + $(NULL) + +DBUS_UTIL_arch_sources = \ + dbus-sysdeps-util-unix.c \ + dbus-userdb-util.c \ + dbus-spawn.c +endif + +if HAVE_LINUX_EPOLL +DBUS_UTIL_arch_sources += dbus-socket-set-epoll.c +endif + +dbusinclude_HEADERS= \ + dbus.h \ + dbus-address.h \ + dbus-bus.h \ + dbus-connection.h \ + dbus-errors.h \ + dbus-macros.h \ + dbus-memory.h \ + dbus-message.h \ + dbus-misc.h \ + dbus-pending-call.h \ + dbus-protocol.h \ + dbus-server.h \ + dbus-shared.h \ + dbus-signature.h \ + dbus-syntax.h \ + dbus-threads.h \ + dbus-types.h + + +nodist_dbusarchinclude_HEADERS= \ + dbus-arch-deps.h + +### source code that goes in the installed client library +### and is specific to library functionality +DBUS_LIB_SOURCES= \ + dbus-address.c \ + dbus-auth.c \ + dbus-auth.h \ + dbus-bus.c \ + dbus-connection.c \ + dbus-connection-internal.h \ + dbus-credentials.c \ + dbus-credentials.h \ + dbus-errors.c \ + dbus-keyring.c \ + dbus-keyring.h \ + dbus-marshal-header.c \ + dbus-marshal-header.h \ + dbus-marshal-byteswap.c \ + dbus-marshal-byteswap.h \ + dbus-marshal-recursive.c \ + dbus-marshal-recursive.h \ + dbus-marshal-validate.c \ + dbus-marshal-validate.h \ + dbus-message.c \ + dbus-message-internal.h \ + dbus-message-private.h \ + dbus-misc.c \ + dbus-nonce.h \ + dbus-nonce.c \ + dbus-object-tree.c \ + dbus-object-tree.h \ + dbus-pending-call.c \ + dbus-pending-call-internal.h \ + dbus-resources.c \ + dbus-resources.h \ + dbus-server.c \ + dbus-server-debug-pipe.c \ + dbus-server-debug-pipe.h \ + dbus-server-protected.h \ + dbus-server-socket.c \ + dbus-server-socket.h \ + $(DBUS_LIB_arch_sources) \ + dbus-sha.c \ + dbus-sha.h \ + dbus-signature.c \ + dbus-syntax.c \ + dbus-timeout.c \ + dbus-timeout.h \ + dbus-threads-internal.h \ + dbus-threads.c \ + dbus-transport.c \ + dbus-transport.h \ + dbus-transport-protected.h \ + dbus-transport-socket.c \ + dbus-transport-socket.h \ + dbus-watch.c \ + dbus-watch.h + +### source code that goes in the installed client library +### AND is generic utility functionality used by the +### daemon or test programs (all symbols in here should +### be underscore-prefixed) +DBUS_SHARED_SOURCES= \ + dbus-dataslot.c \ + dbus-dataslot.h \ + dbus-file.c \ + dbus-file.h \ + dbus-hash.c \ + dbus-hash.h \ + dbus-internals.c \ + dbus-internals.h \ + dbus-list.c \ + dbus-list.h \ + dbus-marshal-basic.c \ + dbus-marshal-basic.h \ + dbus-memory.c \ + dbus-mempool.c \ + dbus-mempool.h \ + dbus-pipe.c \ + dbus-pipe.h \ + dbus-string.c \ + dbus-string.h \ + dbus-string-private.h \ + $(DBUS_SHARED_arch_sources) \ + dbus-sysdeps.c \ + dbus-sysdeps.h \ + dbus-valgrind-internal.h + +### source code that is generic utility functionality used +### by the bus daemon or test apps, but is NOT included +### in the D-Bus client library (all symbols in here +### should be underscore-prefixed but don't really need +### to be unless they move to DBUS_SHARED_SOURCES later) +DBUS_UTIL_SOURCES= \ + dbus-asv-util.c \ + dbus-asv-util.h \ + dbus-auth-script.c \ + dbus-auth-script.h \ + dbus-auth-util.c \ + dbus-credentials-util.c \ + dbus-mainloop.c \ + dbus-mainloop.h \ + dbus-marshal-byteswap-util.c \ + dbus-marshal-recursive-util.c \ + dbus-marshal-validate-util.c \ + dbus-message-factory.c \ + dbus-message-factory.h \ + dbus-message-util.c \ + dbus-shell.c \ + dbus-shell.h \ + $(DBUS_UTIL_arch_sources) \ + dbus-socket-set.h \ + dbus-socket-set.c \ + dbus-socket-set-poll.c \ + dbus-spawn.h \ + dbus-string-util.c \ + dbus-sysdeps-util.c \ + dbus-test.c \ + dbus-test.h + +libdbus_1_la_SOURCES= \ + $(DBUS_LIB_SOURCES) \ + $(DBUS_SHARED_SOURCES) + +libdbus_internal_la_SOURCES= \ + $(DBUS_UTIL_SOURCES) + +BUILT_SOURCES=$(nodist_dbusarchinclude_HEADERS) +EXTRA_DIST=dbus-arch-deps.h.in + +noinst_LTLIBRARIES=libdbus-internal.la + +libdbus_1_la_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -Ddbus_1_EXPORTS \ + $(NULL) + +if HAVE_LD_VERSION_SCRIPT +SYMBOL_EXPORT_LDFLAGS=-Wl,--version-script=Version +else +SYMBOL_EXPORT_LDFLAGS= +endif + +libdbus_1_la_LIBADD= $(LIBDBUS_LIBS) +libdbus_1_la_LDFLAGS = \ + $(AM_LDFLAGS) \ + -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ + $(SYMBOL_EXPORT_LDFLAGS) \ + -no-undefined \ + $(NULL) + +libdbus_internal_la_LIBADD=$(LIBDBUS_LIBS) libdbus-1.la + +if DBUS_WIN +# This must be a separate convenience library, otherwise libtool notices +# that libdbus-1 might contain C++, links it with g++ and links in libstdc++, +# even on Unix where in fact it doesn't contain any C++. For Windows, where +# this code is used, we don't actually need libstdc++. +noinst_LTLIBRARIES += libdbus-init-win.la +libdbus_init_win_la_SOURCES = dbus-init-win.cpp +libdbus_1_la_LIBADD += libdbus-init-win.la +endif + +noinst_PROGRAMS = + +if DBUS_ENABLE_EMBEDDED_TESTS +# We can't actually run this til we've reached test/ +noinst_PROGRAMS += test-dbus +endif + +test_dbus_SOURCES= \ + dbus-test-main.c + +test_dbus_LDADD = libdbus-internal.la + +## mop up the gcov files +clean-local: + /bin/rm *.bb *.bbg *.da *.gcov .libs/*.da .libs/*.bbg || true
diff --git a/dbus/NOTICE b/dbus/NOTICE new file mode 100644 index 0000000..a91ca1d --- /dev/null +++ b/dbus/NOTICE
@@ -0,0 +1,551 @@ +D-Bus is licensed to you under your choice of the Academic Free +License version 2.1, or the GNU General Public License version 2. +Both licenses are included here. Some of the standalone binaries are +under the GPL only; in particular, but not limited to, +tools/dbus-cleanup-sockets.c and test/decode-gcov.c. Each source code +file is marked with the proper copyright information - if you find a +file that isn't marked please bring it to our attention. + + +The Academic Free License +v. 2.1 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following notice immediately following the copyright notice for the Original Work: + +Licensed under the Academic Free License version 2.1 + +1) Grant of Copyright License. Licensor hereby grants You a +world-wide, royalty-free, non-exclusive, perpetual, sublicenseable +license to do the following: + +a) to reproduce the Original Work in copies; + +b) to prepare derivative works ("Derivative Works") based upon the Original Work; + +c) to distribute copies of the Original Work and Derivative Works to the public; + +d) to perform the Original Work publicly; and + +e) to display the Original Work publicly. + +2) Grant of Patent License. Licensor hereby grants You a world-wide, +royalty-free, non-exclusive, perpetual, sublicenseable license, under +patent claims owned or controlled by the Licensor that are embodied in +the Original Work as furnished by the Licensor, to make, use, sell and +offer for sale the Original Work and Derivative Works. + +3) Grant of Source Code License. The term "Source Code" means the +preferred form of the Original Work for making modifications to it and +all available documentation describing how to modify the Original +Work. Licensor hereby agrees to provide a machine-readable copy of the +Source Code of the Original Work along with each copy of the Original +Work that Licensor distributes. Licensor reserves the right to satisfy +this obligation by placing a machine-readable copy of the Source Code +in an information repository reasonably calculated to permit +inexpensive and convenient access by You for as long as Licensor +continues to distribute the Original Work, and by publishing the +address of that information repository in a notice immediately +following the copyright notice that applies to the Original Work. + +4) Exclusions From License Grant. Neither the names of Licensor, nor +the names of any contributors to the Original Work, nor any of their +trademarks or service marks, may be used to endorse or promote +products derived from this Original Work without express prior written +permission of the Licensor. Nothing in this License shall be deemed to +grant any rights to trademarks, copyrights, patents, trade secrets or +any other intellectual property of Licensor except as expressly stated +herein. No patent license is granted to make, use, sell or offer to +sell embodiments of any patent claims other than the licensed claims +defined in Section 2. No right is granted to the trademarks of +Licensor even if such marks are included in the Original Work. Nothing +in this License shall be interpreted to prohibit Licensor from +licensing under different terms from this License any Original Work +that Licensor otherwise would have a right to license. + +5) This section intentionally omitted. + +6) Attribution Rights. You must retain, in the Source Code of any +Derivative Works that You create, all copyright, patent or trademark +notices from the Source Code of the Original Work, as well as any +notices of licensing and any descriptive text identified therein as an +"Attribution Notice." You must cause the Source Code for any +Derivative Works that You create to carry a prominent Attribution +Notice reasonably calculated to inform recipients that You have +modified the Original Work. + +7) Warranty of Provenance and Disclaimer of Warranty. Licensor +warrants that the copyright in and to the Original Work and the patent +rights granted herein by Licensor are owned by the Licensor or are +sublicensed to You under the terms of this License with the permission +of the contributor(s) of those copyrights and patent rights. Except as +expressly stated in the immediately proceeding sentence, the Original +Work is provided under this License on an "AS IS" BASIS and WITHOUT +WARRANTY, either express or implied, including, without limitation, +the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL +WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential +part of this License. No license to Original Work is granted hereunder +except under this disclaimer. + +8) Limitation of Liability. Under no circumstances and under no legal +theory, whether in tort (including negligence), contract, or +otherwise, shall the Licensor be liable to any person for any direct, +indirect, special, incidental, or consequential damages of any +character arising as a result of this License or the use of the +Original Work including, without limitation, damages for loss of +goodwill, work stoppage, computer failure or malfunction, or any and +all other commercial damages or losses. This limitation of liability +shall not apply to liability for death or personal injury resulting +from Licensor's negligence to the extent applicable law prohibits such +limitation. Some jurisdictions do not allow the exclusion or +limitation of incidental or consequential damages, so this exclusion +and limitation may not apply to You. + +9) Acceptance and Termination. If You distribute copies of the +Original Work or a Derivative Work, You must make a reasonable effort +under the circumstances to obtain the express assent of recipients to +the terms of this License. Nothing else but this License (or another +written agreement between Licensor and You) grants You permission to +create Derivative Works based upon the Original Work or to exercise +any of the rights granted in Section 1 herein, and any attempt to do +so except under the terms of this License (or another written +agreement between Licensor and You) is expressly prohibited by +U.S. copyright law, the equivalent laws of other countries, and by +international treaty. Therefore, by exercising any of the rights +granted to You in Section 1 herein, You indicate Your acceptance of +this License and all of its terms and conditions. + +10) Termination for Patent Action. This License shall terminate +automatically and You may no longer exercise any of the rights granted +to You by this License as of the date You commence an action, +including a cross-claim or counterclaim, against Licensor or any +licensee alleging that the Original Work infringes a patent. This +termination provision shall not apply for an action alleging patent +infringement by combinations of the Original Work with other software +or hardware. + +11) Jurisdiction, Venue and Governing Law. Any action or suit relating +to this License may be brought only in the courts of a jurisdiction +wherein the Licensor resides or in which Licensor conducts its primary +business, and under the laws of that jurisdiction excluding its +conflict-of-law provisions. The application of the United Nations +Convention on Contracts for the International Sale of Goods is +expressly excluded. Any use of the Original Work outside the scope of +this License or after its termination shall be subject to the +requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 +et seq., the equivalent laws of other countries, and international +treaty. This section shall survive the termination of this License. + +12) Attorneys Fees. In any action to enforce the terms of this License +or seeking damages relating thereto, the prevailing party shall be +entitled to recover its costs and expenses, including, without +limitation, reasonable attorneys' fees and costs incurred in +connection with such action, including any appeal of such action. This +section shall survive the termination of this License. + +13) Miscellaneous. This License represents the complete agreement +concerning the subject matter hereof. If any provision of this License +is held to be unenforceable, such provision shall be reformed only to +the extent necessary to make it enforceable. + +14) Definition of "You" in This License. "You" throughout this +License, whether in upper or lower case, means an individual or a +legal entity exercising rights under, and complying with all of the +terms of, this License. For legal entities, "You" includes any entity +that controls, is controlled by, or is under common control with +you. For purposes of this definition, "control" means (i) the power, +direct or indirect, to cause the direction or management of such +entity, whether by contract or otherwise, or (ii) ownership of fifty +percent (50%) or more of the outstanding shares, or (iii) beneficial +ownership of such entity. + +15) Right to Use. You may use the Original Work in all ways not +otherwise restricted or conditioned by this License or by law, and +Licensor promises not to interfere with or be responsible for such +uses by You. + +This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights +reserved. Permission is hereby granted to copy and distribute this +license without modification. This license may not be modified without +the express written permission of its copyright owner. + + +-- +END OF ACADEMIC FREE LICENSE. The following is intended to describe the essential +differences between the Academic Free License (AFL) version 1.0 and other +open source licenses: + +The Academic Free License is similar to the BSD, MIT, UoI/NCSA and Apache +licenses in many respects but it is intended to solve a few problems with +those licenses. + +* The AFL is written so as to make it clear what software is being +licensed (by the inclusion of a statement following the copyright notice +in the software). This way, the license functions better than a template +license. The BSD, MIT and UoI/NCSA licenses apply to unidentified software. + +* The AFL contains a complete copyright grant to the software. The BSD +and Apache licenses are vague and incomplete in that respect. + +* The AFL contains a complete patent grant to the software. The BSD, MIT, +UoI/NCSA and Apache licenses rely on an implied patent license and contain +no explicit patent grant. + +* The AFL makes it clear that no trademark rights are granted to the +licensor's trademarks. The Apache license contains such a provision, but the +BSD, MIT and UoI/NCSA licenses do not. + +* The AFL includes the warranty by the licensor that it either owns the +copyright or that it is distributing the software under a license. None of +the other licenses contain that warranty. All other warranties are disclaimed, +as is the case for the other licenses. + +* The AFL is itself copyrighted (with the right granted to copy and distribute +without modification). This ensures that the owner of the copyright to the +license will control changes. The Apache license contains a copyright notice, +but the BSD, MIT and UoI/NCSA licenses do not. +-- +START OF GNU GENERAL PUBLIC LICENSE +-- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE 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. + + 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 +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This 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 Library General +Public License instead of this License.
diff --git a/dbus/Version.in b/dbus/Version.in new file mode 100644 index 0000000..f6cc367 --- /dev/null +++ b/dbus/Version.in
@@ -0,0 +1,10 @@ +LIBDBUS_1_@SOVERSION@ { + global: + dbus_*; + local: + *; +}; +LIBDBUS_PRIVATE_@DBUS_VERSION@ { + global: + _dbus_*; +};
diff --git a/dbus/dbus-address.c b/dbus/dbus-address.c new file mode 100644 index 0000000..c4cfbbe --- /dev/null +++ b/dbus/dbus-address.c
@@ -0,0 +1,828 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-address.c Server address parser. + * + * Copyright (C) 2003 CodeFactory AB + * Copyright (C) 2004,2005 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "dbus-address.h" +#include "dbus-internals.h" +#include "dbus-list.h" +#include "dbus-string.h" +#include "dbus-protocol.h" + +/** + * @defgroup DBusAddressInternals Address parsing + * @ingroup DBusInternals + * @brief Implementation of parsing addresses of D-Bus servers. + * + * @{ + */ + +/** + * Internals of DBusAddressEntry + */ +struct DBusAddressEntry +{ + DBusString method; /**< The address type (unix, tcp, etc.) */ + + DBusList *keys; /**< List of keys */ + DBusList *values; /**< List of values */ +}; + + +/** + * + * Sets #DBUS_ERROR_BAD_ADDRESS. + * If address_problem_type and address_problem_field are not #NULL, + * sets an error message about how the field is no good. Otherwise, sets + * address_problem_other as the error message. + * + * @param error the error to set + * @param address_problem_type the address type of the bad address or #NULL + * @param address_problem_field the missing field of the bad address or #NULL + * @param address_problem_other any other error message or #NULL + */ +void +_dbus_set_bad_address (DBusError *error, + const char *address_problem_type, + const char *address_problem_field, + const char *address_problem_other) +{ + if (address_problem_type != NULL) + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS, + "Server address of type %s was missing argument %s", + address_problem_type, address_problem_field); + else + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS, + "Could not parse server address: %s", + address_problem_other); +} + +/** + * #TRUE if the byte need not be escaped when found in a dbus address. + * All other bytes are required to be escaped in a valid address. + */ +#define _DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE(b) \ + (((b) >= 'a' && (b) <= 'z') || \ + ((b) >= 'A' && (b) <= 'Z') || \ + ((b) >= '0' && (b) <= '9') || \ + (b) == '-' || \ + (b) == '_' || \ + (b) == '/' || \ + (b) == '\\' || \ + (b) == '*' || \ + (b) == '.') + +/** + * Appends an escaped version of one string to another string, + * using the D-Bus address escaping mechanism + * + * @param escaped the string to append to + * @param unescaped the string to escape + * @returns #FALSE if no memory + */ +dbus_bool_t +_dbus_address_append_escaped (DBusString *escaped, + const DBusString *unescaped) +{ + const unsigned char *p; + const unsigned char *end; + dbus_bool_t ret; + int orig_len; + + ret = FALSE; + + orig_len = _dbus_string_get_length (escaped); + p = (const unsigned char *) _dbus_string_get_const_data (unescaped); + end = p + _dbus_string_get_length (unescaped); + while (p != end) + { + if (_DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE (*p)) + { + if (!_dbus_string_append_byte (escaped, *p)) + goto out; + } + else + { + if (!_dbus_string_append_byte (escaped, '%')) + goto out; + if (!_dbus_string_append_byte_as_hex (escaped, *p)) + goto out; + } + + ++p; + } + + ret = TRUE; + + out: + if (!ret) + _dbus_string_set_length (escaped, orig_len); + return ret; +} + +/** @} */ /* End of internals */ + +static void +dbus_address_entry_free (DBusAddressEntry *entry) +{ + DBusList *link; + + _dbus_string_free (&entry->method); + + link = _dbus_list_get_first_link (&entry->keys); + while (link != NULL) + { + _dbus_string_free (link->data); + dbus_free (link->data); + + link = _dbus_list_get_next_link (&entry->keys, link); + } + _dbus_list_clear (&entry->keys); + + link = _dbus_list_get_first_link (&entry->values); + while (link != NULL) + { + _dbus_string_free (link->data); + dbus_free (link->data); + + link = _dbus_list_get_next_link (&entry->values, link); + } + _dbus_list_clear (&entry->values); + + dbus_free (entry); +} + +/** + * @defgroup DBusAddress Address parsing + * @ingroup DBus + * @brief Parsing addresses of D-Bus servers. + * + * @{ + */ + +/** + * Frees a #NULL-terminated array of address entries. + * + * @param entries the array. + */ +void +dbus_address_entries_free (DBusAddressEntry **entries) +{ + int i; + + for (i = 0; entries[i] != NULL; i++) + dbus_address_entry_free (entries[i]); + dbus_free (entries); +} + +static DBusAddressEntry * +create_entry (void) +{ + DBusAddressEntry *entry; + + entry = dbus_new0 (DBusAddressEntry, 1); + + if (entry == NULL) + return NULL; + + if (!_dbus_string_init (&entry->method)) + { + dbus_free (entry); + return NULL; + } + + return entry; +} + +/** + * Returns the method string of an address entry. For example, given + * the address entry "tcp:host=example.com" it would return the string + * "tcp" + * + * @param entry the entry. + * @returns a string describing the method. This string + * must not be freed. + */ +const char * +dbus_address_entry_get_method (DBusAddressEntry *entry) +{ + return _dbus_string_get_const_data (&entry->method); +} + +/** + * Returns a value from a key of an entry. For example, + * given the address "tcp:host=example.com,port=8073" if you asked + * for the key "host" you would get the value "example.com" + * + * The returned value is already unescaped. + * + * @param entry the entry. + * @param key the key. + * @returns the key value. This string must not be freed. + */ +const char * +dbus_address_entry_get_value (DBusAddressEntry *entry, + const char *key) +{ + DBusList *values, *keys; + + keys = _dbus_list_get_first_link (&entry->keys); + values = _dbus_list_get_first_link (&entry->values); + + while (keys != NULL) + { + _dbus_assert (values != NULL); + + if (_dbus_string_equal_c_str (keys->data, key)) + return _dbus_string_get_const_data (values->data); + + keys = _dbus_list_get_next_link (&entry->keys, keys); + values = _dbus_list_get_next_link (&entry->values, values); + } + + return NULL; +} + +static dbus_bool_t +append_unescaped_value (DBusString *unescaped, + const DBusString *escaped, + int escaped_start, + int escaped_len, + DBusError *error) +{ + const char *p; + const char *end; + dbus_bool_t ret; + + ret = FALSE; + + p = _dbus_string_get_const_data (escaped) + escaped_start; + end = p + escaped_len; + while (p != end) + { + if (_DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE (*p)) + { + if (!_dbus_string_append_byte (unescaped, *p)) + goto out; + } + else if (*p == '%') + { + /* Efficiency is king */ + char buf[3]; + DBusString hex; + int hex_end; + + ++p; + + if ((p + 2) > end) + { + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS, + "In D-Bus address, percent character was not followed by two hex digits"); + goto out; + } + + buf[0] = *p; + ++p; + buf[1] = *p; + buf[2] = '\0'; + + _dbus_string_init_const (&hex, buf); + + if (!_dbus_string_hex_decode (&hex, 0, &hex_end, + unescaped, + _dbus_string_get_length (unescaped))) + goto out; + + if (hex_end != 2) + { + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS, + "In D-Bus address, percent character was followed by characters other than hex digits"); + goto out; + } + } + else + { + /* Error, should have been escaped */ + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS, + "In D-Bus address, character '%c' should have been escaped\n", + *p); + goto out; + } + + ++p; + } + + ret = TRUE; + + out: + if (!ret && error && !dbus_error_is_set (error)) + _DBUS_SET_OOM (error); + + _dbus_assert (ret || error == NULL || dbus_error_is_set (error)); + + return ret; +} + +/** + * Parses an address string of the form: + * + * method:key=value,key=value;method:key=value + * + * See the D-Bus specification for complete docs on the format. + * + * When connecting to an address, the first address entries + * in the semicolon-separated list should be tried first. + * + * @param address the address. + * @param entry return location to an array of entries. + * @param array_len return location for array length. + * @param error address where an error can be returned. + * @returns #TRUE on success, #FALSE otherwise. + */ +dbus_bool_t +dbus_parse_address (const char *address, + DBusAddressEntry ***entry, + int *array_len, + DBusError *error) +{ + DBusString str; + int pos, end_pos, len, i; + DBusList *entries, *link; + DBusAddressEntry **entry_array; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + _dbus_string_init_const (&str, address); + + entries = NULL; + pos = 0; + len = _dbus_string_get_length (&str); + + if (len == 0) + { + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS, + "Empty address '%s'", address); + goto error; + } + + while (pos < len) + { + DBusAddressEntry *entry; + + int found_pos; + + entry = create_entry (); + if (!entry) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + + goto error; + } + + /* Append the entry */ + if (!_dbus_list_append (&entries, entry)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + dbus_address_entry_free (entry); + goto error; + } + + /* Look for a semi-colon */ + if (!_dbus_string_find (&str, pos, ";", &end_pos)) + end_pos = len; + + /* Look for the colon : */ + if (!_dbus_string_find_to (&str, pos, end_pos, ":", &found_pos)) + { + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS, "Address does not contain a colon"); + goto error; + } + + if (!_dbus_string_copy_len (&str, pos, found_pos - pos, &entry->method, 0)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto error; + } + + pos = found_pos + 1; + + while (pos < end_pos) + { + int comma_pos, equals_pos; + + if (!_dbus_string_find_to (&str, pos, end_pos, ",", &comma_pos)) + comma_pos = end_pos; + + if (!_dbus_string_find_to (&str, pos, comma_pos, "=", &equals_pos) || + equals_pos == pos || equals_pos + 1 == comma_pos) + { + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS, + "'=' character not found or has no value following it"); + goto error; + } + else + { + DBusString *key; + DBusString *value; + + key = dbus_new0 (DBusString, 1); + + if (!key) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto error; + } + + value = dbus_new0 (DBusString, 1); + if (!value) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + dbus_free (key); + goto error; + } + + if (!_dbus_string_init (key)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + dbus_free (key); + dbus_free (value); + + goto error; + } + + if (!_dbus_string_init (value)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + _dbus_string_free (key); + + dbus_free (key); + dbus_free (value); + goto error; + } + + if (!_dbus_string_copy_len (&str, pos, equals_pos - pos, key, 0)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + _dbus_string_free (key); + _dbus_string_free (value); + + dbus_free (key); + dbus_free (value); + goto error; + } + + if (!append_unescaped_value (value, &str, equals_pos + 1, + comma_pos - equals_pos - 1, error)) + { + _dbus_assert (error == NULL || dbus_error_is_set (error)); + _dbus_string_free (key); + _dbus_string_free (value); + + dbus_free (key); + dbus_free (value); + goto error; + } + + if (!_dbus_list_append (&entry->keys, key)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + _dbus_string_free (key); + _dbus_string_free (value); + + dbus_free (key); + dbus_free (value); + goto error; + } + + if (!_dbus_list_append (&entry->values, value)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + _dbus_string_free (value); + + dbus_free (value); + goto error; + } + } + + pos = comma_pos + 1; + } + + pos = end_pos + 1; + } + + *array_len = _dbus_list_get_length (&entries); + + entry_array = dbus_new (DBusAddressEntry *, *array_len + 1); + + if (!entry_array) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + + goto error; + } + + entry_array [*array_len] = NULL; + + link = _dbus_list_get_first_link (&entries); + i = 0; + while (link != NULL) + { + entry_array[i] = link->data; + i++; + link = _dbus_list_get_next_link (&entries, link); + } + + _dbus_list_clear (&entries); + *entry = entry_array; + + return TRUE; + + error: + + link = _dbus_list_get_first_link (&entries); + while (link != NULL) + { + dbus_address_entry_free (link->data); + link = _dbus_list_get_next_link (&entries, link); + } + + _dbus_list_clear (&entries); + + return FALSE; + +} + +/** + * Escapes the given string as a value in a key=value pair + * for a D-Bus address. + * + * @param value the unescaped value + * @returns newly-allocated escaped value or #NULL if no memory + */ +char* +dbus_address_escape_value (const char *value) +{ + DBusString escaped; + DBusString unescaped; + char *ret; + + ret = NULL; + + _dbus_string_init_const (&unescaped, value); + + if (!_dbus_string_init (&escaped)) + return NULL; + + if (!_dbus_address_append_escaped (&escaped, &unescaped)) + goto out; + + if (!_dbus_string_steal_data (&escaped, &ret)) + goto out; + + out: + _dbus_string_free (&escaped); + return ret; +} + +/** + * Unescapes the given string as a value in a key=value pair + * for a D-Bus address. Note that dbus_address_entry_get_value() + * returns an already-unescaped value. + * + * @param value the escaped value + * @param error error to set if the unescaping fails + * @returns newly-allocated unescaped value or #NULL if no memory + */ +char* +dbus_address_unescape_value (const char *value, + DBusError *error) +{ + DBusString unescaped; + DBusString escaped; + char *ret; + + ret = NULL; + + _dbus_string_init_const (&escaped, value); + + if (!_dbus_string_init (&unescaped)) + return NULL; + + if (!append_unescaped_value (&unescaped, &escaped, + 0, _dbus_string_get_length (&escaped), + error)) + goto out; + + if (!_dbus_string_steal_data (&unescaped, &ret)) + goto out; + + out: + if (ret == NULL && error && !dbus_error_is_set (error)) + _DBUS_SET_OOM (error); + + _dbus_assert (ret != NULL || error == NULL || dbus_error_is_set (error)); + + _dbus_string_free (&unescaped); + return ret; +} + +/** @} */ /* End of public API */ + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + +#include "dbus-test.h" +#include <stdlib.h> + +typedef struct +{ + const char *escaped; + const char *unescaped; +} EscapeTest; + +static const EscapeTest escape_tests[] = { + { "abcde", "abcde" }, + { "", "" }, + { "%20%20", " " }, + { "%24", "$" }, + { "%25", "%" }, + { "abc%24", "abc$" }, + { "%24abc", "$abc" }, + { "abc%24abc", "abc$abc" }, + { "/", "/" }, + { "-", "-" }, + { "_", "_" }, + { "A", "A" }, + { "I", "I" }, + { "Z", "Z" }, + { "a", "a" }, + { "i", "i" }, + { "z", "z" }, + /* Bug: https://bugs.freedesktop.org/show_bug.cgi?id=53499 */ + { "%c3%b6", "\xc3\xb6" } +}; + +static const char* invalid_escaped_values[] = { + "%a", + "%q", + "%az", + "%%", + "%$$", + "abc%a", + "%axyz", + "%", + "$", + " ", +}; + +dbus_bool_t +_dbus_address_test (void) +{ + DBusAddressEntry **entries; + int len; + DBusError error = DBUS_ERROR_INIT; + int i; + + i = 0; + while (i < _DBUS_N_ELEMENTS (escape_tests)) + { + const EscapeTest *test = &escape_tests[i]; + char *escaped; + char *unescaped; + + escaped = dbus_address_escape_value (test->unescaped); + if (escaped == NULL) + _dbus_assert_not_reached ("oom"); + + if (strcmp (escaped, test->escaped) != 0) + { + _dbus_warn ("Escaped '%s' as '%s' should have been '%s'\n", + test->unescaped, escaped, test->escaped); + exit (1); + } + dbus_free (escaped); + + unescaped = dbus_address_unescape_value (test->escaped, &error); + if (unescaped == NULL) + { + _dbus_warn ("Failed to unescape '%s': %s\n", + test->escaped, error.message); + dbus_error_free (&error); + exit (1); + } + + if (strcmp (unescaped, test->unescaped) != 0) + { + _dbus_warn ("Unescaped '%s' as '%s' should have been '%s'\n", + test->escaped, unescaped, test->unescaped); + exit (1); + } + dbus_free (unescaped); + + ++i; + } + + i = 0; + while (i < _DBUS_N_ELEMENTS (invalid_escaped_values)) + { + char *unescaped; + + unescaped = dbus_address_unescape_value (invalid_escaped_values[i], + &error); + if (unescaped != NULL) + { + _dbus_warn ("Should not have successfully unescaped '%s' to '%s'\n", + invalid_escaped_values[i], unescaped); + dbus_free (unescaped); + exit (1); + } + + _dbus_assert (dbus_error_is_set (&error)); + dbus_error_free (&error); + + ++i; + } + + if (!dbus_parse_address ("unix:path=/tmp/foo;debug:name=test,sliff=sloff;", + &entries, &len, &error)) + _dbus_assert_not_reached ("could not parse address"); + _dbus_assert (len == 2); + _dbus_assert (strcmp (dbus_address_entry_get_value (entries[0], "path"), "/tmp/foo") == 0); + _dbus_assert (strcmp (dbus_address_entry_get_value (entries[1], "name"), "test") == 0); + _dbus_assert (strcmp (dbus_address_entry_get_value (entries[1], "sliff"), "sloff") == 0); + + dbus_address_entries_free (entries); + + /* Different possible errors */ + if (dbus_parse_address ("", &entries, &len, &error)) + _dbus_assert_not_reached ("Parsed incorrect address."); + else + dbus_error_free (&error); + + if (dbus_parse_address ("foo", &entries, &len, &error)) + _dbus_assert_not_reached ("Parsed incorrect address."); + else + dbus_error_free (&error); + + if (dbus_parse_address ("foo:bar", &entries, &len, &error)) + _dbus_assert_not_reached ("Parsed incorrect address."); + else + dbus_error_free (&error); + + if (dbus_parse_address ("foo:bar,baz", &entries, &len, &error)) + _dbus_assert_not_reached ("Parsed incorrect address."); + else + dbus_error_free (&error); + + if (dbus_parse_address ("foo:bar=foo,baz", &entries, &len, &error)) + _dbus_assert_not_reached ("Parsed incorrect address."); + else + dbus_error_free (&error); + + if (dbus_parse_address ("foo:bar=foo;baz", &entries, &len, &error)) + _dbus_assert_not_reached ("Parsed incorrect address."); + else + dbus_error_free (&error); + + if (dbus_parse_address ("foo:=foo", &entries, &len, &error)) + _dbus_assert_not_reached ("Parsed incorrect address."); + else + dbus_error_free (&error); + + if (dbus_parse_address ("foo:foo=", &entries, &len, &error)) + _dbus_assert_not_reached ("Parsed incorrect address."); + else + dbus_error_free (&error); + + if (dbus_parse_address ("foo:foo,bar=baz", &entries, &len, &error)) + _dbus_assert_not_reached ("Parsed incorrect address."); + else + dbus_error_free (&error); + + return TRUE; +} + +#endif /* !DOXYGEN_SHOULD_SKIP_THIS */ + +#endif
diff --git a/dbus/dbus-address.h b/dbus/dbus-address.h new file mode 100644 index 0000000..e51ef0a --- /dev/null +++ b/dbus/dbus-address.h
@@ -0,0 +1,67 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-address.h Server address parser. + * + * Copyright (C) 2003 CodeFactory AB + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) +#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents." +#endif + +#ifndef DBUS_ADDRESS_H +#define DBUS_ADDRESS_H + +#include <dbus/dbus-types.h> +#include <dbus/dbus-errors.h> + +DBUS_BEGIN_DECLS + +/** + * @addtogroup DBusAddress + * @{ + */ + +/** Opaque type representing one of the semicolon-separated items in an address */ +typedef struct DBusAddressEntry DBusAddressEntry; + +DBUS_EXPORT +dbus_bool_t dbus_parse_address (const char *address, + DBusAddressEntry ***entry, + int *array_len, + DBusError *error); +DBUS_EXPORT +const char *dbus_address_entry_get_value (DBusAddressEntry *entry, + const char *key); +DBUS_EXPORT +const char *dbus_address_entry_get_method (DBusAddressEntry *entry); +DBUS_EXPORT +void dbus_address_entries_free (DBusAddressEntry **entries); + +DBUS_EXPORT +char* dbus_address_escape_value (const char *value); +DBUS_EXPORT +char* dbus_address_unescape_value (const char *value, + DBusError *error); + +/** @} */ + +DBUS_END_DECLS + +#endif /* DBUS_ADDRESS_H */ +
diff --git a/dbus/dbus-arch-deps.h b/dbus/dbus-arch-deps.h new file mode 100644 index 0000000..361b02f --- /dev/null +++ b/dbus/dbus-arch-deps.h
@@ -0,0 +1,61 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-arch-deps.h Header with architecture/compiler specific information, installed to libdir + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.0 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) +#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents." +#endif + +#ifndef DBUS_ARCH_DEPS_H +#define DBUS_ARCH_DEPS_H + +#include <dbus/dbus-macros.h> + +DBUS_BEGIN_DECLS + +/* D-Bus no longer supports platforms with no 64-bit integer type. */ +#define DBUS_HAVE_INT64 1 +_DBUS_GNUC_EXTENSION typedef long long dbus_int64_t; +_DBUS_GNUC_EXTENSION typedef unsigned long long dbus_uint64_t; + +#define DBUS_INT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION (val##LL)) +#define DBUS_UINT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION (val##ULL)) + +typedef int dbus_int32_t; +typedef unsigned int dbus_uint32_t; + +typedef short dbus_int16_t; +typedef unsigned short dbus_uint16_t; + +/* This is not really arch-dependent, but it's not worth + * creating an additional generated header just for this + */ +#define DBUS_MAJOR_VERSION 1 +#define DBUS_MINOR_VERSION 10 +#define DBUS_MICRO_VERSION 12 + +#define DBUS_VERSION_STRING "1.10.12" + +#define DBUS_VERSION ((1 << 16) | (10 << 8) | (12)) + +DBUS_END_DECLS + +#endif /* DBUS_ARCH_DEPS_H */
diff --git a/dbus/dbus-arch-deps.h.in b/dbus/dbus-arch-deps.h.in new file mode 100644 index 0000000..dfc3589 --- /dev/null +++ b/dbus/dbus-arch-deps.h.in
@@ -0,0 +1,61 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-arch-deps.h Header with architecture/compiler specific information, installed to libdir + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.0 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) +#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents." +#endif + +#ifndef DBUS_ARCH_DEPS_H +#define DBUS_ARCH_DEPS_H + +#include <dbus/dbus-macros.h> + +DBUS_BEGIN_DECLS + +/* D-Bus no longer supports platforms with no 64-bit integer type. */ +#define DBUS_HAVE_INT64 1 +_DBUS_GNUC_EXTENSION typedef @DBUS_INT64_TYPE@ dbus_int64_t; +_DBUS_GNUC_EXTENSION typedef unsigned @DBUS_INT64_TYPE@ dbus_uint64_t; + +#define DBUS_INT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION @DBUS_INT64_CONSTANT@) +#define DBUS_UINT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION @DBUS_UINT64_CONSTANT@) + +typedef @DBUS_INT32_TYPE@ dbus_int32_t; +typedef unsigned @DBUS_INT32_TYPE@ dbus_uint32_t; + +typedef @DBUS_INT16_TYPE@ dbus_int16_t; +typedef unsigned @DBUS_INT16_TYPE@ dbus_uint16_t; + +/* This is not really arch-dependent, but it's not worth + * creating an additional generated header just for this + */ +#define DBUS_MAJOR_VERSION @DBUS_MAJOR_VERSION@ +#define DBUS_MINOR_VERSION @DBUS_MINOR_VERSION@ +#define DBUS_MICRO_VERSION @DBUS_MICRO_VERSION@ + +#define DBUS_VERSION_STRING "@DBUS_VERSION@" + +#define DBUS_VERSION ((@DBUS_MAJOR_VERSION@ << 16) | (@DBUS_MINOR_VERSION@ << 8) | (@DBUS_MICRO_VERSION@)) + +DBUS_END_DECLS + +#endif /* DBUS_ARCH_DEPS_H */
diff --git a/dbus/dbus-asv-util.c b/dbus/dbus-asv-util.c new file mode 100644 index 0000000..d3ac5e9 --- /dev/null +++ b/dbus/dbus-asv-util.c
@@ -0,0 +1,314 @@ +/* dbus-asv-util.c - utility functions for a{sv} + * + * Copyright © 2011-2012 Nokia Corporation + * Copyright © 2012-2013 Collabora Ltd. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <config.h> + +#include <dbus/dbus.h> + +#include "dbus/dbus-asv-util.h" + +/** + * Convenience function to create a method-call reply whose type is a{sv} + * (map from string to variant). + * + * Append values with 0 or more sequences of _dbus_asv_open_entry(), + * appending a value to var_iter, and _dbus_asv_close_entry(), + * then close the a{sv} with _dbus_asv_close() or _dbus_asv_abandon(). + * + * This must be paired with a call to _dbus_asv_close() or _dbus_asv_abandon(). + * + * @param message a method call message + * @param iter an iterator which will be initialized to append to the message + * @param arr_iter an iterator which will be initialized to append to the array + * @returns a new message, or #NULL if not enough memory + */ +DBusMessage * +_dbus_asv_new_method_return (DBusMessage *message, + DBusMessageIter *iter, + DBusMessageIter *arr_iter) +{ + DBusMessage *reply = dbus_message_new_method_return (message); + + if (reply == NULL) + return NULL; + + dbus_message_iter_init_append (reply, iter); + + if (!dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, "{sv}", + arr_iter)) + { + dbus_message_unref (reply); + return NULL; + } + + return reply; +} + +/* + * Open a new entry in an a{sv} (map from string to variant). + * + * This must be paired with a call to either _dbus_asv_close_entry() + * or _dbus_asv_abandon_entry(). + * + * If this function fails, the a{sv} must be abandoned, for instance + * with _dbus_asv_abandon(). + * + * @param arr_iter the iterator which is appending to the array + * @param entry_iter will be initialized to append to the dict-entry + * @param key a UTF-8 key for the map + * @param type the type of the variant value, e.g. DBUS_TYPE_STRING_AS_STRING + * @param var_iter will be initialized to append (i.e. write) to the variant + * @returns #TRUE on success, or #FALSE if not enough memory + */ +static dbus_bool_t +_dbus_asv_open_entry (DBusMessageIter *arr_iter, + DBusMessageIter *entry_iter, + const char *key, + const char *type, + DBusMessageIter *var_iter) +{ + if (!dbus_message_iter_open_container (arr_iter, DBUS_TYPE_DICT_ENTRY, + NULL, entry_iter)) + return FALSE; + + if (!dbus_message_iter_append_basic (entry_iter, DBUS_TYPE_STRING, &key)) + { + dbus_message_iter_abandon_container (arr_iter, entry_iter); + return FALSE; + } + + if (!dbus_message_iter_open_container (entry_iter, DBUS_TYPE_VARIANT, + type, var_iter)) + { + dbus_message_iter_abandon_container (arr_iter, entry_iter); + return FALSE; + } + + return TRUE; +} + +/* + * Closes an a{sv} entry after successfully appending the value. + * + * If this function fails, the a{sv} must be abandoned, for instance + * with _dbus_asv_abandon(). + * + * @param arr_iter the iterator which is appending to the array + * @param entry_iter the iterator appending to the dict-entry, will be closed + * @param var_iter the iterator appending to the variant, will be closed + * @returns #TRUE on success, or #FALSE if not enough memory + */ +static dbus_bool_t +_dbus_asv_close_entry (DBusMessageIter *arr_iter, + DBusMessageIter *entry_iter, + DBusMessageIter *var_iter) +{ + if (!dbus_message_iter_close_container (entry_iter, var_iter)) + { + dbus_message_iter_abandon_container (arr_iter, entry_iter); + return FALSE; + } + + if (!dbus_message_iter_close_container (arr_iter, entry_iter)) + return FALSE; + + return TRUE; +} + +/** + * Closes an a{sv} after successfully appending all values. + * + * If this function fails, you must abandon iter and whatever + * larger data structure (message, etc.) the a{sv} was embedded in. + * + * @param iter the iterator which is appending to the message or other data structure containing the a{sv} + * @param arr_iter the iterator appending to the array, will be closed + * @returns #TRUE on success, or #FALSE if not enough memory + */ +dbus_bool_t +_dbus_asv_close (DBusMessageIter *iter, + DBusMessageIter *arr_iter) +{ + return dbus_message_iter_close_container (iter, arr_iter); +} + +/* + * Closes an a{sv} entry after unsuccessfully appending a value. + * You must also abandon the a{sv} itself (for instance with + * _dbus_asv_abandon()), and abandon whatever larger data structure + * the a{sv} was embedded in. + * + * @param iter the iterator which is appending to the message or other data structure containing the a{sv} + * @param arr_iter the iterator appending to the array, will be closed + * @returns #TRUE on success, or #FALSE if not enough memory + */ +static void +_dbus_asv_abandon_entry (DBusMessageIter *arr_iter, + DBusMessageIter *entry_iter, + DBusMessageIter *var_iter) +{ + dbus_message_iter_abandon_container (entry_iter, var_iter); + dbus_message_iter_abandon_container (arr_iter, entry_iter); +} + +/** + * Closes an a{sv} after unsuccessfully appending a value. + * + * You must also abandon whatever larger data structure (message, etc.) + * the a{sv} was embedded in. + * + * @param iter the iterator which is appending to the message or other data structure containing the a{sv} + * @param arr_iter the iterator appending to the array, will be closed + */ +void +_dbus_asv_abandon (DBusMessageIter *iter, + DBusMessageIter *arr_iter) +{ + dbus_message_iter_abandon_container (iter, arr_iter); +} + +/** + * Create a new entry in an a{sv} (map from string to variant) + * with a 32-bit unsigned integer value. + * + * If this function fails, the a{sv} must be abandoned, for instance + * with _dbus_asv_abandon(). + * + * @param arr_iter the iterator which is appending to the array + * @param key a UTF-8 key for the map + * @param value the value + * @returns #TRUE on success, or #FALSE if not enough memory + */ +dbus_bool_t +_dbus_asv_add_uint32 (DBusMessageIter *arr_iter, + const char *key, + dbus_uint32_t value) +{ + DBusMessageIter entry_iter, var_iter; + + if (!_dbus_asv_open_entry (arr_iter, &entry_iter, key, + DBUS_TYPE_UINT32_AS_STRING, &var_iter)) + return FALSE; + + if (!dbus_message_iter_append_basic (&var_iter, DBUS_TYPE_UINT32, + &value)) + { + _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter); + return FALSE; + } + + if (!_dbus_asv_close_entry (arr_iter, &entry_iter, &var_iter)) + return FALSE; + + return TRUE; +} + +/** + * Create a new entry in an a{sv} (map from string to variant) + * with a UTF-8 string value. + * + * If this function fails, the a{sv} must be abandoned, for instance + * with _dbus_asv_abandon(). + * + * @param arr_iter the iterator which is appending to the array + * @param key a UTF-8 key for the map + * @param value the value + * @returns #TRUE on success, or #FALSE if not enough memory + */ +dbus_bool_t +_dbus_asv_add_string (DBusMessageIter *arr_iter, + const char *key, + const char *value) +{ + DBusMessageIter entry_iter, var_iter; + + if (!_dbus_asv_open_entry (arr_iter, &entry_iter, key, + DBUS_TYPE_STRING_AS_STRING, &var_iter)) + return FALSE; + + if (!dbus_message_iter_append_basic (&var_iter, DBUS_TYPE_STRING, + &value)) + { + _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter); + return FALSE; + } + + if (!_dbus_asv_close_entry (arr_iter, &entry_iter, &var_iter)) + return FALSE; + + return TRUE; +} + +/** + * Create a new entry in an a{sv} (map from string to variant) + * with a byte array value. + * + * If this function fails, the a{sv} must be abandoned, for instance + * with _dbus_asv_abandon(). + * + * @param arr_iter the iterator which is appending to the array + * @param key a UTF-8 key for the map + * @param value the value + * @param n_elements the number of elements to append + * @returns #TRUE on success, or #FALSE if not enough memory + */ +dbus_bool_t +_dbus_asv_add_byte_array (DBusMessageIter *arr_iter, + const char *key, + const void *value, + int n_elements) +{ + DBusMessageIter entry_iter; + DBusMessageIter var_iter; + DBusMessageIter byte_array_iter; + + if (!_dbus_asv_open_entry (arr_iter, &entry_iter, key, "ay", &var_iter)) + return FALSE; + + if (!dbus_message_iter_open_container (&var_iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_BYTE_AS_STRING, + &byte_array_iter)) + { + _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter); + return FALSE; + } + + if (!dbus_message_iter_append_fixed_array (&byte_array_iter, DBUS_TYPE_BYTE, + &value, n_elements)) + { + dbus_message_iter_abandon_container (&var_iter, &byte_array_iter); + _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter); + return FALSE; + } + + if (!dbus_message_iter_close_container (&var_iter, &byte_array_iter)) + { + _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter); + return FALSE; + } + + if (!_dbus_asv_close_entry (arr_iter, &entry_iter, &var_iter)) + return FALSE; + + return TRUE; +}
diff --git a/dbus/dbus-asv-util.h b/dbus/dbus-asv-util.h new file mode 100644 index 0000000..277ab80 --- /dev/null +++ b/dbus/dbus-asv-util.h
@@ -0,0 +1,50 @@ +/* dbus-asv-util.h - utility functions for a{sv} + * + * Copyright © 2011-2012 Nokia Corporation + * Copyright © 2012-2013 Collabora Ltd. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef DBUS_ASV_UTIL_H +#define DBUS_ASV_UTIL_H + +#include <dbus/dbus-internals.h> + +DBUS_BEGIN_DECLS + +DBusMessage *_dbus_asv_new_method_return (DBusMessage *message, + DBusMessageIter *iter, + DBusMessageIter *arr_iter); +dbus_bool_t _dbus_asv_close (DBusMessageIter *iter, + DBusMessageIter *arr_iter); +void _dbus_asv_abandon (DBusMessageIter *iter, + DBusMessageIter *arr_iter); + +dbus_bool_t _dbus_asv_add_uint32 (DBusMessageIter *arr_iter, + const char *key, + dbus_uint32_t value); +dbus_bool_t _dbus_asv_add_string (DBusMessageIter *arr_iter, + const char *key, + const char *value); +dbus_bool_t _dbus_asv_add_byte_array (DBusMessageIter *arr_iter, + const char *key, + const void *value, + int n_elements); + +#endif
diff --git a/dbus/dbus-auth-script.c b/dbus/dbus-auth-script.c new file mode 100644 index 0000000..aaaed30 --- /dev/null +++ b/dbus/dbus-auth-script.c
@@ -0,0 +1,811 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-auth-script.c Test DBusAuth using a special script file (internal to D-Bus implementation) + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#include <config.h> + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + +#include "dbus-auth-script.h" + +#include <stdio.h> + +#include "dbus-auth.h" +#include "dbus-string.h" +#include "dbus-hash.h" +#include "dbus-credentials.h" +#include "dbus-internals.h" + +/** + * @defgroup DBusAuthScript code for running unit test scripts for DBusAuth + * @ingroup DBusInternals + * @brief DBusAuth unit test scripting + * + * The code in here is used for unit testing, it loads + * up a script that tests DBusAuth. + * + * @{ + */ + +/* this is slightly different from the other append_quoted_string + * in dbus-message-builder.c + */ +static dbus_bool_t +append_quoted_string (DBusString *dest, + const DBusString *quoted) +{ + dbus_bool_t in_quotes = FALSE; + dbus_bool_t in_backslash = FALSE; + int i; + + i = 0; + while (i < _dbus_string_get_length (quoted)) + { + unsigned char b; + + b = _dbus_string_get_byte (quoted, i); + + if (in_backslash) + { + unsigned char a; + + if (b == 'r') + a = '\r'; + else if (b == 'n') + a = '\n'; + else if (b == '\\') + a = '\\'; + else + { + _dbus_warn ("bad backslashed byte %c\n", b); + return FALSE; + } + + if (!_dbus_string_append_byte (dest, a)) + return FALSE; + + in_backslash = FALSE; + } + else if (b == '\\') + { + in_backslash = TRUE; + } + else if (in_quotes) + { + if (b == '\'') + in_quotes = FALSE; + else + { + if (!_dbus_string_append_byte (dest, b)) + return FALSE; + } + } + else + { + if (b == '\'') + in_quotes = TRUE; + else if (b == ' ' || b == '\n' || b == '\t') + break; /* end on whitespace if not quoted */ + else + { + if (!_dbus_string_append_byte (dest, b)) + return FALSE; + } + } + + ++i; + } + + return TRUE; +} + +static dbus_bool_t +same_first_word (const DBusString *a, + const DBusString *b) +{ + int first_a_blank, first_b_blank; + + _dbus_string_find_blank (a, 0, &first_a_blank); + _dbus_string_find_blank (b, 0, &first_b_blank); + + if (first_a_blank != first_b_blank) + return FALSE; + + return _dbus_string_equal_len (a, b, first_a_blank); +} + +static DBusAuthState +auth_state_from_string (const DBusString *str) +{ + if (_dbus_string_starts_with_c_str (str, "WAITING_FOR_INPUT")) + return DBUS_AUTH_STATE_WAITING_FOR_INPUT; + else if (_dbus_string_starts_with_c_str (str, "WAITING_FOR_MEMORY")) + return DBUS_AUTH_STATE_WAITING_FOR_MEMORY; + else if (_dbus_string_starts_with_c_str (str, "HAVE_BYTES_TO_SEND")) + return DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND; + else if (_dbus_string_starts_with_c_str (str, "NEED_DISCONNECT")) + return DBUS_AUTH_STATE_NEED_DISCONNECT; + else if (_dbus_string_starts_with_c_str (str, "AUTHENTICATED")) + return DBUS_AUTH_STATE_AUTHENTICATED; + else + return -1; +} + +static const char* +auth_state_to_string (DBusAuthState state) +{ + switch (state) + { + case DBUS_AUTH_STATE_WAITING_FOR_INPUT: + return "WAITING_FOR_INPUT"; + case DBUS_AUTH_STATE_WAITING_FOR_MEMORY: + return "WAITING_FOR_MEMORY"; + case DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND: + return "HAVE_BYTES_TO_SEND"; + case DBUS_AUTH_STATE_NEED_DISCONNECT: + return "NEED_DISCONNECT"; + case DBUS_AUTH_STATE_AUTHENTICATED: + return "AUTHENTICATED"; + } + + return "unknown"; +} + +static char ** +split_string (DBusString *str) +{ + int i, j, k, count, end; + char **array; + + end = _dbus_string_get_length (str); + + i = 0; + _dbus_string_skip_blank (str, i, &i); + for (count = 0; i < end; count++) + { + _dbus_string_find_blank (str, i, &i); + _dbus_string_skip_blank (str, i, &i); + } + + array = dbus_new0 (char *, count + 1); + if (array == NULL) + return NULL; + + i = 0; + _dbus_string_skip_blank (str, i, &i); + for (k = 0; k < count; k++) + { + _dbus_string_find_blank (str, i, &j); + + array[k] = dbus_malloc (j - i + 1); + if (array[k] == NULL) + { + dbus_free_string_array (array); + return NULL; + } + memcpy (array[k], + _dbus_string_get_const_data_len (str, i, j - i), j - i); + array[k][j - i] = '\0'; + + _dbus_string_skip_blank (str, j, &i); + } + array[k] = NULL; + + return array; +} + +static void +auth_set_unix_credentials(DBusAuth *auth, + dbus_uid_t uid, + dbus_pid_t pid) +{ + DBusCredentials *credentials; + + credentials = _dbus_credentials_new (); + if (credentials == NULL) + _dbus_assert_not_reached ("no memory"); + + if (uid != DBUS_UID_UNSET) + { + if (!_dbus_credentials_add_unix_uid (credentials, uid)) + _dbus_assert_not_reached ("no memory"); + } + if (pid != DBUS_PID_UNSET) + { + if (!_dbus_credentials_add_pid (credentials, pid)) + _dbus_assert_not_reached ("no memory"); + } + _dbus_auth_set_credentials (auth, credentials); + + _dbus_credentials_unref (credentials); +} + +/** + * Runs an "auth script" which is a script for testing the + * authentication protocol. Scripts send and receive data, and then + * include assertions about the state of both ends of the connection + * after processing the data. A script succeeds if these assertions + * hold. + * + * @param filename the file containing the script to run + * @returns #TRUE if the script succeeds, #FALSE otherwise + */ +dbus_bool_t +_dbus_auth_script_run (const DBusString *filename) +{ + DBusString file; + DBusError error = DBUS_ERROR_INIT; + DBusString line; + dbus_bool_t retval; + int line_no; + DBusAuth *auth; + DBusString from_auth; + DBusAuthState state; + DBusString context; + DBusString guid; + + retval = FALSE; + auth = NULL; + + _dbus_string_init_const (&guid, "5fa01f4202cd837709a3274ca0df9d00"); + _dbus_string_init_const (&context, "org_freedesktop_test"); + + if (!_dbus_string_init (&file)) + return FALSE; + + if (!_dbus_string_init (&line)) + { + _dbus_string_free (&file); + return FALSE; + } + + if (!_dbus_string_init (&from_auth)) + { + _dbus_string_free (&file); + _dbus_string_free (&line); + return FALSE; + } + + if (!_dbus_file_get_contents (&file, filename, &error)) { + _dbus_warn ("Getting contents of %s failed: %s\n", + _dbus_string_get_const_data (filename), error.message); + dbus_error_free (&error); + goto out; + } + + state = DBUS_AUTH_STATE_NEED_DISCONNECT; + line_no = 0; + + next_iteration: + while (_dbus_string_pop_line (&file, &line)) + { + line_no += 1; + + /* _dbus_warn ("%s\n", _dbus_string_get_const_data (&line)); */ + + _dbus_string_delete_leading_blanks (&line); + + if (auth != NULL) + { + while ((state = _dbus_auth_do_work (auth)) == + DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND) + { + const DBusString *tmp; + if (_dbus_auth_get_bytes_to_send (auth, &tmp)) + { + int count = _dbus_string_get_length (tmp); + + if (_dbus_string_copy (tmp, 0, &from_auth, + _dbus_string_get_length (&from_auth))) + _dbus_auth_bytes_sent (auth, count); + } + } + } + + if (_dbus_string_get_length (&line) == 0) + { + /* empty line */ + goto next_iteration; + } + else if (_dbus_string_starts_with_c_str (&line, + "#")) + { + /* Ignore this comment */ + goto next_iteration; + } +#ifdef DBUS_WIN + else if (_dbus_string_starts_with_c_str (&line, + "WIN_ONLY")) + { + /* Ignore this line */ + goto next_iteration; + } + else if (_dbus_string_starts_with_c_str (&line, + "UNIX_ONLY")) + { + /* skip this file */ + fprintf (stderr, "skipping unix only auth script\n"); + retval = TRUE; + goto out; + } +#endif +#ifdef DBUS_UNIX + else if (_dbus_string_starts_with_c_str (&line, + "UNIX_ONLY")) + { + /* Ignore this line */ + goto next_iteration; + } + else if (_dbus_string_starts_with_c_str (&line, + "WIN_ONLY")) + { + /* skip this file */ + fprintf (stderr, "skipping windows only auth script\n"); + retval = TRUE; + goto out; + } +#endif + else if (_dbus_string_starts_with_c_str (&line, + "CLIENT")) + { + DBusCredentials *creds; + + if (auth != NULL) + { + _dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)\n"); + goto out; + } + + auth = _dbus_auth_client_new (); + if (auth == NULL) + { + _dbus_warn ("no memory to create DBusAuth\n"); + goto out; + } + + /* test ref/unref */ + _dbus_auth_ref (auth); + _dbus_auth_unref (auth); + + creds = _dbus_credentials_new_from_current_process (); + if (creds == NULL) + { + _dbus_warn ("no memory for credentials\n"); + _dbus_auth_unref (auth); + auth = NULL; + goto out; + } + + if (!_dbus_auth_set_credentials (auth, creds)) + { + _dbus_warn ("no memory for setting credentials\n"); + _dbus_auth_unref (auth); + auth = NULL; + _dbus_credentials_unref (creds); + goto out; + } + + _dbus_credentials_unref (creds); + } + else if (_dbus_string_starts_with_c_str (&line, + "SERVER")) + { + DBusCredentials *creds; + + if (auth != NULL) + { + _dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)\n"); + goto out; + } + + auth = _dbus_auth_server_new (&guid); + if (auth == NULL) + { + _dbus_warn ("no memory to create DBusAuth\n"); + goto out; + } + + /* test ref/unref */ + _dbus_auth_ref (auth); + _dbus_auth_unref (auth); + + creds = _dbus_credentials_new_from_current_process (); + if (creds == NULL) + { + _dbus_warn ("no memory for credentials\n"); + _dbus_auth_unref (auth); + auth = NULL; + goto out; + } + + if (!_dbus_auth_set_credentials (auth, creds)) + { + _dbus_warn ("no memory for setting credentials\n"); + _dbus_auth_unref (auth); + auth = NULL; + _dbus_credentials_unref (creds); + goto out; + } + + _dbus_credentials_unref (creds); + + _dbus_auth_set_context (auth, &context); + } + else if (auth == NULL) + { + _dbus_warn ("must specify CLIENT or SERVER\n"); + goto out; + + } + else if (_dbus_string_starts_with_c_str (&line, + "NO_CREDENTIALS")) + { + auth_set_unix_credentials (auth, DBUS_UID_UNSET, DBUS_PID_UNSET); + } + else if (_dbus_string_starts_with_c_str (&line, + "ROOT_CREDENTIALS")) + { + auth_set_unix_credentials (auth, 0, DBUS_PID_UNSET); + } + else if (_dbus_string_starts_with_c_str (&line, + "SILLY_CREDENTIALS")) + { + auth_set_unix_credentials (auth, 4312, DBUS_PID_UNSET); + } + else if (_dbus_string_starts_with_c_str (&line, + "ALLOWED_MECHS")) + { + char **mechs; + + _dbus_string_delete_first_word (&line); + mechs = split_string (&line); + _dbus_auth_set_mechanisms (auth, (const char **) mechs); + dbus_free_string_array (mechs); + } + else if (_dbus_string_starts_with_c_str (&line, + "SEND")) + { + DBusString to_send; + + _dbus_string_delete_first_word (&line); + + if (!_dbus_string_init (&to_send)) + { + _dbus_warn ("no memory to allocate string\n"); + goto out; + } + + if (!append_quoted_string (&to_send, &line)) + { + _dbus_warn ("failed to append quoted string line %d\n", + line_no); + _dbus_string_free (&to_send); + goto out; + } + + _dbus_verbose ("Sending '%s'\n", _dbus_string_get_const_data (&to_send)); + + if (!_dbus_string_append (&to_send, "\r\n")) + { + _dbus_warn ("failed to append \r\n from line %d\n", + line_no); + _dbus_string_free (&to_send); + goto out; + } + + /* Replace USERID_HEX with our username in hex */ + { + int where; + + if (_dbus_string_find (&to_send, 0, + "USERID_HEX", &where)) + { + DBusString username; + + if (!_dbus_string_init (&username)) + { + _dbus_warn ("no memory for userid\n"); + _dbus_string_free (&to_send); + goto out; + } + + if (!_dbus_append_user_from_current_process (&username)) + { + _dbus_warn ("no memory for userid\n"); + _dbus_string_free (&username); + _dbus_string_free (&to_send); + goto out; + } + + _dbus_string_delete (&to_send, where, (int) strlen ("USERID_HEX")); + + if (!_dbus_string_hex_encode (&username, 0, + &to_send, where)) + { + _dbus_warn ("no memory to subst USERID_HEX\n"); + _dbus_string_free (&username); + _dbus_string_free (&to_send); + goto out; + } + + _dbus_string_free (&username); + } + else if (_dbus_string_find (&to_send, 0, + "USERNAME_HEX", &where)) + { + DBusString username; + + if (!_dbus_string_init (&username)) + { + _dbus_warn ("no memory for username\n"); + _dbus_string_free (&to_send); + goto out; + } + + if (!_dbus_append_user_from_current_process (&username)) + { + _dbus_warn ("no memory for username\n"); + _dbus_string_free (&username); + _dbus_string_free (&to_send); + goto out; + } + + _dbus_string_delete (&to_send, where, (int) strlen ("USERNAME_HEX")); + + if (!_dbus_string_hex_encode (&username, 0, + &to_send, where)) + { + _dbus_warn ("no memory to subst USERNAME_HEX\n"); + _dbus_string_free (&username); + _dbus_string_free (&to_send); + goto out; + } + + _dbus_string_free (&username); + } + } + + { + DBusString *buffer; + + _dbus_auth_get_buffer (auth, &buffer); + if (!_dbus_string_copy (&to_send, 0, + buffer, _dbus_string_get_length (buffer))) + { + _dbus_warn ("not enough memory to call bytes_received, or can't add bytes to auth object already in end state\n"); + _dbus_string_free (&to_send); + _dbus_auth_return_buffer (auth, buffer); + goto out; + } + + _dbus_auth_return_buffer (auth, buffer); + } + + _dbus_string_free (&to_send); + } + else if (_dbus_string_starts_with_c_str (&line, + "EXPECT_STATE")) + { + DBusAuthState expected; + + _dbus_string_delete_first_word (&line); + + expected = auth_state_from_string (&line); + if (expected < 0) + { + _dbus_warn ("bad auth state given to EXPECT_STATE\n"); + goto parse_failed; + } + + if (expected != state) + { + _dbus_warn ("expected auth state %s but got %s on line %d\n", + auth_state_to_string (expected), + auth_state_to_string (state), + line_no); + goto out; + } + } + else if (_dbus_string_starts_with_c_str (&line, + "EXPECT_COMMAND")) + { + DBusString received; + + _dbus_string_delete_first_word (&line); + + if (!_dbus_string_init (&received)) + { + _dbus_warn ("no mem to allocate string received\n"); + goto out; + } + + if (!_dbus_string_pop_line (&from_auth, &received)) + { + _dbus_warn ("no line popped from the DBusAuth being tested, expected command %s on line %d\n", + _dbus_string_get_const_data (&line), line_no); + _dbus_string_free (&received); + goto out; + } + + if (!same_first_word (&received, &line)) + { + _dbus_warn ("line %d expected command '%s' and got '%s'\n", + line_no, + _dbus_string_get_const_data (&line), + _dbus_string_get_const_data (&received)); + _dbus_string_free (&received); + goto out; + } + + _dbus_string_free (&received); + } + else if (_dbus_string_starts_with_c_str (&line, + "EXPECT_UNUSED")) + { + DBusString expected; + const DBusString *unused; + + _dbus_string_delete_first_word (&line); + + if (!_dbus_string_init (&expected)) + { + _dbus_warn ("no mem to allocate string expected\n"); + goto out; + } + + if (!append_quoted_string (&expected, &line)) + { + _dbus_warn ("failed to append quoted string line %d\n", + line_no); + _dbus_string_free (&expected); + goto out; + } + + _dbus_auth_get_unused_bytes (auth, &unused); + + if (_dbus_string_equal (&expected, unused)) + { + _dbus_auth_delete_unused_bytes (auth); + _dbus_string_free (&expected); + } + else + { + _dbus_warn ("Expected unused bytes '%s' and have '%s'\n", + _dbus_string_get_const_data (&expected), + _dbus_string_get_const_data (unused)); + _dbus_string_free (&expected); + goto out; + } + } + else if (_dbus_string_starts_with_c_str (&line, + "EXPECT_HAVE_NO_CREDENTIALS")) + { + DBusCredentials *authorized_identity; + + authorized_identity = _dbus_auth_get_identity (auth); + if (!_dbus_credentials_are_anonymous (authorized_identity)) + { + _dbus_warn ("Expected anonymous login or failed login, but some credentials were authorized\n"); + goto out; + } + } + else if (_dbus_string_starts_with_c_str (&line, + "EXPECT_HAVE_SOME_CREDENTIALS")) + { + DBusCredentials *authorized_identity; + + authorized_identity = _dbus_auth_get_identity (auth); + if (_dbus_credentials_are_anonymous (authorized_identity)) + { + _dbus_warn ("Expected to have some credentials, but we don't\n"); + goto out; + } + } + else if (_dbus_string_starts_with_c_str (&line, + "EXPECT")) + { + DBusString expected; + + _dbus_string_delete_first_word (&line); + + if (!_dbus_string_init (&expected)) + { + _dbus_warn ("no mem to allocate string expected\n"); + goto out; + } + + if (!append_quoted_string (&expected, &line)) + { + _dbus_warn ("failed to append quoted string line %d\n", + line_no); + _dbus_string_free (&expected); + goto out; + } + + if (_dbus_string_equal_len (&expected, &from_auth, + _dbus_string_get_length (&expected))) + { + _dbus_string_delete (&from_auth, 0, + _dbus_string_get_length (&expected)); + _dbus_string_free (&expected); + } + else + { + _dbus_warn ("Expected exact string '%s' and have '%s'\n", + _dbus_string_get_const_data (&expected), + _dbus_string_get_const_data (&from_auth)); + _dbus_string_free (&expected); + goto out; + } + } + else + goto parse_failed; + + goto next_iteration; /* skip parse_failed */ + + parse_failed: + { + _dbus_warn ("couldn't process line %d \"%s\"\n", + line_no, _dbus_string_get_const_data (&line)); + goto out; + } + } + + if (auth == NULL) + { + _dbus_warn ("Auth script is bogus, did not even have CLIENT or SERVER\n"); + goto out; + } + else if (state == DBUS_AUTH_STATE_AUTHENTICATED) + { + const DBusString *unused; + + _dbus_auth_get_unused_bytes (auth, &unused); + + if (_dbus_string_get_length (unused) > 0) + { + _dbus_warn ("did not expect unused bytes (scripts must specify explicitly if they are expected)\n"); + goto out; + } + } + + if (_dbus_string_get_length (&from_auth) > 0) + { + _dbus_warn ("script did not have EXPECT_ statements for all the data received from the DBusAuth\n"); + _dbus_warn ("Leftover data: %s\n", _dbus_string_get_const_data (&from_auth)); + goto out; + } + + retval = TRUE; + + out: + if (auth) + _dbus_auth_unref (auth); + + _dbus_string_free (&file); + _dbus_string_free (&line); + _dbus_string_free (&from_auth); + + return retval; +} + +/** @} */ +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-auth-script.h b/dbus/dbus-auth-script.h new file mode 100644 index 0000000..39e6c7c --- /dev/null +++ b/dbus/dbus-auth-script.h
@@ -0,0 +1,37 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-auth-script.h Test DBusAuth using a special script file (internal to D-Bus implementation) + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef DBUS_AUTH_SCRIPT_H +#define DBUS_AUTH_SCRIPT_H + +#include <dbus/dbus-memory.h> +#include <dbus/dbus-types.h> +#include <dbus/dbus-string.h> + +DBUS_BEGIN_DECLS + +dbus_bool_t _dbus_auth_script_run (const DBusString *filename); + +DBUS_END_DECLS + +#endif /* DBUS_AUTH_SCRIPT_H */
diff --git a/dbus/dbus-auth-util.c b/dbus/dbus-auth-util.c new file mode 100644 index 0000000..10cbc49 --- /dev/null +++ b/dbus/dbus-auth-util.c
@@ -0,0 +1,169 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-auth-util.c Would be in dbus-auth.c, but only used for tests/bus + * + * Copyright (C) 2002, 2003, 2004 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "dbus-internals.h" +#include "dbus-test.h" +#include "dbus-auth.h" + +/** + * @addtogroup DBusAuth + * @{ + */ + +/** @} */ + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS +#include "dbus-auth-script.h" +#include <stdio.h> + +static dbus_bool_t +process_test_subdir (const DBusString *test_base_dir, + const char *subdir) +{ + DBusString test_directory; + DBusString filename; + DBusDirIter *dir; + dbus_bool_t retval; + DBusError error = DBUS_ERROR_INIT; + + retval = FALSE; + dir = NULL; + + if (!_dbus_string_init (&test_directory)) + _dbus_assert_not_reached ("didn't allocate test_directory\n"); + + _dbus_string_init_const (&filename, subdir); + + if (!_dbus_string_copy (test_base_dir, 0, + &test_directory, 0)) + _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory"); + + if (!_dbus_concat_dir_and_file (&test_directory, &filename)) + _dbus_assert_not_reached ("couldn't allocate full path"); + + _dbus_string_free (&filename); + if (!_dbus_string_init (&filename)) + _dbus_assert_not_reached ("didn't allocate filename string\n"); + + dir = _dbus_directory_open (&test_directory, &error); + if (dir == NULL) + { + _dbus_warn ("Could not open %s: %s\n", + _dbus_string_get_const_data (&test_directory), + error.message); + dbus_error_free (&error); + goto failed; + } + + printf ("Testing %s:\n", subdir); + + next: + while (_dbus_directory_get_next_file (dir, &filename, &error)) + { + DBusString full_path; + + if (!_dbus_string_init (&full_path)) + _dbus_assert_not_reached ("couldn't init string"); + + if (!_dbus_string_copy (&test_directory, 0, &full_path, 0)) + _dbus_assert_not_reached ("couldn't copy dir to full_path"); + + if (!_dbus_concat_dir_and_file (&full_path, &filename)) + _dbus_assert_not_reached ("couldn't concat file to dir"); + + if (!_dbus_string_ends_with_c_str (&filename, ".auth-script")) + { + _dbus_verbose ("Skipping non-.auth-script file %s\n", + _dbus_string_get_const_data (&filename)); + _dbus_string_free (&full_path); + goto next; + } + + printf (" %s\n", _dbus_string_get_const_data (&filename)); + + if (!_dbus_auth_script_run (&full_path)) + { + _dbus_string_free (&full_path); + goto failed; + } + else + _dbus_string_free (&full_path); + } + + if (dbus_error_is_set (&error)) + { + _dbus_warn ("Could not get next file in %s: %s\n", + _dbus_string_get_const_data (&test_directory), error.message); + dbus_error_free (&error); + goto failed; + } + + retval = TRUE; + + failed: + + if (dir) + _dbus_directory_close (dir); + _dbus_string_free (&test_directory); + _dbus_string_free (&filename); + + return retval; +} + +static dbus_bool_t +process_test_dirs (const char *test_data_dir) +{ + DBusString test_directory; + dbus_bool_t retval; + + retval = FALSE; + + _dbus_string_init_const (&test_directory, test_data_dir); + + if (!process_test_subdir (&test_directory, "auth")) + goto failed; + + retval = TRUE; + + failed: + + _dbus_string_free (&test_directory); + + return retval; +} + +dbus_bool_t +_dbus_auth_test (const char *test_data_dir) +{ + + if (test_data_dir == NULL) + return TRUE; + + if (!process_test_dirs (test_data_dir)) + return FALSE; + + return TRUE; +} + +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-auth.c b/dbus/dbus-auth.c new file mode 100644 index 0000000..ea43ce7 --- /dev/null +++ b/dbus/dbus-auth.c
@@ -0,0 +1,2842 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-auth.c Authentication + * + * Copyright (C) 2002, 2003, 2004 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "dbus-auth.h" +#include "dbus-string.h" +#include "dbus-list.h" +#include "dbus-internals.h" +#include "dbus-keyring.h" +#include "dbus-sha.h" +#include "dbus-protocol.h" +#include "dbus-credentials.h" + +/** + * @defgroup DBusAuth Authentication + * @ingroup DBusInternals + * @brief DBusAuth object + * + * DBusAuth manages the authentication negotiation when a connection + * is first established, and also manages any encryption used over a + * connection. + * + * @todo some SASL profiles require sending the empty string as a + * challenge/response, but we don't currently allow that in our + * protocol. + * + * @todo right now sometimes both ends will block waiting for input + * from the other end, e.g. if there's an error during + * DBUS_COOKIE_SHA1. + * + * @todo the cookie keyring needs to be cached globally not just + * per-auth (which raises threadsafety issues too) + * + * @todo grep FIXME in dbus-auth.c + */ + +/** + * @defgroup DBusAuthInternals Authentication implementation details + * @ingroup DBusInternals + * @brief DBusAuth implementation details + * + * Private details of authentication code. + * + * @{ + */ + +/** + * This function appends an initial client response to the given string + */ +typedef dbus_bool_t (* DBusInitialResponseFunction) (DBusAuth *auth, + DBusString *response); + +/** + * This function processes a block of data received from the peer. + * i.e. handles a DATA command. + */ +typedef dbus_bool_t (* DBusAuthDataFunction) (DBusAuth *auth, + const DBusString *data); + +/** + * This function encodes a block of data from the peer. + */ +typedef dbus_bool_t (* DBusAuthEncodeFunction) (DBusAuth *auth, + const DBusString *data, + DBusString *encoded); + +/** + * This function decodes a block of data from the peer. + */ +typedef dbus_bool_t (* DBusAuthDecodeFunction) (DBusAuth *auth, + const DBusString *data, + DBusString *decoded); + +/** + * This function is called when the mechanism is abandoned. + */ +typedef void (* DBusAuthShutdownFunction) (DBusAuth *auth); + +/** + * Virtual table representing a particular auth mechanism. + */ +typedef struct +{ + const char *mechanism; /**< Name of the mechanism */ + DBusAuthDataFunction server_data_func; /**< Function on server side for DATA */ + DBusAuthEncodeFunction server_encode_func; /**< Function on server side to encode */ + DBusAuthDecodeFunction server_decode_func; /**< Function on server side to decode */ + DBusAuthShutdownFunction server_shutdown_func; /**< Function on server side to shut down */ + DBusInitialResponseFunction client_initial_response_func; /**< Function on client side to handle initial response */ + DBusAuthDataFunction client_data_func; /**< Function on client side for DATA */ + DBusAuthEncodeFunction client_encode_func; /**< Function on client side for encode */ + DBusAuthDecodeFunction client_decode_func; /**< Function on client side for decode */ + DBusAuthShutdownFunction client_shutdown_func; /**< Function on client side for shutdown */ +} DBusAuthMechanismHandler; + +/** + * Enumeration for the known authentication commands. + */ +typedef enum { + DBUS_AUTH_COMMAND_AUTH, + DBUS_AUTH_COMMAND_CANCEL, + DBUS_AUTH_COMMAND_DATA, + DBUS_AUTH_COMMAND_BEGIN, + DBUS_AUTH_COMMAND_REJECTED, + DBUS_AUTH_COMMAND_OK, + DBUS_AUTH_COMMAND_ERROR, + DBUS_AUTH_COMMAND_UNKNOWN, + DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD, + DBUS_AUTH_COMMAND_AGREE_UNIX_FD +} DBusAuthCommand; + +/** + * Auth state function, determines the reaction to incoming events for + * a particular state. Returns whether we had enough memory to + * complete the operation. + */ +typedef dbus_bool_t (* DBusAuthStateFunction) (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args); + +/** + * Information about a auth state. + */ +typedef struct +{ + const char *name; /**< Name of the state */ + DBusAuthStateFunction handler; /**< State function for this state */ +} DBusAuthStateData; + +/** + * Internal members of DBusAuth. + */ +struct DBusAuth +{ + int refcount; /**< reference count */ + const char *side; /**< Client or server */ + + DBusString incoming; /**< Incoming data buffer */ + DBusString outgoing; /**< Outgoing data buffer */ + + const DBusAuthStateData *state; /**< Current protocol state */ + + const DBusAuthMechanismHandler *mech; /**< Current auth mechanism */ + + DBusString identity; /**< Current identity we're authorizing + * as. + */ + + DBusCredentials *credentials; /**< Credentials read from socket + */ + + DBusCredentials *authorized_identity; /**< Credentials that are authorized */ + + DBusCredentials *desired_identity; /**< Identity client has requested */ + + DBusString context; /**< Cookie scope */ + DBusKeyring *keyring; /**< Keyring for cookie mechanism. */ + int cookie_id; /**< ID of cookie to use */ + DBusString challenge; /**< Challenge sent to client */ + + char **allowed_mechs; /**< Mechanisms we're allowed to use, + * or #NULL if we can use any + */ + + unsigned int needed_memory : 1; /**< We needed memory to continue since last + * successful getting something done + */ + unsigned int already_got_mechanisms : 1; /**< Client already got mech list */ + unsigned int already_asked_for_initial_response : 1; /**< Already sent a blank challenge to get an initial response */ + unsigned int buffer_outstanding : 1; /**< Buffer is "checked out" for reading data into */ + + unsigned int unix_fd_possible : 1; /**< This side could do unix fd passing */ + unsigned int unix_fd_negotiated : 1; /**< Unix fd was successfully negotiated */ +}; + +/** + * "Subclass" of DBusAuth for client side + */ +typedef struct +{ + DBusAuth base; /**< Parent class */ + + DBusList *mechs_to_try; /**< Mechanisms we got from the server that we're going to try using */ + + DBusString guid_from_server; /**< GUID received from server */ + +} DBusAuthClient; + +/** + * "Subclass" of DBusAuth for server side. + */ +typedef struct +{ + DBusAuth base; /**< Parent class */ + + int failures; /**< Number of times client has been rejected */ + int max_failures; /**< Number of times we reject before disconnect */ + + DBusString guid; /**< Our globally unique ID in hex encoding */ + +} DBusAuthServer; + +static void goto_state (DBusAuth *auth, + const DBusAuthStateData *new_state); +static dbus_bool_t send_auth (DBusAuth *auth, + const DBusAuthMechanismHandler *mech); +static dbus_bool_t send_data (DBusAuth *auth, + DBusString *data); +static dbus_bool_t send_rejected (DBusAuth *auth); +static dbus_bool_t send_error (DBusAuth *auth, + const char *message); +static dbus_bool_t send_ok (DBusAuth *auth); +static dbus_bool_t send_begin (DBusAuth *auth); +static dbus_bool_t send_cancel (DBusAuth *auth); +static dbus_bool_t send_negotiate_unix_fd (DBusAuth *auth); +static dbus_bool_t send_agree_unix_fd (DBusAuth *auth); + +/** + * Client states + */ + +static dbus_bool_t handle_server_state_waiting_for_auth (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args); +static dbus_bool_t handle_server_state_waiting_for_data (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args); +static dbus_bool_t handle_server_state_waiting_for_begin (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args); + +static const DBusAuthStateData server_state_waiting_for_auth = { + "WaitingForAuth", handle_server_state_waiting_for_auth +}; +static const DBusAuthStateData server_state_waiting_for_data = { + "WaitingForData", handle_server_state_waiting_for_data +}; +static const DBusAuthStateData server_state_waiting_for_begin = { + "WaitingForBegin", handle_server_state_waiting_for_begin +}; + +/** + * Client states + */ + +static dbus_bool_t handle_client_state_waiting_for_data (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args); +static dbus_bool_t handle_client_state_waiting_for_ok (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args); +static dbus_bool_t handle_client_state_waiting_for_reject (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args); +static dbus_bool_t handle_client_state_waiting_for_agree_unix_fd (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args); + +static const DBusAuthStateData client_state_need_send_auth = { + "NeedSendAuth", NULL +}; +static const DBusAuthStateData client_state_waiting_for_data = { + "WaitingForData", handle_client_state_waiting_for_data +}; +/* The WaitingForOK state doesn't appear to be used. + * See https://bugs.freedesktop.org/show_bug.cgi?id=97298 */ +_DBUS_GNUC_UNUSED +static const DBusAuthStateData client_state_waiting_for_ok = { + "WaitingForOK", handle_client_state_waiting_for_ok +}; +static const DBusAuthStateData client_state_waiting_for_reject = { + "WaitingForReject", handle_client_state_waiting_for_reject +}; +static const DBusAuthStateData client_state_waiting_for_agree_unix_fd = { + "WaitingForAgreeUnixFD", handle_client_state_waiting_for_agree_unix_fd +}; + +/** + * Common terminal states. Terminal states have handler == NULL. + */ + +static const DBusAuthStateData common_state_authenticated = { + "Authenticated", NULL +}; + +static const DBusAuthStateData common_state_need_disconnect = { + "NeedDisconnect", NULL +}; + +static const char auth_side_client[] = "client"; +static const char auth_side_server[] = "server"; +/** + * @param auth the auth conversation + * @returns #TRUE if the conversation is the server side + */ +#define DBUS_AUTH_IS_SERVER(auth) ((auth)->side == auth_side_server) +/** + * @param auth the auth conversation + * @returns #TRUE if the conversation is the client side + */ +#define DBUS_AUTH_IS_CLIENT(auth) ((auth)->side == auth_side_client) +/** + * @param auth the auth conversation + * @returns auth cast to DBusAuthClient + */ +#define DBUS_AUTH_CLIENT(auth) ((DBusAuthClient*)(auth)) +/** + * @param auth the auth conversation + * @returns auth cast to DBusAuthServer + */ +#define DBUS_AUTH_SERVER(auth) ((DBusAuthServer*)(auth)) + +/** + * The name of the auth ("client" or "server") + * @param auth the auth conversation + * @returns a string + */ +#define DBUS_AUTH_NAME(auth) ((auth)->side) + +static DBusAuth* +_dbus_auth_new (int size) +{ + DBusAuth *auth; + + auth = dbus_malloc0 (size); + if (auth == NULL) + return NULL; + + auth->refcount = 1; + + auth->keyring = NULL; + auth->cookie_id = -1; + + /* note that we don't use the max string length feature, + * because you can't use that feature if you're going to + * try to recover from out-of-memory (it creates + * what looks like unrecoverable inability to alloc + * more space in the string). But we do handle + * overlong buffers in _dbus_auth_do_work(). + */ + + if (!_dbus_string_init (&auth->incoming)) + goto enomem_0; + + if (!_dbus_string_init (&auth->outgoing)) + goto enomem_1; + + if (!_dbus_string_init (&auth->identity)) + goto enomem_2; + + if (!_dbus_string_init (&auth->context)) + goto enomem_3; + + if (!_dbus_string_init (&auth->challenge)) + goto enomem_4; + + /* default context if none is specified */ + if (!_dbus_string_append (&auth->context, "org_freedesktop_general")) + goto enomem_5; + + auth->credentials = _dbus_credentials_new (); + if (auth->credentials == NULL) + goto enomem_6; + + auth->authorized_identity = _dbus_credentials_new (); + if (auth->authorized_identity == NULL) + goto enomem_7; + + auth->desired_identity = _dbus_credentials_new (); + if (auth->desired_identity == NULL) + goto enomem_8; + + return auth; + +#if 0 + enomem_9: + _dbus_credentials_unref (auth->desired_identity); +#endif + enomem_8: + _dbus_credentials_unref (auth->authorized_identity); + enomem_7: + _dbus_credentials_unref (auth->credentials); + enomem_6: + /* last alloc was an append to context, which is freed already below */ ; + enomem_5: + _dbus_string_free (&auth->challenge); + enomem_4: + _dbus_string_free (&auth->context); + enomem_3: + _dbus_string_free (&auth->identity); + enomem_2: + _dbus_string_free (&auth->outgoing); + enomem_1: + _dbus_string_free (&auth->incoming); + enomem_0: + dbus_free (auth); + return NULL; +} + +static void +shutdown_mech (DBusAuth *auth) +{ + /* Cancel any auth */ + auth->already_asked_for_initial_response = FALSE; + _dbus_string_set_length (&auth->identity, 0); + + _dbus_credentials_clear (auth->authorized_identity); + _dbus_credentials_clear (auth->desired_identity); + + if (auth->mech != NULL) + { + _dbus_verbose ("%s: Shutting down mechanism %s\n", + DBUS_AUTH_NAME (auth), auth->mech->mechanism); + + if (DBUS_AUTH_IS_CLIENT (auth)) + (* auth->mech->client_shutdown_func) (auth); + else + (* auth->mech->server_shutdown_func) (auth); + + auth->mech = NULL; + } +} + +/* + * DBUS_COOKIE_SHA1 mechanism + */ + +/* Returns TRUE but with an empty string hash if the + * cookie_id isn't known. As with all this code + * TRUE just means we had enough memory. + */ +static dbus_bool_t +sha1_compute_hash (DBusAuth *auth, + int cookie_id, + const DBusString *server_challenge, + const DBusString *client_challenge, + DBusString *hash) +{ + DBusString cookie; + DBusString to_hash; + dbus_bool_t retval; + + _dbus_assert (auth->keyring != NULL); + + retval = FALSE; + + if (!_dbus_string_init (&cookie)) + return FALSE; + + if (!_dbus_keyring_get_hex_key (auth->keyring, cookie_id, + &cookie)) + goto out_0; + + if (_dbus_string_get_length (&cookie) == 0) + { + retval = TRUE; + goto out_0; + } + + if (!_dbus_string_init (&to_hash)) + goto out_0; + + if (!_dbus_string_copy (server_challenge, 0, + &to_hash, _dbus_string_get_length (&to_hash))) + goto out_1; + + if (!_dbus_string_append (&to_hash, ":")) + goto out_1; + + if (!_dbus_string_copy (client_challenge, 0, + &to_hash, _dbus_string_get_length (&to_hash))) + goto out_1; + + if (!_dbus_string_append (&to_hash, ":")) + goto out_1; + + if (!_dbus_string_copy (&cookie, 0, + &to_hash, _dbus_string_get_length (&to_hash))) + goto out_1; + + if (!_dbus_sha_compute (&to_hash, hash)) + goto out_1; + + retval = TRUE; + + out_1: + _dbus_string_zero (&to_hash); + _dbus_string_free (&to_hash); + out_0: + _dbus_string_zero (&cookie); + _dbus_string_free (&cookie); + return retval; +} + +/** http://www.ietf.org/rfc/rfc2831.txt suggests at least 64 bits of + * entropy, we use 128. This is the number of bytes in the random + * challenge. + */ +#define N_CHALLENGE_BYTES (128/8) + +static dbus_bool_t +sha1_handle_first_client_response (DBusAuth *auth, + const DBusString *data) +{ + /* We haven't sent a challenge yet, we're expecting a desired + * username from the client. + */ + DBusString tmp; + DBusString tmp2; + dbus_bool_t retval = FALSE; + DBusError error = DBUS_ERROR_INIT; + + _dbus_string_set_length (&auth->challenge, 0); + + if (_dbus_string_get_length (data) > 0) + { + if (_dbus_string_get_length (&auth->identity) > 0) + { + /* Tried to send two auth identities, wtf */ + _dbus_verbose ("%s: client tried to send auth identity, but we already have one\n", + DBUS_AUTH_NAME (auth)); + return send_rejected (auth); + } + else + { + /* this is our auth identity */ + if (!_dbus_string_copy (data, 0, &auth->identity, 0)) + return FALSE; + } + } + + if (!_dbus_credentials_add_from_user (auth->desired_identity, data)) + { + _dbus_verbose ("%s: Did not get a valid username from client\n", + DBUS_AUTH_NAME (auth)); + return send_rejected (auth); + } + + if (!_dbus_string_init (&tmp)) + return FALSE; + + if (!_dbus_string_init (&tmp2)) + { + _dbus_string_free (&tmp); + return FALSE; + } + + /* we cache the keyring for speed, so here we drop it if it's the + * wrong one. FIXME caching the keyring here is useless since we use + * a different DBusAuth for every connection. + */ + if (auth->keyring && + !_dbus_keyring_is_for_credentials (auth->keyring, + auth->desired_identity)) + { + _dbus_keyring_unref (auth->keyring); + auth->keyring = NULL; + } + + if (auth->keyring == NULL) + { + auth->keyring = _dbus_keyring_new_for_credentials (auth->desired_identity, + &auth->context, + &error); + + if (auth->keyring == NULL) + { + if (dbus_error_has_name (&error, + DBUS_ERROR_NO_MEMORY)) + { + dbus_error_free (&error); + goto out; + } + else + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + _dbus_verbose ("%s: Error loading keyring: %s\n", + DBUS_AUTH_NAME (auth), error.message); + if (send_rejected (auth)) + retval = TRUE; /* retval is only about mem */ + dbus_error_free (&error); + goto out; + } + } + else + { + _dbus_assert (!dbus_error_is_set (&error)); + } + } + + _dbus_assert (auth->keyring != NULL); + + auth->cookie_id = _dbus_keyring_get_best_key (auth->keyring, &error); + if (auth->cookie_id < 0) + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + _dbus_verbose ("%s: Could not get a cookie ID to send to client: %s\n", + DBUS_AUTH_NAME (auth), error.message); + if (send_rejected (auth)) + retval = TRUE; + dbus_error_free (&error); + goto out; + } + else + { + _dbus_assert (!dbus_error_is_set (&error)); + } + + if (!_dbus_string_copy (&auth->context, 0, + &tmp2, _dbus_string_get_length (&tmp2))) + goto out; + + if (!_dbus_string_append (&tmp2, " ")) + goto out; + + if (!_dbus_string_append_int (&tmp2, auth->cookie_id)) + goto out; + + if (!_dbus_string_append (&tmp2, " ")) + goto out; + + if (!_dbus_generate_random_bytes (&tmp, N_CHALLENGE_BYTES, &error)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + dbus_error_free (&error); + goto out; + } + else + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + _dbus_verbose ("%s: Error generating challenge: %s\n", + DBUS_AUTH_NAME (auth), error.message); + if (send_rejected (auth)) + retval = TRUE; /* retval is only about mem */ + + dbus_error_free (&error); + goto out; + } + } + + _dbus_string_set_length (&auth->challenge, 0); + if (!_dbus_string_hex_encode (&tmp, 0, &auth->challenge, 0)) + goto out; + + if (!_dbus_string_hex_encode (&tmp, 0, &tmp2, + _dbus_string_get_length (&tmp2))) + goto out; + + if (!send_data (auth, &tmp2)) + goto out; + + goto_state (auth, &server_state_waiting_for_data); + retval = TRUE; + + out: + _dbus_string_zero (&tmp); + _dbus_string_free (&tmp); + _dbus_string_zero (&tmp2); + _dbus_string_free (&tmp2); + + return retval; +} + +static dbus_bool_t +sha1_handle_second_client_response (DBusAuth *auth, + const DBusString *data) +{ + /* We are expecting a response which is the hex-encoded client + * challenge, space, then SHA-1 hash of the concatenation of our + * challenge, ":", client challenge, ":", secret key, all + * hex-encoded. + */ + int i; + DBusString client_challenge; + DBusString client_hash; + dbus_bool_t retval; + DBusString correct_hash; + + retval = FALSE; + + if (!_dbus_string_find_blank (data, 0, &i)) + { + _dbus_verbose ("%s: no space separator in client response\n", + DBUS_AUTH_NAME (auth)); + return send_rejected (auth); + } + + if (!_dbus_string_init (&client_challenge)) + goto out_0; + + if (!_dbus_string_init (&client_hash)) + goto out_1; + + if (!_dbus_string_copy_len (data, 0, i, &client_challenge, + 0)) + goto out_2; + + _dbus_string_skip_blank (data, i, &i); + + if (!_dbus_string_copy_len (data, i, + _dbus_string_get_length (data) - i, + &client_hash, + 0)) + goto out_2; + + if (_dbus_string_get_length (&client_challenge) == 0 || + _dbus_string_get_length (&client_hash) == 0) + { + _dbus_verbose ("%s: zero-length client challenge or hash\n", + DBUS_AUTH_NAME (auth)); + if (send_rejected (auth)) + retval = TRUE; + goto out_2; + } + + if (!_dbus_string_init (&correct_hash)) + goto out_2; + + if (!sha1_compute_hash (auth, auth->cookie_id, + &auth->challenge, + &client_challenge, + &correct_hash)) + goto out_3; + + /* if cookie_id was invalid, then we get an empty hash */ + if (_dbus_string_get_length (&correct_hash) == 0) + { + if (send_rejected (auth)) + retval = TRUE; + goto out_3; + } + + if (!_dbus_string_equal (&client_hash, &correct_hash)) + { + if (send_rejected (auth)) + retval = TRUE; + goto out_3; + } + + if (!_dbus_credentials_add_credentials (auth->authorized_identity, + auth->desired_identity)) + goto out_3; + + /* Copy process ID from the socket credentials if it's there + */ + if (!_dbus_credentials_add_credential (auth->authorized_identity, + DBUS_CREDENTIAL_UNIX_PROCESS_ID, + auth->credentials)) + goto out_3; + + if (!send_ok (auth)) + goto out_3; + + _dbus_verbose ("%s: authenticated client using DBUS_COOKIE_SHA1\n", + DBUS_AUTH_NAME (auth)); + + retval = TRUE; + + out_3: + _dbus_string_zero (&correct_hash); + _dbus_string_free (&correct_hash); + out_2: + _dbus_string_zero (&client_hash); + _dbus_string_free (&client_hash); + out_1: + _dbus_string_free (&client_challenge); + out_0: + return retval; +} + +static dbus_bool_t +handle_server_data_cookie_sha1_mech (DBusAuth *auth, + const DBusString *data) +{ + if (auth->cookie_id < 0) + return sha1_handle_first_client_response (auth, data); + else + return sha1_handle_second_client_response (auth, data); +} + +static void +handle_server_shutdown_cookie_sha1_mech (DBusAuth *auth) +{ + auth->cookie_id = -1; + _dbus_string_set_length (&auth->challenge, 0); +} + +static dbus_bool_t +handle_client_initial_response_cookie_sha1_mech (DBusAuth *auth, + DBusString *response) +{ + DBusString username; + dbus_bool_t retval; + + retval = FALSE; + + if (!_dbus_string_init (&username)) + return FALSE; + + if (!_dbus_append_user_from_current_process (&username)) + goto out_0; + + if (!_dbus_string_hex_encode (&username, 0, + response, + _dbus_string_get_length (response))) + goto out_0; + + retval = TRUE; + + out_0: + _dbus_string_free (&username); + + return retval; +} + +static dbus_bool_t +handle_client_data_cookie_sha1_mech (DBusAuth *auth, + const DBusString *data) +{ + /* The data we get from the server should be the cookie context + * name, the cookie ID, and the server challenge, separated by + * spaces. We send back our challenge string and the correct hash. + */ + dbus_bool_t retval = FALSE; + DBusString context; + DBusString cookie_id_str; + DBusString server_challenge; + DBusString client_challenge; + DBusString correct_hash; + DBusString tmp; + int i, j; + long val; + DBusError error = DBUS_ERROR_INIT; + + if (!_dbus_string_find_blank (data, 0, &i)) + { + if (send_error (auth, + "Server did not send context/ID/challenge properly")) + retval = TRUE; + goto out_0; + } + + if (!_dbus_string_init (&context)) + goto out_0; + + if (!_dbus_string_copy_len (data, 0, i, + &context, 0)) + goto out_1; + + _dbus_string_skip_blank (data, i, &i); + if (!_dbus_string_find_blank (data, i, &j)) + { + if (send_error (auth, + "Server did not send context/ID/challenge properly")) + retval = TRUE; + goto out_1; + } + + if (!_dbus_string_init (&cookie_id_str)) + goto out_1; + + if (!_dbus_string_copy_len (data, i, j - i, + &cookie_id_str, 0)) + goto out_2; + + if (!_dbus_string_init (&server_challenge)) + goto out_2; + + i = j; + _dbus_string_skip_blank (data, i, &i); + j = _dbus_string_get_length (data); + + if (!_dbus_string_copy_len (data, i, j - i, + &server_challenge, 0)) + goto out_3; + + if (!_dbus_keyring_validate_context (&context)) + { + if (send_error (auth, "Server sent invalid cookie context")) + retval = TRUE; + goto out_3; + } + + if (!_dbus_string_parse_int (&cookie_id_str, 0, &val, NULL)) + { + if (send_error (auth, "Could not parse cookie ID as an integer")) + retval = TRUE; + goto out_3; + } + + if (_dbus_string_get_length (&server_challenge) == 0) + { + if (send_error (auth, "Empty server challenge string")) + retval = TRUE; + goto out_3; + } + + if (auth->keyring == NULL) + { + auth->keyring = _dbus_keyring_new_for_credentials (NULL, + &context, + &error); + + if (auth->keyring == NULL) + { + if (dbus_error_has_name (&error, + DBUS_ERROR_NO_MEMORY)) + { + dbus_error_free (&error); + goto out_3; + } + else + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + + _dbus_verbose ("%s: Error loading keyring: %s\n", + DBUS_AUTH_NAME (auth), error.message); + + if (send_error (auth, "Could not load cookie file")) + retval = TRUE; /* retval is only about mem */ + + dbus_error_free (&error); + goto out_3; + } + } + else + { + _dbus_assert (!dbus_error_is_set (&error)); + } + } + + _dbus_assert (auth->keyring != NULL); + + if (!_dbus_string_init (&tmp)) + goto out_3; + + if (!_dbus_generate_random_bytes (&tmp, N_CHALLENGE_BYTES, &error)) + { + if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) + { + dbus_error_free (&error); + goto out_4; + } + else + { + _DBUS_ASSERT_ERROR_IS_SET (&error); + + _dbus_verbose ("%s: Failed to generate challenge: %s\n", + DBUS_AUTH_NAME (auth), error.message); + + if (send_error (auth, "Failed to generate challenge")) + retval = TRUE; /* retval is only about mem */ + + dbus_error_free (&error); + goto out_4; + } + } + + if (!_dbus_string_init (&client_challenge)) + goto out_4; + + if (!_dbus_string_hex_encode (&tmp, 0, &client_challenge, 0)) + goto out_5; + + if (!_dbus_string_init (&correct_hash)) + goto out_5; + + if (!sha1_compute_hash (auth, val, + &server_challenge, + &client_challenge, + &correct_hash)) + goto out_6; + + if (_dbus_string_get_length (&correct_hash) == 0) + { + /* couldn't find the cookie ID or something */ + if (send_error (auth, "Don't have the requested cookie ID")) + retval = TRUE; + goto out_6; + } + + _dbus_string_set_length (&tmp, 0); + + if (!_dbus_string_copy (&client_challenge, 0, &tmp, + _dbus_string_get_length (&tmp))) + goto out_6; + + if (!_dbus_string_append (&tmp, " ")) + goto out_6; + + if (!_dbus_string_copy (&correct_hash, 0, &tmp, + _dbus_string_get_length (&tmp))) + goto out_6; + + if (!send_data (auth, &tmp)) + goto out_6; + + retval = TRUE; + + out_6: + _dbus_string_zero (&correct_hash); + _dbus_string_free (&correct_hash); + out_5: + _dbus_string_free (&client_challenge); + out_4: + _dbus_string_zero (&tmp); + _dbus_string_free (&tmp); + out_3: + _dbus_string_free (&server_challenge); + out_2: + _dbus_string_free (&cookie_id_str); + out_1: + _dbus_string_free (&context); + out_0: + return retval; +} + +static void +handle_client_shutdown_cookie_sha1_mech (DBusAuth *auth) +{ + auth->cookie_id = -1; + _dbus_string_set_length (&auth->challenge, 0); +} + +/* + * EXTERNAL mechanism + */ + +static dbus_bool_t +handle_server_data_external_mech (DBusAuth *auth, + const DBusString *data) +{ + if (_dbus_credentials_are_anonymous (auth->credentials)) + { + _dbus_verbose ("%s: no credentials, mechanism EXTERNAL can't authenticate\n", + DBUS_AUTH_NAME (auth)); + return send_rejected (auth); + } + + if (_dbus_string_get_length (data) > 0) + { + if (_dbus_string_get_length (&auth->identity) > 0) + { + /* Tried to send two auth identities, wtf */ + _dbus_verbose ("%s: client tried to send auth identity, but we already have one\n", + DBUS_AUTH_NAME (auth)); + return send_rejected (auth); + } + else + { + /* this is our auth identity */ + if (!_dbus_string_copy (data, 0, &auth->identity, 0)) + return FALSE; + } + } + + /* Poke client for an auth identity, if none given */ + if (_dbus_string_get_length (&auth->identity) == 0 && + !auth->already_asked_for_initial_response) + { + if (send_data (auth, NULL)) + { + _dbus_verbose ("%s: sending empty challenge asking client for auth identity\n", + DBUS_AUTH_NAME (auth)); + auth->already_asked_for_initial_response = TRUE; + goto_state (auth, &server_state_waiting_for_data); + return TRUE; + } + else + return FALSE; + } + + _dbus_credentials_clear (auth->desired_identity); + + /* If auth->identity is still empty here, then client + * responded with an empty string after we poked it for + * an initial response. This means to try to auth the + * identity provided in the credentials. + */ + if (_dbus_string_get_length (&auth->identity) == 0) + { + if (!_dbus_credentials_add_credentials (auth->desired_identity, + auth->credentials)) + { + return FALSE; /* OOM */ + } + } + else + { + if (!_dbus_credentials_add_from_user (auth->desired_identity, + &auth->identity)) + { + _dbus_verbose ("%s: could not get credentials from uid string\n", + DBUS_AUTH_NAME (auth)); + return send_rejected (auth); + } + } + + if (_dbus_credentials_are_anonymous (auth->desired_identity)) + { + _dbus_verbose ("%s: desired user %s is no good\n", + DBUS_AUTH_NAME (auth), + _dbus_string_get_const_data (&auth->identity)); + return send_rejected (auth); + } + + if (_dbus_credentials_are_superset (auth->credentials, + auth->desired_identity)) + { + /* client has authenticated */ + if (!_dbus_credentials_add_credentials (auth->authorized_identity, + auth->desired_identity)) + return FALSE; + + /* also copy misc process info from the socket credentials + */ + if (!_dbus_credentials_add_credential (auth->authorized_identity, + DBUS_CREDENTIAL_UNIX_PROCESS_ID, + auth->credentials)) + return FALSE; + + if (!_dbus_credentials_add_credential (auth->authorized_identity, + DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID, + auth->credentials)) + return FALSE; + + if (!_dbus_credentials_add_credential (auth->authorized_identity, + DBUS_CREDENTIAL_LINUX_SECURITY_LABEL, + auth->credentials)) + return FALSE; + + if (!send_ok (auth)) + return FALSE; + + _dbus_verbose ("%s: authenticated client based on socket credentials\n", + DBUS_AUTH_NAME (auth)); + + return TRUE; + } + else + { + _dbus_verbose ("%s: desired identity not found in socket credentials\n", + DBUS_AUTH_NAME (auth)); + return send_rejected (auth); + } +} + +static void +handle_server_shutdown_external_mech (DBusAuth *auth) +{ + +} + +static dbus_bool_t +handle_client_initial_response_external_mech (DBusAuth *auth, + DBusString *response) +{ + /* We always append our UID as an initial response, so the server + * doesn't have to send back an empty challenge to check whether we + * want to specify an identity. i.e. this avoids a round trip that + * the spec for the EXTERNAL mechanism otherwise requires. + */ + DBusString plaintext; + + if (!_dbus_string_init (&plaintext)) + return FALSE; + + if (!_dbus_append_user_from_current_process (&plaintext)) + goto failed; + + if (!_dbus_string_hex_encode (&plaintext, 0, + response, + _dbus_string_get_length (response))) + goto failed; + + _dbus_string_free (&plaintext); + + return TRUE; + + failed: + _dbus_string_free (&plaintext); + return FALSE; +} + +static dbus_bool_t +handle_client_data_external_mech (DBusAuth *auth, + const DBusString *data) +{ + + return TRUE; +} + +static void +handle_client_shutdown_external_mech (DBusAuth *auth) +{ + +} + +/* + * ANONYMOUS mechanism + */ + +static dbus_bool_t +handle_server_data_anonymous_mech (DBusAuth *auth, + const DBusString *data) +{ + if (_dbus_string_get_length (data) > 0) + { + /* Client is allowed to send "trace" data, the only defined + * meaning is that if it contains '@' it is an email address, + * and otherwise it is anything else, and it's supposed to be + * UTF-8 + */ + if (!_dbus_string_validate_utf8 (data, 0, _dbus_string_get_length (data))) + { + _dbus_verbose ("%s: Received invalid UTF-8 trace data from ANONYMOUS client\n", + DBUS_AUTH_NAME (auth)); + return send_rejected (auth); + } + + _dbus_verbose ("%s: ANONYMOUS client sent trace string: '%s'\n", + DBUS_AUTH_NAME (auth), + _dbus_string_get_const_data (data)); + } + + /* We want to be anonymous (clear in case some other protocol got midway through I guess) */ + _dbus_credentials_clear (auth->desired_identity); + + /* Copy process ID from the socket credentials + */ + if (!_dbus_credentials_add_credential (auth->authorized_identity, + DBUS_CREDENTIAL_UNIX_PROCESS_ID, + auth->credentials)) + return FALSE; + + /* Anonymous is always allowed */ + if (!send_ok (auth)) + return FALSE; + + _dbus_verbose ("%s: authenticated client as anonymous\n", + DBUS_AUTH_NAME (auth)); + + return TRUE; +} + +static void +handle_server_shutdown_anonymous_mech (DBusAuth *auth) +{ + +} + +static dbus_bool_t +handle_client_initial_response_anonymous_mech (DBusAuth *auth, + DBusString *response) +{ + /* Our initial response is a "trace" string which must be valid UTF-8 + * and must be an email address if it contains '@'. + * We just send the dbus implementation info, like a user-agent or + * something, because... why not. There's nothing guaranteed here + * though, we could change it later. + */ + DBusString plaintext; + + if (!_dbus_string_init (&plaintext)) + return FALSE; + + if (!_dbus_string_append (&plaintext, + "libdbus " DBUS_VERSION_STRING)) + goto failed; + + if (!_dbus_string_hex_encode (&plaintext, 0, + response, + _dbus_string_get_length (response))) + goto failed; + + _dbus_string_free (&plaintext); + + return TRUE; + + failed: + _dbus_string_free (&plaintext); + return FALSE; +} + +static dbus_bool_t +handle_client_data_anonymous_mech (DBusAuth *auth, + const DBusString *data) +{ + + return TRUE; +} + +static void +handle_client_shutdown_anonymous_mech (DBusAuth *auth) +{ + +} + +/* Put mechanisms here in order of preference. + * Right now we have: + * + * - EXTERNAL checks socket credentials (or in the future, other info from the OS) + * - DBUS_COOKIE_SHA1 uses a cookie in the home directory, like xauth or ICE + * - ANONYMOUS checks nothing but doesn't auth the person as a user + * + * We might ideally add a mechanism to chain to Cyrus SASL so we can + * use its mechanisms as well. + * + */ +static const DBusAuthMechanismHandler +all_mechanisms[] = { + { "EXTERNAL", + handle_server_data_external_mech, + NULL, NULL, + handle_server_shutdown_external_mech, + handle_client_initial_response_external_mech, + handle_client_data_external_mech, + NULL, NULL, + handle_client_shutdown_external_mech }, + { "DBUS_COOKIE_SHA1", + handle_server_data_cookie_sha1_mech, + NULL, NULL, + handle_server_shutdown_cookie_sha1_mech, + handle_client_initial_response_cookie_sha1_mech, + handle_client_data_cookie_sha1_mech, + NULL, NULL, + handle_client_shutdown_cookie_sha1_mech }, + { "ANONYMOUS", + handle_server_data_anonymous_mech, + NULL, NULL, + handle_server_shutdown_anonymous_mech, + handle_client_initial_response_anonymous_mech, + handle_client_data_anonymous_mech, + NULL, NULL, + handle_client_shutdown_anonymous_mech }, + { NULL, NULL } +}; + +static const DBusAuthMechanismHandler* +find_mech (const DBusString *name, + char **allowed_mechs) +{ + int i; + + if (allowed_mechs != NULL && + !_dbus_string_array_contains ((const char**) allowed_mechs, + _dbus_string_get_const_data (name))) + return NULL; + + i = 0; + while (all_mechanisms[i].mechanism != NULL) + { + if (_dbus_string_equal_c_str (name, + all_mechanisms[i].mechanism)) + + return &all_mechanisms[i]; + + ++i; + } + + return NULL; +} + +static dbus_bool_t +send_auth (DBusAuth *auth, const DBusAuthMechanismHandler *mech) +{ + DBusString auth_command; + + if (!_dbus_string_init (&auth_command)) + return FALSE; + + if (!_dbus_string_append (&auth_command, + "AUTH ")) + { + _dbus_string_free (&auth_command); + return FALSE; + } + + if (!_dbus_string_append (&auth_command, + mech->mechanism)) + { + _dbus_string_free (&auth_command); + return FALSE; + } + + if (mech->client_initial_response_func != NULL) + { + if (!_dbus_string_append (&auth_command, " ")) + { + _dbus_string_free (&auth_command); + return FALSE; + } + + if (!(* mech->client_initial_response_func) (auth, &auth_command)) + { + _dbus_string_free (&auth_command); + return FALSE; + } + } + + if (!_dbus_string_append (&auth_command, + "\r\n")) + { + _dbus_string_free (&auth_command); + return FALSE; + } + + if (!_dbus_string_copy (&auth_command, 0, + &auth->outgoing, + _dbus_string_get_length (&auth->outgoing))) + { + _dbus_string_free (&auth_command); + return FALSE; + } + + _dbus_string_free (&auth_command); + shutdown_mech (auth); + auth->mech = mech; + goto_state (auth, &client_state_waiting_for_data); + + return TRUE; +} + +static dbus_bool_t +send_data (DBusAuth *auth, DBusString *data) +{ + int old_len; + + if (data == NULL || _dbus_string_get_length (data) == 0) + return _dbus_string_append (&auth->outgoing, "DATA\r\n"); + else + { + old_len = _dbus_string_get_length (&auth->outgoing); + if (!_dbus_string_append (&auth->outgoing, "DATA ")) + goto out; + + if (!_dbus_string_hex_encode (data, 0, &auth->outgoing, + _dbus_string_get_length (&auth->outgoing))) + goto out; + + if (!_dbus_string_append (&auth->outgoing, "\r\n")) + goto out; + + return TRUE; + + out: + _dbus_string_set_length (&auth->outgoing, old_len); + + return FALSE; + } +} + +static dbus_bool_t +send_rejected (DBusAuth *auth) +{ + DBusString command; + DBusAuthServer *server_auth; + int i; + + if (!_dbus_string_init (&command)) + return FALSE; + + if (!_dbus_string_append (&command, + "REJECTED")) + goto nomem; + + i = 0; + while (all_mechanisms[i].mechanism != NULL) + { + if (!_dbus_string_append (&command, + " ")) + goto nomem; + + if (!_dbus_string_append (&command, + all_mechanisms[i].mechanism)) + goto nomem; + + ++i; + } + + if (!_dbus_string_append (&command, "\r\n")) + goto nomem; + + if (!_dbus_string_copy (&command, 0, &auth->outgoing, + _dbus_string_get_length (&auth->outgoing))) + goto nomem; + + shutdown_mech (auth); + + _dbus_assert (DBUS_AUTH_IS_SERVER (auth)); + server_auth = DBUS_AUTH_SERVER (auth); + server_auth->failures += 1; + + if (server_auth->failures >= server_auth->max_failures) + goto_state (auth, &common_state_need_disconnect); + else + goto_state (auth, &server_state_waiting_for_auth); + + _dbus_string_free (&command); + + return TRUE; + + nomem: + _dbus_string_free (&command); + return FALSE; +} + +static dbus_bool_t +send_error (DBusAuth *auth, const char *message) +{ + return _dbus_string_append_printf (&auth->outgoing, + "ERROR \"%s\"\r\n", message); +} + +static dbus_bool_t +send_ok (DBusAuth *auth) +{ + int orig_len; + + orig_len = _dbus_string_get_length (&auth->outgoing); + + if (_dbus_string_append (&auth->outgoing, "OK ") && + _dbus_string_copy (& DBUS_AUTH_SERVER (auth)->guid, + 0, + &auth->outgoing, + _dbus_string_get_length (&auth->outgoing)) && + _dbus_string_append (&auth->outgoing, "\r\n")) + { + goto_state (auth, &server_state_waiting_for_begin); + return TRUE; + } + else + { + _dbus_string_set_length (&auth->outgoing, orig_len); + return FALSE; + } +} + +static dbus_bool_t +send_begin (DBusAuth *auth) +{ + + if (!_dbus_string_append (&auth->outgoing, + "BEGIN\r\n")) + return FALSE; + + goto_state (auth, &common_state_authenticated); + return TRUE; +} + +static dbus_bool_t +process_ok(DBusAuth *auth, + const DBusString *args_from_ok) { + + int end_of_hex; + + /* "args_from_ok" should be the GUID, whitespace already pulled off the front */ + _dbus_assert (_dbus_string_get_length (& DBUS_AUTH_CLIENT (auth)->guid_from_server) == 0); + + /* We decode the hex string to binary, using guid_from_server as scratch... */ + + end_of_hex = 0; + if (!_dbus_string_hex_decode (args_from_ok, 0, &end_of_hex, + & DBUS_AUTH_CLIENT (auth)->guid_from_server, 0)) + return FALSE; + + /* now clear out the scratch */ + _dbus_string_set_length (& DBUS_AUTH_CLIENT (auth)->guid_from_server, 0); + + if (end_of_hex != _dbus_string_get_length (args_from_ok) || + end_of_hex == 0) + { + _dbus_verbose ("Bad GUID from server, parsed %d bytes and had %d bytes from server\n", + end_of_hex, _dbus_string_get_length (args_from_ok)); + goto_state (auth, &common_state_need_disconnect); + return TRUE; + } + + if (!_dbus_string_copy (args_from_ok, 0, &DBUS_AUTH_CLIENT (auth)->guid_from_server, 0)) { + _dbus_string_set_length (& DBUS_AUTH_CLIENT (auth)->guid_from_server, 0); + return FALSE; + } + + _dbus_verbose ("Got GUID '%s' from the server\n", + _dbus_string_get_const_data (& DBUS_AUTH_CLIENT (auth)->guid_from_server)); + + if (auth->unix_fd_possible) + return send_negotiate_unix_fd(auth); + + _dbus_verbose("Not negotiating unix fd passing, since not possible\n"); + return send_begin (auth); +} + +static dbus_bool_t +send_cancel (DBusAuth *auth) +{ + if (_dbus_string_append (&auth->outgoing, "CANCEL\r\n")) + { + goto_state (auth, &client_state_waiting_for_reject); + return TRUE; + } + else + return FALSE; +} + +static dbus_bool_t +process_data (DBusAuth *auth, + const DBusString *args, + DBusAuthDataFunction data_func) +{ + int end; + DBusString decoded; + + if (!_dbus_string_init (&decoded)) + return FALSE; + + if (!_dbus_string_hex_decode (args, 0, &end, &decoded, 0)) + { + _dbus_string_free (&decoded); + return FALSE; + } + + if (_dbus_string_get_length (args) != end) + { + _dbus_string_free (&decoded); + if (!send_error (auth, "Invalid hex encoding")) + return FALSE; + + return TRUE; + } + +#ifdef DBUS_ENABLE_VERBOSE_MODE + if (_dbus_string_validate_ascii (&decoded, 0, + _dbus_string_get_length (&decoded))) + _dbus_verbose ("%s: data: '%s'\n", + DBUS_AUTH_NAME (auth), + _dbus_string_get_const_data (&decoded)); +#endif + + if (!(* data_func) (auth, &decoded)) + { + _dbus_string_free (&decoded); + return FALSE; + } + + _dbus_string_free (&decoded); + return TRUE; +} + +static dbus_bool_t +send_negotiate_unix_fd (DBusAuth *auth) +{ + if (!_dbus_string_append (&auth->outgoing, + "NEGOTIATE_UNIX_FD\r\n")) + return FALSE; + + goto_state (auth, &client_state_waiting_for_agree_unix_fd); + return TRUE; +} + +static dbus_bool_t +send_agree_unix_fd (DBusAuth *auth) +{ + _dbus_assert(auth->unix_fd_possible); + + auth->unix_fd_negotiated = TRUE; + _dbus_verbose("Agreed to UNIX FD passing\n"); + + if (!_dbus_string_append (&auth->outgoing, + "AGREE_UNIX_FD\r\n")) + return FALSE; + + goto_state (auth, &server_state_waiting_for_begin); + return TRUE; +} + +static dbus_bool_t +handle_auth (DBusAuth *auth, const DBusString *args) +{ + if (_dbus_string_get_length (args) == 0) + { + /* No args to the auth, send mechanisms */ + if (!send_rejected (auth)) + return FALSE; + + return TRUE; + } + else + { + int i; + DBusString mech; + DBusString hex_response; + + _dbus_string_find_blank (args, 0, &i); + + if (!_dbus_string_init (&mech)) + return FALSE; + + if (!_dbus_string_init (&hex_response)) + { + _dbus_string_free (&mech); + return FALSE; + } + + if (!_dbus_string_copy_len (args, 0, i, &mech, 0)) + goto failed; + + _dbus_string_skip_blank (args, i, &i); + if (!_dbus_string_copy (args, i, &hex_response, 0)) + goto failed; + + auth->mech = find_mech (&mech, auth->allowed_mechs); + if (auth->mech != NULL) + { + _dbus_verbose ("%s: Trying mechanism %s\n", + DBUS_AUTH_NAME (auth), + auth->mech->mechanism); + + if (!process_data (auth, &hex_response, + auth->mech->server_data_func)) + goto failed; + } + else + { + /* Unsupported mechanism */ + _dbus_verbose ("%s: Unsupported mechanism %s\n", + DBUS_AUTH_NAME (auth), + _dbus_string_get_const_data (&mech)); + + if (!send_rejected (auth)) + goto failed; + } + + _dbus_string_free (&mech); + _dbus_string_free (&hex_response); + + return TRUE; + + failed: + auth->mech = NULL; + _dbus_string_free (&mech); + _dbus_string_free (&hex_response); + return FALSE; + } +} + +static dbus_bool_t +handle_server_state_waiting_for_auth (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args) +{ + switch (command) + { + case DBUS_AUTH_COMMAND_AUTH: + return handle_auth (auth, args); + + case DBUS_AUTH_COMMAND_CANCEL: + case DBUS_AUTH_COMMAND_DATA: + return send_error (auth, "Not currently in an auth conversation"); + + case DBUS_AUTH_COMMAND_BEGIN: + goto_state (auth, &common_state_need_disconnect); + return TRUE; + + case DBUS_AUTH_COMMAND_ERROR: + return send_rejected (auth); + + case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: + return send_error (auth, "Need to authenticate first"); + + case DBUS_AUTH_COMMAND_REJECTED: + case DBUS_AUTH_COMMAND_OK: + case DBUS_AUTH_COMMAND_UNKNOWN: + case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + default: + return send_error (auth, "Unknown command"); + } +} + +static dbus_bool_t +handle_server_state_waiting_for_data (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args) +{ + switch (command) + { + case DBUS_AUTH_COMMAND_AUTH: + return send_error (auth, "Sent AUTH while another AUTH in progress"); + + case DBUS_AUTH_COMMAND_CANCEL: + case DBUS_AUTH_COMMAND_ERROR: + return send_rejected (auth); + + case DBUS_AUTH_COMMAND_DATA: + return process_data (auth, args, auth->mech->server_data_func); + + case DBUS_AUTH_COMMAND_BEGIN: + goto_state (auth, &common_state_need_disconnect); + return TRUE; + + case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: + return send_error (auth, "Need to authenticate first"); + + case DBUS_AUTH_COMMAND_REJECTED: + case DBUS_AUTH_COMMAND_OK: + case DBUS_AUTH_COMMAND_UNKNOWN: + case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + default: + return send_error (auth, "Unknown command"); + } +} + +static dbus_bool_t +handle_server_state_waiting_for_begin (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args) +{ + switch (command) + { + case DBUS_AUTH_COMMAND_AUTH: + return send_error (auth, "Sent AUTH while expecting BEGIN"); + + case DBUS_AUTH_COMMAND_DATA: + return send_error (auth, "Sent DATA while expecting BEGIN"); + + case DBUS_AUTH_COMMAND_BEGIN: + goto_state (auth, &common_state_authenticated); + return TRUE; + + case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: + if (auth->unix_fd_possible) + return send_agree_unix_fd(auth); + else + return send_error(auth, "Unix FD passing not supported, not authenticated or otherwise not possible"); + + case DBUS_AUTH_COMMAND_REJECTED: + case DBUS_AUTH_COMMAND_OK: + case DBUS_AUTH_COMMAND_UNKNOWN: + case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + default: + return send_error (auth, "Unknown command"); + + case DBUS_AUTH_COMMAND_CANCEL: + case DBUS_AUTH_COMMAND_ERROR: + return send_rejected (auth); + } +} + +/* return FALSE if no memory, TRUE if all OK */ +static dbus_bool_t +get_word (const DBusString *str, + int *start, + DBusString *word) +{ + int i; + + _dbus_string_skip_blank (str, *start, start); + _dbus_string_find_blank (str, *start, &i); + + if (i > *start) + { + if (!_dbus_string_copy_len (str, *start, i - *start, word, 0)) + return FALSE; + + *start = i; + } + + return TRUE; +} + +static dbus_bool_t +record_mechanisms (DBusAuth *auth, + const DBusString *args) +{ + int next; + int len; + + if (auth->already_got_mechanisms) + return TRUE; + + len = _dbus_string_get_length (args); + + next = 0; + while (next < len) + { + DBusString m; + const DBusAuthMechanismHandler *mech; + + if (!_dbus_string_init (&m)) + goto nomem; + + if (!get_word (args, &next, &m)) + { + _dbus_string_free (&m); + goto nomem; + } + + mech = find_mech (&m, auth->allowed_mechs); + + if (mech != NULL) + { + /* FIXME right now we try mechanisms in the order + * the server lists them; should we do them in + * some more deterministic order? + * + * Probably in all_mechanisms order, our order of + * preference. Of course when the server is us, + * it lists things in that order anyhow. + */ + + if (mech != &all_mechanisms[0]) + { + _dbus_verbose ("%s: Adding mechanism %s to list we will try\n", + DBUS_AUTH_NAME (auth), mech->mechanism); + + if (!_dbus_list_append (& DBUS_AUTH_CLIENT (auth)->mechs_to_try, + (void*) mech)) + { + _dbus_string_free (&m); + goto nomem; + } + } + else + { + _dbus_verbose ("%s: Already tried mechanism %s; not adding to list we will try\n", + DBUS_AUTH_NAME (auth), mech->mechanism); + } + } + else + { + _dbus_verbose ("%s: Server offered mechanism \"%s\" that we don't know how to use\n", + DBUS_AUTH_NAME (auth), + _dbus_string_get_const_data (&m)); + } + + _dbus_string_free (&m); + } + + auth->already_got_mechanisms = TRUE; + + return TRUE; + + nomem: + _dbus_list_clear (& DBUS_AUTH_CLIENT (auth)->mechs_to_try); + + return FALSE; +} + +static dbus_bool_t +process_rejected (DBusAuth *auth, const DBusString *args) +{ + const DBusAuthMechanismHandler *mech; + DBusAuthClient *client; + + client = DBUS_AUTH_CLIENT (auth); + + if (!auth->already_got_mechanisms) + { + if (!record_mechanisms (auth, args)) + return FALSE; + } + + if (DBUS_AUTH_CLIENT (auth)->mechs_to_try != NULL) + { + mech = client->mechs_to_try->data; + + if (!send_auth (auth, mech)) + return FALSE; + + _dbus_list_pop_first (&client->mechs_to_try); + + _dbus_verbose ("%s: Trying mechanism %s\n", + DBUS_AUTH_NAME (auth), + mech->mechanism); + } + else + { + /* Give up */ + _dbus_verbose ("%s: Disconnecting because we are out of mechanisms to try using\n", + DBUS_AUTH_NAME (auth)); + goto_state (auth, &common_state_need_disconnect); + } + + return TRUE; +} + + +static dbus_bool_t +handle_client_state_waiting_for_data (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args) +{ + _dbus_assert (auth->mech != NULL); + + switch (command) + { + case DBUS_AUTH_COMMAND_DATA: + return process_data (auth, args, auth->mech->client_data_func); + + case DBUS_AUTH_COMMAND_REJECTED: + return process_rejected (auth, args); + + case DBUS_AUTH_COMMAND_OK: + return process_ok(auth, args); + + case DBUS_AUTH_COMMAND_ERROR: + return send_cancel (auth); + + case DBUS_AUTH_COMMAND_AUTH: + case DBUS_AUTH_COMMAND_CANCEL: + case DBUS_AUTH_COMMAND_BEGIN: + case DBUS_AUTH_COMMAND_UNKNOWN: + case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: + case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + default: + return send_error (auth, "Unknown command"); + } +} + +static dbus_bool_t +handle_client_state_waiting_for_ok (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args) +{ + switch (command) + { + case DBUS_AUTH_COMMAND_REJECTED: + return process_rejected (auth, args); + + case DBUS_AUTH_COMMAND_OK: + return process_ok(auth, args); + + case DBUS_AUTH_COMMAND_DATA: + case DBUS_AUTH_COMMAND_ERROR: + return send_cancel (auth); + + case DBUS_AUTH_COMMAND_AUTH: + case DBUS_AUTH_COMMAND_CANCEL: + case DBUS_AUTH_COMMAND_BEGIN: + case DBUS_AUTH_COMMAND_UNKNOWN: + case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: + case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + default: + return send_error (auth, "Unknown command"); + } +} + +static dbus_bool_t +handle_client_state_waiting_for_reject (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args) +{ + switch (command) + { + case DBUS_AUTH_COMMAND_REJECTED: + return process_rejected (auth, args); + + case DBUS_AUTH_COMMAND_AUTH: + case DBUS_AUTH_COMMAND_CANCEL: + case DBUS_AUTH_COMMAND_DATA: + case DBUS_AUTH_COMMAND_BEGIN: + case DBUS_AUTH_COMMAND_OK: + case DBUS_AUTH_COMMAND_ERROR: + case DBUS_AUTH_COMMAND_UNKNOWN: + case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: + case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + default: + goto_state (auth, &common_state_need_disconnect); + return TRUE; + } +} + +static dbus_bool_t +handle_client_state_waiting_for_agree_unix_fd(DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args) +{ + switch (command) + { + case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + _dbus_assert(auth->unix_fd_possible); + auth->unix_fd_negotiated = TRUE; + _dbus_verbose("Successfully negotiated UNIX FD passing\n"); + return send_begin (auth); + + case DBUS_AUTH_COMMAND_ERROR: + _dbus_assert(auth->unix_fd_possible); + auth->unix_fd_negotiated = FALSE; + _dbus_verbose("Failed to negotiate UNIX FD passing\n"); + return send_begin (auth); + + case DBUS_AUTH_COMMAND_OK: + case DBUS_AUTH_COMMAND_DATA: + case DBUS_AUTH_COMMAND_REJECTED: + case DBUS_AUTH_COMMAND_AUTH: + case DBUS_AUTH_COMMAND_CANCEL: + case DBUS_AUTH_COMMAND_BEGIN: + case DBUS_AUTH_COMMAND_UNKNOWN: + case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: + default: + return send_error (auth, "Unknown command"); + } +} + +/** + * Mapping from command name to enum + */ +typedef struct { + const char *name; /**< Name of the command */ + DBusAuthCommand command; /**< Corresponding enum */ +} DBusAuthCommandName; + +static const DBusAuthCommandName auth_command_names[] = { + { "AUTH", DBUS_AUTH_COMMAND_AUTH }, + { "CANCEL", DBUS_AUTH_COMMAND_CANCEL }, + { "DATA", DBUS_AUTH_COMMAND_DATA }, + { "BEGIN", DBUS_AUTH_COMMAND_BEGIN }, + { "REJECTED", DBUS_AUTH_COMMAND_REJECTED }, + { "OK", DBUS_AUTH_COMMAND_OK }, + { "ERROR", DBUS_AUTH_COMMAND_ERROR }, + { "NEGOTIATE_UNIX_FD", DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD }, + { "AGREE_UNIX_FD", DBUS_AUTH_COMMAND_AGREE_UNIX_FD } +}; + +static DBusAuthCommand +lookup_command_from_name (DBusString *command) +{ + int i; + + for (i = 0; i < _DBUS_N_ELEMENTS (auth_command_names); i++) + { + if (_dbus_string_equal_c_str (command, + auth_command_names[i].name)) + return auth_command_names[i].command; + } + + return DBUS_AUTH_COMMAND_UNKNOWN; +} + +static void +goto_state (DBusAuth *auth, + const DBusAuthStateData *state) +{ + _dbus_verbose ("%s: going from state %s to state %s\n", + DBUS_AUTH_NAME (auth), + auth->state->name, + state->name); + + auth->state = state; +} + +/* returns whether to call it again right away */ +static dbus_bool_t +process_command (DBusAuth *auth) +{ + DBusAuthCommand command; + DBusString line; + DBusString args; + int eol; + int i, j; + dbus_bool_t retval; + + /* _dbus_verbose ("%s: trying process_command()\n"); */ + + retval = FALSE; + + eol = 0; + if (!_dbus_string_find (&auth->incoming, 0, "\r\n", &eol)) + return FALSE; + + if (!_dbus_string_init (&line)) + { + auth->needed_memory = TRUE; + return FALSE; + } + + if (!_dbus_string_init (&args)) + { + _dbus_string_free (&line); + auth->needed_memory = TRUE; + return FALSE; + } + + if (!_dbus_string_copy_len (&auth->incoming, 0, eol, &line, 0)) + goto out; + + if (!_dbus_string_validate_ascii (&line, 0, + _dbus_string_get_length (&line))) + { + _dbus_verbose ("%s: Command contained non-ASCII chars or embedded nul\n", + DBUS_AUTH_NAME (auth)); + if (!send_error (auth, "Command contained non-ASCII")) + goto out; + else + goto next_command; + } + + _dbus_verbose ("%s: got command \"%s\"\n", + DBUS_AUTH_NAME (auth), + _dbus_string_get_const_data (&line)); + + _dbus_string_find_blank (&line, 0, &i); + _dbus_string_skip_blank (&line, i, &j); + + if (j > i) + _dbus_string_delete (&line, i, j - i); + + if (!_dbus_string_move (&line, i, &args, 0)) + goto out; + + /* FIXME 1.0 we should probably validate that only the allowed + * chars are in the command name + */ + + command = lookup_command_from_name (&line); + if (!(* auth->state->handler) (auth, command, &args)) + goto out; + + next_command: + + /* We've succeeded in processing the whole command so drop it out + * of the incoming buffer and return TRUE to try another command. + */ + + _dbus_string_delete (&auth->incoming, 0, eol); + + /* kill the \r\n */ + _dbus_string_delete (&auth->incoming, 0, 2); + + retval = TRUE; + + out: + _dbus_string_free (&args); + _dbus_string_free (&line); + + if (!retval) + auth->needed_memory = TRUE; + else + auth->needed_memory = FALSE; + + return retval; +} + + +/** @} */ + +/** + * @addtogroup DBusAuth + * @{ + */ + +/** + * Creates a new auth conversation object for the server side. + * See http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol + * for full details on what this object does. + * + * @returns the new object or #NULL if no memory + */ +DBusAuth* +_dbus_auth_server_new (const DBusString *guid) +{ + DBusAuth *auth; + DBusAuthServer *server_auth; + DBusString guid_copy; + + if (!_dbus_string_init (&guid_copy)) + return NULL; + + if (!_dbus_string_copy (guid, 0, &guid_copy, 0)) + { + _dbus_string_free (&guid_copy); + return NULL; + } + + auth = _dbus_auth_new (sizeof (DBusAuthServer)); + if (auth == NULL) + { + _dbus_string_free (&guid_copy); + return NULL; + } + + auth->side = auth_side_server; + auth->state = &server_state_waiting_for_auth; + + server_auth = DBUS_AUTH_SERVER (auth); + + server_auth->guid = guid_copy; + + /* perhaps this should be per-mechanism with a lower + * max + */ + server_auth->failures = 0; + server_auth->max_failures = 6; + + return auth; +} + +/** + * Creates a new auth conversation object for the client side. + * See http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol + * for full details on what this object does. + * + * @returns the new object or #NULL if no memory + */ +DBusAuth* +_dbus_auth_client_new (void) +{ + DBusAuth *auth; + DBusString guid_str; + + if (!_dbus_string_init (&guid_str)) + return NULL; + + auth = _dbus_auth_new (sizeof (DBusAuthClient)); + if (auth == NULL) + { + _dbus_string_free (&guid_str); + return NULL; + } + + DBUS_AUTH_CLIENT (auth)->guid_from_server = guid_str; + + auth->side = auth_side_client; + auth->state = &client_state_need_send_auth; + + /* Start the auth conversation by sending AUTH for our default + * mechanism */ + if (!send_auth (auth, &all_mechanisms[0])) + { + _dbus_auth_unref (auth); + return NULL; + } + + return auth; +} + +/** + * Increments the refcount of an auth object. + * + * @param auth the auth conversation + * @returns the auth conversation + */ +DBusAuth * +_dbus_auth_ref (DBusAuth *auth) +{ + _dbus_assert (auth != NULL); + + auth->refcount += 1; + + return auth; +} + +/** + * Decrements the refcount of an auth object. + * + * @param auth the auth conversation + */ +void +_dbus_auth_unref (DBusAuth *auth) +{ + _dbus_assert (auth != NULL); + _dbus_assert (auth->refcount > 0); + + auth->refcount -= 1; + if (auth->refcount == 0) + { + shutdown_mech (auth); + + if (DBUS_AUTH_IS_CLIENT (auth)) + { + _dbus_string_free (& DBUS_AUTH_CLIENT (auth)->guid_from_server); + _dbus_list_clear (& DBUS_AUTH_CLIENT (auth)->mechs_to_try); + } + else + { + _dbus_assert (DBUS_AUTH_IS_SERVER (auth)); + + _dbus_string_free (& DBUS_AUTH_SERVER (auth)->guid); + } + + if (auth->keyring) + _dbus_keyring_unref (auth->keyring); + + _dbus_string_free (&auth->context); + _dbus_string_free (&auth->challenge); + _dbus_string_free (&auth->identity); + _dbus_string_free (&auth->incoming); + _dbus_string_free (&auth->outgoing); + + dbus_free_string_array (auth->allowed_mechs); + + _dbus_credentials_unref (auth->credentials); + _dbus_credentials_unref (auth->authorized_identity); + _dbus_credentials_unref (auth->desired_identity); + + dbus_free (auth); + } +} + +/** + * Sets an array of authentication mechanism names + * that we are willing to use. + * + * @param auth the auth conversation + * @param mechanisms #NULL-terminated array of mechanism names + * @returns #FALSE if no memory + */ +dbus_bool_t +_dbus_auth_set_mechanisms (DBusAuth *auth, + const char **mechanisms) +{ + char **copy; + + if (mechanisms != NULL) + { + copy = _dbus_dup_string_array (mechanisms); + if (copy == NULL) + return FALSE; + } + else + copy = NULL; + + dbus_free_string_array (auth->allowed_mechs); + + auth->allowed_mechs = copy; + + return TRUE; +} + +/** + * @param auth the auth conversation object + * @returns #TRUE if we're in a final state + */ +#define DBUS_AUTH_IN_END_STATE(auth) ((auth)->state->handler == NULL) + +/** + * Analyzes buffered input and moves the auth conversation forward, + * returning the new state of the auth conversation. + * + * @param auth the auth conversation + * @returns the new state + */ +DBusAuthState +_dbus_auth_do_work (DBusAuth *auth) +{ + auth->needed_memory = FALSE; + + /* Max amount we'll buffer up before deciding someone's on crack */ +#define MAX_BUFFER (16 * _DBUS_ONE_KILOBYTE) + + do + { + if (DBUS_AUTH_IN_END_STATE (auth)) + break; + + if (_dbus_string_get_length (&auth->incoming) > MAX_BUFFER || + _dbus_string_get_length (&auth->outgoing) > MAX_BUFFER) + { + goto_state (auth, &common_state_need_disconnect); + _dbus_verbose ("%s: Disconnecting due to excessive data buffered in auth phase\n", + DBUS_AUTH_NAME (auth)); + break; + } + } + while (process_command (auth)); + + if (auth->needed_memory) + return DBUS_AUTH_STATE_WAITING_FOR_MEMORY; + else if (_dbus_string_get_length (&auth->outgoing) > 0) + return DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND; + else if (auth->state == &common_state_need_disconnect) + return DBUS_AUTH_STATE_NEED_DISCONNECT; + else if (auth->state == &common_state_authenticated) + return DBUS_AUTH_STATE_AUTHENTICATED; + else return DBUS_AUTH_STATE_WAITING_FOR_INPUT; +} + +/** + * Gets bytes that need to be sent to the peer we're conversing with. + * After writing some bytes, _dbus_auth_bytes_sent() must be called + * to notify the auth object that they were written. + * + * @param auth the auth conversation + * @param str return location for a ref to the buffer to send + * @returns #FALSE if nothing to send + */ +dbus_bool_t +_dbus_auth_get_bytes_to_send (DBusAuth *auth, + const DBusString **str) +{ + _dbus_assert (auth != NULL); + _dbus_assert (str != NULL); + + *str = NULL; + + if (_dbus_string_get_length (&auth->outgoing) == 0) + return FALSE; + + *str = &auth->outgoing; + + return TRUE; +} + +/** + * Notifies the auth conversation object that + * the given number of bytes of the outgoing buffer + * have been written out. + * + * @param auth the auth conversation + * @param bytes_sent number of bytes written out + */ +void +_dbus_auth_bytes_sent (DBusAuth *auth, + int bytes_sent) +{ + _dbus_verbose ("%s: Sent %d bytes of: %s\n", + DBUS_AUTH_NAME (auth), + bytes_sent, + _dbus_string_get_const_data (&auth->outgoing)); + + _dbus_string_delete (&auth->outgoing, + 0, bytes_sent); +} + +/** + * Get a buffer to be used for reading bytes from the peer we're conversing + * with. Bytes should be appended to this buffer. + * + * @param auth the auth conversation + * @param buffer return location for buffer to append bytes to + */ +void +_dbus_auth_get_buffer (DBusAuth *auth, + DBusString **buffer) +{ + _dbus_assert (auth != NULL); + _dbus_assert (!auth->buffer_outstanding); + + *buffer = &auth->incoming; + + auth->buffer_outstanding = TRUE; +} + +/** + * Returns a buffer with new data read into it. + * + * @param auth the auth conversation + * @param buffer the buffer being returned + */ +void +_dbus_auth_return_buffer (DBusAuth *auth, + DBusString *buffer) +{ + _dbus_assert (buffer == &auth->incoming); + _dbus_assert (auth->buffer_outstanding); + + auth->buffer_outstanding = FALSE; +} + +/** + * Returns leftover bytes that were not used as part of the auth + * conversation. These bytes will be part of the message stream + * instead. This function may not be called until authentication has + * succeeded. + * + * @param auth the auth conversation + * @param str return location for pointer to string of unused bytes + */ +void +_dbus_auth_get_unused_bytes (DBusAuth *auth, + const DBusString **str) +{ + if (!DBUS_AUTH_IN_END_STATE (auth)) + return; + + *str = &auth->incoming; +} + + +/** + * Gets rid of unused bytes returned by _dbus_auth_get_unused_bytes() + * after we've gotten them and successfully moved them elsewhere. + * + * @param auth the auth conversation + */ +void +_dbus_auth_delete_unused_bytes (DBusAuth *auth) +{ + if (!DBUS_AUTH_IN_END_STATE (auth)) + return; + + _dbus_string_set_length (&auth->incoming, 0); +} + +/** + * Called post-authentication, indicates whether we need to encode + * the message stream with _dbus_auth_encode_data() prior to + * sending it to the peer. + * + * @param auth the auth conversation + * @returns #TRUE if we need to encode the stream + */ +dbus_bool_t +_dbus_auth_needs_encoding (DBusAuth *auth) +{ + if (auth->state != &common_state_authenticated) + return FALSE; + + if (auth->mech != NULL) + { + if (DBUS_AUTH_IS_CLIENT (auth)) + return auth->mech->client_encode_func != NULL; + else + return auth->mech->server_encode_func != NULL; + } + else + return FALSE; +} + +/** + * Called post-authentication, encodes a block of bytes for sending to + * the peer. If no encoding was negotiated, just copies the bytes + * (you can avoid this by checking _dbus_auth_needs_encoding()). + * + * @param auth the auth conversation + * @param plaintext the plain text data + * @param encoded initialized string to where encoded data is appended + * @returns #TRUE if we had enough memory and successfully encoded + */ +dbus_bool_t +_dbus_auth_encode_data (DBusAuth *auth, + const DBusString *plaintext, + DBusString *encoded) +{ + _dbus_assert (plaintext != encoded); + + if (auth->state != &common_state_authenticated) + return FALSE; + + if (_dbus_auth_needs_encoding (auth)) + { + if (DBUS_AUTH_IS_CLIENT (auth)) + return (* auth->mech->client_encode_func) (auth, plaintext, encoded); + else + return (* auth->mech->server_encode_func) (auth, plaintext, encoded); + } + else + { + return _dbus_string_copy (plaintext, 0, encoded, + _dbus_string_get_length (encoded)); + } +} + +/** + * Called post-authentication, indicates whether we need to decode + * the message stream with _dbus_auth_decode_data() after + * receiving it from the peer. + * + * @param auth the auth conversation + * @returns #TRUE if we need to encode the stream + */ +dbus_bool_t +_dbus_auth_needs_decoding (DBusAuth *auth) +{ + if (auth->state != &common_state_authenticated) + return FALSE; + + if (auth->mech != NULL) + { + if (DBUS_AUTH_IS_CLIENT (auth)) + return auth->mech->client_decode_func != NULL; + else + return auth->mech->server_decode_func != NULL; + } + else + return FALSE; +} + + +/** + * Called post-authentication, decodes a block of bytes received from + * the peer. If no encoding was negotiated, just copies the bytes (you + * can avoid this by checking _dbus_auth_needs_decoding()). + * + * @todo 1.0? We need to be able to distinguish "out of memory" error + * from "the data is hosed" error. + * + * @param auth the auth conversation + * @param encoded the encoded data + * @param plaintext initialized string where decoded data is appended + * @returns #TRUE if we had enough memory and successfully decoded + */ +dbus_bool_t +_dbus_auth_decode_data (DBusAuth *auth, + const DBusString *encoded, + DBusString *plaintext) +{ + _dbus_assert (plaintext != encoded); + + if (auth->state != &common_state_authenticated) + return FALSE; + + if (_dbus_auth_needs_decoding (auth)) + { + if (DBUS_AUTH_IS_CLIENT (auth)) + return (* auth->mech->client_decode_func) (auth, encoded, plaintext); + else + return (* auth->mech->server_decode_func) (auth, encoded, plaintext); + } + else + { + return _dbus_string_copy (encoded, 0, plaintext, + _dbus_string_get_length (plaintext)); + } +} + +/** + * Sets credentials received via reliable means from the operating + * system. + * + * @param auth the auth conversation + * @param credentials the credentials received + * @returns #FALSE on OOM + */ +dbus_bool_t +_dbus_auth_set_credentials (DBusAuth *auth, + DBusCredentials *credentials) +{ + _dbus_credentials_clear (auth->credentials); + return _dbus_credentials_add_credentials (auth->credentials, + credentials); +} + +/** + * Gets the identity we authorized the client as. Apps may have + * different policies as to what identities they allow. + * + * Returned credentials are not a copy and should not be modified + * + * @param auth the auth conversation + * @returns the credentials we've authorized BY REFERENCE do not modify + */ +DBusCredentials* +_dbus_auth_get_identity (DBusAuth *auth) +{ + if (auth->state == &common_state_authenticated) + { + return auth->authorized_identity; + } + else + { + /* FIXME instead of this, keep an empty credential around that + * doesn't require allocation or something + */ + /* return empty credentials */ + _dbus_assert (_dbus_credentials_are_empty (auth->authorized_identity)); + return auth->authorized_identity; + } +} + +/** + * Gets the GUID from the server if we've authenticated; gets + * #NULL otherwise. + * @param auth the auth object + * @returns the GUID in ASCII hex format + */ +const char* +_dbus_auth_get_guid_from_server (DBusAuth *auth) +{ + _dbus_assert (DBUS_AUTH_IS_CLIENT (auth)); + + if (auth->state == &common_state_authenticated) + return _dbus_string_get_const_data (& DBUS_AUTH_CLIENT (auth)->guid_from_server); + else + return NULL; +} + +/** + * Sets the "authentication context" which scopes cookies + * with the DBUS_COOKIE_SHA1 auth mechanism for example. + * + * @param auth the auth conversation + * @param context the context + * @returns #FALSE if no memory + */ +dbus_bool_t +_dbus_auth_set_context (DBusAuth *auth, + const DBusString *context) +{ + return _dbus_string_replace_len (context, 0, _dbus_string_get_length (context), + &auth->context, 0, _dbus_string_get_length (context)); +} + +/** + * Sets whether unix fd passing is potentially on the transport and + * hence shall be negotiated. + * + * @param auth the auth conversation + * @param b TRUE when unix fd passing shall be negotiated, otherwise FALSE + */ +void +_dbus_auth_set_unix_fd_possible(DBusAuth *auth, dbus_bool_t b) +{ + auth->unix_fd_possible = b; +} + +/** + * Queries whether unix fd passing was successfully negotiated. + * + * @param auth the auth conversion + * @returns #TRUE when unix fd passing was negotiated. + */ +dbus_bool_t +_dbus_auth_get_unix_fd_negotiated(DBusAuth *auth) +{ + return auth->unix_fd_negotiated; +} + +/** @} */ + +/* tests in dbus-auth-util.c */
diff --git a/dbus/dbus-auth.h b/dbus/dbus-auth.h new file mode 100644 index 0000000..e032302 --- /dev/null +++ b/dbus/dbus-auth.h
@@ -0,0 +1,97 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-auth.h Authentication + * + * Copyright (C) 2002 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#ifndef DBUS_AUTH_H +#define DBUS_AUTH_H + +#include <dbus/dbus-macros.h> +#include <dbus/dbus-errors.h> +#include <dbus/dbus-string.h> +#include <dbus/dbus-sysdeps.h> + +DBUS_BEGIN_DECLS + +typedef struct DBusAuth DBusAuth; + +typedef enum +{ + DBUS_AUTH_STATE_WAITING_FOR_INPUT, + DBUS_AUTH_STATE_WAITING_FOR_MEMORY, + DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND, + DBUS_AUTH_STATE_NEED_DISCONNECT, + DBUS_AUTH_STATE_AUTHENTICATED +} DBusAuthState; + +DBUS_PRIVATE_EXPORT +DBusAuth* _dbus_auth_server_new (const DBusString *guid); +DBUS_PRIVATE_EXPORT +DBusAuth* _dbus_auth_client_new (void); +DBUS_PRIVATE_EXPORT +DBusAuth* _dbus_auth_ref (DBusAuth *auth); +DBUS_PRIVATE_EXPORT +void _dbus_auth_unref (DBusAuth *auth); +DBUS_PRIVATE_EXPORT +dbus_bool_t _dbus_auth_set_mechanisms (DBusAuth *auth, + const char **mechanisms); +DBUS_PRIVATE_EXPORT +DBusAuthState _dbus_auth_do_work (DBusAuth *auth); +DBUS_PRIVATE_EXPORT +dbus_bool_t _dbus_auth_get_bytes_to_send (DBusAuth *auth, + const DBusString **str); +DBUS_PRIVATE_EXPORT +void _dbus_auth_bytes_sent (DBusAuth *auth, + int bytes_sent); +DBUS_PRIVATE_EXPORT +void _dbus_auth_get_buffer (DBusAuth *auth, + DBusString **buffer); +DBUS_PRIVATE_EXPORT +void _dbus_auth_return_buffer (DBusAuth *auth, + DBusString *buffer); +DBUS_PRIVATE_EXPORT +void _dbus_auth_get_unused_bytes (DBusAuth *auth, + const DBusString **str); +DBUS_PRIVATE_EXPORT +void _dbus_auth_delete_unused_bytes (DBusAuth *auth); +dbus_bool_t _dbus_auth_needs_encoding (DBusAuth *auth); +dbus_bool_t _dbus_auth_encode_data (DBusAuth *auth, + const DBusString *plaintext, + DBusString *encoded); +dbus_bool_t _dbus_auth_needs_decoding (DBusAuth *auth); +dbus_bool_t _dbus_auth_decode_data (DBusAuth *auth, + const DBusString *encoded, + DBusString *plaintext); +DBUS_PRIVATE_EXPORT +dbus_bool_t _dbus_auth_set_credentials (DBusAuth *auth, + DBusCredentials *credentials); +DBUS_PRIVATE_EXPORT +DBusCredentials* _dbus_auth_get_identity (DBusAuth *auth); +DBUS_PRIVATE_EXPORT +dbus_bool_t _dbus_auth_set_context (DBusAuth *auth, + const DBusString *context); +const char* _dbus_auth_get_guid_from_server(DBusAuth *auth); + +void _dbus_auth_set_unix_fd_possible(DBusAuth *auth, dbus_bool_t b); +dbus_bool_t _dbus_auth_get_unix_fd_negotiated(DBusAuth *auth); + +DBUS_END_DECLS + +#endif /* DBUS_AUTH_H */
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c new file mode 100644 index 0000000..0fd4831 --- /dev/null +++ b/dbus/dbus-bus.c
@@ -0,0 +1,1602 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-bus.c Convenience functions for communicating with the bus. + * + * Copyright (C) 2003 CodeFactory AB + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "dbus-bus.h" +#include "dbus-protocol.h" +#include "dbus-internals.h" +#include "dbus-message.h" +#include "dbus-marshal-validate.h" +#include "dbus-misc.h" +#include "dbus-threads-internal.h" +#include "dbus-connection-internal.h" +#include "dbus-string.h" + +/** + * @defgroup DBusBus Message bus APIs + * @ingroup DBus + * @brief Functions for communicating with the message bus + * + * dbus_bus_get() allows all modules and libraries in a given + * process to share the same connection to the bus daemon by storing + * the connection globally. + * + * All other functions in this module are just convenience functions; + * most of them invoke methods on the bus daemon, by sending method + * call messages to #DBUS_SERVICE_DBUS. These convenience functions + * often make blocking method calls. If you don't want to block, + * you can send the method call messages manually in the same way + * you would any other method call message. + * + * This module is the only one in libdbus that's specific to + * communicating with the message bus daemon. The rest of the API can + * also be used for connecting to another application directly. + * + * @todo right now the default address of the system bus is hardcoded, + * so if you change it in the global config file suddenly you have to + * set DBUS_SYSTEM_BUS_ADDRESS env variable. Might be nice if the + * client lib somehow read the config file, or if the bus on startup + * somehow wrote out its address to a well-known spot, but might also + * not be worth it. + */ + +/** + * @defgroup DBusBusInternals Message bus APIs internals + * @ingroup DBusInternals + * @brief Internals of functions for communicating with the message bus + * + * @{ + */ + +/** + * Block of message-bus-related data we attach to each + * #DBusConnection used with these convenience functions. + * + */ +typedef struct +{ + DBusConnection *connection; /**< Connection we're associated with */ + char *unique_name; /**< Unique name of this connection */ + + unsigned int is_well_known : 1; /**< Is one of the well-known connections in our global array */ +} BusData; + +/** The slot we have reserved to store BusData. + */ +static dbus_int32_t bus_data_slot = -1; + +/** Number of bus types */ +#define N_BUS_TYPES 3 + +static DBusConnection *bus_connections[N_BUS_TYPES]; +static char *bus_connection_addresses[N_BUS_TYPES] = { NULL, NULL, NULL }; + +static DBusBusType activation_bus_type = DBUS_BUS_STARTER; + +static dbus_bool_t initialized = FALSE; + +static void +addresses_shutdown_func (void *data) +{ + int i; + + i = 0; + while (i < N_BUS_TYPES) + { + if (bus_connections[i] != NULL) + _dbus_warn_check_failed ("dbus_shutdown() called but connections were still live. This probably means the application did not drop all its references to bus connections.\n"); + + dbus_free (bus_connection_addresses[i]); + bus_connection_addresses[i] = NULL; + ++i; + } + + activation_bus_type = DBUS_BUS_STARTER; + + initialized = FALSE; +} + +static dbus_bool_t +get_from_env (char **connection_p, + const char *env_var) +{ + const char *s; + + _dbus_assert (*connection_p == NULL); + + s = _dbus_getenv (env_var); + if (s == NULL || *s == '\0') + return TRUE; /* successfully didn't use the env var */ + else + { + *connection_p = _dbus_strdup (s); + return *connection_p != NULL; + } +} + +static dbus_bool_t +init_session_address (void) +{ + dbus_bool_t retval; + + retval = FALSE; + + /* First, look in the environment. This is the normal case on + * freedesktop.org/Unix systems. */ + get_from_env (&bus_connection_addresses[DBUS_BUS_SESSION], + "DBUS_SESSION_BUS_ADDRESS"); + if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL) + { + dbus_bool_t supported; + DBusString addr; + DBusError error = DBUS_ERROR_INIT; + + if (!_dbus_string_init (&addr)) + return FALSE; + + supported = FALSE; + /* So it's not in the environment - let's try a platform-specific method. + * On MacOS, this involves asking launchd. On Windows (not specified yet) + * we might do a COM lookup. + * Ignore errors - if we failed, fall back to autolaunch. */ + retval = _dbus_lookup_session_address (&supported, &addr, &error); + if (supported && retval) + { + retval =_dbus_string_steal_data (&addr, &bus_connection_addresses[DBUS_BUS_SESSION]); + } + else if (supported && !retval) + { + if (dbus_error_is_set(&error)) + _dbus_warn ("Dynamic session lookup supported but failed: %s\n", error.message); + else + _dbus_warn ("Dynamic session lookup supported but failed silently\n"); + } + _dbus_string_free (&addr); + } + else + retval = TRUE; + + if (!retval) + return FALSE; + + /* We have a hard-coded (but compile-time-configurable) fallback address for + * the session bus. */ + if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL) + bus_connection_addresses[DBUS_BUS_SESSION] = + _dbus_strdup (DBUS_SESSION_BUS_CONNECT_ADDRESS); + + if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL) + return FALSE; + + return TRUE; +} + +static dbus_bool_t +init_connections_unlocked (void) +{ + if (!initialized) + { + const char *s; + int i; + + i = 0; + while (i < N_BUS_TYPES) + { + bus_connections[i] = NULL; + ++i; + } + + /* Don't init these twice, we may run this code twice if + * init_connections_unlocked() fails midway through. + * In practice, each block below should contain only one + * "return FALSE" or running through twice may not + * work right. + */ + + if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL) + { + _dbus_verbose ("Filling in system bus address...\n"); + + if (!get_from_env (&bus_connection_addresses[DBUS_BUS_SYSTEM], + "DBUS_SYSTEM_BUS_ADDRESS")) + return FALSE; + } + + + if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL) + { + /* Use default system bus address if none set in environment */ + bus_connection_addresses[DBUS_BUS_SYSTEM] = + _dbus_strdup (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS); + + if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL) + return FALSE; + + _dbus_verbose (" used default system bus \"%s\"\n", + bus_connection_addresses[DBUS_BUS_SYSTEM]); + } + else + _dbus_verbose (" used env var system bus \"%s\"\n", + bus_connection_addresses[DBUS_BUS_SYSTEM]); + + if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL) + { + _dbus_verbose ("Filling in session bus address...\n"); + + if (!init_session_address ()) + return FALSE; + + _dbus_verbose (" \"%s\"\n", bus_connection_addresses[DBUS_BUS_SESSION] ? + bus_connection_addresses[DBUS_BUS_SESSION] : "none set"); + } + + if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL) + { + _dbus_verbose ("Filling in activation bus address...\n"); + + if (!get_from_env (&bus_connection_addresses[DBUS_BUS_STARTER], + "DBUS_STARTER_ADDRESS")) + return FALSE; + + _dbus_verbose (" \"%s\"\n", bus_connection_addresses[DBUS_BUS_STARTER] ? + bus_connection_addresses[DBUS_BUS_STARTER] : "none set"); + } + + + if (bus_connection_addresses[DBUS_BUS_STARTER] != NULL) + { + s = _dbus_getenv ("DBUS_STARTER_BUS_TYPE"); + + if (s != NULL) + { + _dbus_verbose ("Bus activation type was set to \"%s\"\n", s); + + if (strcmp (s, "system") == 0) + activation_bus_type = DBUS_BUS_SYSTEM; + else if (strcmp (s, "session") == 0) + activation_bus_type = DBUS_BUS_SESSION; + } + } + else + { + /* Default to the session bus instead if available */ + if (bus_connection_addresses[DBUS_BUS_SESSION] != NULL) + { + bus_connection_addresses[DBUS_BUS_STARTER] = + _dbus_strdup (bus_connection_addresses[DBUS_BUS_SESSION]); + if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL) + return FALSE; + } + } + + /* If we return FALSE we have to be sure that restarting + * the above code will work right + */ + + if (!_dbus_register_shutdown_func (addresses_shutdown_func, + NULL)) + return FALSE; + + initialized = TRUE; + } + + return initialized; +} + +static void +bus_data_free (void *data) +{ + BusData *bd = data; + + if (bd->is_well_known) + { + int i; + + if (!_DBUS_LOCK (bus)) + _dbus_assert_not_reached ("global locks should have been initialized " + "when we attached bus data"); + + /* We may be stored in more than one slot */ + /* This should now be impossible - these slots are supposed to + * be cleared on disconnect, so should not need to be cleared on + * finalize + */ + i = 0; + while (i < N_BUS_TYPES) + { + if (bus_connections[i] == bd->connection) + bus_connections[i] = NULL; + + ++i; + } + _DBUS_UNLOCK (bus); + } + + dbus_free (bd->unique_name); + dbus_free (bd); + + dbus_connection_free_data_slot (&bus_data_slot); +} + +static BusData* +ensure_bus_data (DBusConnection *connection) +{ + BusData *bd; + + if (!dbus_connection_allocate_data_slot (&bus_data_slot)) + return NULL; + + bd = dbus_connection_get_data (connection, bus_data_slot); + if (bd == NULL) + { + bd = dbus_new0 (BusData, 1); + if (bd == NULL) + { + dbus_connection_free_data_slot (&bus_data_slot); + return NULL; + } + + bd->connection = connection; + + if (!dbus_connection_set_data (connection, bus_data_slot, bd, + bus_data_free)) + { + dbus_free (bd); + dbus_connection_free_data_slot (&bus_data_slot); + return NULL; + } + + /* Data slot refcount now held by the BusData */ + } + else + { + dbus_connection_free_data_slot (&bus_data_slot); + } + + return bd; +} + +/** + * Internal function that checks to see if this + * is a shared connection owned by the bus and if it is unref it. + * + * @param connection a connection that has been disconnected. + */ +void +_dbus_bus_notify_shared_connection_disconnected_unlocked (DBusConnection *connection) +{ + int i; + + if (!_DBUS_LOCK (bus)) + { + /* If it was in bus_connections, we would have initialized global locks + * when we added it. So, it can't be. */ + return; + } + + /* We are expecting to have the connection saved in only one of these + * slots, but someone could in a pathological case set system and session + * bus to the same bus or something. Or set one of them to the starter + * bus without setting the starter bus type in the env variable. + * So we don't break the loop as soon as we find a match. + */ + for (i = 0; i < N_BUS_TYPES; ++i) + { + if (bus_connections[i] == connection) + { + bus_connections[i] = NULL; + } + } + + _DBUS_UNLOCK (bus); +} + +static DBusConnection * +internal_bus_get (DBusBusType type, + dbus_bool_t private, + DBusError *error) +{ + const char *address; + DBusConnection *connection; + BusData *bd; + DBusBusType address_type; + + _dbus_return_val_if_fail (type >= 0 && type < N_BUS_TYPES, NULL); + _dbus_return_val_if_error_is_set (error, NULL); + + connection = NULL; + + if (!_DBUS_LOCK (bus)) + { + _DBUS_SET_OOM (error); + /* do not "goto out", that would try to unlock */ + return NULL; + } + + if (!init_connections_unlocked ()) + { + _DBUS_SET_OOM (error); + goto out; + } + + /* We want to use the activation address even if the + * activating bus is the session or system bus, + * per the spec. + */ + address_type = type; + + /* Use the real type of the activation bus for getting its + * connection, but only if the real type's address is available. (If + * the activating bus isn't a well-known bus then + * activation_bus_type == DBUS_BUS_STARTER) + */ + if (type == DBUS_BUS_STARTER && + bus_connection_addresses[activation_bus_type] != NULL) + type = activation_bus_type; + + if (!private && bus_connections[type] != NULL) + { + connection = bus_connections[type]; + dbus_connection_ref (connection); + goto out; + } + + address = bus_connection_addresses[address_type]; + if (address == NULL) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "Unable to determine the address of the message bus (try 'man dbus-launch' and 'man dbus-daemon' for help)"); + goto out; + } + + if (private) + connection = dbus_connection_open_private (address, error); + else + connection = dbus_connection_open (address, error); + + if (!connection) + { + goto out; + } + + if (!dbus_bus_register (connection, error)) + { + _dbus_connection_close_possibly_shared (connection); + dbus_connection_unref (connection); + connection = NULL; + goto out; + } + + if (!private) + { + /* store a weak ref to the connection (dbus-connection.c is + * supposed to have a strong ref that it drops on disconnect, + * since this is a shared connection) + */ + bus_connections[type] = connection; + } + + /* By default we're bound to the lifecycle of + * the message bus. + */ + dbus_connection_set_exit_on_disconnect (connection, + TRUE); + + if (!_DBUS_LOCK (bus_datas)) + _dbus_assert_not_reached ("global locks were initialized already"); + + bd = ensure_bus_data (connection); + _dbus_assert (bd != NULL); /* it should have been created on + register, so OOM not possible */ + bd->is_well_known = TRUE; + _DBUS_UNLOCK (bus_datas); + +out: + /* Return a reference to the caller, or NULL with error set. */ + if (connection == NULL) + _DBUS_ASSERT_ERROR_IS_SET (error); + + _DBUS_UNLOCK (bus); + return connection; +} + + +/** @} */ /* end of implementation details docs */ + +/** + * @addtogroup DBusBus + * @{ + */ + +/** + * Connects to a bus daemon and registers the client with it. If a + * connection to the bus already exists, then that connection is + * returned. The caller of this function owns a reference to the bus. + * + * The caller may NOT call dbus_connection_close() on this connection; + * see dbus_connection_open() and dbus_connection_close() for details + * on that. + * + * If this function obtains a new connection object never before + * returned from dbus_bus_get(), it will call + * dbus_connection_set_exit_on_disconnect(), so the application + * will exit if the connection closes. You can undo this + * by calling dbus_connection_set_exit_on_disconnect() yourself + * after you get the connection. + * + * dbus_bus_get() calls dbus_bus_register() for you. + * + * If returning a newly-created connection, this function will block + * until authentication and bus registration are complete. + * + * @param type bus type + * @param error address where an error can be returned. + * @returns a #DBusConnection with new ref or #NULL on error + */ +DBusConnection * +dbus_bus_get (DBusBusType type, + DBusError *error) +{ + return internal_bus_get (type, FALSE, error); +} + +/** + * Connects to a bus daemon and registers the client with it as with + * dbus_bus_register(). Unlike dbus_bus_get(), always creates a new + * connection. This connection will not be saved or recycled by + * libdbus. Caller owns a reference to the bus and must either close + * it or know it to be closed prior to releasing this reference. + * + * See dbus_connection_open_private() for more details on when to + * close and unref this connection. + * + * This function calls + * dbus_connection_set_exit_on_disconnect() on the new connection, so the application + * will exit if the connection closes. You can undo this + * by calling dbus_connection_set_exit_on_disconnect() yourself + * after you get the connection. + * + * dbus_bus_get_private() calls dbus_bus_register() for you. + * + * This function will block until authentication and bus registration + * are complete. + * + * @param type bus type + * @param error address where an error can be returned. + * @returns a DBusConnection with new ref + */ +DBusConnection * +dbus_bus_get_private (DBusBusType type, + DBusError *error) +{ + return internal_bus_get (type, TRUE, error); +} + +/** + * Registers a connection with the bus. This must be the first + * thing an application does when connecting to the message bus. + * If registration succeeds, the unique name will be set, + * and can be obtained using dbus_bus_get_unique_name(). + * + * This function will block until registration is complete. + * + * If the connection has already registered with the bus + * (determined by checking whether dbus_bus_get_unique_name() + * returns a non-#NULL value), then this function does nothing. + * + * If you use dbus_bus_get() or dbus_bus_get_private() this + * function will be called for you. + * + * @note Just use dbus_bus_get() or dbus_bus_get_private() instead of + * dbus_bus_register() and save yourself some pain. Using + * dbus_bus_register() manually is only useful if you have your + * own custom message bus not found in #DBusBusType. + * + * If you open a bus connection with dbus_connection_open() or + * dbus_connection_open_private() you will have to dbus_bus_register() + * yourself, or make the appropriate registration method calls + * yourself. If you send the method calls yourself, call + * dbus_bus_set_unique_name() with the unique bus name you get from + * the bus. + * + * For shared connections (created with dbus_connection_open()) in a + * multithreaded application, you can't really make the registration + * calls yourself, because you don't know whether some other thread is + * also registering, and the bus will kick you off if you send two + * registration messages. + * + * If you use dbus_bus_register() however, there is a lock that + * keeps both apps from registering at the same time. + * + * The rule in a multithreaded app, then, is that dbus_bus_register() + * must be used to register, or you need to have your own locks that + * all threads in the app will respect. + * + * In a single-threaded application you can register by hand instead + * of using dbus_bus_register(), as long as you check + * dbus_bus_get_unique_name() to see if a unique name has already been + * stored by another thread before you send the registration messages. + * + * @param connection the connection + * @param error place to store errors + * @returns #TRUE on success + */ +dbus_bool_t +dbus_bus_register (DBusConnection *connection, + DBusError *error) +{ + DBusMessage *message, *reply; + char *name; + BusData *bd; + dbus_bool_t retval; + + _dbus_return_val_if_fail (connection != NULL, FALSE); + _dbus_return_val_if_error_is_set (error, FALSE); + + retval = FALSE; + message = NULL; + reply = NULL; + + if (!_DBUS_LOCK (bus_datas)) + { + _DBUS_SET_OOM (error); + /* do not "goto out", that would try to unlock */ + return FALSE; + } + + bd = ensure_bus_data (connection); + if (bd == NULL) + { + _DBUS_SET_OOM (error); + goto out; + } + + if (bd->unique_name != NULL) + { + _dbus_verbose ("Ignoring attempt to register the same DBusConnection %s with the message bus a second time.\n", + bd->unique_name); + /* Success! */ + retval = TRUE; + goto out; + } + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "Hello"); + + if (!message) + { + _DBUS_SET_OOM (error); + goto out; + } + + reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error); + + if (reply == NULL) + goto out; + else if (dbus_set_error_from_message (error, reply)) + goto out; + else if (!dbus_message_get_args (reply, error, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + goto out; + + bd->unique_name = _dbus_strdup (name); + if (bd->unique_name == NULL) + { + _DBUS_SET_OOM (error); + goto out; + } + + retval = TRUE; + + out: + _DBUS_UNLOCK (bus_datas); + + if (message) + dbus_message_unref (message); + + if (reply) + dbus_message_unref (reply); + + if (!retval) + _DBUS_ASSERT_ERROR_IS_SET (error); + + return retval; +} + + +/** + * Sets the unique name of the connection, as assigned by the message + * bus. Can only be used if you registered with the bus manually + * (i.e. if you did not call dbus_bus_register()). Can only be called + * once per connection. After the unique name is set, you can get it + * with dbus_bus_get_unique_name(). + * + * The only reason to use this function is to re-implement the + * equivalent of dbus_bus_register() yourself. One (probably unusual) + * reason to do that might be to do the bus registration call + * asynchronously instead of synchronously. + * + * @note Just use dbus_bus_get() or dbus_bus_get_private(), or worst + * case dbus_bus_register(), instead of messing with this + * function. There's really no point creating pain for yourself by + * doing things manually. + * + * It's hard to use this function safely on shared connections + * (created by dbus_connection_open()) in a multithreaded application, + * because only one registration attempt can be sent to the bus. If + * two threads are both sending the registration message, there is no + * mechanism in libdbus itself to avoid sending it twice. + * + * Thus, you need a way to coordinate which thread sends the + * registration attempt; which also means you know which thread + * will call dbus_bus_set_unique_name(). If you don't know + * about all threads in the app (for example, if some libraries + * you're using might start libdbus-using threads), then you + * need to avoid using this function on shared connections. + * + * @param connection the connection + * @param unique_name the unique name + * @returns #FALSE if not enough memory + */ +dbus_bool_t +dbus_bus_set_unique_name (DBusConnection *connection, + const char *unique_name) +{ + BusData *bd; + dbus_bool_t success = FALSE; + + _dbus_return_val_if_fail (connection != NULL, FALSE); + _dbus_return_val_if_fail (unique_name != NULL, FALSE); + + if (!_DBUS_LOCK (bus_datas)) + { + /* do not "goto out", that would try to unlock */ + return FALSE; + } + + bd = ensure_bus_data (connection); + if (bd == NULL) + goto out; + + _dbus_assert (bd->unique_name == NULL); + + bd->unique_name = _dbus_strdup (unique_name); + success = bd->unique_name != NULL; + +out: + _DBUS_UNLOCK (bus_datas); + + return success; +} + +/** + * Gets the unique name of the connection as assigned by the message + * bus. Only possible after the connection has been registered with + * the message bus. All connections returned by dbus_bus_get() or + * dbus_bus_get_private() have been successfully registered. + * + * The name remains valid until the connection is freed, and + * should not be freed by the caller. + * + * Other than dbus_bus_get(), there are two ways to set the unique + * name; one is dbus_bus_register(), the other is + * dbus_bus_set_unique_name(). You are responsible for calling + * dbus_bus_set_unique_name() if you register by hand instead of using + * dbus_bus_register(). + * + * @param connection the connection + * @returns the unique name or #NULL on error + */ +const char* +dbus_bus_get_unique_name (DBusConnection *connection) +{ + BusData *bd; + const char *unique_name = NULL; + + _dbus_return_val_if_fail (connection != NULL, NULL); + + if (!_DBUS_LOCK (bus_datas)) + { + /* We'd have initialized locks when we gave it its unique name, if it + * had one. Don't "goto out", that would try to unlock. */ + return NULL; + } + + bd = ensure_bus_data (connection); + if (bd == NULL) + goto out; + + unique_name = bd->unique_name; + +out: + _DBUS_UNLOCK (bus_datas); + + return unique_name; +} + +/** + * Asks the bus to return the UID the named connection authenticated + * as, if any. Only works on UNIX; only works for connections on the + * same machine as the bus. If you are not on the same machine as the + * bus, then calling this is probably a bad idea, since the UID will + * mean little to your application. + * + * For the system message bus you're guaranteed to be on the same + * machine since it only listens on a UNIX domain socket (at least, + * as shipped by default). + * + * This function only works for connections that authenticated as + * a UNIX user, right now that includes all bus connections, but + * it's very possible to have connections with no associated UID. + * So check for errors and do something sensible if they happen. + * + * This function will always return an error on Windows. + * + * @param connection the connection + * @param name a name owned by the connection + * @param error location to store the error + * @returns the unix user id, or ((unsigned)-1) if error is set + */ +unsigned long +dbus_bus_get_unix_user (DBusConnection *connection, + const char *name, + DBusError *error) +{ + DBusMessage *message, *reply; + dbus_uint32_t uid; + + _dbus_return_val_if_fail (connection != NULL, DBUS_UID_UNSET); + _dbus_return_val_if_fail (name != NULL, DBUS_UID_UNSET); + _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), DBUS_UID_UNSET); + _dbus_return_val_if_error_is_set (error, DBUS_UID_UNSET); + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "GetConnectionUnixUser"); + + if (message == NULL) + { + _DBUS_SET_OOM (error); + return DBUS_UID_UNSET; + } + + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + _DBUS_SET_OOM (error); + return DBUS_UID_UNSET; + } + + reply = dbus_connection_send_with_reply_and_block (connection, message, -1, + error); + + dbus_message_unref (message); + + if (reply == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return DBUS_UID_UNSET; + } + + if (dbus_set_error_from_message (error, reply)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return DBUS_UID_UNSET; + } + + if (!dbus_message_get_args (reply, error, + DBUS_TYPE_UINT32, &uid, + DBUS_TYPE_INVALID)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return DBUS_UID_UNSET; + } + + dbus_message_unref (reply); + + return (unsigned long) uid; +} + +/** + * Asks the bus to return its globally unique ID, as described in the + * D-Bus specification. For the session bus, this is useful as a way + * to uniquely identify each user session. For the system bus, + * probably the bus ID is not useful; instead, use the machine ID + * since it's accessible without necessarily connecting to the bus and + * may be persistent beyond a single bus instance (across reboots for + * example). See dbus_get_local_machine_id(). + * + * In addition to an ID for each bus and an ID for each machine, there is + * an ID for each address that the bus is listening on; that can + * be retrieved with dbus_connection_get_server_id(), though it is + * probably not very useful. + * + * @param connection the connection + * @param error location to store the error + * @returns the bus ID or #NULL if error is set + */ +char* +dbus_bus_get_id (DBusConnection *connection, + DBusError *error) +{ + DBusMessage *message, *reply; + char *id; + const char *v_STRING; + + _dbus_return_val_if_fail (connection != NULL, NULL); + _dbus_return_val_if_error_is_set (error, NULL); + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "GetId"); + + if (message == NULL) + { + _DBUS_SET_OOM (error); + return NULL; + } + + reply = dbus_connection_send_with_reply_and_block (connection, message, -1, + error); + + dbus_message_unref (message); + + if (reply == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return NULL; + } + + if (dbus_set_error_from_message (error, reply)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return NULL; + } + + v_STRING = NULL; + if (!dbus_message_get_args (reply, error, + DBUS_TYPE_STRING, &v_STRING, + DBUS_TYPE_INVALID)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return NULL; + } + + id = _dbus_strdup (v_STRING); /* may be NULL */ + + dbus_message_unref (reply); + + if (id == NULL) + _DBUS_SET_OOM (error); + + /* FIXME it might be nice to cache the ID locally */ + + return id; +} + +/** + * Asks the bus to assign the given name to this connection by invoking + * the RequestName method on the bus. This method is fully documented + * in the D-Bus specification. For quick reference, the flags and + * result codes are discussed here, but the specification is the + * canonical version of this information. + * + * First you should know that for each bus name, the bus stores + * a queue of connections that would like to own it. Only + * one owns it at a time - called the primary owner. If the primary + * owner releases the name or disconnects, then the next owner in the + * queue atomically takes over. + * + * So for example if you have an application org.freedesktop.TextEditor + * and multiple instances of it can be run, you can have all of them + * sitting in the queue. The first one to start up will receive messages + * sent to org.freedesktop.TextEditor, but if that one exits another + * will become the primary owner and receive messages. + * + * The queue means you don't need to manually watch for the current owner to + * disappear and then request the name again. + * + * When requesting a name, you can specify several flags. + * + * #DBUS_NAME_FLAG_ALLOW_REPLACEMENT and #DBUS_NAME_FLAG_DO_NOT_QUEUE + * are properties stored by the bus for this connection with respect to + * each requested bus name. These properties are stored even if the + * connection is queued and does not become the primary owner. + * You can update these flags by calling RequestName again (even if + * you already own the name). + * + * #DBUS_NAME_FLAG_ALLOW_REPLACEMENT means that another requestor of the + * name can take it away from you by specifying #DBUS_NAME_FLAG_REPLACE_EXISTING. + * + * #DBUS_NAME_FLAG_DO_NOT_QUEUE means that if you aren't the primary owner, + * you don't want to be queued up - you only care about being the + * primary owner. + * + * Unlike the other two flags, #DBUS_NAME_FLAG_REPLACE_EXISTING is a property + * of the individual RequestName call, i.e. the bus does not persistently + * associate it with the connection-name pair. If a RequestName call includes + * the #DBUS_NAME_FLAG_REPLACE_EXISTING flag, and the current primary + * owner has #DBUS_NAME_FLAG_ALLOW_REPLACEMENT set, then the current primary + * owner will be kicked off. + * + * If no flags are given, an application will receive the requested + * name only if the name is currently unowned; and it will NOT give + * up the name if another application asks to take it over using + * #DBUS_NAME_FLAG_REPLACE_EXISTING. + * + * This function returns a result code. The possible result codes + * are as follows. + * + * #DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER means that the name had no + * existing owner, and the caller is now the primary owner; or that + * the name had an owner, and the caller specified + * #DBUS_NAME_FLAG_REPLACE_EXISTING, and the current owner + * specified #DBUS_NAME_FLAG_ALLOW_REPLACEMENT. + * + * #DBUS_REQUEST_NAME_REPLY_IN_QUEUE happens only if the caller does NOT + * specify #DBUS_NAME_FLAG_DO_NOT_QUEUE and either the current owner + * did NOT specify #DBUS_NAME_FLAG_ALLOW_REPLACEMENT or the caller did NOT + * specify #DBUS_NAME_FLAG_REPLACE_EXISTING. In this case the caller ends up + * in a queue to own the name after the current owner gives it up. + * + * #DBUS_REQUEST_NAME_REPLY_EXISTS happens if the name has an owner + * already and the caller specifies #DBUS_NAME_FLAG_DO_NOT_QUEUE + * and either the current owner has NOT specified + * #DBUS_NAME_FLAG_ALLOW_REPLACEMENT or the caller did NOT specify + * #DBUS_NAME_FLAG_REPLACE_EXISTING. + * + * #DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER happens if an application + * requests a name it already owns. (Re-requesting a name is useful if + * you want to change the #DBUS_NAME_FLAG_ALLOW_REPLACEMENT or + * #DBUS_NAME_FLAG_DO_NOT_QUEUE settings.) + * + * When a service represents an application, say "text editor," then + * it should specify #DBUS_NAME_FLAG_ALLOW_REPLACEMENT if it wants + * the last editor started to be the user's editor vs. the first one + * started. Then any editor that can be the user's editor should + * specify #DBUS_NAME_FLAG_REPLACE_EXISTING to either take over + * (last-started-wins) or be queued up (first-started-wins) according + * to whether #DBUS_NAME_FLAG_ALLOW_REPLACEMENT was given. + * + * Conventionally, single-instance applications often offer a command + * line option called --replace which means to replace the current + * instance. To implement this, always set + * #DBUS_NAME_FLAG_ALLOW_REPLACEMENT when you request your + * application's bus name. When you lose ownership of your bus name, + * you need to exit. Look for the signal "NameLost" from + * #DBUS_SERVICE_DBUS and #DBUS_INTERFACE_DBUS (the signal's first + * argument is the bus name that was lost). If starting up without + * --replace, do not specify #DBUS_NAME_FLAG_REPLACE_EXISTING, and + * exit if you fail to become the bus name owner. If --replace is + * given, ask to replace the old owner. + * + * @param connection the connection + * @param name the name to request + * @param flags flags + * @param error location to store the error + * @returns a result code, -1 if error is set + */ +int +dbus_bus_request_name (DBusConnection *connection, + const char *name, + unsigned int flags, + DBusError *error) +{ + DBusMessage *message, *reply; + dbus_uint32_t result; + + _dbus_return_val_if_fail (connection != NULL, 0); + _dbus_return_val_if_fail (name != NULL, 0); + _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0); + _dbus_return_val_if_error_is_set (error, 0); + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "RequestName"); + + if (message == NULL) + { + _DBUS_SET_OOM (error); + return -1; + } + + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + _DBUS_SET_OOM (error); + return -1; + } + + reply = dbus_connection_send_with_reply_and_block (connection, message, -1, + error); + + dbus_message_unref (message); + + if (reply == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return -1; + } + + if (dbus_set_error_from_message (error, reply)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return -1; + } + + if (!dbus_message_get_args (reply, error, + DBUS_TYPE_UINT32, &result, + DBUS_TYPE_INVALID)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return -1; + } + + dbus_message_unref (reply); + + return result; +} + + +/** + * Asks the bus to unassign the given name from this connection by + * invoking the ReleaseName method on the bus. The "ReleaseName" + * method is canonically documented in the D-Bus specification. + * + * Possible results are: #DBUS_RELEASE_NAME_REPLY_RELEASED + * which means you owned the name or were in the queue to own it, + * and and now you don't own it and aren't in the queue. + * #DBUS_RELEASE_NAME_REPLY_NOT_OWNER which means someone else + * owns the name so you can't release it. + * #DBUS_RELEASE_NAME_REPLY_NON_EXISTENT + * which means nobody owned the name. + * + * @param connection the connection + * @param name the name to remove + * @param error location to store the error + * @returns a result code, -1 if error is set + */ +int +dbus_bus_release_name (DBusConnection *connection, + const char *name, + DBusError *error) +{ + DBusMessage *message, *reply; + dbus_uint32_t result; + + _dbus_return_val_if_fail (connection != NULL, 0); + _dbus_return_val_if_fail (name != NULL, 0); + _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0); + _dbus_return_val_if_error_is_set (error, 0); + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "ReleaseName"); + + if (message == NULL) + { + _DBUS_SET_OOM (error); + return -1; + } + + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + _DBUS_SET_OOM (error); + return -1; + } + + reply = dbus_connection_send_with_reply_and_block (connection, message, -1, + error); + + dbus_message_unref (message); + + if (reply == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return -1; + } + + if (dbus_set_error_from_message (error, reply)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return -1; + } + + if (!dbus_message_get_args (reply, error, + DBUS_TYPE_UINT32, &result, + DBUS_TYPE_INVALID)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return -1; + } + + dbus_message_unref (reply); + + return result; +} + +/** + * Asks the bus whether a certain name has an owner. + * + * Using this can easily result in a race condition, + * since an owner can appear or disappear after you + * call this. + * + * If you want to request a name, just request it; + * if you want to avoid replacing a current owner, + * don't specify #DBUS_NAME_FLAG_REPLACE_EXISTING and + * you will get an error if there's already an owner. + * + * @param connection the connection + * @param name the name + * @param error location to store any errors + * @returns #TRUE if the name exists, #FALSE if not or on error + */ +dbus_bool_t +dbus_bus_name_has_owner (DBusConnection *connection, + const char *name, + DBusError *error) +{ + DBusMessage *message, *reply; + dbus_bool_t exists; + + _dbus_return_val_if_fail (connection != NULL, FALSE); + _dbus_return_val_if_fail (name != NULL, FALSE); + _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE); + _dbus_return_val_if_error_is_set (error, FALSE); + + message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "NameHasOwner"); + if (message == NULL) + { + _DBUS_SET_OOM (error); + return FALSE; + } + + if (!dbus_message_append_args (message, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (message); + _DBUS_SET_OOM (error); + return FALSE; + } + + reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error); + dbus_message_unref (message); + + if (reply == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return FALSE; + } + + if (!dbus_message_get_args (reply, error, + DBUS_TYPE_BOOLEAN, &exists, + DBUS_TYPE_INVALID)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return FALSE; + } + + dbus_message_unref (reply); + return exists; +} + +/** + * Starts a service that will request ownership of the given name. + * The returned result will be one of be one of + * #DBUS_START_REPLY_SUCCESS or #DBUS_START_REPLY_ALREADY_RUNNING if + * successful. Pass #NULL if you don't care about the result. + * + * The flags parameter is for future expansion, currently you should + * specify 0. + * + * It's often easier to avoid explicitly starting services, and + * just send a method call to the service's bus name instead. + * Method calls start a service to handle them by default + * unless you call dbus_message_set_auto_start() to disable this + * behavior. + * + * @param connection the connection + * @param name the name we want the new service to request + * @param flags the flags (should always be 0 for now) + * @param result a place to store the result or #NULL + * @param error location to store any errors + * @returns #TRUE if the activation succeeded, #FALSE if not + */ +dbus_bool_t +dbus_bus_start_service_by_name (DBusConnection *connection, + const char *name, + dbus_uint32_t flags, + dbus_uint32_t *result, + DBusError *error) +{ + DBusMessage *msg; + DBusMessage *reply; + + _dbus_return_val_if_fail (connection != NULL, FALSE); + _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE); + + msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "StartServiceByName"); + + if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &name, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID)) + { + dbus_message_unref (msg); + _DBUS_SET_OOM (error); + return FALSE; + } + + reply = dbus_connection_send_with_reply_and_block (connection, msg, + -1, error); + dbus_message_unref (msg); + + if (reply == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return FALSE; + } + + if (dbus_set_error_from_message (error, reply)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return FALSE; + } + + if (result != NULL && + !dbus_message_get_args (reply, error, DBUS_TYPE_UINT32, + result, DBUS_TYPE_INVALID)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return FALSE; + } + + dbus_message_unref (reply); + return TRUE; +} + +static void +send_no_return_values (DBusConnection *connection, + DBusMessage *msg, + DBusError *error) +{ + if (error) + { + /* Block to check success codepath */ + DBusMessage *reply; + + reply = dbus_connection_send_with_reply_and_block (connection, msg, + -1, error); + + if (reply == NULL) + _DBUS_ASSERT_ERROR_IS_SET (error); + else + dbus_message_unref (reply); + } + else + { + /* Silently-fail nonblocking codepath */ + dbus_message_set_no_reply (msg, TRUE); + dbus_connection_send (connection, msg, NULL); + } +} + +/** + * Adds a match rule to match messages going through the message bus. + * The "rule" argument is the string form of a match rule. + * + * If you pass #NULL for the error, this function will not + * block; the match thus won't be added until you flush the + * connection, and if there's an error adding the match + * you won't find out about it. This is generally acceptable, since the + * possible errors (including a lack of resources in the bus, the connection + * having exceeded its quota of active match rules, or the match rule being + * unparseable) are generally unrecoverable. + * + * If you pass non-#NULL for the error this function will + * block until it gets a reply. This may be useful when using match rule keys + * introduced in recent versions of D-Bus, like 'arg0namespace', to allow the + * application to fall back to less efficient match rules supported by older + * versions of the daemon if the running version is not new enough; or when + * using user-supplied rules rather than rules hard-coded at compile time. + * + * Normal API conventions would have the function return + * a boolean value indicating whether the error was set, + * but that would require blocking always to determine + * the return value. + * + * The AddMatch method is fully documented in the D-Bus + * specification. For quick reference, the format of the + * match rules is discussed here, but the specification + * is the canonical version of this information. + * + * Rules are specified as a string of comma separated + * key/value pairs. An example is + * "type='signal',sender='org.freedesktop.DBus', + * interface='org.freedesktop.DBus',member='Foo', + * path='/bar/foo',destination=':452345.34'" + * + * Possible keys you can match on are type, sender, + * interface, member, path, destination and numbered + * keys to match message args (keys are 'arg0', 'arg1', etc.). + * Omitting a key from the rule indicates + * a wildcard match. For instance omitting + * the member from a match rule but adding a sender would + * let all messages from that sender through regardless of + * the member. + * + * Matches are inclusive not exclusive so as long as one + * rule matches the message will get through. It is important + * to note this because every time a message is received the + * application will be paged into memory to process it. This + * can cause performance problems such as draining batteries + * on embedded platforms. + * + * If you match message args ('arg0', 'arg1', and so forth) + * only string arguments will match. That is, arg0='5' means + * match the string "5" not the integer 5. + * + * Currently there is no way to match against non-string arguments. + * + * A specialised form of wildcard matching on arguments is + * supported for path-like namespaces. If your argument match has + * a 'path' suffix (eg: "arg0path='/some/path/'") then it is + * considered a match if the argument exactly matches the given + * string or if one of them ends in a '/' and is a prefix of the + * other. + * + * Matching on interface is tricky because method call + * messages only optionally specify the interface. + * If a message omits the interface, then it will NOT match + * if the rule specifies an interface name. This means match + * rules on method calls should not usually give an interface. + * + * However, signal messages are required to include the interface + * so when matching signals usually you should specify the interface + * in the match rule. + * + * For security reasons, you can match arguments only up to + * #DBUS_MAXIMUM_MATCH_RULE_ARG_NUMBER. + * + * Match rules have a maximum length of #DBUS_MAXIMUM_MATCH_RULE_LENGTH + * bytes. + * + * Both of these maximums are much higher than you're likely to need, + * they only exist because the D-Bus bus daemon has fixed limits on + * all resource usage. + * + * @param connection connection to the message bus + * @param rule textual form of match rule + * @param error location to store any errors + */ +void +dbus_bus_add_match (DBusConnection *connection, + const char *rule, + DBusError *error) +{ + DBusMessage *msg; + + _dbus_return_if_fail (rule != NULL); + + msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "AddMatch"); + + if (msg == NULL) + { + _DBUS_SET_OOM (error); + return; + } + + if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (msg); + _DBUS_SET_OOM (error); + return; + } + + send_no_return_values (connection, msg, error); + + dbus_message_unref (msg); +} + +/** + * Removes a previously-added match rule "by value" (the most + * recently-added identical rule gets removed). The "rule" argument + * is the string form of a match rule. + * + * The bus compares match rules semantically, not textually, so + * whitespace and ordering don't have to be identical to + * the rule you passed to dbus_bus_add_match(). + * + * If you pass #NULL for the error, this function will not + * block; otherwise it will. See detailed explanation in + * docs for dbus_bus_add_match(). + * + * @param connection connection to the message bus + * @param rule textual form of match rule + * @param error location to store any errors + */ +void +dbus_bus_remove_match (DBusConnection *connection, + const char *rule, + DBusError *error) +{ + DBusMessage *msg; + + _dbus_return_if_fail (rule != NULL); + + msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "RemoveMatch"); + + if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (msg); + _DBUS_SET_OOM (error); + return; + } + + send_no_return_values (connection, msg, error); + + dbus_message_unref (msg); +} + +/** @} */
diff --git a/dbus/dbus-bus.h b/dbus/dbus-bus.h new file mode 100644 index 0000000..02a9571 --- /dev/null +++ b/dbus/dbus-bus.h
@@ -0,0 +1,95 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-bus.h Convenience functions for communicating with the bus. + * + * Copyright (C) 2003 CodeFactory AB + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) +#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents." +#endif + +#ifndef DBUS_BUS_H +#define DBUS_BUS_H + +#include <dbus/dbus-connection.h> + +DBUS_BEGIN_DECLS + +/** + * @addtogroup DBusBus + * @{ + */ + +DBUS_EXPORT +DBusConnection *dbus_bus_get (DBusBusType type, + DBusError *error); +DBUS_EXPORT +DBusConnection *dbus_bus_get_private (DBusBusType type, + DBusError *error); + +DBUS_EXPORT +dbus_bool_t dbus_bus_register (DBusConnection *connection, + DBusError *error); +DBUS_EXPORT +dbus_bool_t dbus_bus_set_unique_name (DBusConnection *connection, + const char *unique_name); +DBUS_EXPORT +const char* dbus_bus_get_unique_name (DBusConnection *connection); +DBUS_EXPORT +unsigned long dbus_bus_get_unix_user (DBusConnection *connection, + const char *name, + DBusError *error); +DBUS_EXPORT +char* dbus_bus_get_id (DBusConnection *connection, + DBusError *error); +DBUS_EXPORT +int dbus_bus_request_name (DBusConnection *connection, + const char *name, + unsigned int flags, + DBusError *error); +DBUS_EXPORT +int dbus_bus_release_name (DBusConnection *connection, + const char *name, + DBusError *error); +DBUS_EXPORT +dbus_bool_t dbus_bus_name_has_owner (DBusConnection *connection, + const char *name, + DBusError *error); + +DBUS_EXPORT +dbus_bool_t dbus_bus_start_service_by_name (DBusConnection *connection, + const char *name, + dbus_uint32_t flags, + dbus_uint32_t *reply, + DBusError *error); + +DBUS_EXPORT +void dbus_bus_add_match (DBusConnection *connection, + const char *rule, + DBusError *error); +DBUS_EXPORT +void dbus_bus_remove_match (DBusConnection *connection, + const char *rule, + DBusError *error); + +/** @} */ + +DBUS_END_DECLS + +#endif /* DBUS_BUS_H */
diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h new file mode 100644 index 0000000..4835732 --- /dev/null +++ b/dbus/dbus-connection-internal.h
@@ -0,0 +1,154 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-connection-internal.h DBusConnection internal interfaces + * + * Copyright (C) 2002 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#ifndef DBUS_CONNECTION_INTERNAL_H +#define DBUS_CONNECTION_INTERNAL_H + +#include <dbus/dbus-internals.h> +#include <dbus/dbus-connection.h> +#include <dbus/dbus-message.h> +#include <dbus/dbus-transport.h> +#include <dbus/dbus-resources.h> +#include <dbus/dbus-list.h> +#include <dbus/dbus-timeout.h> +#include <dbus/dbus-dataslot.h> + +DBUS_BEGIN_DECLS + +typedef enum +{ + DBUS_ITERATION_DO_WRITING = 1 << 0, /**< Write messages out. */ + DBUS_ITERATION_DO_READING = 1 << 1, /**< Read messages in. */ + DBUS_ITERATION_BLOCK = 1 << 2 /**< Block if nothing to do. */ +} DBusIterationFlags; + +/** default timeout value when waiting for a message reply, 25 seconds */ +#define _DBUS_DEFAULT_TIMEOUT_VALUE (25 * 1000) + +typedef void (* DBusPendingFdsChangeFunction) (void *data); + +DBUS_PRIVATE_EXPORT +void _dbus_connection_lock (DBusConnection *connection); +DBUS_PRIVATE_EXPORT +void _dbus_connection_unlock (DBusConnection *connection); +DBUS_PRIVATE_EXPORT +DBusConnection * _dbus_connection_ref_unlocked (DBusConnection *connection); +DBUS_PRIVATE_EXPORT +void _dbus_connection_unref_unlocked (DBusConnection *connection); +void _dbus_connection_queue_received_message_link (DBusConnection *connection, + DBusList *link); +dbus_bool_t _dbus_connection_has_messages_to_send_unlocked (DBusConnection *connection); +DBusMessage* _dbus_connection_get_message_to_send (DBusConnection *connection); +void _dbus_connection_message_sent_unlocked (DBusConnection *connection, + DBusMessage *message); +dbus_bool_t _dbus_connection_add_watch_unlocked (DBusConnection *connection, + DBusWatch *watch); +void _dbus_connection_remove_watch_unlocked (DBusConnection *connection, + DBusWatch *watch); +void _dbus_connection_toggle_watch_unlocked (DBusConnection *connection, + DBusWatch *watch, + dbus_bool_t enabled); +dbus_bool_t _dbus_connection_handle_watch (DBusWatch *watch, + unsigned int condition, + void *data); +dbus_bool_t _dbus_connection_add_timeout_unlocked (DBusConnection *connection, + DBusTimeout *timeout); +void _dbus_connection_remove_timeout_unlocked (DBusConnection *connection, + DBusTimeout *timeout); +void _dbus_connection_toggle_timeout_unlocked (DBusConnection *connection, + DBusTimeout *timeout, + dbus_bool_t enabled); +DBusConnection* _dbus_connection_new_for_transport (DBusTransport *transport); +void _dbus_connection_do_iteration_unlocked (DBusConnection *connection, + DBusPendingCall *pending, + unsigned int flags, + int timeout_milliseconds); +void _dbus_connection_close_possibly_shared (DBusConnection *connection); +void _dbus_connection_close_if_only_one_ref (DBusConnection *connection); + +DBusPendingCall* _dbus_pending_call_new (DBusConnection *connection, + int timeout_milliseconds, + DBusTimeoutHandler timeout_handler); +void _dbus_pending_call_notify (DBusPendingCall *pending); +void _dbus_connection_remove_pending_call (DBusConnection *connection, + DBusPendingCall *pending); +void _dbus_connection_block_pending_call (DBusPendingCall *pending); +void _dbus_pending_call_complete_and_unlock (DBusPendingCall *pending, + DBusMessage *message); +dbus_bool_t _dbus_connection_send_and_unlock (DBusConnection *connection, + DBusMessage *message, + dbus_uint32_t *client_serial); + +void _dbus_connection_queue_synthesized_message_link (DBusConnection *connection, + DBusList *link); +DBUS_PRIVATE_EXPORT +void _dbus_connection_test_get_locks (DBusConnection *conn, + DBusMutex **mutex_loc, + DBusMutex **dispatch_mutex_loc, + DBusMutex **io_path_mutex_loc, + DBusCondVar **dispatch_cond_loc, + DBusCondVar **io_path_cond_loc); +DBUS_PRIVATE_EXPORT +int _dbus_connection_get_pending_fds_count (DBusConnection *connection); +DBUS_PRIVATE_EXPORT +void _dbus_connection_set_pending_fds_function (DBusConnection *connection, + DBusPendingFdsChangeFunction callback, + void *data); + +DBUS_PRIVATE_EXPORT +dbus_bool_t _dbus_connection_get_linux_security_label (DBusConnection *connection, + char **label_p); + +/* if DBUS_ENABLE_STATS */ +DBUS_PRIVATE_EXPORT +void _dbus_connection_get_stats (DBusConnection *connection, + dbus_uint32_t *in_messages, + dbus_uint32_t *in_bytes, + dbus_uint32_t *in_fds, + dbus_uint32_t *in_peak_bytes, + dbus_uint32_t *in_peak_fds, + dbus_uint32_t *out_messages, + dbus_uint32_t *out_bytes, + dbus_uint32_t *out_fds, + dbus_uint32_t *out_peak_bytes, + dbus_uint32_t *out_peak_fds); + + +/* if DBUS_ENABLE_EMBEDDED_TESTS */ +const char* _dbus_connection_get_address (DBusConnection *connection); + +/* This _dbus_bus_* stuff doesn't really belong here, but dbus-bus-internal.h seems + * silly for one function + */ +/** + * @addtogroup DBusBusInternals + * @{ + */ + +void _dbus_bus_notify_shared_connection_disconnected_unlocked (DBusConnection *connection); + +/** @} */ + + +DBUS_END_DECLS + +#endif /* DBUS_CONNECTION_INTERNAL_H */
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c new file mode 100644 index 0000000..e3a89b5 --- /dev/null +++ b/dbus/dbus-connection.c
@@ -0,0 +1,6385 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-connection.c DBusConnection object + * + * Copyright (C) 2002-2006 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include <signal.h> +#include "dbus-shared.h" +#include "dbus-connection.h" +#include "dbus-list.h" +#include "dbus-timeout.h" +#include "dbus-transport.h" +#include "dbus-watch.h" +#include "dbus-connection-internal.h" +#include "dbus-pending-call-internal.h" +#include "dbus-list.h" +#include "dbus-hash.h" +#include "dbus-message-internal.h" +#include "dbus-message-private.h" +#include "dbus-threads.h" +#include "dbus-protocol.h" +#include "dbus-dataslot.h" +#include "dbus-string.h" +#include "dbus-signature.h" +#include "dbus-pending-call.h" +#include "dbus-object-tree.h" +#include "dbus-threads-internal.h" +#include "dbus-bus.h" +#include "dbus-marshal-basic.h" + +#ifdef DBUS_DISABLE_CHECKS +#define TOOK_LOCK_CHECK(connection) +#define RELEASING_LOCK_CHECK(connection) +#define HAVE_LOCK_CHECK(connection) +#else +#define TOOK_LOCK_CHECK(connection) do { \ + _dbus_assert (!(connection)->have_connection_lock); \ + (connection)->have_connection_lock = TRUE; \ + } while (0) +#define RELEASING_LOCK_CHECK(connection) do { \ + _dbus_assert ((connection)->have_connection_lock); \ + (connection)->have_connection_lock = FALSE; \ + } while (0) +#define HAVE_LOCK_CHECK(connection) _dbus_assert ((connection)->have_connection_lock) +/* A "DO_NOT_HAVE_LOCK_CHECK" is impossible since we need the lock to check the flag */ +#endif + +#define TRACE_LOCKS 1 + +#define CONNECTION_LOCK(connection) do { \ + if (TRACE_LOCKS) { _dbus_verbose ("LOCK\n"); } \ + _dbus_rmutex_lock ((connection)->mutex); \ + TOOK_LOCK_CHECK (connection); \ + } while (0) + +#define CONNECTION_UNLOCK(connection) _dbus_connection_unlock (connection) + +#define SLOTS_LOCK(connection) do { \ + _dbus_rmutex_lock ((connection)->slot_mutex); \ + } while (0) + +#define SLOTS_UNLOCK(connection) do { \ + _dbus_rmutex_unlock ((connection)->slot_mutex); \ + } while (0) + +#define DISPATCH_STATUS_NAME(s) \ + ((s) == DBUS_DISPATCH_COMPLETE ? "complete" : \ + (s) == DBUS_DISPATCH_DATA_REMAINS ? "data remains" : \ + (s) == DBUS_DISPATCH_NEED_MEMORY ? "need memory" : \ + "???") + +/** + * @defgroup DBusConnection DBusConnection + * @ingroup DBus + * @brief Connection to another application + * + * A DBusConnection represents a connection to another + * application. Messages can be sent and received via this connection. + * The other application may be a message bus; for convenience, the + * function dbus_bus_get() is provided to automatically open a + * connection to the well-known message buses. + * + * In brief a DBusConnection is a message queue associated with some + * message transport mechanism such as a socket. The connection + * maintains a queue of incoming messages and a queue of outgoing + * messages. + * + * Several functions use the following terms: + * <ul> + * <li><b>read</b> means to fill the incoming message queue by reading from the socket</li> + * <li><b>write</b> means to drain the outgoing queue by writing to the socket</li> + * <li><b>dispatch</b> means to drain the incoming queue by invoking application-provided message handlers</li> + * </ul> + * + * The function dbus_connection_read_write_dispatch() for example does all + * three of these things, offering a simple alternative to a main loop. + * + * In an application with a main loop, the read/write/dispatch + * operations are usually separate. + * + * The connection provides #DBusWatch and #DBusTimeout objects to + * the main loop. These are used to know when reading, writing, or + * dispatching should be performed. + * + * Incoming messages are processed + * by calling dbus_connection_dispatch(). dbus_connection_dispatch() + * runs any handlers registered for the topmost message in the message + * queue, then discards the message, then returns. + * + * dbus_connection_get_dispatch_status() indicates whether + * messages are currently in the queue that need dispatching. + * dbus_connection_set_dispatch_status_function() allows + * you to set a function to be used to monitor the dispatch status. + * + * If you're using GLib or Qt add-on libraries for D-Bus, there are + * special convenience APIs in those libraries that hide + * all the details of dispatch and watch/timeout monitoring. + * For example, dbus_connection_setup_with_g_main(). + * + * If you aren't using these add-on libraries, but want to process + * messages asynchronously, you must manually call + * dbus_connection_set_dispatch_status_function(), + * dbus_connection_set_watch_functions(), + * dbus_connection_set_timeout_functions() providing appropriate + * functions to integrate the connection with your application's main + * loop. This can be tricky to get right; main loops are not simple. + * + * If you don't need to be asynchronous, you can ignore #DBusWatch, + * #DBusTimeout, and dbus_connection_dispatch(). Instead, + * dbus_connection_read_write_dispatch() can be used. + * + * Or, in <em>very</em> simple applications, + * dbus_connection_pop_message() may be all you need, allowing you to + * avoid setting up any handler functions (see + * dbus_connection_add_filter(), + * dbus_connection_register_object_path() for more on handlers). + * + * When you use dbus_connection_send() or one of its variants to send + * a message, the message is added to the outgoing queue. It's + * actually written to the network later; either in + * dbus_watch_handle() invoked by your main loop, or in + * dbus_connection_flush() which blocks until it can write out the + * entire outgoing queue. The GLib/Qt add-on libraries again + * handle the details here for you by setting up watch functions. + * + * When a connection is disconnected, you are guaranteed to get a + * signal "Disconnected" from the interface + * #DBUS_INTERFACE_LOCAL, path + * #DBUS_PATH_LOCAL. + * + * You may not drop the last reference to a #DBusConnection + * until that connection has been disconnected. + * + * You may dispatch the unprocessed incoming message queue even if the + * connection is disconnected. However, "Disconnected" will always be + * the last message in the queue (obviously no messages are received + * after disconnection). + * + * After calling dbus_threads_init(), #DBusConnection has thread + * locks and drops them when invoking user callbacks, so in general is + * transparently threadsafe. However, #DBusMessage does NOT have + * thread locks; you must not send the same message to multiple + * #DBusConnection if those connections will be used from different threads, + * for example. + * + * Also, if you dispatch or pop messages from multiple threads, it + * may work in the sense that it won't crash, but it's tough to imagine + * sane results; it will be completely unpredictable which messages + * go to which threads. + * + * It's recommended to dispatch from a single thread. + * + * The most useful function to call from multiple threads at once + * is dbus_connection_send_with_reply_and_block(). That is, + * multiple threads can make method calls at the same time. + * + * If you aren't using threads, you can use a main loop and + * dbus_pending_call_set_notify() to achieve a similar result. + */ + +/** + * @defgroup DBusConnectionInternals DBusConnection implementation details + * @ingroup DBusInternals + * @brief Implementation details of DBusConnection + * + * @{ + */ + +static void +_dbus_connection_trace_ref (DBusConnection *connection, + int old_refcount, + int new_refcount, + const char *why) +{ +#ifdef DBUS_ENABLE_VERBOSE_MODE + static int enabled = -1; + + _dbus_trace_ref ("DBusConnection", connection, old_refcount, new_refcount, + why, "DBUS_CONNECTION_TRACE", &enabled); +#endif +} + +/** + * Internal struct representing a message filter function + */ +typedef struct DBusMessageFilter DBusMessageFilter; + +/** + * Internal struct representing a message filter function + */ +struct DBusMessageFilter +{ + DBusAtomic refcount; /**< Reference count */ + DBusHandleMessageFunction function; /**< Function to call to filter */ + void *user_data; /**< User data for the function */ + DBusFreeFunction free_user_data_function; /**< Function to free the user data */ +}; + + +/** + * Internals of DBusPreallocatedSend + */ +struct DBusPreallocatedSend +{ + DBusConnection *connection; /**< Connection we'd send the message to */ + DBusList *queue_link; /**< Preallocated link in the queue */ + DBusList *counter_link; /**< Preallocated link in the resource counter */ +}; + +#if HAVE_DECL_MSG_NOSIGNAL +static dbus_bool_t _dbus_modify_sigpipe = FALSE; +#else +static dbus_bool_t _dbus_modify_sigpipe = TRUE; +#endif + +/** + * Implementation details of DBusConnection. All fields are private. + */ +struct DBusConnection +{ + DBusAtomic refcount; /**< Reference count. */ + + DBusRMutex *mutex; /**< Lock on the entire DBusConnection */ + + DBusCMutex *dispatch_mutex; /**< Protects dispatch_acquired */ + DBusCondVar *dispatch_cond; /**< Notify when dispatch_acquired is available */ + DBusCMutex *io_path_mutex; /**< Protects io_path_acquired */ + DBusCondVar *io_path_cond; /**< Notify when io_path_acquired is available */ + + DBusList *outgoing_messages; /**< Queue of messages we need to send, send the end of the list first. */ + DBusList *incoming_messages; /**< Queue of messages we have received, end of the list received most recently. */ + DBusList *expired_messages; /**< Messages that will be released when we next unlock. */ + + DBusMessage *message_borrowed; /**< Filled in if the first incoming message has been borrowed; + * dispatch_acquired will be set by the borrower + */ + + int n_outgoing; /**< Length of outgoing queue. */ + int n_incoming; /**< Length of incoming queue. */ + + DBusCounter *outgoing_counter; /**< Counts size of outgoing messages. */ + + DBusTransport *transport; /**< Object that sends/receives messages over network. */ + DBusWatchList *watches; /**< Stores active watches. */ + DBusTimeoutList *timeouts; /**< Stores active timeouts. */ + + DBusList *filter_list; /**< List of filters. */ + + DBusRMutex *slot_mutex; /**< Lock on slot_list so overall connection lock need not be taken */ + DBusDataSlotList slot_list; /**< Data stored by allocated integer ID */ + + DBusHashTable *pending_replies; /**< Hash of message serials to #DBusPendingCall. */ + + dbus_uint32_t client_serial; /**< Client serial. Increments each time a message is sent */ + DBusList *disconnect_message_link; /**< Preallocated list node for queueing the disconnection message */ + + DBusWakeupMainFunction wakeup_main_function; /**< Function to wake up the mainloop */ + void *wakeup_main_data; /**< Application data for wakeup_main_function */ + DBusFreeFunction free_wakeup_main_data; /**< free wakeup_main_data */ + + DBusDispatchStatusFunction dispatch_status_function; /**< Function on dispatch status changes */ + void *dispatch_status_data; /**< Application data for dispatch_status_function */ + DBusFreeFunction free_dispatch_status_data; /**< free dispatch_status_data */ + + DBusDispatchStatus last_dispatch_status; /**< The last dispatch status we reported to the application. */ + + DBusObjectTree *objects; /**< Object path handlers registered with this connection */ + + char *server_guid; /**< GUID of server if we are in shared_connections, #NULL if server GUID is unknown or connection is private */ + + /* These two MUST be bools and not bitfields, because they are protected by a separate lock + * from connection->mutex and all bitfields in a word have to be read/written together. + * So you can't have a different lock for different bitfields in the same word. + */ + dbus_bool_t dispatch_acquired; /**< Someone has dispatch path (can drain incoming queue) */ + dbus_bool_t io_path_acquired; /**< Someone has transport io path (can use the transport to read/write messages) */ + + unsigned int shareable : 1; /**< #TRUE if libdbus owns a reference to the connection and can return it from dbus_connection_open() more than once */ + + unsigned int exit_on_disconnect : 1; /**< If #TRUE, exit after handling disconnect signal */ + + unsigned int route_peer_messages : 1; /**< If #TRUE, if org.freedesktop.DBus.Peer messages have a bus name, don't handle them automatically */ + + unsigned int disconnected_message_arrived : 1; /**< We popped or are dispatching the disconnected message. + * if the disconnect_message_link is NULL then we queued it, but + * this flag is whether it got to the head of the queue. + */ + unsigned int disconnected_message_processed : 1; /**< We did our default handling of the disconnected message, + * such as closing the connection. + */ + +#ifndef DBUS_DISABLE_CHECKS + unsigned int have_connection_lock : 1; /**< Used to check locking */ +#endif + +#if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT) + int generation; /**< _dbus_current_generation that should correspond to this connection */ +#endif +}; + +static DBusDispatchStatus _dbus_connection_get_dispatch_status_unlocked (DBusConnection *connection); +static void _dbus_connection_update_dispatch_status_and_unlock (DBusConnection *connection, + DBusDispatchStatus new_status); +static void _dbus_connection_last_unref (DBusConnection *connection); +static void _dbus_connection_acquire_dispatch (DBusConnection *connection); +static void _dbus_connection_release_dispatch (DBusConnection *connection); +static DBusDispatchStatus _dbus_connection_flush_unlocked (DBusConnection *connection); +static void _dbus_connection_close_possibly_shared_and_unlock (DBusConnection *connection); +static dbus_bool_t _dbus_connection_get_is_connected_unlocked (DBusConnection *connection); +static dbus_bool_t _dbus_connection_peek_for_reply_unlocked (DBusConnection *connection, + dbus_uint32_t client_serial); + +static DBusMessageFilter * +_dbus_message_filter_ref (DBusMessageFilter *filter) +{ +#ifdef DBUS_DISABLE_ASSERT + _dbus_atomic_inc (&filter->refcount); +#else + dbus_int32_t old_value; + + old_value = _dbus_atomic_inc (&filter->refcount); + _dbus_assert (old_value > 0); +#endif + + return filter; +} + +static void +_dbus_message_filter_unref (DBusMessageFilter *filter) +{ + dbus_int32_t old_value; + + old_value = _dbus_atomic_dec (&filter->refcount); + _dbus_assert (old_value > 0); + + if (old_value == 1) + { + if (filter->free_user_data_function) + (* filter->free_user_data_function) (filter->user_data); + + dbus_free (filter); + } +} + +/** + * Acquires the connection lock. + * + * @param connection the connection. + */ +void +_dbus_connection_lock (DBusConnection *connection) +{ + CONNECTION_LOCK (connection); +} + +/** + * Releases the connection lock. + * + * @param connection the connection. + */ +void +_dbus_connection_unlock (DBusConnection *connection) +{ + DBusList *expired_messages; + DBusList *iter; + + if (TRACE_LOCKS) + { + _dbus_verbose ("UNLOCK\n"); + } + + /* If we had messages that expired (fell off the incoming or outgoing + * queues) while we were locked, actually release them now */ + expired_messages = connection->expired_messages; + connection->expired_messages = NULL; + + RELEASING_LOCK_CHECK (connection); + _dbus_rmutex_unlock (connection->mutex); + + for (iter = _dbus_list_pop_first_link (&expired_messages); + iter != NULL; + iter = _dbus_list_pop_first_link (&expired_messages)) + { + DBusMessage *message = iter->data; + + dbus_message_unref (message); + _dbus_list_free_link (iter); + } +} + +/** + * Wakes up the main loop if it is sleeping + * Needed if we're e.g. queueing outgoing messages + * on a thread while the mainloop sleeps. + * + * @param connection the connection. + */ +static void +_dbus_connection_wakeup_mainloop (DBusConnection *connection) +{ + if (connection->wakeup_main_function) + (*connection->wakeup_main_function) (connection->wakeup_main_data); +} + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS +/** + * Gets the locks so we can examine them + * + * @param connection the connection. + * @param mutex_loc return for the location of the main mutex pointer + * @param dispatch_mutex_loc return location of the dispatch mutex pointer + * @param io_path_mutex_loc return location of the io_path mutex pointer + * @param dispatch_cond_loc return location of the dispatch conditional + * variable pointer + * @param io_path_cond_loc return location of the io_path conditional + * variable pointer + */ +void +_dbus_connection_test_get_locks (DBusConnection *connection, + DBusMutex **mutex_loc, + DBusMutex **dispatch_mutex_loc, + DBusMutex **io_path_mutex_loc, + DBusCondVar **dispatch_cond_loc, + DBusCondVar **io_path_cond_loc) +{ + *mutex_loc = (DBusMutex *) connection->mutex; + *dispatch_mutex_loc = (DBusMutex *) connection->dispatch_mutex; + *io_path_mutex_loc = (DBusMutex *) connection->io_path_mutex; + *dispatch_cond_loc = connection->dispatch_cond; + *io_path_cond_loc = connection->io_path_cond; +} +#endif + +/** + * Adds a message-containing list link to the incoming message queue, + * taking ownership of the link and the message's current refcount. + * Cannot fail due to lack of memory. + * + * @param connection the connection. + * @param link the message link to queue. + */ +void +_dbus_connection_queue_received_message_link (DBusConnection *connection, + DBusList *link) +{ + DBusPendingCall *pending; + dbus_uint32_t reply_serial; + DBusMessage *message; + + _dbus_assert (_dbus_transport_peek_is_authenticated (connection->transport)); + + _dbus_list_append_link (&connection->incoming_messages, + link); + message = link->data; + + /* If this is a reply we're waiting on, remove timeout for it */ + reply_serial = dbus_message_get_reply_serial (message); + if (reply_serial != 0) + { + pending = _dbus_hash_table_lookup_int (connection->pending_replies, + reply_serial); + if (pending != NULL) + { + if (_dbus_pending_call_is_timeout_added_unlocked (pending)) + _dbus_connection_remove_timeout_unlocked (connection, + _dbus_pending_call_get_timeout_unlocked (pending)); + + _dbus_pending_call_set_timeout_added_unlocked (pending, FALSE); + } + } + + + + connection->n_incoming += 1; + + _dbus_connection_wakeup_mainloop (connection); + + _dbus_verbose ("Message %p (%s %s %s %s '%s' reply to %u) added to incoming queue %p, %d incoming\n", + message, + dbus_message_type_to_string (dbus_message_get_type (message)), + dbus_message_get_path (message) ? + dbus_message_get_path (message) : + "no path", + dbus_message_get_interface (message) ? + dbus_message_get_interface (message) : + "no interface", + dbus_message_get_member (message) ? + dbus_message_get_member (message) : + "no member", + dbus_message_get_signature (message), + dbus_message_get_reply_serial (message), + connection, + connection->n_incoming); + + _dbus_message_trace_ref (message, -1, -1, + "_dbus_conection_queue_received_message_link"); +} + +/** + * Adds a link + message to the incoming message queue. + * Can't fail. Takes ownership of both link and message. + * + * @param connection the connection. + * @param link the list node and message to queue. + * + */ +void +_dbus_connection_queue_synthesized_message_link (DBusConnection *connection, + DBusList *link) +{ + HAVE_LOCK_CHECK (connection); + + _dbus_list_append_link (&connection->incoming_messages, link); + + connection->n_incoming += 1; + + _dbus_connection_wakeup_mainloop (connection); + + _dbus_message_trace_ref (link->data, -1, -1, + "_dbus_connection_queue_synthesized_message_link"); + + _dbus_verbose ("Synthesized message %p added to incoming queue %p, %d incoming\n", + link->data, connection, connection->n_incoming); +} + + +/** + * Checks whether there are messages in the outgoing message queue. + * Called with connection lock held. + * + * @param connection the connection. + * @returns #TRUE if the outgoing queue is non-empty. + */ +dbus_bool_t +_dbus_connection_has_messages_to_send_unlocked (DBusConnection *connection) +{ + HAVE_LOCK_CHECK (connection); + return connection->outgoing_messages != NULL; +} + +/** + * Checks whether there are messages in the outgoing message queue. + * Use dbus_connection_flush() to block until all outgoing + * messages have been written to the underlying transport + * (such as a socket). + * + * @param connection the connection. + * @returns #TRUE if the outgoing queue is non-empty. + */ +dbus_bool_t +dbus_connection_has_messages_to_send (DBusConnection *connection) +{ + dbus_bool_t v; + + _dbus_return_val_if_fail (connection != NULL, FALSE); + + CONNECTION_LOCK (connection); + v = _dbus_connection_has_messages_to_send_unlocked (connection); + CONNECTION_UNLOCK (connection); + + return v; +} + +/** + * Gets the next outgoing message. The message remains in the + * queue, and the caller does not own a reference to it. + * + * @param connection the connection. + * @returns the message to be sent. + */ +DBusMessage* +_dbus_connection_get_message_to_send (DBusConnection *connection) +{ + HAVE_LOCK_CHECK (connection); + + return _dbus_list_get_last (&connection->outgoing_messages); +} + +/** + * Notifies the connection that a message has been sent, so the + * message can be removed from the outgoing queue. + * Called with the connection lock held. + * + * @param connection the connection. + * @param message the message that was sent. + */ +void +_dbus_connection_message_sent_unlocked (DBusConnection *connection, + DBusMessage *message) +{ + DBusList *link; + + HAVE_LOCK_CHECK (connection); + + /* This can be called before we even complete authentication, since + * it's called on disconnect to clean up the outgoing queue. + * It's also called as we successfully send each message. + */ + + link = _dbus_list_get_last_link (&connection->outgoing_messages); + _dbus_assert (link != NULL); + _dbus_assert (link->data == message); + + _dbus_list_unlink (&connection->outgoing_messages, + link); + _dbus_list_prepend_link (&connection->expired_messages, link); + + connection->n_outgoing -= 1; + + _dbus_verbose ("Message %p (%s %s %s %s '%s') removed from outgoing queue %p, %d left to send\n", + message, + dbus_message_type_to_string (dbus_message_get_type (message)), + dbus_message_get_path (message) ? + dbus_message_get_path (message) : + "no path", + dbus_message_get_interface (message) ? + dbus_message_get_interface (message) : + "no interface", + dbus_message_get_member (message) ? + dbus_message_get_member (message) : + "no member", + dbus_message_get_signature (message), + connection, connection->n_outgoing); + + /* It's OK that in principle we call the notify function, because for the + * outgoing limit, there isn't one */ + _dbus_message_remove_counter (message, connection->outgoing_counter); + + /* The message will actually be unreffed when we unlock */ +} + +/** Function to be called in protected_change_watch() with refcount held */ +typedef dbus_bool_t (* DBusWatchAddFunction) (DBusWatchList *list, + DBusWatch *watch); +/** Function to be called in protected_change_watch() with refcount held */ +typedef void (* DBusWatchRemoveFunction) (DBusWatchList *list, + DBusWatch *watch); +/** Function to be called in protected_change_watch() with refcount held */ +typedef void (* DBusWatchToggleFunction) (DBusWatchList *list, + DBusWatch *watch, + dbus_bool_t enabled); + +static dbus_bool_t +protected_change_watch (DBusConnection *connection, + DBusWatch *watch, + DBusWatchAddFunction add_function, + DBusWatchRemoveFunction remove_function, + DBusWatchToggleFunction toggle_function, + dbus_bool_t enabled) +{ + dbus_bool_t retval; + + HAVE_LOCK_CHECK (connection); + + /* The original purpose of protected_change_watch() was to hold a + * ref on the connection while dropping the connection lock, then + * calling out to the app. This was a broken hack that did not + * work, since the connection was in a hosed state (no WatchList + * field) while calling out. + * + * So for now we'll just keep the lock while calling out. This means + * apps are not allowed to call DBusConnection methods inside a + * watch function or they will deadlock. + * + * The "real fix" is to use the _and_unlock() pattern found + * elsewhere in the code, to defer calling out to the app until + * we're about to drop locks and return flow of control to the app + * anyway. + * + * See http://lists.freedesktop.org/archives/dbus/2007-July/thread.html#8144 + */ + + if (connection->watches) + { + if (add_function) + retval = (* add_function) (connection->watches, watch); + else if (remove_function) + { + retval = TRUE; + (* remove_function) (connection->watches, watch); + } + else + { + retval = TRUE; + (* toggle_function) (connection->watches, watch, enabled); + } + return retval; + } + else + return FALSE; +} + + +/** + * Adds a watch using the connection's DBusAddWatchFunction if + * available. Otherwise records the watch to be added when said + * function is available. Also re-adds the watch if the + * DBusAddWatchFunction changes. May fail due to lack of memory. + * Connection lock should be held when calling this. + * + * @param connection the connection. + * @param watch the watch to add. + * @returns #TRUE on success. + */ +dbus_bool_t +_dbus_connection_add_watch_unlocked (DBusConnection *connection, + DBusWatch *watch) +{ + return protected_change_watch (connection, watch, + _dbus_watch_list_add_watch, + NULL, NULL, FALSE); +} + +/** + * Removes a watch using the connection's DBusRemoveWatchFunction + * if available. It's an error to call this function on a watch + * that was not previously added. + * Connection lock should be held when calling this. + * + * @param connection the connection. + * @param watch the watch to remove. + */ +void +_dbus_connection_remove_watch_unlocked (DBusConnection *connection, + DBusWatch *watch) +{ + protected_change_watch (connection, watch, + NULL, + _dbus_watch_list_remove_watch, + NULL, FALSE); +} + +/** + * Toggles a watch and notifies app via connection's + * DBusWatchToggledFunction if available. It's an error to call this + * function on a watch that was not previously added. + * Connection lock should be held when calling this. + * + * @param connection the connection. + * @param watch the watch to toggle. + * @param enabled whether to enable or disable + */ +void +_dbus_connection_toggle_watch_unlocked (DBusConnection *connection, + DBusWatch *watch, + dbus_bool_t enabled) +{ + _dbus_assert (watch != NULL); + + protected_change_watch (connection, watch, + NULL, NULL, + _dbus_watch_list_toggle_watch, + enabled); +} + +/** Function to be called in protected_change_timeout() with refcount held */ +typedef dbus_bool_t (* DBusTimeoutAddFunction) (DBusTimeoutList *list, + DBusTimeout *timeout); +/** Function to be called in protected_change_timeout() with refcount held */ +typedef void (* DBusTimeoutRemoveFunction) (DBusTimeoutList *list, + DBusTimeout *timeout); +/** Function to be called in protected_change_timeout() with refcount held */ +typedef void (* DBusTimeoutToggleFunction) (DBusTimeoutList *list, + DBusTimeout *timeout, + dbus_bool_t enabled); + +static dbus_bool_t +protected_change_timeout (DBusConnection *connection, + DBusTimeout *timeout, + DBusTimeoutAddFunction add_function, + DBusTimeoutRemoveFunction remove_function, + DBusTimeoutToggleFunction toggle_function, + dbus_bool_t enabled) +{ + dbus_bool_t retval; + + HAVE_LOCK_CHECK (connection); + + /* The original purpose of protected_change_timeout() was to hold a + * ref on the connection while dropping the connection lock, then + * calling out to the app. This was a broken hack that did not + * work, since the connection was in a hosed state (no TimeoutList + * field) while calling out. + * + * So for now we'll just keep the lock while calling out. This means + * apps are not allowed to call DBusConnection methods inside a + * timeout function or they will deadlock. + * + * The "real fix" is to use the _and_unlock() pattern found + * elsewhere in the code, to defer calling out to the app until + * we're about to drop locks and return flow of control to the app + * anyway. + * + * See http://lists.freedesktop.org/archives/dbus/2007-July/thread.html#8144 + */ + + if (connection->timeouts) + { + if (add_function) + retval = (* add_function) (connection->timeouts, timeout); + else if (remove_function) + { + retval = TRUE; + (* remove_function) (connection->timeouts, timeout); + } + else + { + retval = TRUE; + (* toggle_function) (connection->timeouts, timeout, enabled); + } + return retval; + } + else + return FALSE; +} + +/** + * Adds a timeout using the connection's DBusAddTimeoutFunction if + * available. Otherwise records the timeout to be added when said + * function is available. Also re-adds the timeout if the + * DBusAddTimeoutFunction changes. May fail due to lack of memory. + * The timeout will fire repeatedly until removed. + * Connection lock should be held when calling this. + * + * @param connection the connection. + * @param timeout the timeout to add. + * @returns #TRUE on success. + */ +dbus_bool_t +_dbus_connection_add_timeout_unlocked (DBusConnection *connection, + DBusTimeout *timeout) +{ + return protected_change_timeout (connection, timeout, + _dbus_timeout_list_add_timeout, + NULL, NULL, FALSE); +} + +/** + * Removes a timeout using the connection's DBusRemoveTimeoutFunction + * if available. It's an error to call this function on a timeout + * that was not previously added. + * Connection lock should be held when calling this. + * + * @param connection the connection. + * @param timeout the timeout to remove. + */ +void +_dbus_connection_remove_timeout_unlocked (DBusConnection *connection, + DBusTimeout *timeout) +{ + protected_change_timeout (connection, timeout, + NULL, + _dbus_timeout_list_remove_timeout, + NULL, FALSE); +} + +/** + * Toggles a timeout and notifies app via connection's + * DBusTimeoutToggledFunction if available. It's an error to call this + * function on a timeout that was not previously added. + * Connection lock should be held when calling this. + * + * @param connection the connection. + * @param timeout the timeout to toggle. + * @param enabled whether to enable or disable + */ +void +_dbus_connection_toggle_timeout_unlocked (DBusConnection *connection, + DBusTimeout *timeout, + dbus_bool_t enabled) +{ + protected_change_timeout (connection, timeout, + NULL, NULL, + _dbus_timeout_list_toggle_timeout, + enabled); +} + +static dbus_bool_t +_dbus_connection_attach_pending_call_unlocked (DBusConnection *connection, + DBusPendingCall *pending) +{ + dbus_uint32_t reply_serial; + DBusTimeout *timeout; + + HAVE_LOCK_CHECK (connection); + + reply_serial = _dbus_pending_call_get_reply_serial_unlocked (pending); + + _dbus_assert (reply_serial != 0); + + timeout = _dbus_pending_call_get_timeout_unlocked (pending); + + if (timeout) + { + if (!_dbus_connection_add_timeout_unlocked (connection, timeout)) + return FALSE; + + if (!_dbus_hash_table_insert_int (connection->pending_replies, + reply_serial, + pending)) + { + _dbus_connection_remove_timeout_unlocked (connection, timeout); + + _dbus_pending_call_set_timeout_added_unlocked (pending, FALSE); + HAVE_LOCK_CHECK (connection); + return FALSE; + } + + _dbus_pending_call_set_timeout_added_unlocked (pending, TRUE); + } + else + { + if (!_dbus_hash_table_insert_int (connection->pending_replies, + reply_serial, + pending)) + { + HAVE_LOCK_CHECK (connection); + return FALSE; + } + } + + _dbus_pending_call_ref_unlocked (pending); + + HAVE_LOCK_CHECK (connection); + + return TRUE; +} + +static void +free_pending_call_on_hash_removal (void *data) +{ + DBusPendingCall *pending; + DBusConnection *connection; + + if (data == NULL) + return; + + pending = data; + + connection = _dbus_pending_call_get_connection_unlocked (pending); + + HAVE_LOCK_CHECK (connection); + + if (_dbus_pending_call_is_timeout_added_unlocked (pending)) + { + _dbus_connection_remove_timeout_unlocked (connection, + _dbus_pending_call_get_timeout_unlocked (pending)); + + _dbus_pending_call_set_timeout_added_unlocked (pending, FALSE); + } + + /* FIXME 1.0? this is sort of dangerous and undesirable to drop the lock + * here, but the pending call finalizer could in principle call out to + * application code so we pretty much have to... some larger code reorg + * might be needed. + */ + _dbus_connection_ref_unlocked (connection); + _dbus_pending_call_unref_and_unlock (pending); + CONNECTION_LOCK (connection); + _dbus_connection_unref_unlocked (connection); +} + +static void +_dbus_connection_detach_pending_call_unlocked (DBusConnection *connection, + DBusPendingCall *pending) +{ + /* This ends up unlocking to call the pending call finalizer, which is unexpected to + * say the least. + */ + _dbus_hash_table_remove_int (connection->pending_replies, + _dbus_pending_call_get_reply_serial_unlocked (pending)); +} + +static void +_dbus_connection_detach_pending_call_and_unlock (DBusConnection *connection, + DBusPendingCall *pending) +{ + /* The idea here is to avoid finalizing the pending call + * with the lock held, since there's a destroy notifier + * in pending call that goes out to application code. + * + * There's an extra unlock inside the hash table + * "free pending call" function FIXME... + */ + _dbus_pending_call_ref_unlocked (pending); + _dbus_hash_table_remove_int (connection->pending_replies, + _dbus_pending_call_get_reply_serial_unlocked (pending)); + + if (_dbus_pending_call_is_timeout_added_unlocked (pending)) + _dbus_connection_remove_timeout_unlocked (connection, + _dbus_pending_call_get_timeout_unlocked (pending)); + + _dbus_pending_call_set_timeout_added_unlocked (pending, FALSE); + + _dbus_pending_call_unref_and_unlock (pending); +} + +/** + * Removes a pending call from the connection, such that + * the pending reply will be ignored. May drop the last + * reference to the pending call. + * + * @param connection the connection + * @param pending the pending call + */ +void +_dbus_connection_remove_pending_call (DBusConnection *connection, + DBusPendingCall *pending) +{ + CONNECTION_LOCK (connection); + _dbus_connection_detach_pending_call_and_unlock (connection, pending); +} + +/** + * Acquire the transporter I/O path. This must be done before + * doing any I/O in the transporter. May sleep and drop the + * IO path mutex while waiting for the I/O path. + * + * @param connection the connection. + * @param timeout_milliseconds maximum blocking time, or -1 for no limit. + * @returns TRUE if the I/O path was acquired. + */ +static dbus_bool_t +_dbus_connection_acquire_io_path (DBusConnection *connection, + int timeout_milliseconds) +{ + dbus_bool_t we_acquired; + + HAVE_LOCK_CHECK (connection); + + /* We don't want the connection to vanish */ + _dbus_connection_ref_unlocked (connection); + + /* We will only touch io_path_acquired which is protected by our mutex */ + CONNECTION_UNLOCK (connection); + + _dbus_verbose ("locking io_path_mutex\n"); + _dbus_cmutex_lock (connection->io_path_mutex); + + _dbus_verbose ("start connection->io_path_acquired = %d timeout = %d\n", + connection->io_path_acquired, timeout_milliseconds); + + we_acquired = FALSE; + + if (connection->io_path_acquired) + { + if (timeout_milliseconds != -1) + { + _dbus_verbose ("waiting %d for IO path to be acquirable\n", + timeout_milliseconds); + + if (!_dbus_condvar_wait_timeout (connection->io_path_cond, + connection->io_path_mutex, + timeout_milliseconds)) + { + /* We timed out before anyone signaled. */ + /* (writing the loop to handle the !timedout case by + * waiting longer if needed is a pain since dbus + * wraps pthread_cond_timedwait to take a relative + * time instead of absolute, something kind of stupid + * on our part. for now it doesn't matter, we will just + * end up back here eventually.) + */ + } + } + else + { + while (connection->io_path_acquired) + { + _dbus_verbose ("waiting for IO path to be acquirable\n"); + _dbus_condvar_wait (connection->io_path_cond, + connection->io_path_mutex); + } + } + } + + if (!connection->io_path_acquired) + { + we_acquired = TRUE; + connection->io_path_acquired = TRUE; + } + + _dbus_verbose ("end connection->io_path_acquired = %d we_acquired = %d\n", + connection->io_path_acquired, we_acquired); + + _dbus_verbose ("unlocking io_path_mutex\n"); + _dbus_cmutex_unlock (connection->io_path_mutex); + + CONNECTION_LOCK (connection); + + HAVE_LOCK_CHECK (connection); + + _dbus_connection_unref_unlocked (connection); + + return we_acquired; +} + +/** + * Release the I/O path when you're done with it. Only call + * after you've acquired the I/O. Wakes up at most one thread + * currently waiting to acquire the I/O path. + * + * @param connection the connection. + */ +static void +_dbus_connection_release_io_path (DBusConnection *connection) +{ + HAVE_LOCK_CHECK (connection); + + _dbus_verbose ("locking io_path_mutex\n"); + _dbus_cmutex_lock (connection->io_path_mutex); + + _dbus_assert (connection->io_path_acquired); + + _dbus_verbose ("start connection->io_path_acquired = %d\n", + connection->io_path_acquired); + + connection->io_path_acquired = FALSE; + _dbus_condvar_wake_one (connection->io_path_cond); + + _dbus_verbose ("unlocking io_path_mutex\n"); + _dbus_cmutex_unlock (connection->io_path_mutex); +} + +/** + * Queues incoming messages and sends outgoing messages for this + * connection, optionally blocking in the process. Each call to + * _dbus_connection_do_iteration_unlocked() will call select() or poll() one + * time and then read or write data if possible. + * + * The purpose of this function is to be able to flush outgoing + * messages or queue up incoming messages without returning + * control to the application and causing reentrancy weirdness. + * + * The flags parameter allows you to specify whether to + * read incoming messages, write outgoing messages, or both, + * and whether to block if no immediate action is possible. + * + * The timeout_milliseconds parameter does nothing unless the + * iteration is blocking. + * + * If there are no outgoing messages and DBUS_ITERATION_DO_READING + * wasn't specified, then it's impossible to block, even if + * you specify DBUS_ITERATION_BLOCK; in that case the function + * returns immediately. + * + * If pending is not NULL then a check is made if the pending call + * is completed after the io path has been required. If the call + * has been completed nothing is done. This must be done since + * the _dbus_connection_acquire_io_path releases the connection + * lock for a while. + * + * Called with connection lock held. + * + * @param connection the connection. + * @param pending the pending call that should be checked or NULL + * @param flags iteration flags. + * @param timeout_milliseconds maximum blocking time, or -1 for no limit. + */ +void +_dbus_connection_do_iteration_unlocked (DBusConnection *connection, + DBusPendingCall *pending, + unsigned int flags, + int timeout_milliseconds) +{ + _dbus_verbose ("start\n"); + + HAVE_LOCK_CHECK (connection); + + if (connection->n_outgoing == 0) + flags &= ~DBUS_ITERATION_DO_WRITING; + + if (_dbus_connection_acquire_io_path (connection, + (flags & DBUS_ITERATION_BLOCK) ? timeout_milliseconds : 0)) + { + HAVE_LOCK_CHECK (connection); + + if ( (pending != NULL) && _dbus_pending_call_get_completed_unlocked(pending)) + { + _dbus_verbose ("pending call completed while acquiring I/O path"); + } + else if ( (pending != NULL) && + _dbus_connection_peek_for_reply_unlocked (connection, + _dbus_pending_call_get_reply_serial_unlocked (pending))) + { + _dbus_verbose ("pending call completed while acquiring I/O path (reply found in queue)"); + } + else + { + _dbus_transport_do_iteration (connection->transport, + flags, timeout_milliseconds); + } + + _dbus_connection_release_io_path (connection); + } + + HAVE_LOCK_CHECK (connection); + + _dbus_verbose ("end\n"); +} + +/** + * Creates a new connection for the given transport. A transport + * represents a message stream that uses some concrete mechanism, such + * as UNIX domain sockets. May return #NULL if insufficient + * memory exists to create the connection. + * + * @param transport the transport. + * @returns the new connection, or #NULL on failure. + */ +DBusConnection* +_dbus_connection_new_for_transport (DBusTransport *transport) +{ + DBusConnection *connection; + DBusWatchList *watch_list; + DBusTimeoutList *timeout_list; + DBusHashTable *pending_replies; + DBusList *disconnect_link; + DBusMessage *disconnect_message; + DBusCounter *outgoing_counter; + DBusObjectTree *objects; + + watch_list = NULL; + connection = NULL; + pending_replies = NULL; + timeout_list = NULL; + disconnect_link = NULL; + disconnect_message = NULL; + outgoing_counter = NULL; + objects = NULL; + + watch_list = _dbus_watch_list_new (); + if (watch_list == NULL) + goto error; + + timeout_list = _dbus_timeout_list_new (); + if (timeout_list == NULL) + goto error; + + pending_replies = + _dbus_hash_table_new (DBUS_HASH_INT, + NULL, + (DBusFreeFunction)free_pending_call_on_hash_removal); + if (pending_replies == NULL) + goto error; + + connection = dbus_new0 (DBusConnection, 1); + if (connection == NULL) + goto error; + + _dbus_rmutex_new_at_location (&connection->mutex); + if (connection->mutex == NULL) + goto error; + + _dbus_cmutex_new_at_location (&connection->io_path_mutex); + if (connection->io_path_mutex == NULL) + goto error; + + _dbus_cmutex_new_at_location (&connection->dispatch_mutex); + if (connection->dispatch_mutex == NULL) + goto error; + + _dbus_condvar_new_at_location (&connection->dispatch_cond); + if (connection->dispatch_cond == NULL) + goto error; + + _dbus_condvar_new_at_location (&connection->io_path_cond); + if (connection->io_path_cond == NULL) + goto error; + + _dbus_rmutex_new_at_location (&connection->slot_mutex); + if (connection->slot_mutex == NULL) + goto error; + + disconnect_message = dbus_message_new_signal (DBUS_PATH_LOCAL, + DBUS_INTERFACE_LOCAL, + "Disconnected"); + + if (disconnect_message == NULL) + goto error; + + disconnect_link = _dbus_list_alloc_link (disconnect_message); + if (disconnect_link == NULL) + goto error; + + outgoing_counter = _dbus_counter_new (); + if (outgoing_counter == NULL) + goto error; + + objects = _dbus_object_tree_new (connection); + if (objects == NULL) + goto error; + + if (_dbus_modify_sigpipe) + _dbus_disable_sigpipe (); + + /* initialized to 0: use atomic op to avoid mixing atomic and non-atomic */ + _dbus_atomic_inc (&connection->refcount); + connection->transport = transport; + connection->watches = watch_list; + connection->timeouts = timeout_list; + connection->pending_replies = pending_replies; + connection->outgoing_counter = outgoing_counter; + connection->filter_list = NULL; + connection->last_dispatch_status = DBUS_DISPATCH_COMPLETE; /* so we're notified first time there's data */ + connection->objects = objects; + connection->exit_on_disconnect = FALSE; + connection->shareable = FALSE; + connection->route_peer_messages = FALSE; + connection->disconnected_message_arrived = FALSE; + connection->disconnected_message_processed = FALSE; + +#if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT) + connection->generation = _dbus_current_generation; +#endif + + _dbus_data_slot_list_init (&connection->slot_list); + + connection->client_serial = 1; + + connection->disconnect_message_link = disconnect_link; + + CONNECTION_LOCK (connection); + + if (!_dbus_transport_set_connection (transport, connection)) + { + CONNECTION_UNLOCK (connection); + + goto error; + } + + _dbus_transport_ref (transport); + + CONNECTION_UNLOCK (connection); + + _dbus_connection_trace_ref (connection, 0, 1, "new_for_transport"); + return connection; + + error: + if (disconnect_message != NULL) + dbus_message_unref (disconnect_message); + + if (disconnect_link != NULL) + _dbus_list_free_link (disconnect_link); + + if (connection != NULL) + { + _dbus_condvar_free_at_location (&connection->io_path_cond); + _dbus_condvar_free_at_location (&connection->dispatch_cond); + _dbus_rmutex_free_at_location (&connection->mutex); + _dbus_cmutex_free_at_location (&connection->io_path_mutex); + _dbus_cmutex_free_at_location (&connection->dispatch_mutex); + _dbus_rmutex_free_at_location (&connection->slot_mutex); + dbus_free (connection); + } + if (pending_replies) + _dbus_hash_table_unref (pending_replies); + + if (watch_list) + _dbus_watch_list_free (watch_list); + + if (timeout_list) + _dbus_timeout_list_free (timeout_list); + + if (outgoing_counter) + _dbus_counter_unref (outgoing_counter); + + if (objects) + _dbus_object_tree_unref (objects); + + return NULL; +} + +/** + * Increments the reference count of a DBusConnection. + * Requires that the caller already holds the connection lock. + * + * @param connection the connection. + * @returns the connection. + */ +DBusConnection * +_dbus_connection_ref_unlocked (DBusConnection *connection) +{ + dbus_int32_t old_refcount; + + _dbus_assert (connection != NULL); + _dbus_assert (connection->generation == _dbus_current_generation); + + HAVE_LOCK_CHECK (connection); + + old_refcount = _dbus_atomic_inc (&connection->refcount); + _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1, + "ref_unlocked"); + + return connection; +} + +/** + * Decrements the reference count of a DBusConnection. + * Requires that the caller already holds the connection lock. + * + * @param connection the connection. + */ +void +_dbus_connection_unref_unlocked (DBusConnection *connection) +{ + dbus_int32_t old_refcount; + + HAVE_LOCK_CHECK (connection); + + _dbus_assert (connection != NULL); + + old_refcount = _dbus_atomic_dec (&connection->refcount); + + _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1, + "unref_unlocked"); + + if (old_refcount == 1) + _dbus_connection_last_unref (connection); +} + +static dbus_uint32_t +_dbus_connection_get_next_client_serial (DBusConnection *connection) +{ + dbus_uint32_t serial; + + serial = connection->client_serial++; + + if (connection->client_serial == 0) + connection->client_serial = 1; + + return serial; +} + +/** + * A callback for use with dbus_watch_new() to create a DBusWatch. + * + * @todo This is basically a hack - we could delete _dbus_transport_handle_watch() + * and the virtual handle_watch in DBusTransport if we got rid of it. + * The reason this is some work is threading, see the _dbus_connection_handle_watch() + * implementation. + * + * @param watch the watch. + * @param condition the current condition of the file descriptors being watched. + * @param data must be a pointer to a #DBusConnection + * @returns #FALSE if the IO condition may not have been fully handled due to lack of memory + */ +dbus_bool_t +_dbus_connection_handle_watch (DBusWatch *watch, + unsigned int condition, + void *data) +{ + DBusConnection *connection; + dbus_bool_t retval; + DBusDispatchStatus status; + + connection = data; + + _dbus_verbose ("start\n"); + + CONNECTION_LOCK (connection); + + if (!_dbus_connection_acquire_io_path (connection, 1)) + { + /* another thread is handling the message */ + CONNECTION_UNLOCK (connection); + return TRUE; + } + + HAVE_LOCK_CHECK (connection); + retval = _dbus_transport_handle_watch (connection->transport, + watch, condition); + + _dbus_connection_release_io_path (connection); + + HAVE_LOCK_CHECK (connection); + + _dbus_verbose ("middle\n"); + + status = _dbus_connection_get_dispatch_status_unlocked (connection); + + /* this calls out to user code */ + _dbus_connection_update_dispatch_status_and_unlock (connection, status); + + _dbus_verbose ("end\n"); + + return retval; +} + +/* Protected by _DBUS_LOCK (shared_connections) */ +static DBusHashTable *shared_connections = NULL; +static DBusList *shared_connections_no_guid = NULL; + +static void +close_connection_on_shutdown (DBusConnection *connection) +{ + DBusMessage *message; + + dbus_connection_ref (connection); + _dbus_connection_close_possibly_shared (connection); + + /* Churn through to the Disconnected message */ + while ((message = dbus_connection_pop_message (connection))) + { + dbus_message_unref (message); + } + dbus_connection_unref (connection); +} + +static void +shared_connections_shutdown (void *data) +{ + int n_entries; + + if (!_DBUS_LOCK (shared_connections)) + { + /* We'd have initialized locks before adding anything, so there + * can't be anything there. */ + return; + } + + /* This is a little bit unpleasant... better ideas? */ + while ((n_entries = _dbus_hash_table_get_n_entries (shared_connections)) > 0) + { + DBusConnection *connection; + DBusHashIter iter; + + _dbus_hash_iter_init (shared_connections, &iter); + _dbus_hash_iter_next (&iter); + + connection = _dbus_hash_iter_get_value (&iter); + + _DBUS_UNLOCK (shared_connections); + close_connection_on_shutdown (connection); + if (!_DBUS_LOCK (shared_connections)) + _dbus_assert_not_reached ("global locks were already initialized"); + + /* The connection should now be dead and not in our hash ... */ + _dbus_assert (_dbus_hash_table_get_n_entries (shared_connections) < n_entries); + } + + _dbus_assert (_dbus_hash_table_get_n_entries (shared_connections) == 0); + + _dbus_hash_table_unref (shared_connections); + shared_connections = NULL; + + if (shared_connections_no_guid != NULL) + { + DBusConnection *connection; + connection = _dbus_list_pop_first (&shared_connections_no_guid); + while (connection != NULL) + { + _DBUS_UNLOCK (shared_connections); + close_connection_on_shutdown (connection); + if (!_DBUS_LOCK (shared_connections)) + _dbus_assert_not_reached ("global locks were already initialized"); + connection = _dbus_list_pop_first (&shared_connections_no_guid); + } + } + + shared_connections_no_guid = NULL; + + _DBUS_UNLOCK (shared_connections); +} + +static dbus_bool_t +connection_lookup_shared (DBusAddressEntry *entry, + DBusConnection **result) +{ + _dbus_verbose ("checking for existing connection\n"); + + *result = NULL; + + if (!_DBUS_LOCK (shared_connections)) + { + /* If it was shared, we'd have initialized global locks when we put + * it in shared_connections. */ + return FALSE; + } + + if (shared_connections == NULL) + { + _dbus_verbose ("creating shared_connections hash table\n"); + + shared_connections = _dbus_hash_table_new (DBUS_HASH_STRING, + dbus_free, + NULL); + if (shared_connections == NULL) + { + _DBUS_UNLOCK (shared_connections); + return FALSE; + } + + if (!_dbus_register_shutdown_func (shared_connections_shutdown, NULL)) + { + _dbus_hash_table_unref (shared_connections); + shared_connections = NULL; + _DBUS_UNLOCK (shared_connections); + return FALSE; + } + + _dbus_verbose (" successfully created shared_connections\n"); + + _DBUS_UNLOCK (shared_connections); + return TRUE; /* no point looking up in the hash we just made */ + } + else + { + const char *guid; + + guid = dbus_address_entry_get_value (entry, "guid"); + + if (guid != NULL) + { + DBusConnection *connection; + + connection = _dbus_hash_table_lookup_string (shared_connections, + guid); + + if (connection) + { + /* The DBusConnection can't be finalized without taking + * the shared_connections lock to remove it from the + * hash. So it's safe to ref the connection here. + * However, it may be disconnected if the Disconnected + * message hasn't been processed yet, in which case we + * want to pretend it isn't in the hash and avoid + * returning it. + * + * The idea is to avoid ever returning a disconnected connection + * from dbus_connection_open(). We could just synchronously + * drop our shared ref to the connection on connection disconnect, + * and then assert here that the connection is connected, but + * that causes reentrancy headaches. + */ + CONNECTION_LOCK (connection); + if (_dbus_connection_get_is_connected_unlocked (connection)) + { + _dbus_connection_ref_unlocked (connection); + *result = connection; + _dbus_verbose ("looked up existing connection to server guid %s\n", + guid); + } + else + { + _dbus_verbose ("looked up existing connection to server guid %s but it was disconnected so ignoring it\n", + guid); + } + CONNECTION_UNLOCK (connection); + } + } + + _DBUS_UNLOCK (shared_connections); + return TRUE; + } +} + +static dbus_bool_t +connection_record_shared_unlocked (DBusConnection *connection, + const char *guid) +{ + char *guid_key; + char *guid_in_connection; + + HAVE_LOCK_CHECK (connection); + _dbus_assert (connection->server_guid == NULL); + _dbus_assert (connection->shareable); + + /* get a hard ref on this connection, even if + * we won't in fact store it in the hash, we still + * need to hold a ref on it until it's disconnected. + */ + _dbus_connection_ref_unlocked (connection); + + if (guid == NULL) + { + if (!_DBUS_LOCK (shared_connections)) + return FALSE; + + if (!_dbus_list_prepend (&shared_connections_no_guid, connection)) + { + _DBUS_UNLOCK (shared_connections); + return FALSE; + } + + _DBUS_UNLOCK (shared_connections); + return TRUE; /* don't store in the hash */ + } + + /* A separate copy of the key is required in the hash table, because + * we don't have a lock on the connection when we are doing a hash + * lookup. + */ + + guid_key = _dbus_strdup (guid); + if (guid_key == NULL) + return FALSE; + + guid_in_connection = _dbus_strdup (guid); + if (guid_in_connection == NULL) + { + dbus_free (guid_key); + return FALSE; + } + + if (!_DBUS_LOCK (shared_connections)) + { + dbus_free (guid_in_connection); + dbus_free (guid_key); + return FALSE; + } + + _dbus_assert (shared_connections != NULL); + + if (!_dbus_hash_table_insert_string (shared_connections, + guid_key, connection)) + { + dbus_free (guid_key); + dbus_free (guid_in_connection); + _DBUS_UNLOCK (shared_connections); + return FALSE; + } + + connection->server_guid = guid_in_connection; + + _dbus_verbose ("stored connection to %s to be shared\n", + connection->server_guid); + + _DBUS_UNLOCK (shared_connections); + + _dbus_assert (connection->server_guid != NULL); + + return TRUE; +} + +static void +connection_forget_shared_unlocked (DBusConnection *connection) +{ + HAVE_LOCK_CHECK (connection); + + if (!connection->shareable) + return; + + if (!_DBUS_LOCK (shared_connections)) + { + /* If it was shared, we'd have initialized global locks when we put + * it in the table; so it can't be there. */ + return; + } + + if (connection->server_guid != NULL) + { + _dbus_verbose ("dropping connection to %s out of the shared table\n", + connection->server_guid); + + if (!_dbus_hash_table_remove_string (shared_connections, + connection->server_guid)) + _dbus_assert_not_reached ("connection was not in the shared table"); + + dbus_free (connection->server_guid); + connection->server_guid = NULL; + } + else + { + _dbus_list_remove (&shared_connections_no_guid, connection); + } + + _DBUS_UNLOCK (shared_connections); + + /* remove our reference held on all shareable connections */ + _dbus_connection_unref_unlocked (connection); +} + +static DBusConnection* +connection_try_from_address_entry (DBusAddressEntry *entry, + DBusError *error) +{ + DBusTransport *transport; + DBusConnection *connection; + + transport = _dbus_transport_open (entry, error); + + if (transport == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return NULL; + } + + connection = _dbus_connection_new_for_transport (transport); + + _dbus_transport_unref (transport); + + if (connection == NULL) + { + _DBUS_SET_OOM (error); + return NULL; + } + +#ifndef DBUS_DISABLE_CHECKS + _dbus_assert (!connection->have_connection_lock); +#endif + return connection; +} + +/* + * If the shared parameter is true, then any existing connection will + * be used (and if a new connection is created, it will be available + * for use by others). If the shared parameter is false, a new + * connection will always be created, and the new connection will + * never be returned to other callers. + * + * @param address the address + * @param shared whether the connection is shared or private + * @param error error return + * @returns the connection or #NULL on error + */ +static DBusConnection* +_dbus_connection_open_internal (const char *address, + dbus_bool_t shared, + DBusError *error) +{ + DBusConnection *connection; + DBusAddressEntry **entries; + DBusError tmp_error = DBUS_ERROR_INIT; + DBusError first_error = DBUS_ERROR_INIT; + int len, i; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + _dbus_verbose ("opening %s connection to: %s\n", + shared ? "shared" : "private", address); + + if (!dbus_parse_address (address, &entries, &len, error)) + return NULL; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + connection = NULL; + + for (i = 0; i < len; i++) + { + if (shared) + { + if (!connection_lookup_shared (entries[i], &connection)) + _DBUS_SET_OOM (&tmp_error); + } + + if (connection == NULL) + { + connection = connection_try_from_address_entry (entries[i], + &tmp_error); + + if (connection != NULL && shared) + { + const char *guid; + + connection->shareable = TRUE; + + /* guid may be NULL */ + guid = dbus_address_entry_get_value (entries[i], "guid"); + + CONNECTION_LOCK (connection); + + if (!connection_record_shared_unlocked (connection, guid)) + { + _DBUS_SET_OOM (&tmp_error); + _dbus_connection_close_possibly_shared_and_unlock (connection); + dbus_connection_unref (connection); + connection = NULL; + } + else + CONNECTION_UNLOCK (connection); + } + } + + if (connection) + break; + + _DBUS_ASSERT_ERROR_IS_SET (&tmp_error); + + if (i == 0) + dbus_move_error (&tmp_error, &first_error); + else + dbus_error_free (&tmp_error); + } + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error); + + if (connection == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (&first_error); + dbus_move_error (&first_error, error); + } + else + dbus_error_free (&first_error); + + dbus_address_entries_free (entries); + return connection; +} + +/** + * Closes a shared OR private connection, while dbus_connection_close() can + * only be used on private connections. Should only be called by the + * dbus code that owns the connection - an owner must be known, + * the open/close state is like malloc/free, not like ref/unref. + * + * @param connection the connection + */ +void +_dbus_connection_close_possibly_shared (DBusConnection *connection) +{ + _dbus_assert (connection != NULL); + _dbus_assert (connection->generation == _dbus_current_generation); + + CONNECTION_LOCK (connection); + _dbus_connection_close_possibly_shared_and_unlock (connection); +} + +static DBusPreallocatedSend* +_dbus_connection_preallocate_send_unlocked (DBusConnection *connection) +{ + DBusPreallocatedSend *preallocated; + + HAVE_LOCK_CHECK (connection); + + _dbus_assert (connection != NULL); + + preallocated = dbus_new (DBusPreallocatedSend, 1); + if (preallocated == NULL) + return NULL; + + preallocated->queue_link = _dbus_list_alloc_link (NULL); + if (preallocated->queue_link == NULL) + goto failed_0; + + preallocated->counter_link = _dbus_list_alloc_link (connection->outgoing_counter); + if (preallocated->counter_link == NULL) + goto failed_1; + + _dbus_counter_ref (preallocated->counter_link->data); + + preallocated->connection = connection; + + return preallocated; + + failed_1: + _dbus_list_free_link (preallocated->queue_link); + failed_0: + dbus_free (preallocated); + + return NULL; +} + +/* Called with lock held, does not update dispatch status */ +static void +_dbus_connection_send_preallocated_unlocked_no_update (DBusConnection *connection, + DBusPreallocatedSend *preallocated, + DBusMessage *message, + dbus_uint32_t *client_serial) +{ + dbus_uint32_t serial; + + preallocated->queue_link->data = message; + _dbus_list_prepend_link (&connection->outgoing_messages, + preallocated->queue_link); + + /* It's OK that we'll never call the notify function, because for the + * outgoing limit, there isn't one */ + _dbus_message_add_counter_link (message, + preallocated->counter_link); + + dbus_free (preallocated); + preallocated = NULL; + + dbus_message_ref (message); + + connection->n_outgoing += 1; + + _dbus_verbose ("Message %p (%s %s %s %s '%s') for %s added to outgoing queue %p, %d pending to send\n", + message, + dbus_message_type_to_string (dbus_message_get_type (message)), + dbus_message_get_path (message) ? + dbus_message_get_path (message) : + "no path", + dbus_message_get_interface (message) ? + dbus_message_get_interface (message) : + "no interface", + dbus_message_get_member (message) ? + dbus_message_get_member (message) : + "no member", + dbus_message_get_signature (message), + dbus_message_get_destination (message) ? + dbus_message_get_destination (message) : + "null", + connection, + connection->n_outgoing); + + if (dbus_message_get_serial (message) == 0) + { + serial = _dbus_connection_get_next_client_serial (connection); + dbus_message_set_serial (message, serial); + if (client_serial) + *client_serial = serial; + } + else + { + if (client_serial) + *client_serial = dbus_message_get_serial (message); + } + + _dbus_verbose ("Message %p serial is %u\n", + message, dbus_message_get_serial (message)); + + dbus_message_lock (message); + + /* Now we need to run an iteration to hopefully just write the messages + * out immediately, and otherwise get them queued up + */ + _dbus_connection_do_iteration_unlocked (connection, + NULL, + DBUS_ITERATION_DO_WRITING, + -1); + + /* If stuff is still queued up, be sure we wake up the main loop */ + if (connection->n_outgoing > 0) + _dbus_connection_wakeup_mainloop (connection); +} + +static void +_dbus_connection_send_preallocated_and_unlock (DBusConnection *connection, + DBusPreallocatedSend *preallocated, + DBusMessage *message, + dbus_uint32_t *client_serial) +{ + DBusDispatchStatus status; + + HAVE_LOCK_CHECK (connection); + + _dbus_connection_send_preallocated_unlocked_no_update (connection, + preallocated, + message, client_serial); + + _dbus_verbose ("middle\n"); + status = _dbus_connection_get_dispatch_status_unlocked (connection); + + /* this calls out to user code */ + _dbus_connection_update_dispatch_status_and_unlock (connection, status); +} + +/** + * Like dbus_connection_send(), but assumes the connection + * is already locked on function entry, and unlocks before returning. + * + * @param connection the connection + * @param message the message to send + * @param client_serial return location for client serial of sent message + * @returns #FALSE on out-of-memory + */ +dbus_bool_t +_dbus_connection_send_and_unlock (DBusConnection *connection, + DBusMessage *message, + dbus_uint32_t *client_serial) +{ + DBusPreallocatedSend *preallocated; + + _dbus_assert (connection != NULL); + _dbus_assert (message != NULL); + + preallocated = _dbus_connection_preallocate_send_unlocked (connection); + if (preallocated == NULL) + { + CONNECTION_UNLOCK (connection); + return FALSE; + } + + _dbus_connection_send_preallocated_and_unlock (connection, + preallocated, + message, + client_serial); + return TRUE; +} + +/** + * Used internally to handle the semantics of dbus_server_set_new_connection_function(). + * If the new connection function does not ref the connection, we want to close it. + * + * A bit of a hack, probably the new connection function should have returned a value + * for whether to close, or should have had to close the connection itself if it + * didn't want it. + * + * But, this works OK as long as the new connection function doesn't do anything + * crazy like keep the connection around without ref'ing it. + * + * We have to lock the connection across refcount check and close in case + * the new connection function spawns a thread that closes and unrefs. + * In that case, if the app thread + * closes and unrefs first, we'll harmlessly close again; if the app thread + * still has the ref, we'll close and then the app will close harmlessly. + * If the app unrefs without closing, the app is broken since if the + * app refs from the new connection function it is supposed to also close. + * + * If we didn't atomically check the refcount and close with the lock held + * though, we could screw this up. + * + * @param connection the connection + */ +void +_dbus_connection_close_if_only_one_ref (DBusConnection *connection) +{ + dbus_int32_t refcount; + + CONNECTION_LOCK (connection); + + refcount = _dbus_atomic_get (&connection->refcount); + /* The caller should have at least one ref */ + _dbus_assert (refcount >= 1); + + if (refcount == 1) + _dbus_connection_close_possibly_shared_and_unlock (connection); + else + CONNECTION_UNLOCK (connection); +} + + +/** + * When a function that blocks has been called with a timeout, and we + * run out of memory, the time to wait for memory is based on the + * timeout. If the caller was willing to block a long time we wait a + * relatively long time for memory, if they were only willing to block + * briefly then we retry for memory at a rapid rate. + * + * @param timeout_milliseconds the timeout requested for blocking + */ +static void +_dbus_memory_pause_based_on_timeout (int timeout_milliseconds) +{ + if (timeout_milliseconds == -1) + _dbus_sleep_milliseconds (1000); + else if (timeout_milliseconds < 100) + ; /* just busy loop */ + else if (timeout_milliseconds <= 1000) + _dbus_sleep_milliseconds (timeout_milliseconds / 3); + else + _dbus_sleep_milliseconds (1000); +} + +static DBusMessage * +generate_local_error_message (dbus_uint32_t serial, + char *error_name, + char *error_msg) +{ + DBusMessage *message; + message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR); + if (!message) + goto out; + + if (!dbus_message_set_error_name (message, error_name)) + { + dbus_message_unref (message); + message = NULL; + goto out; + } + + dbus_message_set_no_reply (message, TRUE); + + if (!dbus_message_set_reply_serial (message, + serial)) + { + dbus_message_unref (message); + message = NULL; + goto out; + } + + if (error_msg != NULL) + { + DBusMessageIter iter; + + dbus_message_iter_init_append (message, &iter); + if (!dbus_message_iter_append_basic (&iter, + DBUS_TYPE_STRING, + &error_msg)) + { + dbus_message_unref (message); + message = NULL; + goto out; + } + } + + out: + return message; +} + +/* + * Peek the incoming queue to see if we got reply for a specific serial + */ +static dbus_bool_t +_dbus_connection_peek_for_reply_unlocked (DBusConnection *connection, + dbus_uint32_t client_serial) +{ + DBusList *link; + HAVE_LOCK_CHECK (connection); + + link = _dbus_list_get_first_link (&connection->incoming_messages); + + while (link != NULL) + { + DBusMessage *reply = link->data; + + if (dbus_message_get_reply_serial (reply) == client_serial) + { + _dbus_verbose ("%s reply to %d found in queue\n", _DBUS_FUNCTION_NAME, client_serial); + return TRUE; + } + link = _dbus_list_get_next_link (&connection->incoming_messages, link); + } + + return FALSE; +} + +/* This is slightly strange since we can pop a message here without + * the dispatch lock. + */ +static DBusMessage* +check_for_reply_unlocked (DBusConnection *connection, + dbus_uint32_t client_serial) +{ + DBusList *link; + + HAVE_LOCK_CHECK (connection); + + link = _dbus_list_get_first_link (&connection->incoming_messages); + + while (link != NULL) + { + DBusMessage *reply = link->data; + + if (dbus_message_get_reply_serial (reply) == client_serial) + { + _dbus_list_remove_link (&connection->incoming_messages, link); + connection->n_incoming -= 1; + return reply; + } + link = _dbus_list_get_next_link (&connection->incoming_messages, link); + } + + return NULL; +} + +static void +connection_timeout_and_complete_all_pending_calls_unlocked (DBusConnection *connection) +{ + /* We can't iterate over the hash in the normal way since we'll be + * dropping the lock for each item. So we restart the + * iter each time as we drain the hash table. + */ + + while (_dbus_hash_table_get_n_entries (connection->pending_replies) > 0) + { + DBusPendingCall *pending; + DBusHashIter iter; + + _dbus_hash_iter_init (connection->pending_replies, &iter); + _dbus_hash_iter_next (&iter); + + pending = _dbus_hash_iter_get_value (&iter); + _dbus_pending_call_ref_unlocked (pending); + + _dbus_pending_call_queue_timeout_error_unlocked (pending, + connection); + + if (_dbus_pending_call_is_timeout_added_unlocked (pending)) + _dbus_connection_remove_timeout_unlocked (connection, + _dbus_pending_call_get_timeout_unlocked (pending)); + _dbus_pending_call_set_timeout_added_unlocked (pending, FALSE); + _dbus_hash_iter_remove_entry (&iter); + + _dbus_pending_call_unref_and_unlock (pending); + CONNECTION_LOCK (connection); + } + HAVE_LOCK_CHECK (connection); +} + +static void +complete_pending_call_and_unlock (DBusConnection *connection, + DBusPendingCall *pending, + DBusMessage *message) +{ + _dbus_pending_call_set_reply_unlocked (pending, message); + _dbus_pending_call_ref_unlocked (pending); /* in case there's no app with a ref held */ + _dbus_connection_detach_pending_call_and_unlock (connection, pending); + + /* Must be called unlocked since it invokes app callback */ + _dbus_pending_call_complete (pending); + dbus_pending_call_unref (pending); +} + +static dbus_bool_t +check_for_reply_and_update_dispatch_unlocked (DBusConnection *connection, + DBusPendingCall *pending) +{ + DBusMessage *reply; + DBusDispatchStatus status; + + reply = check_for_reply_unlocked (connection, + _dbus_pending_call_get_reply_serial_unlocked (pending)); + if (reply != NULL) + { + _dbus_verbose ("checked for reply\n"); + + _dbus_verbose ("dbus_connection_send_with_reply_and_block(): got reply\n"); + + complete_pending_call_and_unlock (connection, pending, reply); + dbus_message_unref (reply); + + CONNECTION_LOCK (connection); + status = _dbus_connection_get_dispatch_status_unlocked (connection); + _dbus_connection_update_dispatch_status_and_unlock (connection, status); + dbus_pending_call_unref (pending); + + return TRUE; + } + + return FALSE; +} + +/** + * Blocks until a pending call times out or gets a reply. + * + * Does not re-enter the main loop or run filter/path-registered + * callbacks. The reply to the message will not be seen by + * filter callbacks. + * + * Returns immediately if pending call already got a reply. + * + * @todo could use performance improvements (it keeps scanning + * the whole message queue for example) + * + * @param pending the pending call we block for a reply on + */ +void +_dbus_connection_block_pending_call (DBusPendingCall *pending) +{ + long start_tv_sec, start_tv_usec; + long tv_sec, tv_usec; + DBusDispatchStatus status; + DBusConnection *connection; + dbus_uint32_t client_serial; + DBusTimeout *timeout; + int timeout_milliseconds, elapsed_milliseconds; + + _dbus_assert (pending != NULL); + + if (dbus_pending_call_get_completed (pending)) + return; + + dbus_pending_call_ref (pending); /* necessary because the call could be canceled */ + + connection = _dbus_pending_call_get_connection_and_lock (pending); + + /* Flush message queue - note, can affect dispatch status */ + _dbus_connection_flush_unlocked (connection); + + client_serial = _dbus_pending_call_get_reply_serial_unlocked (pending); + + /* note that timeout_milliseconds is limited to a smallish value + * in _dbus_pending_call_new() so overflows aren't possible + * below + */ + timeout = _dbus_pending_call_get_timeout_unlocked (pending); + _dbus_get_monotonic_time (&start_tv_sec, &start_tv_usec); + if (timeout) + { + timeout_milliseconds = dbus_timeout_get_interval (timeout); + + _dbus_verbose ("dbus_connection_send_with_reply_and_block(): will block %d milliseconds for reply serial %u from %ld sec %ld usec\n", + timeout_milliseconds, + client_serial, + start_tv_sec, start_tv_usec); + } + else + { + timeout_milliseconds = -1; + + _dbus_verbose ("dbus_connection_send_with_reply_and_block(): will block for reply serial %u\n", client_serial); + } + + /* check to see if we already got the data off the socket */ + /* from another blocked pending call */ + if (check_for_reply_and_update_dispatch_unlocked (connection, pending)) + return; + + /* Now we wait... */ + /* always block at least once as we know we don't have the reply yet */ + _dbus_connection_do_iteration_unlocked (connection, + pending, + DBUS_ITERATION_DO_READING | + DBUS_ITERATION_BLOCK, + timeout_milliseconds); + + recheck_status: + + _dbus_verbose ("top of recheck\n"); + + HAVE_LOCK_CHECK (connection); + + /* queue messages and get status */ + + status = _dbus_connection_get_dispatch_status_unlocked (connection); + + /* the get_completed() is in case a dispatch() while we were blocking + * got the reply instead of us. + */ + if (_dbus_pending_call_get_completed_unlocked (pending)) + { + _dbus_verbose ("Pending call completed by dispatch\n"); + _dbus_connection_update_dispatch_status_and_unlock (connection, status); + dbus_pending_call_unref (pending); + return; + } + + if (status == DBUS_DISPATCH_DATA_REMAINS) + { + if (check_for_reply_and_update_dispatch_unlocked (connection, pending)) + return; + } + + _dbus_get_monotonic_time (&tv_sec, &tv_usec); + elapsed_milliseconds = (tv_sec - start_tv_sec) * 1000 + + (tv_usec - start_tv_usec) / 1000; + + if (!_dbus_connection_get_is_connected_unlocked (connection)) + { + DBusMessage *error_msg; + + error_msg = generate_local_error_message (client_serial, + DBUS_ERROR_DISCONNECTED, + "Connection was disconnected before a reply was received"); + + /* on OOM error_msg is set to NULL */ + complete_pending_call_and_unlock (connection, pending, error_msg); + dbus_pending_call_unref (pending); + return; + } + else if (connection->disconnect_message_link == NULL) + _dbus_verbose ("dbus_connection_send_with_reply_and_block(): disconnected\n"); + else if (timeout == NULL) + { + if (status == DBUS_DISPATCH_NEED_MEMORY) + { + /* Try sleeping a bit, as we aren't sure we need to block for reading, + * we may already have a reply in the buffer and just can't process + * it. + */ + _dbus_verbose ("dbus_connection_send_with_reply_and_block() waiting for more memory\n"); + + _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds); + } + else + { + /* block again, we don't have the reply buffered yet. */ + _dbus_connection_do_iteration_unlocked (connection, + pending, + DBUS_ITERATION_DO_READING | + DBUS_ITERATION_BLOCK, + timeout_milliseconds - elapsed_milliseconds); + } + + goto recheck_status; + } + else if (tv_sec < start_tv_sec) + _dbus_verbose ("dbus_connection_send_with_reply_and_block(): clock set backward\n"); + else if (elapsed_milliseconds < timeout_milliseconds) + { + _dbus_verbose ("dbus_connection_send_with_reply_and_block(): %d milliseconds remain\n", timeout_milliseconds - elapsed_milliseconds); + + if (status == DBUS_DISPATCH_NEED_MEMORY) + { + /* Try sleeping a bit, as we aren't sure we need to block for reading, + * we may already have a reply in the buffer and just can't process + * it. + */ + _dbus_verbose ("dbus_connection_send_with_reply_and_block() waiting for more memory\n"); + + _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds); + } + else + { + /* block again, we don't have the reply buffered yet. */ + _dbus_connection_do_iteration_unlocked (connection, + NULL, + DBUS_ITERATION_DO_READING | + DBUS_ITERATION_BLOCK, + timeout_milliseconds - elapsed_milliseconds); + } + + goto recheck_status; + } + + _dbus_verbose ("dbus_connection_send_with_reply_and_block(): Waited %d milliseconds and got no reply\n", + elapsed_milliseconds); + + _dbus_assert (!_dbus_pending_call_get_completed_unlocked (pending)); + + /* unlock and call user code */ + complete_pending_call_and_unlock (connection, pending, NULL); + + /* update user code on dispatch status */ + CONNECTION_LOCK (connection); + status = _dbus_connection_get_dispatch_status_unlocked (connection); + _dbus_connection_update_dispatch_status_and_unlock (connection, status); + dbus_pending_call_unref (pending); +} + +/** + * Return how many file descriptors are pending in the loader + * + * @param connection the connection + */ +int +_dbus_connection_get_pending_fds_count (DBusConnection *connection) +{ + return _dbus_transport_get_pending_fds_count (connection->transport); +} + +/** + * Register a function to be called whenever the number of pending file + * descriptors in the loader change. + * + * @param connection the connection + * @param callback the callback + */ +void +_dbus_connection_set_pending_fds_function (DBusConnection *connection, + DBusPendingFdsChangeFunction callback, + void *data) +{ + _dbus_transport_set_pending_fds_function (connection->transport, + callback, data); +} + +/** @} */ + +/** + * @addtogroup DBusConnection + * + * @{ + */ + +/** + * Gets a connection to a remote address. If a connection to the given + * address already exists, returns the existing connection with its + * reference count incremented. Otherwise, returns a new connection + * and saves the new connection for possible re-use if a future call + * to dbus_connection_open() asks to connect to the same server. + * + * Use dbus_connection_open_private() to get a dedicated connection + * not shared with other callers of dbus_connection_open(). + * + * If the open fails, the function returns #NULL, and provides a + * reason for the failure in the error parameter. Pass #NULL for the + * error parameter if you aren't interested in the reason for + * failure. + * + * Because this connection is shared, no user of the connection + * may call dbus_connection_close(). However, when you are done with the + * connection you should call dbus_connection_unref(). + * + * @note Prefer dbus_connection_open() to dbus_connection_open_private() + * unless you have good reason; connections are expensive enough + * that it's wasteful to create lots of connections to the same + * server. + * + * @param address the address. + * @param error address where an error can be returned. + * @returns new connection, or #NULL on failure. + */ +DBusConnection* +dbus_connection_open (const char *address, + DBusError *error) +{ + DBusConnection *connection; + + _dbus_return_val_if_fail (address != NULL, NULL); + _dbus_return_val_if_error_is_set (error, NULL); + + connection = _dbus_connection_open_internal (address, + TRUE, + error); + + return connection; +} + +/** + * Opens a new, dedicated connection to a remote address. Unlike + * dbus_connection_open(), always creates a new connection. + * This connection will not be saved or recycled by libdbus. + * + * If the open fails, the function returns #NULL, and provides a + * reason for the failure in the error parameter. Pass #NULL for the + * error parameter if you aren't interested in the reason for + * failure. + * + * When you are done with this connection, you must + * dbus_connection_close() to disconnect it, + * and dbus_connection_unref() to free the connection object. + * + * (The dbus_connection_close() can be skipped if the + * connection is already known to be disconnected, for example + * if you are inside a handler for the Disconnected signal.) + * + * @note Prefer dbus_connection_open() to dbus_connection_open_private() + * unless you have good reason; connections are expensive enough + * that it's wasteful to create lots of connections to the same + * server. + * + * @param address the address. + * @param error address where an error can be returned. + * @returns new connection, or #NULL on failure. + */ +DBusConnection* +dbus_connection_open_private (const char *address, + DBusError *error) +{ + DBusConnection *connection; + + _dbus_return_val_if_fail (address != NULL, NULL); + _dbus_return_val_if_error_is_set (error, NULL); + + connection = _dbus_connection_open_internal (address, + FALSE, + error); + + return connection; +} + +/** + * Increments the reference count of a DBusConnection. + * + * @param connection the connection. + * @returns the connection. + */ +DBusConnection * +dbus_connection_ref (DBusConnection *connection) +{ + dbus_int32_t old_refcount; + + _dbus_return_val_if_fail (connection != NULL, NULL); + _dbus_return_val_if_fail (connection->generation == _dbus_current_generation, NULL); + old_refcount = _dbus_atomic_inc (&connection->refcount); + _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1, + "ref"); + + return connection; +} + +static void +free_outgoing_message (void *element, + void *data) +{ + DBusMessage *message = element; + DBusConnection *connection = data; + + _dbus_message_remove_counter (message, connection->outgoing_counter); + dbus_message_unref (message); +} + +/* This is run without the mutex held, but after the last reference + * to the connection has been dropped we should have no thread-related + * problems + */ +static void +_dbus_connection_last_unref (DBusConnection *connection) +{ + DBusList *link; + + _dbus_verbose ("Finalizing connection %p\n", connection); + + _dbus_assert (_dbus_atomic_get (&connection->refcount) == 0); + + /* You have to disconnect the connection before unref:ing it. Otherwise + * you won't get the disconnected message. + */ + _dbus_assert (!_dbus_transport_get_is_connected (connection->transport)); + _dbus_assert (connection->server_guid == NULL); + + /* ---- We're going to call various application callbacks here, hope it doesn't break anything... */ + _dbus_object_tree_free_all_unlocked (connection->objects); + + dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL); + dbus_connection_set_wakeup_main_function (connection, NULL, NULL, NULL); + dbus_connection_set_unix_user_function (connection, NULL, NULL, NULL); + dbus_connection_set_windows_user_function (connection, NULL, NULL, NULL); + + _dbus_watch_list_free (connection->watches); + connection->watches = NULL; + + _dbus_timeout_list_free (connection->timeouts); + connection->timeouts = NULL; + + _dbus_data_slot_list_free (&connection->slot_list); + + link = _dbus_list_get_first_link (&connection->filter_list); + while (link != NULL) + { + DBusMessageFilter *filter = link->data; + DBusList *next = _dbus_list_get_next_link (&connection->filter_list, link); + + filter->function = NULL; + _dbus_message_filter_unref (filter); /* calls app callback */ + link->data = NULL; + + link = next; + } + _dbus_list_clear (&connection->filter_list); + + /* ---- Done with stuff that invokes application callbacks */ + + _dbus_object_tree_unref (connection->objects); + + _dbus_hash_table_unref (connection->pending_replies); + connection->pending_replies = NULL; + + _dbus_list_clear (&connection->filter_list); + + _dbus_list_foreach (&connection->outgoing_messages, + free_outgoing_message, + connection); + _dbus_list_clear (&connection->outgoing_messages); + + _dbus_list_foreach (&connection->incoming_messages, + (DBusForeachFunction) dbus_message_unref, + NULL); + _dbus_list_clear (&connection->incoming_messages); + + _dbus_counter_unref (connection->outgoing_counter); + + _dbus_transport_unref (connection->transport); + + if (connection->disconnect_message_link) + { + DBusMessage *message = connection->disconnect_message_link->data; + dbus_message_unref (message); + _dbus_list_free_link (connection->disconnect_message_link); + } + + _dbus_condvar_free_at_location (&connection->dispatch_cond); + _dbus_condvar_free_at_location (&connection->io_path_cond); + + _dbus_cmutex_free_at_location (&connection->io_path_mutex); + _dbus_cmutex_free_at_location (&connection->dispatch_mutex); + + _dbus_rmutex_free_at_location (&connection->slot_mutex); + + _dbus_rmutex_free_at_location (&connection->mutex); + + dbus_free (connection); +} + +/** + * Decrements the reference count of a DBusConnection, and finalizes + * it if the count reaches zero. + * + * Note: it is a bug to drop the last reference to a connection that + * is still connected. + * + * For shared connections, libdbus will own a reference + * as long as the connection is connected, so you can know that either + * you don't have the last reference, or it's OK to drop the last reference. + * Most connections are shared. dbus_connection_open() and dbus_bus_get() + * return shared connections. + * + * For private connections, the creator of the connection must arrange for + * dbus_connection_close() to be called prior to dropping the last reference. + * Private connections come from dbus_connection_open_private() or dbus_bus_get_private(). + * + * @param connection the connection. + */ +void +dbus_connection_unref (DBusConnection *connection) +{ + dbus_int32_t old_refcount; + + _dbus_return_if_fail (connection != NULL); + _dbus_return_if_fail (connection->generation == _dbus_current_generation); + + old_refcount = _dbus_atomic_dec (&connection->refcount); + + _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1, + "unref"); + + if (old_refcount == 1) + { +#ifndef DBUS_DISABLE_CHECKS + if (_dbus_transport_get_is_connected (connection->transport)) + { + _dbus_warn_check_failed ("The last reference on a connection was dropped without closing the connection. This is a bug in an application. See dbus_connection_unref() documentation for details.\n%s", + connection->shareable ? + "Most likely, the application called unref() too many times and removed a reference belonging to libdbus, since this is a shared connection.\n" : + "Most likely, the application was supposed to call dbus_connection_close(), since this is a private connection.\n"); + return; + } +#endif + _dbus_connection_last_unref (connection); + } +} + +/* + * Note that the transport can disconnect itself (other end drops us) + * and in that case this function never runs. So this function must + * not do anything more than disconnect the transport and update the + * dispatch status. + * + * If the transport self-disconnects, then we assume someone will + * dispatch the connection to cause the dispatch status update. + */ +static void +_dbus_connection_close_possibly_shared_and_unlock (DBusConnection *connection) +{ + DBusDispatchStatus status; + + HAVE_LOCK_CHECK (connection); + + _dbus_verbose ("Disconnecting %p\n", connection); + + /* We need to ref because update_dispatch_status_and_unlock will unref + * the connection if it was shared and libdbus was the only remaining + * refcount holder. + */ + _dbus_connection_ref_unlocked (connection); + + _dbus_transport_disconnect (connection->transport); + + /* This has the side effect of queuing the disconnect message link + * (unless we don't have enough memory, possibly, so don't assert it). + * After the disconnect message link is queued, dbus_bus_get/dbus_connection_open + * should never again return the newly-disconnected connection. + * + * However, we only unref the shared connection and exit_on_disconnect when + * the disconnect message reaches the head of the message queue, + * NOT when it's first queued. + */ + status = _dbus_connection_get_dispatch_status_unlocked (connection); + + /* This calls out to user code */ + _dbus_connection_update_dispatch_status_and_unlock (connection, status); + + /* Could also call out to user code */ + dbus_connection_unref (connection); +} + +/** + * Closes a private connection, so no further data can be sent or received. + * This disconnects the transport (such as a socket) underlying the + * connection. + * + * Attempts to send messages after closing a connection are safe, but will result in + * error replies generated locally in libdbus. + * + * This function does not affect the connection's reference count. It's + * safe to close a connection more than once; all calls after the + * first do nothing. It's impossible to "reopen" a connection, a + * new connection must be created. This function may result in a call + * to the DBusDispatchStatusFunction set with + * dbus_connection_set_dispatch_status_function(), as the disconnect + * message it generates needs to be dispatched. + * + * If a connection is dropped by the remote application, it will + * close itself. + * + * You must close a connection prior to releasing the last reference to + * the connection. If you dbus_connection_unref() for the last time + * without closing the connection, the results are undefined; it + * is a bug in your program and libdbus will try to print a warning. + * + * You may not close a shared connection. Connections created with + * dbus_connection_open() or dbus_bus_get() are shared. + * These connections are owned by libdbus, and applications should + * only unref them, never close them. Applications can know it is + * safe to unref these connections because libdbus will be holding a + * reference as long as the connection is open. Thus, either the + * connection is closed and it is OK to drop the last reference, + * or the connection is open and the app knows it does not have the + * last reference. + * + * Connections created with dbus_connection_open_private() or + * dbus_bus_get_private() are not kept track of or referenced by + * libdbus. The creator of these connections is responsible for + * calling dbus_connection_close() prior to releasing the last + * reference, if the connection is not already disconnected. + * + * @param connection the private (unshared) connection to close + */ +void +dbus_connection_close (DBusConnection *connection) +{ + _dbus_return_if_fail (connection != NULL); + _dbus_return_if_fail (connection->generation == _dbus_current_generation); + + CONNECTION_LOCK (connection); + +#ifndef DBUS_DISABLE_CHECKS + if (connection->shareable) + { + CONNECTION_UNLOCK (connection); + + _dbus_warn_check_failed ("Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.\n"); + return; + } +#endif + + _dbus_connection_close_possibly_shared_and_unlock (connection); +} + +static dbus_bool_t +_dbus_connection_get_is_connected_unlocked (DBusConnection *connection) +{ + HAVE_LOCK_CHECK (connection); + return _dbus_transport_get_is_connected (connection->transport); +} + +/** + * Gets whether the connection is currently open. A connection may + * become disconnected when the remote application closes its end, or + * exits; a connection may also be disconnected with + * dbus_connection_close(). + * + * There are not separate states for "closed" and "disconnected," the two + * terms are synonymous. This function should really be called + * get_is_open() but for historical reasons is not. + * + * @param connection the connection. + * @returns #TRUE if the connection is still alive. + */ +dbus_bool_t +dbus_connection_get_is_connected (DBusConnection *connection) +{ + dbus_bool_t res; + + _dbus_return_val_if_fail (connection != NULL, FALSE); + + CONNECTION_LOCK (connection); + res = _dbus_connection_get_is_connected_unlocked (connection); + CONNECTION_UNLOCK (connection); + + return res; +} + +/** + * Gets whether the connection was authenticated. (Note that + * if the connection was authenticated then disconnected, + * this function still returns #TRUE) + * + * @param connection the connection + * @returns #TRUE if the connection was ever authenticated + */ +dbus_bool_t +dbus_connection_get_is_authenticated (DBusConnection *connection) +{ + dbus_bool_t res; + + _dbus_return_val_if_fail (connection != NULL, FALSE); + + CONNECTION_LOCK (connection); + res = _dbus_transport_try_to_authenticate (connection->transport); + CONNECTION_UNLOCK (connection); + + return res; +} + +/** + * Gets whether the connection is not authenticated as a specific + * user. If the connection is not authenticated, this function + * returns #TRUE, and if it is authenticated but as an anonymous user, + * it returns #TRUE. If it is authenticated as a specific user, then + * this returns #FALSE. (Note that if the connection was authenticated + * as anonymous then disconnected, this function still returns #TRUE.) + * + * If the connection is not anonymous, you can use + * dbus_connection_get_unix_user() and + * dbus_connection_get_windows_user() to see who it's authorized as. + * + * If you want to prevent non-anonymous authorization, use + * dbus_server_set_auth_mechanisms() to remove the mechanisms that + * allow proving user identity (i.e. only allow the ANONYMOUS + * mechanism). + * + * @param connection the connection + * @returns #TRUE if not authenticated or authenticated as anonymous + */ +dbus_bool_t +dbus_connection_get_is_anonymous (DBusConnection *connection) +{ + dbus_bool_t res; + + _dbus_return_val_if_fail (connection != NULL, FALSE); + + CONNECTION_LOCK (connection); + res = _dbus_transport_get_is_anonymous (connection->transport); + CONNECTION_UNLOCK (connection); + + return res; +} + +/** + * Gets the ID of the server address we are authenticated to, if this + * connection is on the client side. If the connection is on the + * server side, this will always return #NULL - use dbus_server_get_id() + * to get the ID of your own server, if you are the server side. + * + * If a client-side connection is not authenticated yet, the ID may be + * available if it was included in the server address, but may not be + * available. The only way to be sure the server ID is available + * is to wait for authentication to complete. + * + * In general, each mode of connecting to a given server will have + * its own ID. So for example, if the session bus daemon is listening + * on UNIX domain sockets and on TCP, then each of those modalities + * will have its own server ID. + * + * If you want an ID that identifies an entire session bus, look at + * dbus_bus_get_id() instead (which is just a convenience wrapper + * around the org.freedesktop.DBus.GetId method invoked on the bus). + * + * You can also get a machine ID; see dbus_get_local_machine_id() to + * get the machine you are on. There isn't a convenience wrapper, but + * you can invoke org.freedesktop.DBus.Peer.GetMachineId on any peer + * to get the machine ID on the other end. + * + * The D-Bus specification describes the server ID and other IDs in a + * bit more detail. + * + * @param connection the connection + * @returns the server ID or #NULL if no memory or the connection is server-side + */ +char* +dbus_connection_get_server_id (DBusConnection *connection) +{ + char *id; + + _dbus_return_val_if_fail (connection != NULL, NULL); + + CONNECTION_LOCK (connection); + id = _dbus_strdup (_dbus_transport_get_server_id (connection->transport)); + CONNECTION_UNLOCK (connection); + + return id; +} + +/** + * Tests whether a certain type can be send via the connection. This + * will always return TRUE for all types, with the exception of + * DBUS_TYPE_UNIX_FD. The function will return TRUE for + * DBUS_TYPE_UNIX_FD only on systems that know Unix file descriptors + * and can send them via the chosen transport and when the remote side + * supports this. + * + * This function can be used to do runtime checking for types that + * might be unknown to the specific D-Bus client implementation + * version, i.e. it will return FALSE for all types this + * implementation does not know, including invalid or reserved types. + * + * @param connection the connection + * @param type the type to check + * @returns TRUE if the type may be send via the connection + */ +dbus_bool_t +dbus_connection_can_send_type(DBusConnection *connection, + int type) +{ + _dbus_return_val_if_fail (connection != NULL, FALSE); + + if (!dbus_type_is_valid (type)) + return FALSE; + + if (type != DBUS_TYPE_UNIX_FD) + return TRUE; + +#ifdef HAVE_UNIX_FD_PASSING + { + dbus_bool_t b; + + CONNECTION_LOCK(connection); + b = _dbus_transport_can_pass_unix_fd(connection->transport); + CONNECTION_UNLOCK(connection); + + return b; + } +#endif + + return FALSE; +} + +/** + * Set whether _exit() should be called when the connection receives a + * disconnect signal. The call to _exit() comes after any handlers for + * the disconnect signal run; handlers can cancel the exit by calling + * this function. + * + * By default, exit_on_disconnect is #FALSE; but for message bus + * connections returned from dbus_bus_get() it will be toggled on + * by default. + * + * @param connection the connection + * @param exit_on_disconnect #TRUE if _exit() should be called after a disconnect signal + */ +void +dbus_connection_set_exit_on_disconnect (DBusConnection *connection, + dbus_bool_t exit_on_disconnect) +{ + _dbus_return_if_fail (connection != NULL); + + CONNECTION_LOCK (connection); + connection->exit_on_disconnect = exit_on_disconnect != FALSE; + CONNECTION_UNLOCK (connection); +} + +/** + * Preallocates resources needed to send a message, allowing the message + * to be sent without the possibility of memory allocation failure. + * Allows apps to create a future guarantee that they can send + * a message regardless of memory shortages. + * + * @param connection the connection we're preallocating for. + * @returns the preallocated resources, or #NULL + */ +DBusPreallocatedSend* +dbus_connection_preallocate_send (DBusConnection *connection) +{ + DBusPreallocatedSend *preallocated; + + _dbus_return_val_if_fail (connection != NULL, NULL); + + CONNECTION_LOCK (connection); + + preallocated = + _dbus_connection_preallocate_send_unlocked (connection); + + CONNECTION_UNLOCK (connection); + + return preallocated; +} + +/** + * Frees preallocated message-sending resources from + * dbus_connection_preallocate_send(). Should only + * be called if the preallocated resources are not used + * to send a message. + * + * @param connection the connection + * @param preallocated the resources + */ +void +dbus_connection_free_preallocated_send (DBusConnection *connection, + DBusPreallocatedSend *preallocated) +{ + _dbus_return_if_fail (connection != NULL); + _dbus_return_if_fail (preallocated != NULL); + _dbus_return_if_fail (connection == preallocated->connection); + + _dbus_list_free_link (preallocated->queue_link); + _dbus_counter_unref (preallocated->counter_link->data); + _dbus_list_free_link (preallocated->counter_link); + dbus_free (preallocated); +} + +/** + * Sends a message using preallocated resources. This function cannot fail. + * It works identically to dbus_connection_send() in other respects. + * Preallocated resources comes from dbus_connection_preallocate_send(). + * This function "consumes" the preallocated resources, they need not + * be freed separately. + * + * @param connection the connection + * @param preallocated the preallocated resources + * @param message the message to send + * @param client_serial return location for client serial assigned to the message + */ +void +dbus_connection_send_preallocated (DBusConnection *connection, + DBusPreallocatedSend *preallocated, + DBusMessage *message, + dbus_uint32_t *client_serial) +{ + _dbus_return_if_fail (connection != NULL); + _dbus_return_if_fail (preallocated != NULL); + _dbus_return_if_fail (message != NULL); + _dbus_return_if_fail (preallocated->connection == connection); + _dbus_return_if_fail (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL || + dbus_message_get_member (message) != NULL); + _dbus_return_if_fail (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL || + (dbus_message_get_interface (message) != NULL && + dbus_message_get_member (message) != NULL)); + + CONNECTION_LOCK (connection); + +#ifdef HAVE_UNIX_FD_PASSING + + if (!_dbus_transport_can_pass_unix_fd(connection->transport) && + message->n_unix_fds > 0) + { + /* Refuse to send fds on a connection that cannot handle + them. Unfortunately we cannot return a proper error here, so + the best we can is just return. */ + CONNECTION_UNLOCK (connection); + return; + } + +#endif + + _dbus_connection_send_preallocated_and_unlock (connection, + preallocated, + message, client_serial); +} + +static dbus_bool_t +_dbus_connection_send_unlocked_no_update (DBusConnection *connection, + DBusMessage *message, + dbus_uint32_t *client_serial) +{ + DBusPreallocatedSend *preallocated; + + _dbus_assert (connection != NULL); + _dbus_assert (message != NULL); + + preallocated = _dbus_connection_preallocate_send_unlocked (connection); + if (preallocated == NULL) + return FALSE; + + _dbus_connection_send_preallocated_unlocked_no_update (connection, + preallocated, + message, + client_serial); + return TRUE; +} + +/** + * Adds a message to the outgoing message queue. Does not block to + * write the message to the network; that happens asynchronously. To + * force the message to be written, call dbus_connection_flush() however + * it is not necessary to call dbus_connection_flush() by hand; the + * message will be sent the next time the main loop is run. + * dbus_connection_flush() should only be used, for example, if + * the application was expected to exit before running the main loop. + * + * Because this only queues the message, the only reason it can + * fail is lack of memory. Even if the connection is disconnected, + * no error will be returned. If the function fails due to lack of memory, + * it returns #FALSE. The function will never fail for other reasons; even + * if the connection is disconnected, you can queue an outgoing message, + * though obviously it won't be sent. + * + * The message serial is used by the remote application to send a + * reply; see dbus_message_get_serial() or the D-Bus specification. + * + * dbus_message_unref() can be called as soon as this method returns + * as the message queue will hold its own ref until the message is sent. + * + * @param connection the connection. + * @param message the message to write. + * @param serial return location for message serial, or #NULL if you don't care + * @returns #TRUE on success. + */ +dbus_bool_t +dbus_connection_send (DBusConnection *connection, + DBusMessage *message, + dbus_uint32_t *serial) +{ + _dbus_return_val_if_fail (connection != NULL, FALSE); + _dbus_return_val_if_fail (message != NULL, FALSE); + + CONNECTION_LOCK (connection); + +#ifdef HAVE_UNIX_FD_PASSING + + if (!_dbus_transport_can_pass_unix_fd(connection->transport) && + message->n_unix_fds > 0) + { + /* Refuse to send fds on a connection that cannot handle + them. Unfortunately we cannot return a proper error here, so + the best we can is just return. */ + CONNECTION_UNLOCK (connection); + return FALSE; + } + +#endif + + return _dbus_connection_send_and_unlock (connection, + message, + serial); +} + +static dbus_bool_t +reply_handler_timeout (void *data) +{ + DBusConnection *connection; + DBusDispatchStatus status; + DBusPendingCall *pending = data; + + connection = _dbus_pending_call_get_connection_and_lock (pending); + _dbus_connection_ref_unlocked (connection); + + _dbus_pending_call_queue_timeout_error_unlocked (pending, + connection); + _dbus_connection_remove_timeout_unlocked (connection, + _dbus_pending_call_get_timeout_unlocked (pending)); + _dbus_pending_call_set_timeout_added_unlocked (pending, FALSE); + + _dbus_verbose ("middle\n"); + status = _dbus_connection_get_dispatch_status_unlocked (connection); + + /* Unlocks, and calls out to user code */ + _dbus_connection_update_dispatch_status_and_unlock (connection, status); + dbus_connection_unref (connection); + + return TRUE; +} + +/** + * Queues a message to send, as with dbus_connection_send(), + * but also returns a #DBusPendingCall used to receive a reply to the + * message. If no reply is received in the given timeout_milliseconds, + * this function expires the pending reply and generates a synthetic + * error reply (generated in-process, not by the remote application) + * indicating that a timeout occurred. + * + * A #DBusPendingCall will see a reply message before any filters or + * registered object path handlers. See dbus_connection_dispatch() for + * details on when handlers are run. + * + * A #DBusPendingCall will always see exactly one reply message, + * unless it's cancelled with dbus_pending_call_cancel(). + * + * If #NULL is passed for the pending_return, the #DBusPendingCall + * will still be generated internally, and used to track + * the message reply timeout. This means a timeout error will + * occur if no reply arrives, unlike with dbus_connection_send(). + * + * If -1 is passed for the timeout, a sane default timeout is used. -1 + * is typically the best value for the timeout for this reason, unless + * you want a very short or very long timeout. If #DBUS_TIMEOUT_INFINITE is + * passed for the timeout, no timeout will be set and the call will block + * forever. + * + * @warning if the connection is disconnected or you try to send Unix + * file descriptors on a connection that does not support them, the + * #DBusPendingCall will be set to #NULL, so be careful with this. + * + * @param connection the connection + * @param message the message to send + * @param pending_return return location for a #DBusPendingCall + * object, or #NULL if connection is disconnected or when you try to + * send Unix file descriptors on a connection that does not support + * them. + * @param timeout_milliseconds timeout in milliseconds, -1 (or + * #DBUS_TIMEOUT_USE_DEFAULT) for default or #DBUS_TIMEOUT_INFINITE for no + * timeout + * @returns #FALSE if no memory, #TRUE otherwise. + * + */ +dbus_bool_t +dbus_connection_send_with_reply (DBusConnection *connection, + DBusMessage *message, + DBusPendingCall **pending_return, + int timeout_milliseconds) +{ + DBusPendingCall *pending; + dbus_int32_t serial = -1; + DBusDispatchStatus status; + + _dbus_return_val_if_fail (connection != NULL, FALSE); + _dbus_return_val_if_fail (message != NULL, FALSE); + _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1, FALSE); + + if (pending_return) + *pending_return = NULL; + + CONNECTION_LOCK (connection); + +#ifdef HAVE_UNIX_FD_PASSING + + if (!_dbus_transport_can_pass_unix_fd(connection->transport) && + message->n_unix_fds > 0) + { + /* Refuse to send fds on a connection that cannot handle + them. Unfortunately we cannot return a proper error here, so + the best we can do is return TRUE but leave *pending_return + as NULL. */ + CONNECTION_UNLOCK (connection); + return TRUE; + } + +#endif + + if (!_dbus_connection_get_is_connected_unlocked (connection)) + { + CONNECTION_UNLOCK (connection); + + return TRUE; + } + + pending = _dbus_pending_call_new_unlocked (connection, + timeout_milliseconds, + reply_handler_timeout); + + if (pending == NULL) + { + CONNECTION_UNLOCK (connection); + return FALSE; + } + + /* Assign a serial to the message */ + serial = dbus_message_get_serial (message); + if (serial == 0) + { + serial = _dbus_connection_get_next_client_serial (connection); + dbus_message_set_serial (message, serial); + } + + if (!_dbus_pending_call_set_timeout_error_unlocked (pending, message, serial)) + goto error; + + /* Insert the serial in the pending replies hash; + * hash takes a refcount on DBusPendingCall. + * Also, add the timeout. + */ + if (!_dbus_connection_attach_pending_call_unlocked (connection, + pending)) + goto error; + + if (!_dbus_connection_send_unlocked_no_update (connection, message, NULL)) + { + _dbus_connection_detach_pending_call_and_unlock (connection, + pending); + goto error_unlocked; + } + + if (pending_return) + *pending_return = pending; /* hand off refcount */ + else + { + _dbus_connection_detach_pending_call_unlocked (connection, pending); + /* we still have a ref to the pending call in this case, we unref + * after unlocking, below + */ + } + + status = _dbus_connection_get_dispatch_status_unlocked (connection); + + /* this calls out to user code */ + _dbus_connection_update_dispatch_status_and_unlock (connection, status); + + if (pending_return == NULL) + dbus_pending_call_unref (pending); + + return TRUE; + + error: + CONNECTION_UNLOCK (connection); + error_unlocked: + dbus_pending_call_unref (pending); + return FALSE; +} + +/** + * Sends a message and blocks a certain time period while waiting for + * a reply. This function does not reenter the main loop, + * i.e. messages other than the reply are queued up but not + * processed. This function is used to invoke method calls on a + * remote object. + * + * If a normal reply is received, it is returned, and removed from the + * incoming message queue. If it is not received, #NULL is returned + * and the error is set to #DBUS_ERROR_NO_REPLY. If an error reply is + * received, it is converted to a #DBusError and returned as an error, + * then the reply message is deleted and #NULL is returned. If + * something else goes wrong, result is set to whatever is + * appropriate, such as #DBUS_ERROR_NO_MEMORY or + * #DBUS_ERROR_DISCONNECTED. + * + * @warning While this function blocks the calling thread will not be + * processing the incoming message queue. This means you can end up + * deadlocked if the application you're talking to needs you to reply + * to a method. To solve this, either avoid the situation, block in a + * separate thread from the main connection-dispatching thread, or use + * dbus_pending_call_set_notify() to avoid blocking. + * + * @param connection the connection + * @param message the message to send + * @param timeout_milliseconds timeout in milliseconds, -1 (or + * #DBUS_TIMEOUT_USE_DEFAULT) for default or #DBUS_TIMEOUT_INFINITE for no + * timeout + * @param error return location for error message + * @returns the message that is the reply or #NULL with an error code if the + * function fails. + */ +DBusMessage* +dbus_connection_send_with_reply_and_block (DBusConnection *connection, + DBusMessage *message, + int timeout_milliseconds, + DBusError *error) +{ + DBusMessage *reply; + DBusPendingCall *pending; + + _dbus_return_val_if_fail (connection != NULL, NULL); + _dbus_return_val_if_fail (message != NULL, NULL); + _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1, NULL); + _dbus_return_val_if_error_is_set (error, NULL); + +#ifdef HAVE_UNIX_FD_PASSING + + CONNECTION_LOCK (connection); + if (!_dbus_transport_can_pass_unix_fd(connection->transport) && + message->n_unix_fds > 0) + { + CONNECTION_UNLOCK (connection); + dbus_set_error(error, DBUS_ERROR_FAILED, "Cannot send file descriptors on this connection."); + return NULL; + } + CONNECTION_UNLOCK (connection); + +#endif + + if (!dbus_connection_send_with_reply (connection, message, + &pending, timeout_milliseconds)) + { + _DBUS_SET_OOM (error); + return NULL; + } + + if (pending == NULL) + { + dbus_set_error (error, DBUS_ERROR_DISCONNECTED, "Connection is closed"); + return NULL; + } + + dbus_pending_call_block (pending); + + reply = dbus_pending_call_steal_reply (pending); + dbus_pending_call_unref (pending); + + /* call_complete_and_unlock() called from pending_call_block() should + * always fill this in. + */ + _dbus_assert (reply != NULL); + + if (dbus_set_error_from_message (error, reply)) + { + dbus_message_unref (reply); + return NULL; + } + else + return reply; +} + +/** + * Blocks until the outgoing message queue is empty. + * Assumes connection lock already held. + * + * If you call this, you MUST call update_dispatch_status afterword... + * + * @param connection the connection. + */ +static DBusDispatchStatus +_dbus_connection_flush_unlocked (DBusConnection *connection) +{ + /* We have to specify DBUS_ITERATION_DO_READING here because + * otherwise we could have two apps deadlock if they are both doing + * a flush(), and the kernel buffers fill up. This could change the + * dispatch status. + */ + DBusDispatchStatus status; + + HAVE_LOCK_CHECK (connection); + + while (connection->n_outgoing > 0 && + _dbus_connection_get_is_connected_unlocked (connection)) + { + _dbus_verbose ("doing iteration in\n"); + HAVE_LOCK_CHECK (connection); + _dbus_connection_do_iteration_unlocked (connection, + NULL, + DBUS_ITERATION_DO_READING | + DBUS_ITERATION_DO_WRITING | + DBUS_ITERATION_BLOCK, + -1); + } + + HAVE_LOCK_CHECK (connection); + _dbus_verbose ("middle\n"); + status = _dbus_connection_get_dispatch_status_unlocked (connection); + + HAVE_LOCK_CHECK (connection); + return status; +} + +/** + * Blocks until the outgoing message queue is empty. + * + * @param connection the connection. + */ +void +dbus_connection_flush (DBusConnection *connection) +{ + /* We have to specify DBUS_ITERATION_DO_READING here because + * otherwise we could have two apps deadlock if they are both doing + * a flush(), and the kernel buffers fill up. This could change the + * dispatch status. + */ + DBusDispatchStatus status; + + _dbus_return_if_fail (connection != NULL); + + CONNECTION_LOCK (connection); + + status = _dbus_connection_flush_unlocked (connection); + + HAVE_LOCK_CHECK (connection); + /* Unlocks and calls out to user code */ + _dbus_connection_update_dispatch_status_and_unlock (connection, status); + + _dbus_verbose ("end\n"); +} + +/** + * This function implements dbus_connection_read_write_dispatch() and + * dbus_connection_read_write() (they pass a different value for the + * dispatch parameter). + * + * @param connection the connection + * @param timeout_milliseconds max time to block or -1 for infinite + * @param dispatch dispatch new messages or leave them on the incoming queue + * @returns #TRUE if the disconnect message has not been processed + */ +static dbus_bool_t +_dbus_connection_read_write_dispatch (DBusConnection *connection, + int timeout_milliseconds, + dbus_bool_t dispatch) +{ + DBusDispatchStatus dstatus; + dbus_bool_t progress_possible; + + /* Need to grab a ref here in case we're a private connection and + * the user drops the last ref in a handler we call; see bug + * https://bugs.freedesktop.org/show_bug.cgi?id=15635 + */ + dbus_connection_ref (connection); + dstatus = dbus_connection_get_dispatch_status (connection); + + if (dispatch && dstatus == DBUS_DISPATCH_DATA_REMAINS) + { + _dbus_verbose ("doing dispatch\n"); + dbus_connection_dispatch (connection); + CONNECTION_LOCK (connection); + } + else if (dstatus == DBUS_DISPATCH_NEED_MEMORY) + { + _dbus_verbose ("pausing for memory\n"); + _dbus_memory_pause_based_on_timeout (timeout_milliseconds); + CONNECTION_LOCK (connection); + } + else + { + CONNECTION_LOCK (connection); + if (_dbus_connection_get_is_connected_unlocked (connection)) + { + _dbus_verbose ("doing iteration\n"); + _dbus_connection_do_iteration_unlocked (connection, + NULL, + DBUS_ITERATION_DO_READING | + DBUS_ITERATION_DO_WRITING | + DBUS_ITERATION_BLOCK, + timeout_milliseconds); + } + } + + HAVE_LOCK_CHECK (connection); + /* If we can dispatch, we can make progress until the Disconnected message + * has been processed; if we can only read/write, we can make progress + * as long as the transport is open. + */ + if (dispatch) + progress_possible = connection->n_incoming != 0 || + connection->disconnect_message_link != NULL; + else + progress_possible = _dbus_connection_get_is_connected_unlocked (connection); + + CONNECTION_UNLOCK (connection); + + dbus_connection_unref (connection); + + return progress_possible; /* TRUE if we can make more progress */ +} + + +/** + * This function is intended for use with applications that don't want + * to write a main loop and deal with #DBusWatch and #DBusTimeout. An + * example usage would be: + * + * @code + * while (dbus_connection_read_write_dispatch (connection, -1)) + * ; // empty loop body + * @endcode + * + * In this usage you would normally have set up a filter function to look + * at each message as it is dispatched. The loop terminates when the last + * message from the connection (the disconnected signal) is processed. + * + * If there are messages to dispatch, this function will + * dbus_connection_dispatch() once, and return. If there are no + * messages to dispatch, this function will block until it can read or + * write, then read or write, then return. + * + * The way to think of this function is that it either makes some sort + * of progress, or it blocks. Note that, while it is blocked on I/O, it + * cannot be interrupted (even by other threads), which makes this function + * unsuitable for applications that do more than just react to received + * messages. + * + * The return value indicates whether the disconnect message has been + * processed, NOT whether the connection is connected. This is + * important because even after disconnecting, you want to process any + * messages you received prior to the disconnect. + * + * @param connection the connection + * @param timeout_milliseconds max time to block or -1 for infinite + * @returns #TRUE if the disconnect message has not been processed + */ +dbus_bool_t +dbus_connection_read_write_dispatch (DBusConnection *connection, + int timeout_milliseconds) +{ + _dbus_return_val_if_fail (connection != NULL, FALSE); + _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1, FALSE); + return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds, TRUE); +} + +/** + * This function is intended for use with applications that don't want to + * write a main loop and deal with #DBusWatch and #DBusTimeout. See also + * dbus_connection_read_write_dispatch(). + * + * As long as the connection is open, this function will block until it can + * read or write, then read or write, then return #TRUE. + * + * If the connection is closed, the function returns #FALSE. + * + * The return value indicates whether reading or writing is still + * possible, i.e. whether the connection is connected. + * + * Note that even after disconnection, messages may remain in the + * incoming queue that need to be + * processed. dbus_connection_read_write_dispatch() dispatches + * incoming messages for you; with dbus_connection_read_write() you + * have to arrange to drain the incoming queue yourself. + * + * @param connection the connection + * @param timeout_milliseconds max time to block or -1 for infinite + * @returns #TRUE if still connected + */ +dbus_bool_t +dbus_connection_read_write (DBusConnection *connection, + int timeout_milliseconds) +{ + _dbus_return_val_if_fail (connection != NULL, FALSE); + _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1, FALSE); + return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds, FALSE); +} + +/* We need to call this anytime we pop the head of the queue, and then + * update_dispatch_status_and_unlock needs to be called afterward + * which will "process" the disconnected message and set + * disconnected_message_processed. + */ +static void +check_disconnected_message_arrived_unlocked (DBusConnection *connection, + DBusMessage *head_of_queue) +{ + HAVE_LOCK_CHECK (connection); + + /* checking that the link is NULL is an optimization to avoid the is_signal call */ + if (connection->disconnect_message_link == NULL && + dbus_message_is_signal (head_of_queue, + DBUS_INTERFACE_LOCAL, + "Disconnected")) + { + connection->disconnected_message_arrived = TRUE; + } +} + +/** + * Returns the first-received message from the incoming message queue, + * leaving it in the queue. If the queue is empty, returns #NULL. + * + * The caller does not own a reference to the returned message, and + * must either return it using dbus_connection_return_message() or + * keep it after calling dbus_connection_steal_borrowed_message(). No + * one can get at the message while its borrowed, so return it as + * quickly as possible and don't keep a reference to it after + * returning it. If you need to keep the message, make a copy of it. + * + * dbus_connection_dispatch() will block if called while a borrowed + * message is outstanding; only one piece of code can be playing with + * the incoming queue at a time. This function will block if called + * during a dbus_connection_dispatch(). + * + * @param connection the connection. + * @returns next message in the incoming queue. + */ +DBusMessage* +dbus_connection_borrow_message (DBusConnection *connection) +{ + DBusDispatchStatus status; + DBusMessage *message; + + _dbus_return_val_if_fail (connection != NULL, NULL); + + _dbus_verbose ("start\n"); + + /* this is called for the side effect that it queues + * up any messages from the transport + */ + status = dbus_connection_get_dispatch_status (connection); + if (status != DBUS_DISPATCH_DATA_REMAINS) + return NULL; + + CONNECTION_LOCK (connection); + + _dbus_connection_acquire_dispatch (connection); + + /* While a message is outstanding, the dispatch lock is held */ + _dbus_assert (connection->message_borrowed == NULL); + + connection->message_borrowed = _dbus_list_get_first (&connection->incoming_messages); + + message = connection->message_borrowed; + + check_disconnected_message_arrived_unlocked (connection, message); + + /* Note that we KEEP the dispatch lock until the message is returned */ + if (message == NULL) + _dbus_connection_release_dispatch (connection); + + CONNECTION_UNLOCK (connection); + + _dbus_message_trace_ref (message, -1, -1, "dbus_connection_borrow_message"); + + /* We don't update dispatch status until it's returned or stolen */ + + return message; +} + +/** + * Used to return a message after peeking at it using + * dbus_connection_borrow_message(). Only called if + * message from dbus_connection_borrow_message() was non-#NULL. + * + * @param connection the connection + * @param message the message from dbus_connection_borrow_message() + */ +void +dbus_connection_return_message (DBusConnection *connection, + DBusMessage *message) +{ + DBusDispatchStatus status; + + _dbus_return_if_fail (connection != NULL); + _dbus_return_if_fail (message != NULL); + _dbus_return_if_fail (message == connection->message_borrowed); + _dbus_return_if_fail (connection->dispatch_acquired); + + CONNECTION_LOCK (connection); + + _dbus_assert (message == connection->message_borrowed); + + connection->message_borrowed = NULL; + + _dbus_connection_release_dispatch (connection); + + status = _dbus_connection_get_dispatch_status_unlocked (connection); + _dbus_connection_update_dispatch_status_and_unlock (connection, status); + + _dbus_message_trace_ref (message, -1, -1, "dbus_connection_return_message"); +} + +/** + * Used to keep a message after peeking at it using + * dbus_connection_borrow_message(). Before using this function, see + * the caveats/warnings in the documentation for + * dbus_connection_pop_message(). + * + * @param connection the connection + * @param message the message from dbus_connection_borrow_message() + */ +void +dbus_connection_steal_borrowed_message (DBusConnection *connection, + DBusMessage *message) +{ + DBusMessage *pop_message; + DBusDispatchStatus status; + + _dbus_return_if_fail (connection != NULL); + _dbus_return_if_fail (message != NULL); + _dbus_return_if_fail (message == connection->message_borrowed); + _dbus_return_if_fail (connection->dispatch_acquired); + + CONNECTION_LOCK (connection); + + _dbus_assert (message == connection->message_borrowed); + + pop_message = _dbus_list_pop_first (&connection->incoming_messages); + _dbus_assert (message == pop_message); + (void) pop_message; /* unused unless asserting */ + + connection->n_incoming -= 1; + + _dbus_verbose ("Incoming message %p stolen from queue, %d incoming\n", + message, connection->n_incoming); + + connection->message_borrowed = NULL; + + _dbus_connection_release_dispatch (connection); + + status = _dbus_connection_get_dispatch_status_unlocked (connection); + _dbus_connection_update_dispatch_status_and_unlock (connection, status); + _dbus_message_trace_ref (message, -1, -1, + "dbus_connection_steal_borrowed_message"); +} + +/* See dbus_connection_pop_message, but requires the caller to own + * the lock before calling. May drop the lock while running. + */ +static DBusList* +_dbus_connection_pop_message_link_unlocked (DBusConnection *connection) +{ + HAVE_LOCK_CHECK (connection); + + _dbus_assert (connection->message_borrowed == NULL); + + if (connection->n_incoming > 0) + { + DBusList *link; + + link = _dbus_list_pop_first_link (&connection->incoming_messages); + connection->n_incoming -= 1; + + _dbus_verbose ("Message %p (%s %s %s %s sig:'%s' serial:%u) removed from incoming queue %p, %d incoming\n", + link->data, + dbus_message_type_to_string (dbus_message_get_type (link->data)), + dbus_message_get_path (link->data) ? + dbus_message_get_path (link->data) : + "no path", + dbus_message_get_interface (link->data) ? + dbus_message_get_interface (link->data) : + "no interface", + dbus_message_get_member (link->data) ? + dbus_message_get_member (link->data) : + "no member", + dbus_message_get_signature (link->data), + dbus_message_get_serial (link->data), + connection, connection->n_incoming); + + _dbus_message_trace_ref (link->data, -1, -1, + "_dbus_connection_pop_message_link_unlocked"); + + check_disconnected_message_arrived_unlocked (connection, link->data); + + return link; + } + else + return NULL; +} + +/* See dbus_connection_pop_message, but requires the caller to own + * the lock before calling. May drop the lock while running. + */ +static DBusMessage* +_dbus_connection_pop_message_unlocked (DBusConnection *connection) +{ + DBusList *link; + + HAVE_LOCK_CHECK (connection); + + link = _dbus_connection_pop_message_link_unlocked (connection); + + if (link != NULL) + { + DBusMessage *message; + + message = link->data; + + _dbus_list_free_link (link); + + return message; + } + else + return NULL; +} + +static void +_dbus_connection_putback_message_link_unlocked (DBusConnection *connection, + DBusList *message_link) +{ + HAVE_LOCK_CHECK (connection); + + _dbus_assert (message_link != NULL); + /* You can't borrow a message while a link is outstanding */ + _dbus_assert (connection->message_borrowed == NULL); + /* We had to have the dispatch lock across the pop/putback */ + _dbus_assert (connection->dispatch_acquired); + + _dbus_list_prepend_link (&connection->incoming_messages, + message_link); + connection->n_incoming += 1; + + _dbus_verbose ("Message %p (%s %s %s '%s') put back into queue %p, %d incoming\n", + message_link->data, + dbus_message_type_to_string (dbus_message_get_type (message_link->data)), + dbus_message_get_interface (message_link->data) ? + dbus_message_get_interface (message_link->data) : + "no interface", + dbus_message_get_member (message_link->data) ? + dbus_message_get_member (message_link->data) : + "no member", + dbus_message_get_signature (message_link->data), + connection, connection->n_incoming); + + _dbus_message_trace_ref (message_link->data, -1, -1, + "_dbus_connection_putback_message_link_unlocked"); +} + +/** + * Returns the first-received message from the incoming message queue, + * removing it from the queue. The caller owns a reference to the + * returned message. If the queue is empty, returns #NULL. + * + * This function bypasses any message handlers that are registered, + * and so using it is usually wrong. Instead, let the main loop invoke + * dbus_connection_dispatch(). Popping messages manually is only + * useful in very simple programs that don't share a #DBusConnection + * with any libraries or other modules. + * + * There is a lock that covers all ways of accessing the incoming message + * queue, so dbus_connection_dispatch(), dbus_connection_pop_message(), + * dbus_connection_borrow_message(), etc. will all block while one of the others + * in the group is running. + * + * @param connection the connection. + * @returns next message in the incoming queue. + */ +DBusMessage* +dbus_connection_pop_message (DBusConnection *connection) +{ + DBusMessage *message; + DBusDispatchStatus status; + + _dbus_verbose ("start\n"); + + /* this is called for the side effect that it queues + * up any messages from the transport + */ + status = dbus_connection_get_dispatch_status (connection); + if (status != DBUS_DISPATCH_DATA_REMAINS) + return NULL; + + CONNECTION_LOCK (connection); + _dbus_connection_acquire_dispatch (connection); + HAVE_LOCK_CHECK (connection); + + message = _dbus_connection_pop_message_unlocked (connection); + + _dbus_verbose ("Returning popped message %p\n", message); + + _dbus_connection_release_dispatch (connection); + + status = _dbus_connection_get_dispatch_status_unlocked (connection); + _dbus_connection_update_dispatch_status_and_unlock (connection, status); + + return message; +} + +/** + * Acquire the dispatcher. This is a separate lock so the main + * connection lock can be dropped to call out to application dispatch + * handlers. + * + * @param connection the connection. + */ +static void +_dbus_connection_acquire_dispatch (DBusConnection *connection) +{ + HAVE_LOCK_CHECK (connection); + + _dbus_connection_ref_unlocked (connection); + CONNECTION_UNLOCK (connection); + + _dbus_verbose ("locking dispatch_mutex\n"); + _dbus_cmutex_lock (connection->dispatch_mutex); + + while (connection->dispatch_acquired) + { + _dbus_verbose ("waiting for dispatch to be acquirable\n"); + _dbus_condvar_wait (connection->dispatch_cond, + connection->dispatch_mutex); + } + + _dbus_assert (!connection->dispatch_acquired); + + connection->dispatch_acquired = TRUE; + + _dbus_verbose ("unlocking dispatch_mutex\n"); + _dbus_cmutex_unlock (connection->dispatch_mutex); + + CONNECTION_LOCK (connection); + _dbus_connection_unref_unlocked (connection); +} + +/** + * Release the dispatcher when you're done with it. Only call + * after you've acquired the dispatcher. Wakes up at most one + * thread currently waiting to acquire the dispatcher. + * + * @param connection the connection. + */ +static void +_dbus_connection_release_dispatch (DBusConnection *connection) +{ + HAVE_LOCK_CHECK (connection); + + _dbus_verbose ("locking dispatch_mutex\n"); + _dbus_cmutex_lock (connection->dispatch_mutex); + + _dbus_assert (connection->dispatch_acquired); + + connection->dispatch_acquired = FALSE; + _dbus_condvar_wake_one (connection->dispatch_cond); + + _dbus_verbose ("unlocking dispatch_mutex\n"); + _dbus_cmutex_unlock (connection->dispatch_mutex); +} + +static void +_dbus_connection_failed_pop (DBusConnection *connection, + DBusList *message_link) +{ + _dbus_list_prepend_link (&connection->incoming_messages, + message_link); + connection->n_incoming += 1; +} + +/* Note this may be called multiple times since we don't track whether we already did it */