summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <david@fubar.dk>2006-03-08 01:52:03 +0000
committerDavid Zeuthen <david@fubar.dk>2006-03-08 01:52:03 +0000
commit9a089c64d4c3b16038ed3acb526102d861cc033c (patch)
treefaf4c8d62efe5ad245ed1a2a1c4aee08c5bbd401
downloadpolkit-9a089c64d4c3b16038ed3acb526102d861cc033c.tar.gz
Initial revision
-rw-r--r--AUTHORS1
-rw-r--r--COPYING551
-rw-r--r--ChangeLog4
-rw-r--r--HACKING16
-rw-r--r--Makefile.am13
-rw-r--r--NEWS9
-rw-r--r--README14
-rw-r--r--acinclude.m497
-rwxr-xr-xautogen.sh93
-rw-r--r--configure.in198
-rw-r--r--doc/Makefile.am7
-rw-r--r--doc/TODO2
-rw-r--r--doc/api/Makefile.am46
-rw-r--r--doc/api/polkit-docs.xml14
-rw-r--r--doc/api/tmpl/libpolkit.sgml357
-rw-r--r--doc/api/tmpl/polkit-unused.sgml0
-rw-r--r--gtk-doc.make153
-rw-r--r--libpolkit/Makefile.am39
-rw-r--r--libpolkit/libpolkit-test.c280
-rw-r--r--libpolkit/libpolkit.c836
-rw-r--r--libpolkit/libpolkit.h151
-rwxr-xr-xmkinstalldirs111
-rw-r--r--polkit.pc.in11
-rw-r--r--tools/Makefile.am20
-rw-r--r--tools/Makefile.in487
-rw-r--r--tools/polkit-is-privileged.c194
26 files changed, 3704 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..c686966
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+David Zeuthen <davidz@redhat.com>
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..df24a2f
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,551 @@
+libpolkit 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 individual source code files
+and/or binaries may be under the GPL only or under the LGPG.
+
+Each source code file is marked with the proper copyright information.
+
+
+
+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 St, 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 St, 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..f4fddf2
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,4 @@
+2006-03-07 David Zeuthen <davidz@redhat.com>
+
+ Initial check-in of PolicyKit
+
diff --git a/HACKING b/HACKING
new file mode 100644
index 0000000..039dc6a
--- /dev/null
+++ b/HACKING
@@ -0,0 +1,16 @@
+
+Coding Style
+===
+
+ - Please follow the coding style already used - it's not a must, but it's
+ nice to have consistency.
+
+ - Write docs for all functions and structs and so on.
+
+ - 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).
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..d0478bd
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,13 @@
+## Process this file with automake to produce Makefile.in
+
+SUBDIRS = libpolkit doc tools
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = polkit.pc
+
+DISTCLEANFILES = polkit.pc
+
+EXTRA_DIST = HACKING polkit.pc.in mkinstalldirs
+
+clean-local :
+ rm -f *~
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..43a464a
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,9 @@
+==========
+PolicyKit 0.1 ""
+==========
+
+WRITE ME
+
+Requirements for PolicyKit 0.1 "" (and CVS HEAD)
+
+ - glib >= 2.6.0
diff --git a/README b/README
new file mode 100644
index 0000000..3c03364
--- /dev/null
+++ b/README
@@ -0,0 +1,14 @@
+
+PolicyKit is a framework for defining policy for system-wide components and
+for desktop pieces to configure it. It is used by HAL.
+
+
+See also the file HACKING for notes of interest to developers working
+on PolicyKit.
+
+See http://www.freedesktop.org/Software/hal for lots of documentation,
+mailing lists, etc.
+
+
+
+
diff --git a/acinclude.m4 b/acinclude.m4
new file mode 100644
index 0000000..81ee816
--- /dev/null
+++ b/acinclude.m4
@@ -0,0 +1,97 @@
+
+dnl as-ac-expand.m4 0.1.0
+dnl autostars m4 macro for expanding directories using configure's prefix
+dnl thomas@apestaart.org
+
+dnl AS_AC_EXPAND(VAR, CONFIGURE_VAR)
+dnl
+dnl example
+dnl AS_AC_EXPAND(SYSCONFDIR, $sysconfdir)
+dnl will set SYSCONFDIR to /usr/local/etc if prefix=/usr/local
+
+AC_DEFUN([AS_AC_EXPAND],
+[
+ EXP_VAR=[$1]
+ FROM_VAR=[$2]
+
+ dnl first expand prefix and exec_prefix if necessary
+ prefix_save=$prefix
+ exec_prefix_save=$exec_prefix
+
+ dnl if no prefix given, then use /usr/local, the default prefix
+ if test "x$prefix" = "xNONE"; then
+ prefix=$ac_default_prefix
+ fi
+ dnl if no exec_prefix given, then use prefix
+ if test "x$exec_prefix" = "xNONE"; then
+ exec_prefix=$prefix
+ fi
+
+ full_var="$FROM_VAR"
+ dnl loop until it doesn't change anymore
+ while true; do
+ new_full_var="`eval echo $full_var`"
+ if test "x$new_full_var"="x$full_var"; then break; fi
+ full_var=$new_full_var
+ done
+
+ dnl clean up
+ full_var=$new_full_var
+ AC_SUBST([$1], "$full_var")
+
+ dnl restore prefix and exec_prefix
+ prefix=$prefix_save
+ exec_prefix=$exec_prefix_save
+])
+
+dnl GTK_DOC_CHECK borrowed from cairo, thanks!
+
+dnl Usage:
+dnl GTK_DOC_CHECK([minimum-gtk-doc-version])
+AC_DEFUN([GTK_DOC_CHECK],
+[
+ AC_BEFORE([AC_PROG_LIBTOOL],[$0])dnl setup libtool first
+ AC_BEFORE([AM_PROG_LIBTOOL],[$0])dnl setup libtool first
+ dnl for overriding the documentation installation directory
+ AC_ARG_WITH(html-dir,
+ AC_HELP_STRING([--with-html-dir=PATH], [path to installed docs]),,
+ [with_html_dir='${datadir}/gtk-doc/html'])
+ HTML_DIR="$with_html_dir"
+ AC_SUBST(HTML_DIR)
+
+ dnl enable/disable documentation building
+ AC_ARG_ENABLE(gtk-doc,
+ AC_HELP_STRING([--enable-gtk-doc],
+ [use gtk-doc to build documentation [default=yes]]),,
+ enable_gtk_doc=yes)
+
+ have_gtk_doc=no
+ if test x$enable_gtk_doc = xyes; then
+ if test -z "$PKG_CONFIG"; then
+ AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
+ fi
+ if test "$PKG_CONFIG" != "no" && $PKG_CONFIG --exists gtk-doc; then
+ have_gtk_doc=yes
+ fi
+
+ dnl do we want to do a version check?
+ifelse([$1],[],,
+ [gtk_doc_min_version=$1
+ if test "$have_gtk_doc" = yes; then
+ AC_MSG_CHECKING([gtk-doc version >= $gtk_doc_min_version])
+ if $PKG_CONFIG --atleast-version $gtk_doc_min_version gtk-doc; then
+ AC_MSG_RESULT(yes)
+ else
+ AC_MSG_RESULT(no)
+ have_gtk_doc=no
+ fi
+ fi
+])
+ if test "$have_gtk_doc" != yes; then
+ enable_gtk_doc=no
+ fi
+ fi
+
+ AM_CONDITIONAL(ENABLE_GTK_DOC, test x$enable_gtk_doc = xyes)
+ AM_CONDITIONAL(GTK_DOC_USE_LIBTOOL, test -n "$LIBTOOL")
+])
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..a9ab28c
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+# Run this to generate all the initial makefiles, etc.
+
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+DIE=0
+
+(test -f $srcdir/configure.in) || {
+ echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
+ echo " top-level package directory"
+ exit 1
+}
+
+(autoconf --version) < /dev/null > /dev/null 2>&1 || {
+ echo
+ echo "**Error**: You must have \`autoconf' installed."
+ echo "Download the appropriate package for your distribution,"
+ echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
+ DIE=1
+}
+
+(grep "^AM_PROG_LIBTOOL" $srcdir/configure.in >/dev/null) && {
+ (libtool --version) < /dev/null > /dev/null 2>&1 || {
+ echo
+ echo "**Error**: You must have \`libtool' installed."
+ echo "You can get it from: ftp://ftp.gnu.org/pub/gnu/"
+ DIE=1
+ }
+}
+
+(automake --version) < /dev/null > /dev/null 2>&1 || {
+ echo
+ echo "**Error**: You must have \`automake' installed."
+ echo "You can get it from: ftp://ftp.gnu.org/pub/gnu/"
+ DIE=1
+ NO_AUTOMAKE=yes
+}
+
+
+# if no automake, don't bother testing for aclocal
+test -n "$NO_AUTOMAKE" || (aclocal --version) < /dev/null > /dev/null 2>&1 || {
+ echo
+ echo "**Error**: Missing \`aclocal'. The version of \`automake'"
+ echo "installed doesn't appear recent enough."
+ echo "You can get automake from ftp://ftp.gnu.org/pub/gnu/"
+ DIE=1
+}
+
+if test "$DIE" -eq 1; then
+ exit 1
+fi
+
+if test -z "$*"; then
+ echo "**Warning**: I am going to run \`configure' with no arguments."
+ echo "If you wish to pass any to it, please specify them on the"
+ echo \`$0\'" command line."
+ echo
+fi
+
+case $CC in
+xlc )
+ am_opt=--include-deps;;
+esac
+
+ aclocalinclude="$ACLOCAL_FLAGS"
+
+ if grep "^AM_PROG_LIBTOOL" configure.in >/dev/null; then
+ if test -z "$NO_LIBTOOLIZE" ; then
+ echo "Running libtoolize..."
+ libtoolize --force --copy
+ fi
+ fi
+ echo "Running aclocal $aclocalinclude ..."
+ aclocal $aclocalinclude
+ if grep "^AM_CONFIG_HEADER" configure.in >/dev/null; then
+ echo "Running autoheader..."
+ autoheader
+ fi
+ echo "Running automake --gnu $am_opt ..."
+ automake --add-missing --gnu $am_opt
+ echo "Running autoconf ..."
+ autoconf
+
+conf_flags="--enable-maintainer-mode --enable-gtk-doc"
+
+if test x$NOCONFIGURE = x; then
+ echo Running $srcdir/configure $conf_flags "$@" ...
+ $srcdir/configure $conf_flags "$@" \
+ && echo Now type \`make\' to compile. || exit 1
+else
+ echo Skipping configure process.
+fi
diff --git a/configure.in b/configure.in
new file mode 100644
index 0000000..ecb3cb5
--- /dev/null
+++ b/configure.in
@@ -0,0 +1,198 @@
+dnl Process this file with autoconf to produce a configure script.
+
+AC_PREREQ(2.57)
+AC_INIT(PolicyKit, 0.1, david@fubar.dk)
+AM_INIT_AUTOMAKE(PolicyKit, 0.1)
+AM_CONFIG_HEADER(config.h)
+AM_MAINTAINER_MODE
+
+# libtool versioning - this applies to libpolkit
+#
+# See http://sources.redhat.com/autobook/autobook/autobook_91.html#SEC91 for details
+#
+LT_CURRENT=0
+LT_REVISION=0
+LT_AGE=0
+AC_SUBST(LT_CURRENT)
+AC_SUBST(LT_REVISION)
+AC_SUBST(LT_AGE)
+
+AC_ISC_POSIX
+AC_PROG_CC
+AM_PROG_CC_STDC
+AC_HEADER_STDC
+AM_PROG_LIBTOOL
+AC_PROG_MAKE_SET
+AC_PROG_LN_S
+AC_SYS_LARGEFILE
+
+AC_ARG_WITH(polkit_user,[ --with-polkit-user=<user> User for PolicyKit])
+if test -z "$with_polkit_user" ; then
+ POLKIT_USER=polkit
+else
+ POLKIT_USER=$with_polkit_user
+fi
+AC_SUBST(POLKIT_USER)
+AC_DEFINE_UNQUOTED(POLKIT_USER,"POLKIT_USER", [User for PolicyKit])
+
+AC_ARG_WITH(polkit_group,[ --with-hal-group=<grp> Group for PolicyKit])
+if test -z "$with_polkit_group" ; then
+ POLKIT_GROUP=polkit
+else
+ POLKIT_GROUP=$with_polkit_group
+fi
+AC_SUBST(POLKIT_GROUP)
+AC_DEFINE_UNQUOTED(POLKIT_GROUP,"$POLKIT_GROUP", [Group for PolicyKit])
+
+
+# Taken from dbus
+AC_ARG_ENABLE(ansi, [ --enable-ansi enable -ansi -pedantic gcc flags],enable_ansi=$enableval,enable_ansi=no)
+AC_ARG_ENABLE(verbose-mode, [ --enable-verbose-mode support verbose debug mode],enable_verbose_mode=$enableval,enable_verbose_mode=$USE_MAINTAINER_MODE)
+
+GTK_DOC_CHECK([1.3])
+
+#### gcc warning flags
+
+if test "x$GCC" = "xyes"; then
+ changequote(,)dnl
+ case " $CFLAGS " in
+ *[\ \ ]-Wall[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -Wall" ;;
+ esac
+
+ case " $CFLAGS " in
+ *[\ \ ]-Wchar-subscripts[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -Wchar-subscripts" ;;
+ esac
+
+ case " $CFLAGS " in
+ *[\ \ ]-Wmissing-declarations[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -Wmissing-declarations" ;;
+ esac
+
+ case " $CFLAGS " in
+ *[\ \ ]-Wnested-externs[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -Wnested-externs" ;;
+ esac
+
+ case " $CFLAGS " in
+ *[\ \ ]-Wpointer-arith[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -Wpointer-arith" ;;
+ esac
+
+ case " $CFLAGS " in
+ *[\ \ ]-Wcast-align[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -Wcast-align" ;;
+ esac
+
+ case " $CFLAGS " in
+ *[\ \ ]-Wsign-compare[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -Wsign-compare" ;;
+ esac
+
+ if test "x$enable_ansi" = "xyes"; then
+ case " $CFLAGS " in
+ *[\ \ ]-ansi[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -ansi" ;;
+ esac
+
+ case " $CFLAGS " in
+ *[\ \ ]-D_POSIX_C_SOURCE*) ;;
+ *) CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=199309L" ;;
+ esac
+
+ case " $CFLAGS " in
+ *[\ \ ]-D_BSD_SOURCE[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -D_BSD_SOURCE" ;;
+ esac
+
+ case " $CFLAGS " in
+ *[\ \ ]-pedantic[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -pedantic" ;;
+ esac
+ fi
+ if test x$enable_gcov = xyes; then
+ case " $CFLAGS " in
+ *[\ \ ]-fprofile-arcs[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -fprofile-arcs" ;;
+ esac
+ case " $CFLAGS " in
+ *[\ \ ]-ftest-coverage[\ \ ]*) ;;
+ *) CFLAGS="$CFLAGS -ftest-coverage" ;;
+ esac
+
+ ## remove optimization
+ CFLAGS=`echo "$CFLAGS" | sed -e 's/-O[0-9]*//g'`
+ fi
+ changequote([,])dnl
+else
+ if test x$enable_gcov = xyes; then
+ AC_MSG_ERROR([--enable-gcov can only be used with gcc])
+ fi
+fi
+
+AM_CONDITIONAL(GCOV, test x$enable_gcov = xyes)
+
+PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.6.0])
+AC_SUBST(GLIB_CFLAGS)
+AC_SUBST(GLIB_LIBS)
+
+AC_CHECK_FUNCS(getgrouplist)
+
+AS_AC_EXPAND(LOCALSTATEDIR, $localstatedir)
+AS_AC_EXPAND(SYSCONFDIR, $sysconfdir)
+AS_AC_EXPAND(DATADIR, $datadir)
+AS_AC_EXPAND(BINDIR, $bindir)
+AS_AC_EXPAND(SBINDIR, $sbindir)
+AS_AC_EXPAND(LIBDIR, $libdir)
+AS_AC_EXPAND(LIBEXECDIR, $libexecdir)
+
+# documentation target
+AC_ARG_WITH(doc-dir, [ --with-doc-dir=[dirname] directory to install documentation])
+if ! test -z "$with_doc_dir"; then
+ DOCDIR=$with_doc_dir
+else
+ DOCDIR="$DATADIR/doc/PolicyKit-$VERSION"
+fi
+
+AC_SUBST(DOCDIR)
+
+AC_OUTPUT([
+polkit.pc
+Makefile
+libpolkit/Makefile
+tools/Makefile
+doc/Makefile
+doc/api/Makefile
+])
+
+dnl ==========================================================================
+echo "
+ PolicyKit $VERSION
+ =================
+
+ prefix: ${prefix}
+ libdir: ${LIBDIR}
+ libexecdir: ${LIBEXECDIR}
+ bindir: ${BINDIR}
+ sbindir: ${SBINDIR}
+ datadir: ${DATADIR}
+ sysconfdir: ${SYSCONFDIR}
+ localstatedir: ${LOCALSTATEDIR}
+ docdir: ${DOCDIR}
+
+ compiler: ${CC}
+ cflags: ${CFLAGS}
+ cppflags: ${CPPFLAGS}
+ User for PolicyKit: ${POLKIT_USER}
+ Group for PolicyKit: ${POLKIT_GROUP}
+
+ Maintainer mode: ${USE_MAINTAINER_MODE}
+ Building verbose mode: ${enable_verbose_mode}
+ Building api docs: ${enable_gtk_doc}
+"
+
+
+echo "NOTE: Remember to create user ${POLKIT_USER} and group ${POLKIT_GROUP} before make install"
+echo
+
diff --git a/doc/Makefile.am b/doc/Makefile.am
new file mode 100644
index 0000000..a00fd34
--- /dev/null
+++ b/doc/Makefile.am
@@ -0,0 +1,7 @@
+
+EXTRA_DIST = TODO
+
+SUBDIRS = api
+
+clean-local:
+ rm -f *~
diff --git a/doc/TODO b/doc/TODO
new file mode 100644
index 0000000..6921cea
--- /dev/null
+++ b/doc/TODO
@@ -0,0 +1,2 @@
+
+TODO
diff --git a/doc/api/Makefile.am b/doc/api/Makefile.am
new file mode 100644
index 0000000..5b6818b
--- /dev/null
+++ b/doc/api/Makefile.am
@@ -0,0 +1,46 @@
+
+## Process this file with automake to create Makefile.in.
+
+AUTOMAKE_OPTIONS = 1.7
+
+# The name of the module.
+DOC_MODULE=polkit
+
+# The top-level SGML file.
+DOC_MAIN_SGML_FILE=polkit-docs.xml
+
+# Extra options to supply to gtkdoc-scan
+#SCAN_OPTIONS=--deprecated-guards="CAIRO_DISABLE_DEPRECATED"
+
+# The directory containing the source code. Relative to $(srcdir)
+DOC_SOURCE_DIR=../../libpolkit
+
+# Used for dependencies
+HFILE_GLOB=$(top_srcdir)/libpolkit/*.h
+CFILE_GLOB=$(top_srcdir)/libpolkit/*.c
+
+# Headers to ignore
+IGNORE_HFILES=
+
+# CFLAGS and LDFLAGS for compiling scan program. Only needed
+# if $(DOC_MODULE).types is non-empty.
+INCLUDES =
+GTKDOC_LIBS =
+
+# Extra options to supply to gtkdoc-mkdb
+MKDB_OPTIONS=--sgml-mode --output-format=xml
+
+# Extra options to supply to gtkdoc-mktmpl
+MKTMPL_OPTIONS=
+
+# Non-autogenerated SGML files to be included in $(DOC_MAIN_SGML_FILE)
+content_files =
+
+# Images to copy into HTML directory
+HTML_IMAGES =
+
+# Extra options to supply to gtkdoc-fixref
+FIXXREF_OPTIONS=
+
+include $(top_srcdir)/gtk-doc.make
+
diff --git a/doc/api/polkit-docs.xml b/doc/api/polkit-docs.xml
new file mode 100644
index 0000000..8fceb3b
--- /dev/null
+++ b/doc/api/polkit-docs.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+ "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
+<book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
+ <bookinfo>
+ <title>PolicyKit Reference Manual</title>
+ </bookinfo>
+
+ <chapter>
+ <title>Client library</title>
+ <xi:include href="xml/libpolkit.xml"/>
+ </chapter>
+
+</book>
diff --git a/doc/api/tmpl/libpolkit.sgml b/doc/api/tmpl/libpolkit.sgml
new file mode 100644
index 0000000..fda56c4
--- /dev/null
+++ b/doc/api/tmpl/libpolkit.sgml
@@ -0,0 +1,357 @@
+<!-- ##### SECTION Title ##### -->
+libpolkit
+
+<!-- ##### SECTION Short_Description ##### -->
+
+
+<!-- ##### SECTION Long_Description ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### SECTION See_Also ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### SECTION Stability_Level ##### -->
+
+
+<!-- ##### ENUM LibPolKitResult ##### -->
+<para>
+
+</para>
+
+@LIBPOLKIT_RESULT_OK:
+@LIBPOLKIT_RESULT_ERROR:
+@LIBPOLKIT_RESULT_INVALID_CONTEXT:
+@LIBPOLKIT_RESULT_PERMISSON_DENIED:
+@LIBPOLKIT_RESULT_NO_SUCH_POLICY:
+
+<!-- ##### STRUCT LibPolKitContext_s ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### TYPEDEF LibPolKitContext ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### ENUM LibPolKitElementType ##### -->
+<para>
+
+</para>
+
+@LIBPOLKIT_ELEMENT_TYPE_UID:
+@LIBPOLKIT_ELEMENT_TYPE_GID:
+
+<!-- ##### STRUCT LibPolKitElement_s ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### TYPEDEF LibPolKitElement ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### FUNCTION libpolkit_new_context ##### -->
+<para>
+
+</para>
+
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_context_set_txt_source ##### -->
+<para>
+
+</para>
+
+@ctx:
+@directory:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_free_context ##### -->
+<para>
+
+</para>
+
+@ctx:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_get_policies ##### -->
+<para>
+
+</para>
+
+@ctx:
+@result:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_is_uid_allowed_for_policy ##### -->
+<para>
+
+</para>
+
+@ctx:
+@uid:
+@policy:
+@resource:
+@result:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_is_uid_gid_allowed_for_policy ##### -->
+<para>
+
+</para>
+
+@ctx:
+@uid:
+@num_gids:
+@gid_list:
+@policy:
+@resource:
+@result:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_get_whitelist ##### -->
+<para>
+
+</para>
+
+@ctx:
+@policy:
+@result:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_get_blacklist ##### -->
+<para>
+
+</para>
+
+@ctx:
+@policy:
+@result:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_set_whitelist ##### -->
+<para>
+
+</para>
+
+@ctx:
+@policy:
+@whitelist:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_set_blacklist ##### -->
+<para>
+
+</para>
+
+@ctx:
+@policy:
+@blacklist:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_element_get_type ##### -->
+<para>
+
+</para>
+
+@elem:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_element_get_include_all ##### -->
+<para>
+
+</para>
+
+@elem:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_element_get_exclude_all ##### -->
+<para>
+
+</para>
+
+@elem:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_element_get_uid ##### -->
+<para>
+
+</para>
+
+@elem:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_element_get_gid ##### -->
+<para>
+
+</para>
+
+@elem:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_element_get_resource ##### -->
+<para>
+
+</para>
+
+@elem:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_element_new ##### -->
+<para>
+
+</para>
+
+@ctx:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_element_set_type ##### -->
+<para>
+
+</para>
+
+@elem:
+@type:
+
+
+<!-- ##### FUNCTION libpolkit_element_set_include_all ##### -->
+<para>
+
+</para>
+
+@elem:
+@value:
+
+
+<!-- ##### FUNCTION libpolkit_element_set_exclude_all ##### -->
+<para>
+
+</para>
+
+@elem:
+@value:
+
+
+<!-- ##### FUNCTION libpolkit_element_set_uid ##### -->
+<para>
+
+</para>
+
+@elem:
+@uid:
+
+
+<!-- ##### FUNCTION libpolkit_element_set_gid ##### -->
+<para>
+
+</para>
+
+@elem:
+@gid:
+
+
+<!-- ##### FUNCTION libpolkit_element_set_resource ##### -->
+<para>
+
+</para>
+
+@elem:
+@resource:
+
+
+<!-- ##### FUNCTION libpolkit_free_element ##### -->
+<para>
+
+</para>
+
+@elem:
+
+
+<!-- ##### FUNCTION libpolkit_free_element_list ##### -->
+<para>
+
+</para>
+
+@policy_element_list:
+
+
+<!-- ##### FUNCTION libpolkit_util_uid_to_name ##### -->
+<para>
+
+</para>
+
+@ctx:
+@uid:
+@default_gid:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_util_gid_to_name ##### -->
+<para>
+
+</para>
+
+@ctx:
+@gid:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_util_name_to_uid ##### -->
+<para>
+
+</para>
+
+@ctx:
+@username:
+@default_gid:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_util_name_to_gid ##### -->
+<para>
+
+</para>
+
+@ctx:
+@groupname:
+@Returns:
+
+
+<!-- ##### FUNCTION libpolkit_element_dump ##### -->
+<para>
+
+</para>
+
+@elem:
+@fp:
+
+
diff --git a/doc/api/tmpl/polkit-unused.sgml b/doc/api/tmpl/polkit-unused.sgml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/doc/api/tmpl/polkit-unused.sgml
diff --git a/gtk-doc.make b/gtk-doc.make
new file mode 100644
index 0000000..d50629a
--- /dev/null
+++ b/gtk-doc.make
@@ -0,0 +1,153 @@
+# -*- mode: makefile -*-
+
+####################################
+# Everything below here is generic #
+####################################
+
+if GTK_DOC_USE_LIBTOOL
+GTKDOC_CC = $(LIBTOOL) --mode=compile $(CC) $(INCLUDES) $(AM_CFLAGS) $(CFLAGS)
+GTKDOC_LD = $(LIBTOOL) --mode=link $(CC) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS)
+else
+GTKDOC_CC = $(CC) $(INCLUDES) $(AM_CFLAGS) $(CFLAGS)
+GTKDOC_LD = $(CC) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS)
+endif
+
+# We set GPATH here; this gives us semantics for GNU make
+# which are more like other make's VPATH, when it comes to
+# whether a source that is a target of one rule is then
+# searched for in VPATH/GPATH.
+#
+GPATH = $(srcdir)
+
+TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE)
+
+EXTRA_DIST = \
+ $(content_files) \
+ $(HTML_IMAGES) \
+ $(DOC_MAIN_SGML_FILE) \
+ $(DOC_MODULE)-sections.txt \
+ $(DOC_MODULE)-overrides.txt
+
+DOC_STAMPS=scan-build.stamp tmpl-build.stamp sgml-build.stamp html-build.stamp \
+ $(srcdir)/tmpl.stamp $(srcdir)/sgml.stamp $(srcdir)/html.stamp
+
+SCANOBJ_FILES = \
+ $(DOC_MODULE).args \
+ $(DOC_MODULE).hierarchy \
+ $(DOC_MODULE).interfaces \
+ $(DOC_MODULE).prerequisites \
+ $(DOC_MODULE).signals
+
+CLEANFILES = $(SCANOBJ_FILES) $(DOC_MODULE)-unused.txt $(DOC_STAMPS)
+
+if ENABLE_GTK_DOC
+all-local: html-build.stamp
+
+#### scan ####
+
+scan-build.stamp: $(HFILE_GLOB) $(CFILE_GLOB)
+ @echo 'gtk-doc: Scanning header files'
+ @-chmod -R u+w $(srcdir)
+ if grep -l '^..*$$' $(srcdir)/$(DOC_MODULE).types > /dev/null 2>&1 ; then \
+ CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" CFLAGS="$(GTKDOC_CFLAGS)" LDFLAGS="$(GTKDOC_LIBS)" gtkdoc-scangobj $(SCANGOBJ_OPTIONS) --module=$(DOC_MODULE) --output-dir=$(srcdir) ; \
+ else \
+ cd $(srcdir) ; \
+ for i in $(SCANOBJ_FILES) ; do \
+ test -f $$i || touch $$i ; \
+ done \
+ fi
+ cd $(srcdir) && \
+ gtkdoc-scan --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) --ignore-headers="$(IGNORE_HFILES)" $(SCAN_OPTIONS) $(EXTRA_HFILES)
+ touch scan-build.stamp
+
+$(DOC_MODULE)-decl.txt $(SCANOBJ_FILES): scan-build.stamp
+ @true
+
+#### templates ####
+
+tmpl-build.stamp: $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt
+ @echo 'gtk-doc: Rebuilding template files'
+ @-chmod -R u+w $(srcdir)
+ cd $(srcdir) && gtkdoc-mktmpl --module=$(DOC_MODULE) $(MKTMPL_OPTIONS)
+ touch tmpl-build.stamp
+
+tmpl.stamp: tmpl-build.stamp
+ @true
+
+#### xml ####
+
+sgml-build.stamp: tmpl.stamp $(CFILE_GLOB) $(srcdir)/tmpl/*.sgml $(expand_content_files)
+ @echo 'gtk-doc: Building XML'
+ @-chmod -R u+w $(srcdir)
+ cd $(srcdir) && \
+ gtkdoc-mkdb --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) --output-format=xml --expand-content-files="$(expand_content_files)" --main-sgml-file=$(DOC_MAIN_SGML_FILE) $(MKDB_OPTIONS)
+ touch sgml-build.stamp
+
+sgml.stamp: sgml-build.stamp
+ @true
+
+#### html ####
+
+html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files)
+ @echo 'gtk-doc: Building HTML'
+ @-chmod -R u+w $(srcdir)
+ rm -rf $(srcdir)/html
+ mkdir $(srcdir)/html
+ cd $(srcdir)/html && gtkdoc-mkhtml $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE)
+ test "x$(HTML_IMAGES)" = "x" || ( cd $(srcdir) && cp $(HTML_IMAGES) html )
+ @echo 'gtk-doc: Fixing cross-references'
+ cd $(srcdir) && gtkdoc-fixxref --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS)
+ touch html-build.stamp
+else
+all-local:
+endif
+
+##############
+
+clean-local:
+ rm -f *~ *.bak
+ rm -rf .libs
+
+maintainer-clean-local: clean
+ cd $(srcdir) && rm -rf xml html $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
+
+install-data-local:
+ installfiles=`echo $(srcdir)/html/*`; \
+ if test "$$installfiles" = '$(srcdir)/html/*'; \
+ then echo '-- Nothing to install' ; \
+ else \
+ $(mkinstalldirs) $(DESTDIR)$(TARGET_DIR); \
+ for i in $$installfiles; do \
+ echo '-- Installing '$$i ; \
+ $(INSTALL_DATA) $$i $(DESTDIR)$(TARGET_DIR); \
+ done; \
+ echo '-- Installing $(srcdir)/html/index.sgml' ; \
+ $(INSTALL_DATA) $(srcdir)/html/index.sgml $(DESTDIR)$(TARGET_DIR) || :; \
+ fi
+
+uninstall-local:
+ rm -f $(DESTDIR)$(TARGET_DIR)/*
+
+#
+# Require gtk-doc when making dist
+#
+if ENABLE_GTK_DOC
+dist-check-gtkdoc:
+else
+dist-check-gtkdoc:
+ @echo "*** gtk-doc must be installed and enabled in order to make dist"
+ @false
+endif
+
+dist-hook: dist-check-gtkdoc dist-hook-local
+ mkdir $(distdir)/tmpl
+ mkdir $(distdir)/xml
+ mkdir $(distdir)/html
+ -cp $(srcdir)/tmpl/*.sgml $(distdir)/tmpl
+ -cp $(srcdir)/xml/*.xml $(distdir)/xml
+ -cp $(srcdir)/html/* $(distdir)/html
+ if test -f $(srcdir)/$(DOC_MODULE).types; then \
+ cp $(srcdir)/$(DOC_MODULE).types $(distdir)/$(DOC_MODULE).types; \
+ fi
+
+.PHONY : dist-hook-local
diff --git a/libpolkit/Makefile.am b/libpolkit/Makefile.am
new file mode 100644
index 0000000..135870c
--- /dev/null
+++ b/libpolkit/Makefile.am
@@ -0,0 +1,39 @@
+## Process this file with automake to produce Makefile.in
+
+INCLUDES = \
+ -DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\" \
+ -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_BIN_DIR=\""$(bindir)"\" \
+ -DPACKAGE_LOCALSTATEDIR=\""$(localstatedir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT \
+ @GLIB_CFLAGS@
+
+lib_LTLIBRARIES=libpolkit.la
+
+libpolkitincludedir=$(includedir)/libpolkit
+
+libpolkitinclude_HEADERS = \
+ libpolkit.h
+
+libpolkit_la_SOURCES = \
+ libpolkit.c libpolkit.h
+
+libpolkit_la_LIBADD = @GLIB_LIBS@
+
+libpolkit_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
+
+check_PROGRAMS = libpolkit-test
+
+libpolkit_test_SOURCES = \
+ libpolkit-test.c
+
+libpolkit_test_LDADD = @GLIB_LIBS@ libpolkit.la
+
+TESTS = libpolkit-test
+
+
+clean-local :
+ rm -f *~
+
diff --git a/libpolkit/libpolkit-test.c b/libpolkit/libpolkit-test.c
new file mode 100644
index 0000000..42be6ba
--- /dev/null
+++ b/libpolkit/libpolkit-test.c
@@ -0,0 +1,280 @@
+/***************************************************************************
+ *
+ * libpolkit-test.c : Test harness for libpolkit
+ *
+ * Copyright (C) 2006 David Zeuthen, <david@fubar.dk>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ **************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <glib/gstdio.h>
+
+#include "libpolkit.h"
+
+static LibPolKitContext *ctx;
+
+static char *testdir;
+
+static void
+my_exit (int exit_code)
+{
+ int rc;
+ GDir *dir;
+ GError *err;
+ const char *f;
+
+ g_print ("Removing tmpdir '%s'\n", testdir);
+
+ err = NULL;
+ if ((dir = g_dir_open (testdir, 0, &err)) == NULL) {
+ g_warning ("Unable to open %s: %s", testdir, err->message);
+ g_error_free (err);
+ goto error;
+ }
+ while ((f = g_dir_read_name (dir)) != NULL) {
+ char *file;
+
+ file = g_strdup_printf ("%s/%s", testdir, f);
+ rc = g_unlink (file);
+ if (rc != 0) {
+ g_warning ("Unable to unlink %s: %d (%s)", file, errno, strerror (errno));
+ goto error;
+ }
+ g_free (file);
+ }
+
+ g_dir_close (dir);
+
+ rc = g_rmdir (testdir);
+ if (rc != 0) {
+ g_warning ("Unable to rmdir %s: %d (%s)", testdir, errno, strerror (errno));
+ goto error;
+ }
+
+error:
+ exit (exit_code);
+}
+
+static void
+do_check (const char *policy,
+ uid_t uid,
+ int num_gids,
+ gid_t *gids,
+ const char *resource,
+ gboolean expected)
+{
+ int i;
+ gboolean allowed;
+ char *gidstring;
+ GString *str;
+
+ str = g_string_new ("");
+ for (i = 0; i < num_gids; i++) {
+ if (i != 0)
+ g_string_append (str, ", ");
+ g_string_append_printf (str, "%d", gids[i]);
+ }
+ gidstring = g_string_free (str, FALSE);
+
+ if (LIBPOLKIT_RESULT_OK != libpolkit_is_uid_gid_allowed_for_policy (
+ ctx, uid, num_gids, gids, policy, resource, &allowed)) {
+ g_warning ("fail: no policy %s", policy);
+ my_exit (1);
+ }
+
+ if (allowed != expected) {
+ g_warning ("fail: for uid %d (gids %s) expected %s on policy '%s' for resource '%s' but got %s",
+ uid, gidstring,
+ expected ? "TRUE" : "FALSE",
+ policy,
+ (char*) (resource != NULL ? resource : ""),
+ allowed ? "TRUE" : "FALSE");
+ my_exit (1);
+ }
+
+ g_print ("pass: uid %d (gids %s) got %s on policy '%s' for resource '%s'\n",
+ uid, gidstring,
+ expected ? "TRUE " : "FALSE",
+ policy,
+ (char*) (resource != NULL ? resource : ""));
+
+ g_free (gidstring);
+}
+
+static void
+write_test_policy (const char *policy, const char *allow_rule, const char *deny_rule)
+{
+ char *file;
+ FILE *f;
+
+ file = g_strdup_printf ("%s/%s.policy", testdir, policy);
+ f = fopen (file, "w");
+ if (f == NULL) {
+ g_warning ("Cannot created test policy '%s'", file);
+ my_exit (1);
+ }
+ fprintf (f,
+ "[Policy]\n"
+ "Allow=%s\n"
+ "Deny=%s\n",
+ allow_rule, deny_rule);
+ fclose (f);
+
+ g_print ("Created test policy '%s' at '%s'\n"
+ " Allow '%s'\n"
+ " Deny '%s'\n",
+ policy, file, allow_rule, deny_rule);
+
+ g_free (file);
+}
+
+static void
+do_read_tests (void)
+{
+ gid_t gid500[1] = {500};
+ int gid500_len = sizeof (gid500) / sizeof (gid_t);
+ gid_t gid501[1] = {501};
+ int gid501_len = sizeof (gid501) / sizeof (gid_t);
+ gid_t gid502[1] = {502};
+ int gid502_len = sizeof (gid502) / sizeof (gid_t);
+
+ gid_t gid500_1[2] = {500, 1};
+ int gid500_1_len = sizeof (gid500_1) / sizeof (gid_t);
+ gid_t gid501_1[2] = {501, 1};
+ int gid501_1_len = sizeof (gid501_1) / sizeof (gid_t);
+ gid_t gid502_1[2] = {502, 1};
+ int gid502_1_len = sizeof (gid502_1) / sizeof (gid_t);
+
+ /* feel free to add more tests here */
+
+ write_test_policy ("test0", "uid:__none__ uid:500", "");
+ do_check ("test0", 500, gid500_len, gid500, NULL, TRUE);
+ do_check ("test0", 501, gid501_len, gid501, NULL, FALSE);
+ do_check ("test0", 502, gid502_len, gid502, NULL, FALSE);
+
+ write_test_policy ("test1", "uid:__all__", "uid:500:res0");
+ do_check ("test1", 500, gid500_len, gid500, NULL, TRUE);
+ do_check ("test1", 501, gid501_len, gid501, NULL, TRUE);
+ do_check ("test1", 502, gid502_len, gid502, NULL, TRUE);
+ do_check ("test1", 500, gid500_len, gid500, "res0", FALSE);
+ do_check ("test1", 501, gid501_len, gid501, "res0", TRUE);
+ do_check ("test1", 502, gid502_len, gid502, "res0", TRUE);
+ do_check ("test1", 500, gid500_len, gid500, "res1", TRUE);
+ do_check ("test1", 501, gid501_len, gid501, "res1", TRUE);
+ do_check ("test1", 502, gid502_len, gid502, "res1", TRUE);
+
+ write_test_policy ("test2", "gid:1", "uid:501");
+ do_check ("test2", 500, gid500_len, gid500, NULL, FALSE);
+ do_check ("test2", 501, gid501_len, gid501, NULL, FALSE);
+ do_check ("test2", 502, gid502_len, gid502, NULL, FALSE);
+ do_check ("test2", 500, gid500_1_len, gid500_1, NULL, TRUE);
+ do_check ("test2", 501, gid501_1_len, gid501_1, NULL, FALSE);
+ do_check ("test2", 502, gid502_1_len, gid502_1, NULL, TRUE);
+
+ write_test_policy ("test3", "gid:1 uid:502:res1", "uid:501 uid:500:res0");
+ do_check ("test3", 500, gid500_1_len, gid500_1, "res0", FALSE);
+ do_check ("test3", 501, gid501_1_len, gid501_1, "res0", FALSE);
+ do_check ("test3", 502, gid502_1_len, gid502_1, "res0", TRUE);
+ do_check ("test3", 500, gid500_1_len, gid500_1, "res1", TRUE);
+ do_check ("test3", 501, gid501_1_len, gid501_1, "res1", FALSE);
+ do_check ("test3", 502, gid502_1_len, gid502_1, "res1", TRUE);
+ do_check ("test3", 500, gid500_len, gid500, "res1", FALSE);
+ do_check ("test3", 501, gid501_len, gid501, "res1", FALSE);
+ do_check ("test3", 502, gid502_len, gid502, "res1", TRUE);
+
+ write_test_policy ("test4", "gid:1:res1 uid:500:res2", "gid:502:res2");
+ do_check ("test4", 500, gid500_1_len, gid500_1, "res0", FALSE);
+ do_check ("test4", 501, gid501_1_len, gid501_1, "res0", FALSE);
+ do_check ("test4", 502, gid502_1_len, gid502_1, "res0", FALSE);
+ do_check ("test4", 500, gid500_1_len, gid500_1, "res1", TRUE);
+ do_check ("test4", 501, gid501_1_len, gid501_1, "res1", TRUE);
+ do_check ("test4", 502, gid502_1_len, gid502_1, "res1", TRUE);
+ do_check ("test4", 500, gid500_len, gid500, "res2", TRUE);
+ do_check ("test4", 501, gid501_len, gid501, "res2", FALSE);
+ do_check ("test4", 502, gid502_len, gid502, "res2", FALSE);
+
+ write_test_policy ("test5", "gid:1", "uid:500:res-has-:colon-in-name");
+ do_check ("test5", 500, gid500_1_len, gid500_1, "res-has-:colon-in-name", FALSE);
+ do_check ("test5", 501, gid501_1_len, gid501_1, "res-has-:colon-in-name", TRUE);
+ do_check ("test5", 502, gid502_1_len, gid502_1, "res-has-:colon-in-name", TRUE);
+ do_check ("test5", 500, gid500_len, gid500, "res-has-:colon-in-name", FALSE);
+ do_check ("test5", 501, gid501_len, gid501, "res-has-:colon-in-name", FALSE);
+ do_check ("test5", 502, gid502_len, gid502, "res-has-:colon-in-name", FALSE);
+
+}
+
+int
+main (int argc, char *argv[])
+{
+ int i;
+ GList *l;
+ GList *policies;
+
+ testdir = g_strdup ("/tmp/libpolkit-test-XXXXXX");
+ testdir = mkdtemp (testdir);
+ if (testdir == NULL) {
+ g_warning ("Cannot create tmpdir, errno %d (%s)", errno, strerror (errno));
+ g_free (testdir);
+ exit (1);
+ }
+
+ g_message ("libpolkit-test started; using tmpdir=%s", testdir);
+
+ ctx = libpolkit_new_context ();
+ if (ctx == NULL) {
+ g_message ("Cannot create context");
+ my_exit (1);
+ }
+ if (!libpolkit_context_set_txt_source (ctx, testdir)) {
+ g_message ("Cannot set text source to '%s'", testdir);
+ my_exit (1);
+ }
+
+ do_read_tests ();
+
+ if (libpolkit_get_policies (ctx, &policies) != LIBPOLKIT_RESULT_OK) {
+ g_message ("Cannot get policies");
+ goto fail;
+ }
+ g_print ("Loaded %d policies\n", g_list_length (policies));
+ for (l = policies, i = 0; l != NULL; l = g_list_next (l), i++) {
+ const char *policy;
+ policy = (const char *) l->data;
+ g_print (" policy %d: '%s'\n", i, policy);
+ }
+ g_list_foreach (policies, (GFunc) g_free, NULL);
+ g_list_free (policies);
+
+ if (!libpolkit_free_context (ctx)) {
+ g_warning ("Cannot free context");
+ goto fail;
+ }
+
+ g_print ("libpolkit-test completed\n");
+
+ my_exit (0);
+
+fail:
+ my_exit (1);
+ return 1;
+}
diff --git a/libpolkit/libpolkit.c b/libpolkit/libpolkit.c
new file mode 100644
index 0000000..1809bb9
--- /dev/null
+++ b/libpolkit/libpolkit.c
@@ -0,0 +1,836 @@
+/***************************************************************************
+ *
+ * libpolkit.c : Simple library for system software to query policy and
+ * UI shells to query and modify policy
+ *
+ * Copyright (C) 2006 David Zeuthen, <david@fubar.dk>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include "libpolkit.h"
+
+
+#define LIBPOLKIT_MAGIC 0x3117beef
+
+#ifdef __SUNPRO_C
+#define __FUNCTION__ __func__
+#endif
+
+#define LIBPOLKIT_CHECK_CONTEXT(_ctx_, _ret_) \
+ do { \
+ if (_ctx_ == NULL) { \
+ g_warning ("%s: given LibPolKitContext is NULL", \
+ __FUNCTION__); \
+ return _ret_; \
+ } \
+ if (_ctx_->magic != LIBPOLKIT_MAGIC) { \
+ g_warning ("%s: given LibPolKitContext is invalid", \
+ __FUNCTION__); \
+ return _ret_; \
+ } \
+ } while(0)
+
+
+struct LibPolKitContext_s
+{
+ guint32 magic;
+ char *txt_backend_source;
+};
+
+struct LibPolKitElement_s
+{
+ LibPolKitContext *ctx;
+ LibPolKitElementType type;
+ union {
+ uid_t uid;
+ gid_t gid;
+ } id;
+ gboolean include_all;
+ gboolean exclude_all;
+ char *resource;
+};
+
+
+/** Get a new context.
+ *
+ * @return Pointer to new context or NULL if an error occured
+ */
+LibPolKitContext *
+libpolkit_new_context (void)
+{
+ LibPolKitContext *ctx;
+
+ ctx = g_new0 (LibPolKitContext, 1);
+ ctx->magic = LIBPOLKIT_MAGIC;
+ ctx->txt_backend_source = g_strdup (PACKAGE_SYSCONF_DIR "/PolicyKit/policy");
+ return ctx;
+}
+
+gboolean
+libpolkit_context_set_txt_source (LibPolKitContext *ctx,
+ const char *directory)
+{
+ LIBPOLKIT_CHECK_CONTEXT (ctx, FALSE);
+ g_free (ctx->txt_backend_source);
+ ctx->txt_backend_source = g_strdup (directory);
+ return TRUE;
+}
+
+/** Free a context
+ *
+ * @param ctx The context obtained from libpolkit_new_context
+ * @return Pointer to new context or NULL if an error occured
+ */
+gboolean
+libpolkit_free_context (LibPolKitContext *ctx)
+{
+ LIBPOLKIT_CHECK_CONTEXT (ctx, FALSE);
+ ctx->magic = 0;
+ g_free (ctx->txt_backend_source);
+ g_free (ctx);
+ return TRUE;
+}
+
+static LibPolKitResult
+txt_backend_read_policy (LibPolKitContext *ctx,
+ const char *policy,
+ const char *key,
+ GList **result)
+{
+ int i;
+ GKeyFile *keyfile;
+ GError *error;
+ LibPolKitResult rc;
+ char *path;
+ char *value = NULL;
+ char **tokens = NULL;
+ char *ttype = NULL;
+ char *tvalue = NULL;
+ char *tresource = NULL;
+ LibPolKitElement *elem = NULL;
+ GList *res;
+ GList *l;
+ char *token;
+
+ error = NULL;
+ rc = LIBPOLKIT_RESULT_ERROR;
+ res = NULL;
+ *result = NULL;
+
+ keyfile = g_key_file_new ();
+ path = g_strdup_printf ("%s/%s.policy", ctx->txt_backend_source, policy);
+ /*g_message ("Loading %s", path);*/
+ if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error)) {
+ g_warning ("Couldn't open key-file '%s': %s", path, error->message);
+ g_error_free (error);
+ rc = LIBPOLKIT_RESULT_NO_SUCH_POLICY;
+ goto out;
+ }
+
+ value = g_key_file_get_string (keyfile, "Policy", key, &error);
+ if (value == NULL) {
+ g_warning ("Cannot get key '%s' in group 'Policy' in file '%s': %s", key, path, error->message);
+ g_error_free (error);
+ rc = LIBPOLKIT_RESULT_ERROR;
+ goto out;
+ }
+
+ /*g_message ("value = '%s'", value);*/
+ tokens = g_strsplit (value, " ", 0);
+ for (i = 0; tokens[i] != NULL; i++) {
+ char **components;
+ int num_components;
+
+ token = tokens[i];
+ /*g_message (" token = '%s'", token);*/
+
+ ttype = NULL;
+ tvalue = NULL;
+ tresource = NULL;
+
+ elem = libpolkit_element_new (ctx);
+
+ components = g_strsplit (token, ":", 3);
+ num_components = g_strv_length (components);
+ if (num_components == 2) {
+ ttype = g_strdup (components[0]);
+ tvalue = g_strdup (components[1]);
+ tresource = NULL;
+ } else if (num_components == 3) {
+ ttype = g_strdup (components[0]);
+ tvalue = g_strdup (components[1]);
+ tresource = g_strdup (components[2]);
+ } else {
+ g_strfreev (components);
+ goto malformed_token;
+ }
+ g_strfreev (components);
+
+ /*g_message (" type='%s' value='%s' resource='%s'", ttype, tvalue, tresource != NULL ? tresource : "None");*/
+
+ if (strcmp (ttype, "uid") == 0) {
+ libpolkit_element_set_type (elem, LIBPOLKIT_ELEMENT_TYPE_UID);
+ if (strcmp (tvalue, "__all__") == 0) {
+ libpolkit_element_set_include_all (elem, TRUE);
+ } else if (strcmp (tvalue, "__none__") == 0) {
+ libpolkit_element_set_exclude_all (elem, TRUE);
+ } else {
+ uid_t uid;
+ char *endp;
+ uid = (uid_t) g_ascii_strtoull (tvalue, &endp, 0);
+ if (endp[0] != '\0') {
+ uid = libpolkit_util_name_to_uid (ctx, tvalue, NULL);
+ if (uid == (uid_t) -1) {
+ g_warning ("User '%s' does not exist", tvalue);
+ goto malformed_token;
+ }
+ }
+ libpolkit_element_set_uid (elem, uid);
+ }
+ } else if (strcmp (ttype, "gid") == 0) {
+ libpolkit_element_set_type (elem, LIBPOLKIT_ELEMENT_TYPE_GID);
+ if (strcmp (tvalue, "__all__") == 0) {
+ libpolkit_element_set_include_all (elem, TRUE);
+ } else if (strcmp (tvalue, "__none__") == 0) {
+ libpolkit_element_set_exclude_all (elem, TRUE);
+ } else {
+ gid_t gid;
+ char *endp;
+ gid = (gid_t) g_ascii_strtoull (tvalue, &endp, 0);
+ if (endp[0] != '\0') {
+ gid = libpolkit_util_name_to_gid (ctx, tvalue);
+ if (gid == (gid_t) -1) {
+ g_warning ("Group '%s' does not exist", tvalue);
+ goto malformed_token;
+ }
+ }
+ libpolkit_element_set_gid (elem, gid);
+ }
+ } else {
+ g_warning ("Token '%s' in key '%s' in group 'Policy' in file '%s' malformed",
+ token, key, path);
+ goto malformed_token;
+ }
+
+ if (tresource != NULL) {
+ libpolkit_element_set_resource (elem, tresource);
+ }
+
+ g_free (ttype);
+ g_free (tvalue);
+ g_free (tresource);
+
+ res = g_list_append (res, elem);
+ /*libpolkit_element_dump (elem, stderr);*/
+
+ }
+
+ *result = res;
+ rc = LIBPOLKIT_RESULT_OK;
+ goto out;
+
+malformed_token:
+ g_warning ("Token '%s' in key '%s' in group 'Policy' in file '%s' malformed", token, key, path);
+
+ for (l = res; l != NULL; l = g_list_next (l)) {
+ libpolkit_free_element ((LibPolKitElement *) l->data);
+ }
+ g_list_free (res);
+ libpolkit_free_element (elem);
+ g_free (ttype);
+ g_free (tvalue);
+ g_free (tresource);
+
+out:
+ g_strfreev (tokens);
+ g_free (value);
+
+ g_key_file_free (keyfile);
+ g_free (path);
+
+ return rc;
+}
+
+static void
+afp_process_elem(LibPolKitElement *elem, gboolean *flag, uid_t uid, guint num_gids, gid_t *gid_list)
+{
+ /*libpolkit_element_dump (elem, stderr);*/
+
+ switch (elem->type) {
+ case LIBPOLKIT_ELEMENT_TYPE_UID:
+ if (elem->include_all) {
+ *flag = TRUE;
+ } else if (elem->exclude_all) {
+ *flag = FALSE;
+ }else {
+ if (elem->id.uid == uid)
+ *flag = TRUE;
+ }
+ break;
+
+ case LIBPOLKIT_ELEMENT_TYPE_GID:
+ if (elem->include_all) {
+ *flag = TRUE;
+ } else if (elem->exclude_all) {
+ *flag = FALSE;
+ }else {
+ guint i;
+ for (i = 0; i < num_gids; i++) {
+ if (elem->id.gid == gid_list[i])
+ *flag = TRUE;
+ }
+ }
+ break;
+ }
+}
+
+LibPolKitResult
+libpolkit_is_uid_gid_allowed_for_policy (LibPolKitContext *ctx,
+ uid_t uid,
+ guint num_gids,
+ gid_t *gid_list,
+ const char *policy,
+ const char *resource,
+ gboolean *result)
+{
+ gboolean is_in_whitelist;
+ gboolean is_in_blacklist;
+ GList *l;
+ GList *whitelist;
+ GList *blacklist;
+ LibPolKitResult res;
+
+ LIBPOLKIT_CHECK_CONTEXT (ctx, LIBPOLKIT_RESULT_INVALID_CONTEXT);
+
+ whitelist = NULL;
+ blacklist = NULL;
+ res = LIBPOLKIT_RESULT_ERROR;
+
+ res = libpolkit_get_whitelist (ctx, policy, &whitelist);
+ if (res != LIBPOLKIT_RESULT_OK)
+ goto out;
+
+ res = libpolkit_get_blacklist (ctx, policy, &blacklist);
+ if (res != LIBPOLKIT_RESULT_OK)
+ goto out;
+
+ is_in_whitelist = FALSE;
+ is_in_blacklist = FALSE;
+
+ /* Algorithm: To succeed.. we must be in the whitelist.. and not in the blacklist */
+
+ for (l = whitelist; l != NULL; l = g_list_next (l)) {
+ LibPolKitElement *elem;
+ elem = (LibPolKitElement *) l->data;
+ if ((elem->resource == NULL) ||
+ ((resource != NULL) && (strcmp (elem->resource, resource) == 0))) {
+ afp_process_elem (elem, &is_in_whitelist, uid, num_gids, gid_list);
+ }
+ }
+
+ for (l = blacklist; l != NULL; l = g_list_next (l)) {
+ LibPolKitElement *elem;
+ elem = (LibPolKitElement *) l->data;
+ if ((elem->resource == NULL) ||
+ ((resource != NULL) && (strcmp (elem->resource, resource) == 0))) {
+ afp_process_elem (elem, &is_in_blacklist, uid, num_gids, gid_list);
+ }
+ }
+
+ *result = is_in_whitelist && (!is_in_blacklist);
+
+ res = LIBPOLKIT_RESULT_OK;
+
+out:
+ if (whitelist != NULL)
+ libpolkit_free_element_list (whitelist);
+ if (blacklist != NULL)
+ libpolkit_free_element_list (blacklist);
+
+ return res;
+}
+
+char *
+libpolkit_util_uid_to_name (LibPolKitContext *ctx, uid_t uid, gid_t *default_gid)
+{
+ int rc;
+ char *res;
+ char *buf = NULL;
+ unsigned int bufsize;
+ struct passwd pwd;
+ struct passwd *pwdp;
+
+ LIBPOLKIT_CHECK_CONTEXT (ctx, NULL);
+
+ res = NULL;
+
+ bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
+ buf = g_new0 (char, bufsize);
+
+ rc = getpwuid_r (uid, &pwd, buf, bufsize, &pwdp);
+ if (rc != 0 || pwdp == NULL) {
+ /*g_warning ("getpwuid_r() returned %d", rc);*/
+ goto out;
+ }
+
+ res = g_strdup (pwdp->pw_name);
+ if (default_gid != NULL)
+ *default_gid = pwdp->pw_gid;
+
+out:
+ g_free (buf);
+ return res;
+}
+
+char *
+libpolkit_util_gid_to_name (LibPolKitContext *ctx, gid_t gid)
+{
+ int rc;
+ char *res;
+ char *buf = NULL;
+ unsigned int bufsize;
+ struct group gbuf;
+ struct group *gbufp;
+
+ LIBPOLKIT_CHECK_CONTEXT (ctx, NULL);
+
+ res = NULL;
+
+ bufsize = sysconf (_SC_GETGR_R_SIZE_MAX);
+ buf = g_new0 (char, bufsize);
+
+ rc = getgrgid_r (gid, &gbuf, buf, bufsize, &gbufp);
+ if (rc != 0 || gbufp == NULL) {
+ /*g_warning ("getgrgid_r() returned %d", rc);*/
+ goto out;
+ }
+
+ res = g_strdup (gbufp->gr_name);
+
+out:
+ g_free (buf);
+ return res;
+}
+
+
+
+uid_t
+libpolkit_util_name_to_uid (LibPolKitContext *ctx, const char *username, gid_t *default_gid)
+{
+ int rc;
+ uid_t res;
+ char *buf = NULL;
+ unsigned int bufsize;
+ struct passwd pwd;
+ struct passwd *pwdp;
+
+ LIBPOLKIT_CHECK_CONTEXT (ctx, (uid_t) -1);
+
+ res = (uid_t) -1;
+
+ bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
+ buf = g_new0 (char, bufsize);
+
+ rc = getpwnam_r (username, &pwd, buf, bufsize, &pwdp);
+ if (rc != 0 || pwdp == NULL) {
+ /*g_warning ("getpwnam_r() returned %d", rc);*/
+ goto out;
+ }
+
+ res = pwdp->pw_uid;
+ if (default_gid != NULL)
+ *default_gid = pwdp->pw_gid;
+
+out:
+ g_free (buf);
+ return res;
+}
+
+gid_t
+libpolkit_util_name_to_gid (LibPolKitContext *ctx, const char *groupname)
+{
+ int rc;
+ gid_t res;
+ char *buf = NULL;
+ unsigned int bufsize;
+ struct group gbuf;
+ struct group *gbufp;
+
+ LIBPOLKIT_CHECK_CONTEXT (ctx, (gid_t) -1);
+
+ res = (gid_t) -1;
+
+ bufsize = sysconf (_SC_GETGR_R_SIZE_MAX);
+ buf = g_new0 (char, bufsize);
+
+ rc = getgrnam_r (groupname, &gbuf, buf, bufsize, &gbufp);
+ if (rc != 0 || gbufp == NULL) {
+ /*g_warning ("getgrnam_r() returned %d", rc);*/
+ goto out;
+ }
+
+ res = gbufp->gr_gid;
+
+out:
+ g_free (buf);
+ return res;
+}
+
+
+LibPolKitResult
+libpolkit_is_uid_allowed_for_policy (LibPolKitContext *ctx,
+ uid_t uid,
+ const char *policy,
+ const char *resource,
+ gboolean *result)
+{
+ int num_groups = 0;
+ gid_t *groups = NULL;
+ char *username;
+ gid_t default_gid;
+ LibPolKitResult r;
+
+ LIBPOLKIT_CHECK_CONTEXT (ctx, LIBPOLKIT_RESULT_INVALID_CONTEXT);
+
+ r = LIBPOLKIT_RESULT_ERROR;
+
+ if ((username = libpolkit_util_uid_to_name (ctx, uid, &default_gid)) == NULL)
+ goto out;
+
+ /* TODO: this is glibc only at the moment... */
+ if (getgrouplist(username, default_gid, NULL, &num_groups) < 0) {
+ groups = (gid_t *) g_new0 (gid_t, num_groups);
+ if (getgrouplist(username, default_gid, groups, &num_groups) < 0) {
+ g_warning ("getgrouplist() failed");
+ goto out;
+ }
+ }
+
+ /*
+ {
+ int i;
+ g_debug ("uid %d (%s)", uid, username);
+ for (i = 0; i < num_groups; i++) {
+ char *group_name;
+ group_name = libpolkit_util_gid_to_name (groups[i]);
+ g_debug (" gid %d (%s)", groups[i], group_name);
+ g_free (group_name);
+ }
+ }
+ */
+
+ r = libpolkit_is_uid_gid_allowed_for_policy (ctx,
+ uid,
+ num_groups,
+ groups,
+ policy,
+ resource,
+ result);
+
+out:
+ g_free (username);
+ g_free (groups);
+ return r;
+}
+
+
+/** Return all elements in the white-list for a policy
+ *
+ * @param ctx The context obtained from libpolkit_new_context
+ * @param policy Name of policy
+ * @param results On success set to a list of dynamically allocated LibPolKitElement structures.
+ * Must be freed by the caller
+ * @return Whether the operation succeeded
+ */
+LibPolKitResult
+libpolkit_get_whitelist (LibPolKitContext *ctx,
+ const char *policy,
+ GList **result)
+{
+ LIBPOLKIT_CHECK_CONTEXT (ctx, LIBPOLKIT_RESULT_INVALID_CONTEXT);
+
+ return txt_backend_read_policy (ctx, policy, "Allow", result);
+}
+
+/** Return all elements in the black-list for a policy
+ *
+ * @param ctx The context obtained from libpolkit_new_context
+ * @param policy Name of policy
+ * @param results On success set to a list of dynamically allocated LibPolKitElement structures.
+ * Must be freed by the caller
+ * @return Whether the operation succeeded
+ */
+LibPolKitResult
+libpolkit_get_blacklist (LibPolKitContext *ctx,
+ const char *policy,
+ GList **result)
+{
+ LIBPOLKIT_CHECK_CONTEXT (ctx, LIBPOLKIT_RESULT_INVALID_CONTEXT);
+
+ return txt_backend_read_policy (ctx, policy, "Deny", result);
+}
+
+/** Return all elements in the white-list for a policy
+ *
+ * @param ctx The context obtained from libpolkit_new_context
+ * @param result On success set to a list of dynamically allocated strings.
+ * Must be freed by the caller.
+ * @return Whether the operation succeeded
+ */
+LibPolKitResult
+libpolkit_get_policies (LibPolKitContext *ctx,
+ GList **result)
+{
+ GDir *dir;
+ GError *error;
+ const char *f;
+
+ LIBPOLKIT_CHECK_CONTEXT (ctx, LIBPOLKIT_RESULT_INVALID_CONTEXT);
+
+ error = NULL;
+ *result = NULL;
+
+ if ((dir = g_dir_open (ctx->txt_backend_source, 0, &error)) == NULL) {
+ g_critical ("Unable to open %s: %s", ctx->txt_backend_source, error->message);
+ g_error_free (error);
+ goto error;
+ }
+ while ((f = g_dir_read_name (dir)) != NULL) {
+ if (g_str_has_suffix (f, ".policy")) {
+ char *s;
+ int pos;
+
+ s = g_strdup (f);
+ pos = strlen (s) - 7;
+ if (pos > 0)
+ s[pos] = '\0';
+
+ *result = g_list_append (*result, s);
+ }
+ }
+
+ g_dir_close (dir);
+
+ return LIBPOLKIT_RESULT_OK;
+
+error:
+ return LIBPOLKIT_RESULT_ERROR;
+}
+
+
+LibPolKitElement *
+libpolkit_element_new (LibPolKitContext *ctx)
+{
+ LibPolKitElement *elem;
+
+ LIBPOLKIT_CHECK_CONTEXT (ctx, NULL);
+
+ elem = g_new0 (LibPolKitElement, 1);
+ elem->ctx = ctx;
+ return elem;
+}
+
+void
+libpolkit_element_set_type (LibPolKitElement *elem,
+ LibPolKitElementType type)
+{
+ elem->type = type;
+}
+
+void
+libpolkit_element_set_include_all (LibPolKitElement *elem,
+ gboolean value)
+{
+ elem->include_all = value;
+}
+
+void
+libpolkit_element_set_exclude_all (LibPolKitElement *elem,
+ gboolean value)
+{
+ elem->exclude_all = value;
+}
+
+void
+libpolkit_element_set_uid (LibPolKitElement *elem,
+ uid_t uid)
+{
+ elem->id.uid = uid;
+}
+
+void
+libpolkit_element_set_gid (LibPolKitElement *elem,
+ gid_t gid)
+{
+ elem->id.gid = gid;
+}
+
+void
+libpolkit_element_set_resource (LibPolKitElement *elem,
+ const char *resource)
+{
+ g_free (elem->resource);
+ elem->resource = g_strdup (resource);
+}
+
+
+
+void
+libpolkit_free_element (LibPolKitElement *elem)
+{
+ g_free (elem->resource);
+ g_free (elem);
+}
+
+void
+libpolkit_free_element_list (GList *policy_element_list)
+{
+ GList *l;
+
+ for (l = policy_element_list; l != NULL; l = g_list_next (l)) {
+ LibPolKitElement *elem = (LibPolKitElement *) l->data;
+ libpolkit_free_element (elem);
+ }
+
+ g_list_free (policy_element_list);
+}
+
+LibPolKitElementType
+libpolkit_element_get_type (LibPolKitElement *elem)
+{
+ return elem->type;
+}
+
+gboolean
+libpolkit_element_get_include_all (LibPolKitElement *elem)
+{
+ return elem->include_all;
+}
+
+gboolean
+libpolkit_element_get_exclude_all (LibPolKitElement *elem)
+{
+ return elem->exclude_all;
+}
+
+uid_t
+libpolkit_element_get_uid (LibPolKitElement *elem)
+{
+ return elem->id.uid;
+}
+
+gid_t
+libpolkit_element_get_gid (LibPolKitElement *elem)
+{
+ return elem->id.gid;
+}
+
+const char *
+libpolkit_element_get_resource (LibPolKitElement *elem)
+{
+ return elem->resource;
+}
+
+void
+libpolkit_element_dump (LibPolKitElement *elem, FILE* fp)
+{
+ char *t;
+
+ if (elem->type == LIBPOLKIT_ELEMENT_TYPE_UID)
+ t = "uid";
+ else if (elem->type == LIBPOLKIT_ELEMENT_TYPE_GID)
+ t = "gid";
+ else
+ t = "(Unknown)";
+
+ fprintf (fp, "type: %s\n", t);
+ if (elem->type == LIBPOLKIT_ELEMENT_TYPE_UID) {
+ if (elem->include_all) {
+ fprintf (fp, "uid: all\n");
+ } else if (elem->exclude_all) {
+ fprintf (fp, "uid: none\n");
+ } else {
+ fprintf (fp, "uid: %d\n", (int) elem->id.uid);
+ }
+ } else if (elem->type == LIBPOLKIT_ELEMENT_TYPE_GID) {
+ if (elem->include_all) {
+ fprintf (fp, "gid: all\n");
+ } else if (elem->exclude_all) {
+ fprintf (fp, "gid: none\n");
+ } else {
+ fprintf (fp, "gid: %d\n", (int) elem->id.gid);
+ }
+ }
+ fprintf (fp, "resource: %s\n", elem->resource != NULL ? elem->resource : "(None)");
+}
+
+#ifndef HAVE_GETGROUPLIST
+/* Get group list for the named user.
+ * Return up to ngroups in the groups array.
+ * Return actual number of groups in ngroups.
+ * Return -1 if more groups found than requested.
+ */
+int
+getgrouplist (const char *name, int baseid, int *groups, int *ngroups)
+{
+ struct group *g;
+ int n = 0;
+ int i;
+ int ret;
+
+ if (*ngroups <= 0) {
+ return (-1);
+ }
+
+ *groups++ = baseid;
+ n++;
+
+ setgrent ();
+ while ((g = getgrent ()) != NULL) {
+ for (i = 0; g->gr_mem[i]; i++) {
+ if (strcmp (name, g->gr_mem[0]) == 0) {
+ *groups++ = g->gr_gid;
+ if (++n > *ngroups) {
+ break;
+ }
+ }
+ }
+ }
+ endgrent ();
+
+ ret = (n > *ngroups) ? -1 : n;
+ *ngroups = n;
+ return (ret);
+}
+#endif
diff --git a/libpolkit/libpolkit.h b/libpolkit/libpolkit.h
new file mode 100644
index 0000000..e430b3c
--- /dev/null
+++ b/libpolkit/libpolkit.h
@@ -0,0 +1,151 @@
+/***************************************************************************
+ *
+ * libpolkit.h : Simple library for system software to query policy and
+ * UI shells to query and modify policy
+ *
+ * Copyright (C) 2006 David Zeuthen, <david@fubar.dk>
+ *
+ * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#ifndef LIBPOLKIT_H
+#define LIBPOLKIT_H
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <glib.h>
+
+typedef enum {
+ LIBPOLKIT_RESULT_OK,
+ LIBPOLKIT_RESULT_ERROR,
+ LIBPOLKIT_RESULT_INVALID_CONTEXT,
+ LIBPOLKIT_RESULT_PERMISSON_DENIED,
+ LIBPOLKIT_RESULT_NO_SUCH_POLICY
+} LibPolKitResult;
+
+struct LibPolKitContext_s;
+typedef struct LibPolKitContext_s LibPolKitContext;
+
+
+typedef enum {
+ LIBPOLKIT_ELEMENT_TYPE_UID,
+ LIBPOLKIT_ELEMENT_TYPE_GID
+} LibPolKitElementType;
+
+struct LibPolKitElement_s;
+typedef struct LibPolKitElement_s LibPolKitElement;
+
+
+LibPolKitContext *libpolkit_new_context (void);
+
+gboolean libpolkit_context_set_txt_source (LibPolKitContext *ctx,
+ const char *directory);
+
+gboolean libpolkit_free_context (LibPolKitContext *ctx);
+
+LibPolKitResult libpolkit_get_policies (LibPolKitContext *ctx,
+ GList **result);
+
+LibPolKitResult libpolkit_is_uid_allowed_for_policy (LibPolKitContext *ctx,
+ uid_t uid,
+ const char *policy,
+ const char *resource,
+ gboolean *result);
+
+
+LibPolKitResult libpolkit_is_uid_gid_allowed_for_policy (LibPolKitContext *ctx,
+ uid_t uid,
+ guint num_gids,
+ gid_t *gid_list,
+ const char *policy,
+ const char *resource,
+ gboolean *result);
+
+
+
+LibPolKitResult libpolkit_get_whitelist (LibPolKitContext *ctx,
+ const char *policy,
+ GList **result);
+
+LibPolKitResult libpolkit_get_blacklist (LibPolKitContext *ctx,
+ const char *policy,
+ GList **result);
+
+LibPolKitResult libpolkit_set_whitelist (LibPolKitContext *ctx,
+ const char *policy,
+ GList *whitelist);
+
+LibPolKitResult libpolkit_set_blacklist (LibPolKitContext *ctx,
+ const char *policy,
+ GList *blacklist);
+
+
+LibPolKitElementType libpolkit_element_get_type (LibPolKitElement *elem);
+
+gboolean libpolkit_element_get_include_all (LibPolKitElement *elem);
+
+gboolean libpolkit_element_get_exclude_all (LibPolKitElement *elem);
+
+uid_t libpolkit_element_get_uid (LibPolKitElement *elem);
+
+gid_t libpolkit_element_get_gid (LibPolKitElement *elem);
+
+const char *libpolkit_element_get_resource (LibPolKitElement *elem);
+
+
+
+LibPolKitElement *libpolkit_element_new (LibPolKitContext *ctx);
+
+void libpolkit_element_set_type (LibPolKitElement *elem,
+ LibPolKitElementType type);
+
+void libpolkit_element_set_include_all (LibPolKitElement *elem,
+ gboolean value);
+
+void libpolkit_element_set_exclude_all (LibPolKitElement *elem,
+ gboolean value);
+
+void libpolkit_element_set_uid (LibPolKitElement *elem,
+ uid_t uid);
+
+void libpolkit_element_set_gid (LibPolKitElement *elem,
+ gid_t gid);
+
+void libpolkit_element_set_resource (LibPolKitElement *elem,
+ const char *resource);
+
+
+
+void libpolkit_free_element (LibPolKitElement *elem);
+
+void libpolkit_free_element_list (GList *policy_element_list);
+
+
+
+char *libpolkit_util_uid_to_name (LibPolKitContext *ctx, uid_t uid, gid_t *default_gid);
+char *libpolkit_util_gid_to_name (LibPolKitContext *ctx, gid_t gid);
+
+uid_t libpolkit_util_name_to_uid (LibPolKitContext *ctx, const char *username, gid_t *default_gid);
+gid_t libpolkit_util_name_to_gid (LibPolKitContext *ctx, const char *groupname);
+
+void libpolkit_element_dump (LibPolKitElement *elem, FILE* fp);
+
+#endif /* LIBPOLKIT_H */
+
+
diff --git a/mkinstalldirs b/mkinstalldirs
new file mode 100755
index 0000000..d2d5f21
--- /dev/null
+++ b/mkinstalldirs
@@ -0,0 +1,111 @@
+#! /bin/sh
+# mkinstalldirs --- make directory hierarchy
+# Author: Noah Friedman <friedman@prep.ai.mit.edu>
+# Created: 1993-05-16
+# Public domain
+
+errstatus=0
+dirmode=""
+
+usage="\
+Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
+
+# process command line arguments
+while test $# -gt 0 ; do
+ case $1 in
+ -h | --help | --h*) # -h for help
+ echo "$usage" 1>&2
+ exit 0
+ ;;
+ -m) # -m PERM arg
+ shift
+ test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
+ dirmode=$1
+ shift
+ ;;
+ --) # stop option processing
+ shift
+ break
+ ;;
+ -*) # unknown option
+ echo "$usage" 1>&2
+ exit 1
+ ;;
+ *) # first non-opt arg
+ break
+ ;;
+ esac
+done
+
+for file
+do
+ if test -d "$file"; then
+ shift
+ else
+ break
+ fi
+done
+
+case $# in
+ 0) exit 0 ;;
+esac
+
+case $dirmode in
+ '')
+ if mkdir -p -- . 2>/dev/null; then
+ echo "mkdir -p -- $*"
+ exec mkdir -p -- "$@"
+ fi
+ ;;
+ *)
+ if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
+ echo "mkdir -m $dirmode -p -- $*"
+ exec mkdir -m "$dirmode" -p -- "$@"
+ fi
+ ;;
+esac
+
+for file
+do
+ set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
+ shift
+
+ pathcomp=
+ for d
+ do
+ pathcomp="$pathcomp$d"
+ case $pathcomp in
+ -*) pathcomp=./$pathcomp ;;
+ esac
+
+ if test ! -d "$pathcomp"; then
+ echo "mkdir $pathcomp"
+
+ mkdir "$pathcomp" || lasterr=$?
+
+ if test ! -d "$pathcomp"; then
+ errstatus=$lasterr
+ else
+ if test ! -z "$dirmode"; then
+ echo "chmod $dirmode $pathcomp"
+ lasterr=""
+ chmod "$dirmode" "$pathcomp" || lasterr=$?
+
+ if test ! -z "$lasterr"; then
+ errstatus=$lasterr
+ fi
+ fi
+ fi
+ fi
+
+ pathcomp="$pathcomp/"
+ done
+done
+
+exit $errstatus
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# End:
+# mkinstalldirs ends here
diff --git a/polkit.pc.in b/polkit.pc.in
new file mode 100644
index 0000000..4385be8
--- /dev/null
+++ b/polkit.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libpolkit
+Description: library for querying and setting system-wide policy
+Version: @VERSION@
+Requires: glib-2.0
+Libs: -L${libdir} -llibpolkit
+Cflags: -I${includedir}/polkit
diff --git a/tools/Makefile.am b/tools/Makefile.am
new file mode 100644
index 0000000..e3ce830
--- /dev/null
+++ b/tools/Makefile.am
@@ -0,0 +1,20 @@
+## Process this file with automake to produce Makefile.in
+
+INCLUDES = \
+ -DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\" \
+ -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_BIN_DIR=\""$(bindir)"\" \
+ -DPACKAGE_LOCALSTATEDIR=\""$(localstatedir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ -I$(top_srcdir) \
+ @GLIB_CFLAGS@
+
+bin_PROGRAMS = \
+ polkit-is-privileged
+
+polkit_is_privileged_SOURCES = polkit-is-privileged.c
+polkit_is_privileged_LDADD = @GLIB_LIBS@ $(top_builddir)/libpolkit/libpolkit.la
+
+clean-local :
+ rm -f *~
diff --git a/tools/Makefile.in b/tools/Makefile.in
new file mode 100644
index 0000000..382720b
--- /dev/null
+++ b/tools/Makefile.in
@@ -0,0 +1,487 @@
+# Makefile.in generated by automake 1.9.6 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ..
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = @INSTALL@
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+bin_PROGRAMS = polkit-is-privileged$(EXEEXT)
+subdir = tools
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
+ $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+am__installdirs = "$(DESTDIR)$(bindir)"
+binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
+PROGRAMS = $(bin_PROGRAMS)
+am_polkit_is_privileged_OBJECTS = polkit-is-privileged.$(OBJEXT)
+polkit_is_privileged_OBJECTS = $(am_polkit_is_privileged_OBJECTS)
+polkit_is_privileged_DEPENDENCIES = \
+ $(top_builddir)/libpolkit/libpolkit.la
+DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(polkit_is_privileged_SOURCES)
+DIST_SOURCES = $(polkit_is_privileged_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMDEP_FALSE = @AMDEP_FALSE@
+AMDEP_TRUE = @AMDEP_TRUE@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BINDIR = @BINDIR@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DATADIR = @DATADIR@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DOCDIR = @DOCDIR@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ENABLE_GTK_DOC_FALSE = @ENABLE_GTK_DOC_FALSE@
+ENABLE_GTK_DOC_TRUE = @ENABLE_GTK_DOC_TRUE@
+EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+GCOV_FALSE = @GCOV_FALSE@
+GCOV_TRUE = @GCOV_TRUE@
+GLIB_CFLAGS = @GLIB_CFLAGS@
+GLIB_LIBS = @GLIB_LIBS@
+GTK_DOC_USE_LIBTOOL_FALSE = @GTK_DOC_USE_LIBTOOL_FALSE@
+GTK_DOC_USE_LIBTOOL_TRUE = @GTK_DOC_USE_LIBTOOL_TRUE@
+HTML_DIR = @HTML_DIR@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBDIR = @LIBDIR@
+LIBEXECDIR = @LIBEXECDIR@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+LOCALSTATEDIR = @LOCALSTATEDIR@
+LTLIBOBJS = @LTLIBOBJS@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_REVISION = @LT_REVISION@
+MAINT = @MAINT@
+MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
+MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
+MAKEINFO = @MAKEINFO@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+POLKIT_GROUP = @POLKIT_GROUP@
+POLKIT_USER = @POLKIT_USER@
+RANLIB = @RANLIB@
+SBINDIR = @SBINDIR@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+SYSCONFDIR = @SYSCONFDIR@
+VERSION = @VERSION@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
+ac_ct_RANLIB = @ac_ct_RANLIB@
+ac_ct_STRIP = @ac_ct_STRIP@
+ac_pt_PKG_CONFIG = @ac_pt_PKG_CONFIG@
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
+am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
+am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+datadir = @datadir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+INCLUDES = \
+ -DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\" \
+ -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_BIN_DIR=\""$(bindir)"\" \
+ -DPACKAGE_LOCALSTATEDIR=\""$(localstatedir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ -I$(top_srcdir) \
+ @GLIB_CFLAGS@
+
+polkit_is_privileged_SOURCES = polkit-is-privileged.c
+polkit_is_privileged_LDADD = @GLIB_LIBS@ $(top_builddir)/libpolkit/libpolkit.la
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu tools/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu tools/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+install-binPROGRAMS: $(bin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
+ if test -f $$p \
+ || test -f $$p1 \
+ ; then \
+ f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
+ else :; fi; \
+ done
+
+uninstall-binPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
+ echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
+ rm -f "$(DESTDIR)$(bindir)/$$f"; \
+ done
+
+clean-binPROGRAMS:
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f $$p $$f"; \
+ rm -f $$p $$f ; \
+ done
+polkit-is-privileged$(EXEEXT): $(polkit_is_privileged_OBJECTS) $(polkit_is_privileged_DEPENDENCIES)
+ @rm -f polkit-is-privileged$(EXEEXT)
+ $(LINK) $(polkit_is_privileged_LDFLAGS) $(polkit_is_privileged_OBJECTS) $(polkit_is_privileged_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/polkit-is-privileged.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+ -rm -f libtool
+uninstall-info-am:
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
+ list='$(DISTFILES)'; for file in $$list; do \
+ case $$file in \
+ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
+ $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
+ esac; \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ dir="/$$dir"; \
+ $(mkdir_p) "$(distdir)$$dir"; \
+ else \
+ dir=''; \
+ fi; \
+ if test -d $$d/$$file; then \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+ for dir in "$(DESTDIR)$(bindir)"; do \
+ test -z "$$dir" || $(mkdir_p) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-binPROGRAMS clean-generic clean-libtool clean-local \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-libtool distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am: install-binPROGRAMS
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-binPROGRAMS uninstall-info-am
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
+ clean-generic clean-libtool clean-local ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-binPROGRAMS install-data \
+ install-data-am install-exec install-exec-am install-info \
+ install-info-am install-man install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-am uninstall-binPROGRAMS \
+ uninstall-info-am
+
+
+clean-local :
+ rm -f *~
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/tools/polkit-is-privileged.c b/tools/polkit-is-privileged.c
new file mode 100644
index 0000000..a07f35d
--- /dev/null
+++ b/tools/polkit-is-privileged.c
@@ -0,0 +1,194 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * polkit-is-privileged.c : Small command line wrapper for libpolkit
+ *
+ * Copyright (C) 2006 David Zeuthen, <david@fubar.dk>
+ *
+ * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+
+#include <libpolkit/libpolkit.h>
+
+static void
+usage (int argc, char *argv[])
+{
+ fprintf (stderr, "hal-policy-is-privileged version " PACKAGE_VERSION "\n");
+
+ fprintf (stderr, "\n" "usage : %s -u <uid> -p <policy> [-r <resource>]\n", argv[0]);
+ fprintf (stderr,
+ "\n"
+ "Options:\n"
+ " -u, --uid Username or user id\n"
+ " -r, --resource Resource\n"
+ " -p, --policy policy to test for\n"
+ " -h, --help Show this information and exit\n"
+ " -v, --verbose Verbose operation\n"
+ " -V, --version Print version number\n"
+ "\n"
+ "Queries system policy whether a given user is allowed for a given\n"
+ "policy for a given resource. The resource may be omitted.\n"
+ "\n"
+ "System policies are defined in the " PACKAGE_SYSCONF_DIR "/hal/policy directory.\n"
+ "\n");
+}
+
+int
+main (int argc, char *argv[])
+{
+ int rc;
+ uid_t uid;
+ char *user = NULL;
+ char *policy = NULL;
+ char *resource = NULL;
+ static const struct option long_options[] = {
+ {"uid", required_argument, NULL, 'u'},
+ {"resource", required_argument, NULL, 'r'},
+ {"policy", required_argument, NULL, 'p'},
+ {"help", no_argument, NULL, 'h'},
+ {"verbose", no_argument, NULL, 'v'},
+ {"version", no_argument, NULL, 'V'},
+ {NULL, 0, NULL, 0}
+ };
+ LibPolKitContext *ctx = NULL;
+ char *endp;
+ gboolean is_allowed;
+ LibPolKitResult result;
+ gboolean is_verbose = FALSE;
+
+ rc = 1;
+
+ while (TRUE) {
+ int c;
+
+ c = getopt_long (argc, argv, "u:r:p:UhVv", long_options, NULL);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'u':
+ user = g_strdup (optarg);
+ break;
+
+ case 'r':
+ resource = g_strdup (optarg);
+ break;
+
+ case 'p':
+ policy = g_strdup (optarg);
+ break;
+
+ case 'v':
+ is_verbose = TRUE;
+ break;
+
+ case 'h':
+ usage (argc, argv);
+ rc = 0;
+ goto out;
+
+ case 'V':
+ printf ("hal-policy-is-privileged version " PACKAGE_VERSION "\n");
+ rc = 0;
+ goto out;
+
+ default:
+ usage (argc, argv);
+ goto out;
+ }
+ }
+
+ if (user == NULL || policy == NULL) {
+ usage (argc, argv);
+ return 1;
+ }
+
+ if (is_verbose) {
+ printf ("user = '%s'\n", user);
+ printf ("policy = '%s'\n", policy);
+ printf ("resource = '%s'\n", resource);
+ }
+
+ ctx = libpolkit_new_context ();
+ if (ctx == NULL) {
+ g_warning ("Cannot get policy context");
+ goto out;
+ }
+
+ uid = (uid_t) g_ascii_strtoull (user, &endp, 0);
+ if (endp[0] != '\0') {
+ uid = libpolkit_util_name_to_uid (ctx, user, NULL);
+ if (uid == (uid_t) -1) {
+ g_warning ("User '%s' does not exist", user);
+ goto out;
+ }
+ }
+
+ if (is_verbose) {
+ printf ("user '%s' is uid %d\n", user, (int) uid);
+ }
+
+ result = libpolkit_is_uid_allowed_for_policy (ctx,
+ uid,
+ policy,
+ resource,
+ &is_allowed);
+ switch (result) {
+ case LIBPOLKIT_RESULT_OK:
+ rc = is_allowed ? 0 : 1;
+ break;
+
+ case LIBPOLKIT_RESULT_ERROR:
+ g_warning ("error retrieving policy");
+ break;
+
+ case LIBPOLKIT_RESULT_INVALID_CONTEXT:
+ g_warning ("invalid context");
+ break;
+
+ case LIBPOLKIT_RESULT_PERMISSON_DENIED:
+ g_warning ("permission denied");
+ break;
+
+ case LIBPOLKIT_RESULT_NO_SUCH_POLICY:
+ g_warning ("no such policy '%s'", policy);
+ break;
+ }
+
+ if (is_verbose) {
+ printf ("result %d\n", result);
+ printf ("is_allowed %d\n", is_allowed);
+ }
+
+out:
+ if (ctx != NULL)
+ libpolkit_free_context (ctx);
+
+ return rc;
+}
+