pax_global_header00006660000000000000000000000064143512200340014504gustar00rootroot0000000000000052 comment=94a1e3885f715590d99ef91bb093d6b52db0294b group-service-1.4.0/000077500000000000000000000000001435122003400143005ustar00rootroot00000000000000group-service-1.4.0/COPYING000066400000000000000000001045161435122003400153420ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . group-service-1.4.0/README.md000066400000000000000000000022631435122003400155620ustar00rootroot00000000000000## Tuglie ![admin:](https://github.com/zhuyaliang/images/blob/master/004.png) ![group:](https://github.com/zhuyaliang/images/blob/master/005.png) ## Describe ``` Using Dbus to manage user groups, you can complete the addition and deletion of user groups, add \ remove users to groups, and change the name of user groups.The `test` directory is some testing process. ``` ## Part API Description ``` GasGroupManager *gas_group_manager_get_default() Create GasGroupManager classes GSList *gas_group_manager_list_groups(GasGroupManager *manager) Get classes GasGroup for all groups const char *gas_group_get_group_name(GasGroup *Group) Get the group name void gas_group_set_group_name(GasGroup *group, const char *name); Modify the group name ``` ## Compile ``` meson build -Dprefix=/usr ninja -C build sudo ninja -C build install ``` ## Create deb package on Ubuntu MATE 22.04 LTS ``` sudo apt-get update sudo apt-get install dpkg-dev debhelper-compat meson cmake pkg-config libdbus-1-dev systemd libglib2.0-dev libpolkit-gobject-1-dev polkitd dpkg-buildpackage -uc -us sudo apt-get install ../group-service*.deb ``` group-service-1.4.0/data/000077500000000000000000000000001435122003400152115ustar00rootroot00000000000000group-service-1.4.0/data/group-admin-daemon.service.in000066400000000000000000000005061435122003400226640ustar00rootroot00000000000000[Unit] Description=Group Service After=nss-user-lookup.target Wants=nss-user-lookup.target [Service] Type=dbus BusName=org.group.admin ExecStart=@libexecdir@/group-admin-daemon Environment=GVFS_DISABLE_FUSE=1 Environment=GIO_USE_VFS=local Environment=GVFS_REMOTE_VOLUME_MONITOR_IGNORE=1 [Install] WantedBy=graphical.target group-service-1.4.0/data/meson.build000066400000000000000000000015641435122003400173610ustar00rootroot00000000000000ifaces = files( gas_namespace + '.xml', gas_namespace + '.list.xml', ) install_data( ifaces, install_dir: dbus_ifaces_dir, ) install_data( gas_namespace + '.conf', install_dir: dbus_conf_dir, ) service_conf = configuration_data() service_conf.set('libexecdir', gas_libexecdir) service = gas_namespace + '.service' configure_file( input: service + '.in', output: service, configuration: service_conf, install: true, install_dir: dbus_sys_dir, ) policy = gas_namespace.to_lower() + '.policy' i18n.merge_file( input: policy + '.in', output: policy, po_dir: po_dir, install: true, install_dir: policy_dir, ) if install_systemd_unit_dir service = 'group-admin-daemon.service' configure_file( input: service + '.in', output: service, configuration: service_conf, install: true, install_dir: systemd_system_unit_dir, ) endif group-service-1.4.0/data/org.group.admin.conf000066400000000000000000000015371435122003400210770ustar00rootroot00000000000000 group-service-1.4.0/data/org.group.admin.list.xml000066400000000000000000000016341435122003400217220ustar00rootroot00000000000000 group-service-1.4.0/data/org.group.admin.policy.in000066400000000000000000000017101435122003400220470ustar00rootroot00000000000000 stock_person Change your own user data Authentication is required to change your own user data yes yes yes Manage group admin Authentication is required to change user data auth_admin auth_admin auth_admin_keep group-service-1.4.0/data/org.group.admin.service.in000066400000000000000000000001761435122003400222150ustar00rootroot00000000000000[D-BUS Service] Name=org.group.admin Exec=@libexecdir@/group-admin-daemon User=root SystemdService=group-admin-daemon.service group-service-1.4.0/data/org.group.admin.xml000066400000000000000000000021321435122003400207420ustar00rootroot00000000000000 group-service-1.4.0/debian/000077500000000000000000000000001435122003400155225ustar00rootroot00000000000000group-service-1.4.0/debian/changelog000066400000000000000000000004141435122003400173730ustar00rootroot00000000000000group-service (1.4.0-1) zhuyaliang; urgency=medium * Update release -- zhuyaliang <15132211195@163.com> Fri, 23 Dec 2022 11:27:1 group-service (1.3.0-1) jammy; urgency=medium * Initial release -- N0rbert Fri, 20 May 2022 00:09:59 +0300 group-service-1.4.0/debian/control000066400000000000000000000014731435122003400171320ustar00rootroot00000000000000Source: group-service Section: utils Priority: optional Maintainer: N0rbert Build-Depends: debhelper-compat (= 13), meson (>= 0.53.0), cmake, pkg-config, libdbus-1-dev, systemd, libglib2.0-dev, libpolkit-gobject-1-dev, polkitd Standards-Version: 4.6.0 Homepage: https://github.com/zhuyaliang/group-service Rules-Requires-Root: no Package: group-service Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: Borrowing DBUS services to manage user groups Using Dbus to manage user groups, you can complete the addition and deletion of user groups, add \ remove users to groups, and change the name of user groups.The `test` directory is some testing process. group-service-1.4.0/debian/rules000077500000000000000000000003101435122003400165740ustar00rootroot00000000000000#! /usr/bin/make -f export DEB_BUILD_MAINT_OPTIONS = hardening=+all export DEB_LDFLAGS_MAINT_APPEND = -Wl,-O1 -Wl,-z,defs %: dh $@ override_dh_auto_test: DEB_BUILD_OPTIONS=nocheck dh_auto_test group-service-1.4.0/meson.build000066400000000000000000000115521435122003400164460ustar00rootroot00000000000000project('group-service', 'c', version : '1.4.0', license : 'GPLv3', meson_version : '>=0.50.0', default_options : [ 'warning_level=1', 'buildtype=debugoptimized', 'c_std=gnu11'], ) gas_id = 'gas' gas_name = meson.project_name() gas_api_version = '1.0' gas_api_name = '@0@-@1@'.format(gas_name, gas_api_version) gas_prefix = get_option('prefix') gas_datadir = join_paths(gas_prefix, get_option('datadir')) gas_namespace = 'org.group.admin' data_dir = join_paths(meson.current_source_dir(), 'data') po_dir = join_paths(meson.current_source_dir(), 'po') gas_libexecdir = join_paths(gas_prefix, get_option('libexecdir')) gas_includedir = join_paths(gas_prefix, get_option('includedir')) gas_pkgincludedir = join_paths(gas_includedir, gas_api_name) gas_sysconfdir = join_paths(gas_prefix, get_option('sysconfdir')) soversion = 1 current = 0 revision = 0 libversion = '@0@.@1@.@2@'.format(soversion, current, revision) dbus_dep = dependency('dbus-1') dbus_conf_dir = join_paths(dbus_dep.get_pkgconfig_variable('sysconfdir', define_variable: ['sysconfdir', gas_sysconfdir]), 'dbus-1', 'system.d') dbus_ifaces_dir = dbus_dep.get_pkgconfig_variable('interfaces_dir', define_variable: ['datadir', gas_datadir]) dbus_sys_dir = dbus_dep.get_pkgconfig_variable('system_bus_services_dir', define_variable: ['datadir', gas_datadir]) systemd_system_unit_dir = get_option('systemdsystemunitdir') install_systemd_unit_dir = (systemd_system_unit_dir != 'no') enable_systemd = get_option('systemd') enable_elogind = get_option('elogind') if install_systemd_unit_dir and systemd_system_unit_dir == '' systemd_dep = dependency('systemd', required: false) assert(systemd_dep.found(), 'systemd required but not found, please provide a valid systemd user unit dir or disable it') systemd_system_unit_dir = systemd_dep.get_pkgconfig_variable('systemdsystemunitdir') endif # Compiler & Project arguments add_project_arguments([ '-DHAVE_CONFIG_H', '-I' + meson.build_root(), ], language: 'c') # get suported warning flags test_args = [ '-fstack-protector-strong', '-Waggregate-return', '-Warray-bounds', '-Wcast-align', '-Wclobbered', '-Wdeclaration-after-statement', '-Wempty-body', '-Wextra', '-Wformat=2', '-Wformat-nonliteral', '-Wformat-security', '-Wformat-signedness', '-Wignored-qualifiers', # '-Wimplicit-function-declaration', '-Winit-self', '-Winline', '-Wmissing-declarations', '-Wmissing-format-attribute', '-Wmissing-include-dirs', '-Wmissing-noreturn', '-Wmissing-parameter-type', '-Wmissing-prototypes', '-Wnested-externs', '-Wno-discarded-qualifiers', '-Wno-missing-field-initializers', '-Wno-strict-aliasing', '-Wno-suggest-attribute=format', '-Wno-unused-parameter', '-Wold-style-definition', '-Woverride-init', '-Wpacked', '-Wpointer-arith', '-Wredundant-decls', '-Wreturn-type', '-Wshadow', '-Wsign-compare', '-Wstrict-aliasing', '-Wstrict-prototypes', '-Wswitch-default', '-Wtype-limits', '-Wundef', '-Wuninitialized', '-Wunused-but-set-variable', '-Wwrite-strings' ] cc = meson.get_compiler('c') foreach arg: test_args if cc.has_argument(arg) add_project_arguments(arg, language : 'c') endif endforeach # enable full RELRO where possible # FIXME: until https://github.com/mesonbuild/meson/issues/1140 is fixed global_link_args = [] test_link_args = [ '-Wl,-z,relro', '-Wl,-z,now', ] foreach arg: test_link_args if cc.has_argument(arg) global_link_args += arg endif endforeach add_global_link_arguments( global_link_args, language: 'c' ) # Dependencies gio_dep = dependency('gio-2.0', version: '>= 2.37.3') gio_unix_dep = dependency('gio-unix-2.0') glib_dep = dependency('glib-2.0', version: '>= 2.44') polkit_gobject_dep = dependency('polkit-gobject-1') crypt_dep = cc.find_library('crypt') # Configure data policy_dir = polkit_gobject_dep.get_pkgconfig_variable('policydir', define_variable: ['prefix', gas_prefix]) conf = configuration_data() conf.set_quoted('VERSION', meson.project_version()) conf.set_quoted('PACKAGE_NAME', meson.project_name()) conf.set_quoted('PACKAGE_VERSION', meson.project_version()) conf.set_quoted('GETTEXT_PACKAGE', meson.project_name()) conf.set_quoted('LUNAR_CALENDAR_LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir'))) conf.set_quoted('LIBDIR', join_paths(get_option('prefix'), get_option('libdir'))) conf.set_quoted('BINDIR', join_paths(get_option('prefix'), get_option('bindir'))) conf.set_quoted('SYSCONFDIR', join_paths(get_option('prefix'), get_option('sysconfdir'))) conf.set_quoted('LOCALSTATEDIR', join_paths(get_option('prefix'), get_option('localstatedir'))) conf.set_quoted('LIBEXECDIR', join_paths(get_option('prefix'), get_option('libexecdir'))) configure_file( output : 'config.h', configuration : conf ) top_srcdir = include_directories('.') src_subdir = include_directories('.', 'src') subdir('po') subdir('src') subdir('data') subdir('test') group-service-1.4.0/meson_options.txt000066400000000000000000000020741435122003400177400ustar00rootroot00000000000000option('systemdsystemunitdir', type: 'string', value: '', description: 'custom directory for systemd system units') option('admin_group', type: 'string', value: '', description: 'Set group for administrative accounts') option('user_heuristics', type: 'boolean', value: true, description: 'Enable heuristics for guessing system vs. human users in the range 500-minimum-uid') option('extra_admin_groups', type: 'array', value: [], description: 'Comma-separated list of extra groups that administrator users are part of') option('minimum_uid', type: 'integer', value: 1000, description: 'Set minimum uid for human users') option('systemd', type: 'boolean', value: false, description: 'Use systemd') option('elogind', type: 'boolean', value: false, description: 'Use elogind') option('introspection', type: 'boolean', value: true, description: 'Enable introspection for this build') option('docbook', type: 'boolean', value: false, description: 'build documentation (requires xmlto)') option('gtk_doc', type: 'boolean', value: false, description: 'use gtk-doc to build documentation') group-service-1.4.0/po/000077500000000000000000000000001435122003400147165ustar00rootroot00000000000000group-service-1.4.0/po/LINGUAS000066400000000000000000000000661435122003400157450ustar00rootroot00000000000000# please keep this list sorted alphabetically # zh_CN group-service-1.4.0/po/POTFILES.in000066400000000000000000000001131435122003400164660ustar00rootroot00000000000000data/org.group.admin.policy.in src/main.c src/group-server.c src/group.c group-service-1.4.0/po/fr.po000066400000000000000000000022571435122003400156730ustar00rootroot00000000000000# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the group-service package. # FIRST AUTHOR , YEAR. # msgid "" msgstr "" "Project-Id-Version: group-service\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-12-10 11:20+0800\n" "PO-Revision-Date: 2019-09-12 20:46+0200\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Poedit 2.1.1\n" "Last-Translator: Pierre-Yves \n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" "Language: fr\n" #: data/org.group.admin.policy.in:11 msgid "Change your own user data" msgstr "Modifier vos données utilisateur" #: data/org.group.admin.policy.in:12 msgid "Authentication is required to change your own user data" msgstr "Authentification nécessaire pour modifier vos données utilisateur" #: data/org.group.admin.policy.in:21 msgid "Manage group admin" msgstr "Gestion des groupes" #: data/org.group.admin.policy.in:22 msgid "Authentication is required to change user data" msgstr "Authentification nécessaire pour modifier les données de l'utilisateur" group-service-1.4.0/po/group-service.pot000066400000000000000000000016761435122003400202460ustar00rootroot00000000000000# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the group-service package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: group-service\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-12-10 11:20+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: data/org.group.admin.policy.in:11 msgid "Change your own user data" msgstr "" #: data/org.group.admin.policy.in:12 msgid "Authentication is required to change your own user data" msgstr "" #: data/org.group.admin.policy.in:21 msgid "Manage group admin" msgstr "" #: data/org.group.admin.policy.in:22 msgid "Authentication is required to change user data" msgstr "" group-service-1.4.0/po/meson.build000066400000000000000000000001121435122003400170520ustar00rootroot00000000000000i18n = import('i18n') i18n.gettext(meson.project_name(), preset: 'glib',) group-service-1.4.0/po/zh_CN.po000066400000000000000000000020451435122003400162600ustar00rootroot00000000000000# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the group-service package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: group-service\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-12-10 11:20+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" #: data/org.group.admin.policy.in:11 msgid "Change your own user data" msgstr "修改您的用户数据" #: data/org.group.admin.policy.in:12 msgid "Authentication is required to change your own user data" msgstr "修改您的用户数据:需要授权" #: data/org.group.admin.policy.in:21 msgid "Manage group admin" msgstr "组管理" #: data/org.group.admin.policy.in:22 msgid "Authentication is required to change user data" msgstr "修改用户数据:需要授权" group-service-1.4.0/src/000077500000000000000000000000001435122003400150675ustar00rootroot00000000000000group-service-1.4.0/src/group-server.c000066400000000000000000000603721435122003400177030ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "group-server.h" #define PATH_PASSWD "/etc/passwd" #define PATH_SHADOW "/etc/shadow" #define PATH_GROUP "/etc/group" enum { PROP_0, PROP_MANAGE_VERSION }; struct ManagePrivate { GDBusConnection *BusConnection; GHashTable *GroupsHashTable; GFileMonitor *PasswdMonitor; GFileMonitor *ShadowMonitor; GFileMonitor *GroupMonitor; guint ReloadId; PolkitAuthority *Authority; }; typedef struct group * (* GroupEntryGeneratorFunc) (FILE *); typedef void ( FileChangeCallback )(GFileMonitor *, GFile *, GFile *, GFileMonitorEvent, Manage *); static void manage_user_group_admin_iface_init (UserGroupAdminIface *iface); G_DEFINE_TYPE_WITH_CODE (Manage,manage, USER_GROUP_TYPE_ADMIN_SKELETON, G_ADD_PRIVATE (Manage) G_IMPLEMENT_INTERFACE ( USER_GROUP_TYPE_ADMIN, manage_user_group_admin_iface_init)); G_DEFINE_AUTOPTR_CLEANUP_FUNC (Manage, g_object_unref) static const GDBusErrorEntry group_error_entries[] = { { ERROR_FAILED, "org.group.admin.Error.Failed" }, { ERROR_GROUP_EXISTS, "org.group.admin.Error.GroupExists" }, { ERROR_GROUP_DOES_NOT_EXIST, "org.group.admin.Error.GRoupDoesNotExist" }, { ERROR_PERMISSION_DENIED, "org.group.admin.Error.PermissionDenied" }, { ERROR_NOT_SUPPORTED, "org.group.admin.Error.NotSupported" } }; GQuark error_quark (void) { static volatile gsize quark_volatile = 0; g_dbus_error_register_error_domain ("group_error", &quark_volatile, group_error_entries, G_N_ELEMENTS (group_error_entries)); return (GQuark) quark_volatile; } void DbusPrintf (GDBusMethodInvocation *Invocation, gint ErrorCode, const gchar *format, ...) { va_list args; g_autofree gchar *Message = NULL; va_start (args, format); Message = g_strdup_vprintf (format, args); va_end (args); g_dbus_method_invocation_return_error (Invocation, ERROR, ErrorCode, "%s", Message); } static GHashTable * CreateGroupsHashTable (void) { return g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); } static struct group * entry_generator_fgetgrent (FILE *fd) { struct group *grent; grent = fgetgrent (fd); if (grent != NULL) { return grent; } fclose (fd); return NULL; } static void LoadGroupEntries (GHashTable *groups, GroupEntryGeneratorFunc EntryGenerator, Manage *manage) { struct group *grent; Group *group = NULL; FILE *fd; ManagePrivate *priv = manage_get_instance_private (manage); fd = fopen (PATH_GROUP, "r"); if(fd == NULL) { return; } while(1) { grent = EntryGenerator (fd); if (grent == NULL) { break; } group = g_hash_table_lookup (groups, grent->gr_name); if(group == NULL) { group = g_hash_table_lookup(priv->GroupsHashTable,grent->gr_name); if(group == NULL) { group = group_new (manage,grent->gr_gid); } else { g_object_ref (group); } g_object_freeze_notify (G_OBJECT (group)); group_update_from_grent (group, grent); g_hash_table_insert (groups, g_strdup (group_get_group_name (group)), group); } } } static struct passwd *GetPwent(FILE *fd) { struct passwd *pwent; pwent = fgetpwent (fd); if (pwent != NULL) { return pwent; } fclose (fd); return NULL; } static void LoadPrimaryGroup (GHashTable *groups) { struct passwd *pwent; struct group *grent; Group *group = NULL; FILE *fd; const gchar *users[2]; fd = fopen (PATH_PASSWD, "r"); if(fd == NULL) { return; } while(1) { pwent = GetPwent(fd); if (pwent == NULL) { break; } grent = getgrgid (pwent->pw_gid); if(grent == NULL) { continue; } group = g_hash_table_lookup (groups, grent->gr_name); if(group == NULL) { continue; } g_object_freeze_notify (G_OBJECT (group)); if(grent->gr_mem[0] == NULL) { users[0] = g_strdup(pwent->pw_gecos); users[1] = NULL; user_group_list_set_users(USER_GROUP_LIST(group),users); g_free((gpointer)users[0]); } user_group_list_set_primary_group(USER_GROUP_LIST(group), TRUE); g_object_thaw_notify (G_OBJECT (group)); } } static void ReloadGroups (Manage *manage) { GHashTable *GroupsHashTable; GHashTableIter iter; GHashTable *OldGroups; gpointer name,value; GroupsHashTable = CreateGroupsHashTable (); LoadGroupEntries(GroupsHashTable, entry_generator_fgetgrent,manage); OldGroups = manage->priv->GroupsHashTable; manage->priv->GroupsHashTable = GroupsHashTable; LoadPrimaryGroup(GroupsHashTable); g_hash_table_iter_init (&iter, OldGroups); while (g_hash_table_iter_next (&iter, &name,&value)) { Group *group = value; Group *refreshed_group; refreshed_group = g_hash_table_lookup (GroupsHashTable,name); if(!refreshed_group) { user_group_admin_emit_group_deleted (USER_GROUP_ADMIN(manage), group_get_object_path (group)); UnRegisterGroup (manage,value); } } g_hash_table_iter_init (&iter, GroupsHashTable); while (g_hash_table_iter_next (&iter, &name,&value)) { Group *group = value; Group *stale_group; stale_group = g_hash_table_lookup (OldGroups, name); if (!stale_group) { user_group_admin_emit_group_added(USER_GROUP_ADMIN(manage), group_get_object_path (group)); RegisterGroup (manage,value); } g_object_thaw_notify (G_OBJECT (group)); } g_hash_table_destroy (OldGroups); } static gboolean ReloadGroupsTimeout (Manage *manage) { ReloadGroups (manage); manage->priv->ReloadId = 0; return FALSE; } static void QueueReloadGroupSoon (Manage *manage) { if (manage->priv->ReloadId > 0) { return; } manage->priv->ReloadId = g_timeout_add (500, (GSourceFunc)ReloadGroupsTimeout, manage); } static void GroupsMonitorChanged (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, Manage *manage) { if (event_type != G_FILE_MONITOR_EVENT_CHANGED && event_type != G_FILE_MONITOR_EVENT_CREATED) { return; } QueueReloadGroupSoon(manage); } static GFileMonitor *SetupMonitor (const gchar *FileName, FileChangeCallback *Callback, Manage *manage) { GError *error = NULL; GFile *file; GFileMonitor *Monitor; file = g_file_new_for_path (FileName); Monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error); if (Monitor != NULL) { g_signal_connect (Monitor, "changed", G_CALLBACK (Callback), manage); } else { g_warning ("Unable to monitor %s: %s", FileName, error->message); g_error_free (error); } g_object_unref (file); return Monitor; } static void manage_init (Manage *manage) { manage->priv = manage_get_instance_private (manage); manage->priv->ReloadId = 0; manage->priv->GroupsHashTable = CreateGroupsHashTable(); manage->priv->PasswdMonitor = SetupMonitor (PATH_PASSWD, GroupsMonitorChanged, manage); manage->priv->ShadowMonitor = SetupMonitor (PATH_SHADOW, GroupsMonitorChanged, manage); manage->priv->GroupMonitor = SetupMonitor (PATH_GROUP , GroupsMonitorChanged, manage); ReloadGroupsTimeout (manage); } static void manage_finalize (GObject *object) { ManagePrivate *priv; Manage *manage; manage = MANAGE (object); priv = manage_get_instance_private (manage);; if (priv->BusConnection != NULL) g_object_unref (priv->BusConnection); g_hash_table_destroy (priv->GroupsHashTable); } static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { switch (prop_id) { case PROP_MANAGE_VERSION: g_value_set_string (value, VERSION); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { switch (prop_id) { case PROP_MANAGE_VERSION: g_assert_not_reached (); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void manage_class_init (ManageClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = manage_finalize; object_class->get_property = get_property; object_class->set_property = set_property; g_object_class_override_property (object_class, PROP_MANAGE_VERSION, "daemon-version"); } void ManageLoadGroup (Manage *manage) { ReloadGroups(manage); } Manage *manage_new(void) { Manage *manage = NULL; manage = MANAGE(g_object_new (TYPE_MANAGE, NULL)); return manage; } int RegisterGroupManage (Manage *manage) { GError *error = NULL; manage->priv->Authority = polkit_authority_get_sync (NULL, &error); if (manage->priv->Authority == NULL) { if (error != NULL) { g_print ("error getting polkit authority: %s", error->message); g_error_free(error); } return -1; } manage->priv->BusConnection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (manage->priv->BusConnection == NULL) { if (error != NULL) { g_print ("error getting system bus: %s\r\n", error->message); g_error_free(error); } printf ("error getting system bus\r\n"); return -1; } if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manage), manage->priv->BusConnection, "/org/group/admin", &error)) { if (error != NULL) { g_print ("error export system bus: %s\r\n", error->message); g_print ("error exporting interface: %s\r\n", error->message); g_error_free(error); } printf ("error exporting interface: \r\n"); return -1; } return 0; } typedef struct { Manage *manage; Group *group; AuthorizedCallback Authorized_cb; GDBusMethodInvocation *Invocation; gpointer data; GDestroyNotify DestroyNotify; } CheckAuthData; static void CheckAuthDataFree (CheckAuthData *data) { if(data->manage) g_object_unref (data->manage); if (data->group) g_object_unref (data->group); if (data->DestroyNotify) (*data->DestroyNotify) (data->data); g_free (data); } static void CheckAuth_cb (PolkitAuthority *Authority, GAsyncResult *res, gpointer data) { CheckAuthData *cad = data; PolkitAuthorizationResult *result; GError *error = NULL; gboolean is_authorized = FALSE; result = polkit_authority_check_authorization_finish (Authority, res, &error); if (error) { DbusPrintf (cad->Invocation, ERROR_PERMISSION_DENIED, "Not authorized: %s", error->message); g_error_free(error); } else { if (polkit_authorization_result_get_is_authorized (result)) { is_authorized = TRUE; } else if (polkit_authorization_result_get_is_challenge (result)) { DbusPrintf (cad->Invocation, ERROR_PERMISSION_DENIED, "Authentication is required"); } else { DbusPrintf (cad->Invocation, ERROR_PERMISSION_DENIED, "Not authorized"); } g_object_unref (result); } if (is_authorized) { (* cad->Authorized_cb) (cad->manage, cad->group, cad->Invocation, cad->data); } CheckAuthDataFree (data); } void LocalCheckAuthorization(Manage *manage, Group *group, const gchar *ActionFile, gboolean AllowInteraction, AuthorizedCallback Authorized_cb, GDBusMethodInvocation *Invocation, gpointer Authorized_cb_data, GDestroyNotify DestroyNotify) { ManagePrivate *priv = manage_get_instance_private (manage); CheckAuthData *data; PolkitSubject *subject; PolkitCheckAuthorizationFlags flags; data = g_new0 (CheckAuthData, 1); data->manage = g_object_ref (manage); if (group) { data->group = g_object_ref (group); } data->Invocation = Invocation; data->Authorized_cb = Authorized_cb; data->data = Authorized_cb_data; data->DestroyNotify = DestroyNotify; subject = polkit_system_bus_name_new (g_dbus_method_invocation_get_sender (Invocation)); flags = POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE; if (AllowInteraction) { flags |= POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION; } polkit_authority_check_authorization (priv->Authority, subject, ActionFile, NULL, flags, NULL, (GAsyncReadyCallback) CheckAuth_cb, data); g_object_unref (subject); } static Group * AddNewGroupForDus (Manage *manage,struct group *grent) { Group *group; group = group_new (manage,grent->gr_gid); group_update_from_grent (group, grent); RegisterGroup (manage, group); g_hash_table_insert (manage->priv->GroupsHashTable, g_strdup (group_get_group_name (group)), group); user_group_admin_emit_group_added (USER_GROUP_ADMIN(manage), group_get_object_path (group)); return group; } static Group *ManageLocalFindGroupByid(Manage *manage, gid_t gid) { ManagePrivate *priv = manage_get_instance_private (manage); Group *group; struct group *grent; grent = getgrgid(gid); if (grent == NULL) { g_print ("unable to lookup gid %d",(int)gid); return NULL; } group = g_hash_table_lookup (priv->GroupsHashTable, grent->gr_name); if(group == NULL) { AddNewGroupForDus(manage,grent); } return group; } static gboolean ManageFindGRoupByid (UserGroupAdmin *object, GDBusMethodInvocation *invocation, gint64 gid) { Manage *manage = (Manage *)object; Group *group; group = ManageLocalFindGroupByid (manage, gid); if (group) { user_group_admin_complete_find_group_by_id(NULL,invocation,group_get_object_path (group)); } else { DbusPrintf (invocation, ERROR_FAILED, "Failed to look up group with name %d.", gid); } return TRUE; } static Group *ManageLocalFindGroupByname (Manage *manage, const gchar *name) { ManagePrivate *priv = manage_get_instance_private (manage); Group *group; struct group *grent; grent = getgrnam (name); if (grent == NULL) { g_print ("unable to lookup name %s: %s", name, g_strerror (errno)); return NULL; } group = g_hash_table_lookup (priv->GroupsHashTable, grent->gr_name); if(group == NULL) { group = AddNewGroupForDus (manage, grent); } return group; } static gboolean ManageFindGroupByname(UserGroupAdmin *object, GDBusMethodInvocation *invocation, const gchar *name) { Manage *manage = (Manage *)object; Group *group; group = ManageLocalFindGroupByname (manage, name); if (group) { user_group_admin_complete_find_group_by_name(NULL,invocation,group_get_object_path (group)); } else { DbusPrintf (invocation, ERROR_FAILED, "Failed to look up group with name %s.", name); } return TRUE; } static const gchar * ManageGetDammonVersion (UserGroupAdmin *object) { return VERSION; } typedef struct { gchar *NewGroupName; } CreateGroupData; static void CreateGroupDataFree (gpointer data) { CreateGroupData *cd = data; g_free (cd->NewGroupName); g_free (cd); } static void CreateNewGroup_cb (Manage *manage, Group *g, GDBusMethodInvocation *Invocation, gpointer data) { CreateGroupData *cd = data; GError *error = NULL; Group *group; const gchar *argv[4]; if (getgrnam (cd->NewGroupName) != NULL) { DbusPrintf (Invocation, ERROR_GROUP_EXISTS, "A gtoup with name '%s' already exists", cd->NewGroupName); return; } sys_log (Invocation, "create group '%s'", cd->NewGroupName); argv[0] = "/usr/sbin/groupadd"; argv[1] = "--"; argv[2] = cd->NewGroupName; argv[3] = NULL; if (!spawn_with_login_uid (Invocation, argv, &error)) { DbusPrintf(Invocation, ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message); g_error_free (error); return; } group = ManageLocalFindGroupByname (manage, cd->NewGroupName); user_group_admin_complete_create_group (USER_GROUP_ADMIN(manage), Invocation, group_get_object_path (group)); } static gboolean ManageCreateGroup (UserGroupAdmin *object, GDBusMethodInvocation *Invocation, const gchar *name) { Manage *manage = (Manage *)object; CreateGroupData *data; data = g_new0 (CreateGroupData, 1); data->NewGroupName = g_strdup (name); LocalCheckAuthorization(manage, NULL, "org.group.admin.group-administration", TRUE, CreateNewGroup_cb, Invocation, data, (GDestroyNotify)CreateGroupDataFree); return TRUE; } typedef struct { gint64 gid; } DeleteGroupData; static void DeleteOldGroup_cb (Manage *manage, Group *g, GDBusMethodInvocation *Invocation, gpointer data) { GError *error = NULL; DeleteGroupData *gd = data; struct group *grent; const gchar *argv[4]; grent = getgrgid (gd->gid); if (grent == NULL) { DbusPrintf(Invocation, ERROR_GROUP_DOES_NOT_EXIST, "No group with gid %ld found", gd->gid); return; } sys_log (Invocation, "delete group '%s' (%d)", grent->gr_name, gd->gid); argv[0] = "/usr/sbin/groupdel"; argv[1] = "--"; argv[2] = grent->gr_name; argv[3] = NULL; if (!spawn_with_login_uid (Invocation, argv, &error)) { DbusPrintf (Invocation, ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message); g_error_free (error); return; } user_group_admin_emit_group_deleted(USER_GROUP_ADMIN(manage),group_get_object_path(g)); user_group_admin_complete_delete_group(USER_GROUP_ADMIN(manage),Invocation); } static gboolean ManageDeleteGroup (UserGroupAdmin *object, GDBusMethodInvocation *Invocation, gint64 gid) { Manage *manage = (Manage*)object; DeleteGroupData *data; Group *group; if ((gid_t)gid == 0) { DbusPrintf (Invocation, ERROR_FAILED, "Refuse to delete root group"); return FALSE; } data = g_new0 (DeleteGroupData, 1); data->gid = gid; group = ManageLocalFindGroupByid(manage,gid); LocalCheckAuthorization(manage, group, "org.group.admin.group-administration", TRUE, DeleteOldGroup_cb, Invocation, data, (GDestroyNotify)g_free); return TRUE; } static gboolean ManageListGroup (UserGroupAdmin *object, GDBusMethodInvocation *Invocation) { Manage *manage = (Manage*)object; GPtrArray *GroupPaths; GHashTableIter iter; const gchar *name; Group *group; GroupPaths = g_ptr_array_new (); g_hash_table_iter_init (&iter, manage->priv->GroupsHashTable); while (g_hash_table_iter_next (&iter, (gpointer *)&name, (gpointer *)&group)) { g_ptr_array_add (GroupPaths, (gpointer) group_get_object_path (group)); } g_ptr_array_add (GroupPaths, NULL); user_group_admin_complete_list_cached_groups (object, Invocation, (const gchar * const *)GroupPaths->pdata); g_ptr_array_free (GroupPaths, TRUE); return TRUE; } static void manage_user_group_admin_iface_init (UserGroupAdminIface *iface) { iface->handle_list_cached_groups = ManageListGroup; iface->handle_create_group = ManageCreateGroup; iface->handle_delete_group = ManageDeleteGroup; iface->handle_find_group_by_id = ManageFindGRoupByid; iface->handle_find_group_by_name = ManageFindGroupByname; iface->get_daemon_version = ManageGetDammonVersion; } group-service-1.4.0/src/group-server.h000066400000000000000000000060021435122003400176760ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __GROUP_SERVER__ #define __GROUP_SERVER__ #include "group.h" #include "types.h" G_BEGIN_DECLS #define TYPE_MANAGE (manage_get_type ()) #define MANAGE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_MANAGE, Manage)) #define MANAGE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TYPE_MANAGE, ManageClass)) #define IS_MANAGE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_MANAGE)) #define IS_MANAGE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_MANAGE)) #define MANAGE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_MANAGE, ManageClass)) #define MANAGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MANAGE, ManagePrivate)) typedef struct ManageClass ManageClass; typedef struct Manage Manage; typedef struct ManagePrivate ManagePrivate; struct Manage { UserGroupAdminSkeleton parent; ManagePrivate *priv; }; struct ManageClass { UserGroupAdminSkeletonClass parent_class; }; typedef enum { ERROR_FAILED, ERROR_GROUP_EXISTS, ERROR_GROUP_DOES_NOT_EXIST, ERROR_PERMISSION_DENIED, ERROR_NOT_SUPPORTED, NUM_ERRORS } Error; #define ERROR error_quark () GQuark error_quark (void); GType manage_get_type (void) G_GNUC_CONST; Manage *manage_new (void); typedef void (*AuthorizedCallback) (Manage *, Group *, GDBusMethodInvocation *, gpointer ); void DbusPrintf (GDBusMethodInvocation *Invocation, gint ErrorCode, const gchar *format, ...); int RegisterGroupManage (Manage *manage); void ManageLoadGroup(Manage *manage); void LocalCheckAuthorization(Manage *manage, Group *group, const gchar *ActionFile, gboolean AllowInteraction, AuthorizedCallback Authorized_cb, GDBusMethodInvocation *Invocation, gpointer Authorized_cb_data, GDestroyNotify DestroyNotify); #endif group-service-1.4.0/src/group.c000066400000000000000000000326651435122003400164030ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #ifdef HAVE_SHADOW_H #include #endif #include #include #include #include #include #include #include #include "group.h" #include "group-server.h" static void user_group_list_iface_init (UserGroupListIface *iface); G_DEFINE_TYPE_WITH_CODE (Group, group, USER_GROUP_TYPE_LIST_SKELETON, G_IMPLEMENT_INTERFACE (USER_GROUP_TYPE_LIST, user_group_list_iface_init)); const gchar *group_get_group_name (Group *group) { return user_group_list_get_group_name(USER_GROUP_LIST(group)); } const gchar *group_get_object_path (Group *group) { return group->object_path; } gid_t group_get_gid (Group *group) { return user_group_list_get_gid(USER_GROUP_LIST(group)); } gboolean group_get_local_group(Group *group) { return user_group_list_get_local_group(USER_GROUP_LIST(group)); } gboolean is_user_in_group(Group *group,const char *user) { char const **users; int i = 0; struct group * grent; users = user_group_list_get_users(USER_GROUP_LIST(group)); while(users[i] != NULL) { if(g_strcmp0(users[i],user) == 0) return TRUE; i++; } i = 0; grent = getgrnam(group_get_group_name(group)); while (grent->gr_mem[i] != NULL) { if(g_strcmp0(grent->gr_mem[i],user) == 0) return TRUE; i++; } return FALSE; } void RegisterGroup (Manage *manage,Group *group) { GError *error = NULL; GDBusConnection *Connection = NULL; g_autofree gchar *object_path = NULL; Connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (Connection == NULL) { if (error != NULL) { g_error ("error getting system bus: %s", error->message); g_error_free(error); } return; } object_path = compute_object_path (group); if(g_strcmp0(object_path,group_get_object_path(group)) != 0) { g_error("object_path = %s Non-existent",object_path); return; } group->system_bus_connection = Connection; if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (group), Connection, object_path, &error)) { if (error != NULL) { g_error ("error exporting group object: %s", error->message); g_error_free (error); } return; } } void UnRegisterGroup (Manage *manage,Group *group) { g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (group)); } void group_update_from_grent (Group *group, struct group *grent) { g_object_freeze_notify (G_OBJECT (group)); if (grent->gr_gid != group->gid) { group->gid = grent->gr_gid; g_object_notify (G_OBJECT (group), "gid"); } if (g_strcmp0 (group->group_name, grent->gr_name) != 0) { g_free (group->group_name); group->group_name = g_strdup (grent->gr_name); g_object_notify (G_OBJECT (group), "group-name"); } user_group_list_set_local_group(USER_GROUP_LIST(group),TRUE); user_group_list_set_gid(USER_GROUP_LIST(group),group->gid); user_group_list_set_group_name(USER_GROUP_LIST(group),group->group_name); user_group_list_set_users(USER_GROUP_LIST(group), (const gchar *const *)grent->gr_mem); g_object_thaw_notify (G_OBJECT (group)); } gchar * compute_object_path (Group *group) { gchar *object_path; group->gid = (gulong) user_group_list_get_gid (USER_GROUP_LIST(group)); object_path = g_strdup_printf ("/org/group/admin/Group%ld", (long) group->gid); return object_path; } static void group_finalize (GObject *object) { Group *group; group = GROUP (object); g_free (group->object_path); g_free (group->group_name); } static void group_class_init (GroupClass *class) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (class); gobject_class->finalize = group_finalize; } static void group_init (Group *group) { group->object_path = NULL; group->group_name = NULL; group->gid = -1; } Group * group_new (Manage *manage,gid_t gid) { Group *group; group = g_object_new (TYPE_GROUP, NULL); group->manage = manage; user_group_list_set_gid(USER_GROUP_LIST(group),gid); group->object_path = compute_object_path (group); return group; } static void AddUserAuthorized_cb (Manage *manage, Group *g, GDBusMethodInvocation *Invocation, gpointer udata) { gchar *name = udata; GError *error = NULL; const gchar *argv[6]; struct group * grent; if(getpwnam (name) == NULL) { DbusPrintf(Invocation,ERROR_GROUP_DOES_NOT_EXIST, "%s user does not exist",name); return; } if(!is_user_in_group(g,name)) { sys_log (Invocation, "%s user '%s' %s group '%s'","add", name,"to",group_get_group_name (g)); argv[0] = "/usr/sbin/groupmems"; argv[1] = "-g"; argv[2] = group_get_group_name (g); argv[3] = "-a"; argv[4] = name; argv[5] = NULL; if (!spawn_with_login_uid (Invocation, argv, &error)) { DbusPrintf(Invocation,ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message); g_error_free (error); return; } grent = getgrnam(group_get_group_name(g)); user_group_list_set_users(USER_GROUP_LIST(g), (const gchar *const *)grent->gr_mem); user_group_list_emit_changed (USER_GROUP_LIST(g)); } user_group_list_complete_add_user_to_group(USER_GROUP_LIST(g),Invocation); } static gboolean AddUserToGroup (UserGroupList *object, GDBusMethodInvocation *Invocation, const gchar *name) { Group *group = (Group*) object; LocalCheckAuthorization (group->manage, group, "org.group.admin.group-administration", TRUE, AddUserAuthorized_cb, Invocation, g_strdup (name), (GDestroyNotify)g_free); return TRUE; } static void ChangeNameAuthorized_cb (Manage *manage, Group *g, GDBusMethodInvocation *Invocation, gpointer udata) { gchar *name = udata; GError *error = NULL; const gchar *argv[6]; if (g_strcmp0 (group_get_group_name (g), name) != 0) { sys_log (Invocation, "changing name of group '%s' to '%s'", group_get_group_name (g),name); argv[0] = "/usr/sbin/groupmod"; argv[1] = "-n"; argv[2] = name; argv[3] = "--"; argv[4] = group_get_group_name (g); argv[5] = NULL; if (!spawn_with_login_uid (Invocation, argv, &error)) { DbusPrintf(Invocation,ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message); g_error_free (error); return; } user_group_list_set_group_name(USER_GROUP_LIST(g),name); user_group_list_emit_changed (USER_GROUP_LIST(g)); } user_group_list_complete_change_group_name(USER_GROUP_LIST(g),Invocation); } static gboolean ChangeGroupName (UserGroupList *object, GDBusMethodInvocation *Invocation, const gchar *name) { Group *group = (Group*) object; LocalCheckAuthorization (group->manage, group, "org.group.admin.group-administration", TRUE, ChangeNameAuthorized_cb, Invocation, g_strdup (name), (GDestroyNotify)g_free); return TRUE; } static void ChangeIdAuthorized_cb (Manage *manage, Group *g, GDBusMethodInvocation *Invocation, gpointer udata) { uint id = GPOINTER_TO_UINT (udata); GError *error = NULL; const gchar *Strid = g_strdup_printf("%u",id); const gchar *argv[6]; if (group_get_gid (g) != id) { sys_log (Invocation, "changing id of group '%u' to '%u'", group_get_gid (g),id); argv[0] = "/usr/sbin/groupmod"; argv[1] = "-g"; argv[2] = Strid; argv[3] = "--"; argv[4] = group_get_group_name (g); argv[5] = NULL; if (!spawn_with_login_uid (Invocation, argv, &error)) { DbusPrintf(Invocation,ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message); g_error_free (error); g_free((gpointer)Strid); return; } user_group_list_set_gid(USER_GROUP_LIST(g),id); user_group_list_emit_changed (USER_GROUP_LIST(g)); } user_group_list_complete_change_group_id(USER_GROUP_LIST(g),Invocation); } static gboolean ChangeGroupId (UserGroupList *object, GDBusMethodInvocation *Invocation, guint64 id) { Group *group = (Group*) object; LocalCheckAuthorization (group->manage, group, "org.group.admin.group-administration", TRUE, ChangeIdAuthorized_cb, Invocation, GUINT_TO_POINTER(id), NULL); return TRUE; } static void RemoveUserAuthorized_cb (Manage *manage, Group *g, GDBusMethodInvocation *Invocation, gpointer udata) { gchar *name = udata; GError *error = NULL; const gchar *argv[6]; struct group * grent; if(getpwnam (name) == NULL) { DbusPrintf(Invocation,ERROR_GROUP_DOES_NOT_EXIST, "%s user does not exist",name); return; } if(is_user_in_group(g,name)) { sys_log (Invocation, "%s user '%s' %s group '%s'","remove", name,"from",group_get_group_name (g)); argv[0] = "/usr/sbin/groupmems"; argv[1] = "-g"; argv[2] = group_get_group_name (g); argv[3] = "-d"; argv[4] = name; argv[5] = NULL; if (!spawn_with_login_uid (Invocation, argv, &error)) { DbusPrintf(Invocation,ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message); g_error_free (error); return; } grent = getgrnam(group_get_group_name(g)); user_group_list_set_users(USER_GROUP_LIST(g), (const gchar *const *)grent->gr_mem); user_group_list_emit_changed (USER_GROUP_LIST(g)); } user_group_list_complete_remove_user_from_group (USER_GROUP_LIST(g),Invocation); } static gboolean RemoveUserFromGroup (UserGroupList *object, GDBusMethodInvocation *Invocation, const gchar *name) { Group *group = (Group*) object; LocalCheckAuthorization (group->manage, group, "org.group.admin.group-administration", TRUE, RemoveUserAuthorized_cb, Invocation, g_strdup (name), (GDestroyNotify)g_free); return TRUE; } static void user_group_list_iface_init (UserGroupListIface *iface) { iface->handle_add_user_to_group = AddUserToGroup; iface->handle_change_group_name = ChangeGroupName; iface->handle_change_group_id = ChangeGroupId; iface->handle_remove_user_from_group = RemoveUserFromGroup; } group-service-1.4.0/src/group.h000066400000000000000000000054561435122003400164060ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __GROUP__ #define __GROUP__ #include #include #include #include #include "group-generated.h" #include "group-list-generated.h" #include "util.h" #include "types.h" G_BEGIN_DECLS #define TYPE_GROUP (group_get_type ()) #define GROUP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_GROUP, Group)) #define IS_GROUP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TYPE_GROUP)) typedef struct Group { UserGroupListSkeleton parent; Manage *manage; gchar *object_path; gid_t gid; GDBusConnection *system_bus_connection; gchar *group_name; gboolean local_group; GStrv users; guint changed_timeout_id; }Group; typedef struct GroupClass { UserGroupListSkeletonClass parent_class; } GroupClass; GType group_get_type (void) G_GNUC_CONST; Group * group_new (Manage *manage, gid_t gid); void group_update_from_grent (Group *group, struct group *grent); void RegisterGroup (Manage *manage, Group *group); void UnRegisterGroup (Manage *manage, Group *group); void group_changed (Group *group); const gchar * group_get_object_path (Group *group); gid_t group_get_gid (Group *group); const gchar * group_get_group_name (Group *group); gboolean group_get_local_group (Group *group); GStrv group_get_users (Group *group); gboolean is_user_in_group (Group *group, const char *user); gchar * compute_object_path (Group *group); G_END_DECLS #endif group-service-1.4.0/src/libgroupservice/000077500000000000000000000000001435122003400202735ustar00rootroot00000000000000group-service-1.4.0/src/libgroupservice/gas-group-enum-types.c.template000066400000000000000000000013641435122003400262650ustar00rootroot00000000000000/*** BEGIN file-header ***/ #include "gas-group-enum-types.h" #include /*** END file-header ***/ /*** BEGIN file-production ***/ /* enumerations from "@basename@" */ #include "@basename@" /*** END file-production ***/ /*** BEGIN value-header ***/ GType @enum_name@_get_type (void) { static GType etype = 0; if (etype == 0) { static const G@Type@Value values[] = { /*** END value-header ***/ /*** BEGIN value-production ***/ { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, /*** END value-production ***/ /*** BEGIN value-tail ***/ { 0, NULL, NULL } }; etype = g_@type@_register_static ("@EnumName@", values); } return etype; } /*** END value-tail ***/ /*** BEGIN file-tail ***/ /*** END file-tail ***/ group-service-1.4.0/src/libgroupservice/gas-group-enum-types.h.template000066400000000000000000000007651435122003400262760ustar00rootroot00000000000000/*** BEGIN file-header ***/ #ifndef __GAS_GROUP_ENUM_TYPES_H__ #define __GAS_GROUP_ENUM_TYPES_H__ #include G_BEGIN_DECLS /*** END file-header ***/ /*** BEGIN file-production ***/ /* enumerations from "@basename@" */ /*** END file-production ***/ /*** BEGIN value-header ***/ GType @enum_name@_get_type (void) G_GNUC_CONST; #define GAS_GROUP_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) /*** END value-header ***/ /*** BEGIN file-tail ***/ G_END_DECLS #endif /*** END file-tail ***/ group-service-1.4.0/src/libgroupservice/gas-group-manager.c000066400000000000000000001254051435122003400237620ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "gas-group-manager.h" #include "gas-group-private.h" #include "group-generated.h" #include "group-list-generated.h" #define GROUPADMIN_NAME "org.group.admin" #define GROUPADMIN_PATH "/org/group/admin" #define GROUPADMIN_INTERFACE "org.group.admin" typedef enum { GAS_GROUP_MANAGER_GET_GROUP_STATE_UNFETCHED = 0, GAS_GROUP_MANAGER_GET_GROUP_STATE_WAIT_FOR_LOADED, GAS_GROUP_MANAGER_GET_GROUP_STATE_ASK_GROUP_SERVICE, GAS_GROUP_MANAGER_GET_GROUP_STATE_FETCHED } GasGroupManagerGetGroupState; typedef enum { GAS_GROUP_MANAGER_FETCH_GROUP_FROM_GROUPNAME_REQUEST, GAS_GROUP_MANAGER_FETCH_GROUP_FROM_ID_REQUEST, } GasGroupManagerFetchGroupRequestType; typedef struct { GasGroupManager *manager; GasGroupManagerGetGroupState state; GasGroup *group; GasGroupManagerFetchGroupRequestType type; union { char *name; gid_t gid; }; char *object_path; char *description; } GasGroupManagerFetchGroupRequest; typedef struct { GHashTable *normal_groups_by_name; GHashTable *groups_by_object_path; GDBusConnection *connection; UserGroupAdmin *group_admin_proxy; GSList *new_groups; GSList *new_groups_inhibiting_load; GSList *fetch_group_requests; GSList *exclude_groupnames; GSList *include_groupnames; gboolean is_loaded; gboolean list_cached_groups_done; } GasGroupManagerPrivate; enum { PROP_0, PROP_INCLUDE_GROUPNAMES_LIST, PROP_EXCLUDE_GROUPNAMES_LIST, PROP_IS_LOADED, }; enum { GROUP_ADDED, GROUP_REMOVED, GROUP_IS_LOGGED_IN_CHANGED, GROUP_CHANGED, LAST_SIGNAL }; static guint signals [LAST_SIGNAL] = { 0, }; static void gas_group_manager_finalize (GObject *object); static void fetch_group_incrementally (GasGroupManagerFetchGroupRequest *request); static gboolean ensure_group_admin_proxy (GasGroupManager *manager); static void load_groups (GasGroupManager *manager); static void load_group (GasGroupManager *manager, const char *groupname); static void set_is_loaded (GasGroupManager *manager, gboolean is_loaded); static void on_new_group_loaded (GasGroup *group, GParamSpec *pspec, GasGroupManager *manager); static void give_up (GasGroupManager *manager, GasGroupManagerFetchGroupRequest *request); static void update_group (GasGroupManager *manager, GasGroup *group); static gpointer group_manager_object = NULL; G_DEFINE_TYPE_WITH_PRIVATE (GasGroupManager, gas_group_manager, G_TYPE_OBJECT) static void g_free_list_data(gpointer data,gpointer userdata) { g_free(data); } static const char * DescribeGroup (GasGroup *group) { GasGroupManagerFetchGroupRequest *request; if (gas_group_is_loaded (group)) { static char *description = NULL; g_clear_pointer (&description, (GDestroyNotify) g_free); description = g_strdup_printf ("group %s", gas_group_get_group_name (group)); return description; } request = g_object_get_data (G_OBJECT (group), "fetch-group-request"); if (request != NULL) { return request->description; } return "group"; } static void on_group_changed (GasGroup *group,GasGroupManager *manager) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); if (priv->is_loaded) { g_debug ("GasGroupManager: sending group-changed signal for %s", DescribeGroup (group)); g_signal_emit (manager, signals[GROUP_CHANGED], 0, group); g_debug ("GasGroupManager: sent group-changed signal for %s", DescribeGroup (group)); update_group (manager,group); } } static gint match_name_cmpfunc (gconstpointer a, gconstpointer b) { return g_strcmp0 ((char *) a,(char *) b); } static gboolean groupname_in_exclude_list (GasGroupManager *manager, const char *name) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GSList *found; gboolean ret = FALSE; if (priv->exclude_groupnames != NULL) { found = g_slist_find_custom (priv->exclude_groupnames,name,match_name_cmpfunc); if (found != NULL) { ret = TRUE; } } return ret; } static GasGroup *create_new_group (GasGroupManager *manager) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GasGroup *group; group = g_object_new (GAS_TYPE_GROUP, NULL); priv->new_groups = g_slist_prepend (priv->new_groups, g_object_ref (group)); g_signal_connect_object (group, "notify::is-loaded", G_CALLBACK (on_new_group_loaded), manager, 0); return group; } static void add_group (GasGroupManager *manager, GasGroup *group) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); const char *object_path; g_hash_table_insert (priv->normal_groups_by_name, g_strdup (gas_group_get_group_name (group)), g_object_ref (group)); object_path = gas_group_get_object_path (group); if (object_path != NULL) { g_hash_table_replace (priv->groups_by_object_path, g_strdup (object_path), g_object_ref (group)); } g_signal_connect_object (group, "changed", G_CALLBACK (on_group_changed), manager, 0); g_signal_emit (manager, signals[GROUP_ADDED], 0, group); } static void remove_group (GasGroupManager *manager,GasGroup *group) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); g_object_ref (group); g_signal_handlers_disconnect_by_func (group, on_group_changed, manager); if (gas_group_get_object_path (group) != NULL) { g_hash_table_remove (priv->groups_by_object_path, gas_group_get_object_path (group)); } if (gas_group_get_group_name (group) != NULL) { g_hash_table_remove (priv->normal_groups_by_name, gas_group_get_group_name (group)); } if (priv->is_loaded) { g_debug ("GasGroupManager: loaded, so emitting group-removed signal"); g_signal_emit (manager, signals[GROUP_REMOVED], 0, group); } else { g_debug ("GasGroupManager: not yet loaded, so not emitting group-removed signal"); } g_object_unref (group); } static void update_group (GasGroupManager *manager,GasGroup *group) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); const char *name; name = gas_group_get_group_name (group); if (g_hash_table_lookup (priv->normal_groups_by_name, name) == 0) { g_hash_table_insert (priv->normal_groups_by_name, g_strdup (name), g_object_ref (group)); g_signal_emit (manager, signals[GROUP_ADDED], 0, group); } } static GasGroup *lookup_group_by_name (GasGroupManager *manager, const char *name) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); return g_hash_table_lookup (priv->normal_groups_by_name, name); } static void on_new_group_loaded (GasGroup *group, GParamSpec *pspec, GasGroupManager *manager) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); const char *name; GasGroup *old_group; if (!gas_group_is_loaded (group)) { g_warning ("GasGroupManager: %s loaded function called when not loaded", DescribeGroup (group)); return; } g_signal_handlers_disconnect_by_func (group, on_new_group_loaded, manager); priv->new_groups = g_slist_remove (priv->new_groups,group); priv->new_groups_inhibiting_load = g_slist_remove (priv->new_groups_inhibiting_load, group); name = gas_group_get_group_name (group); if (name == NULL) { const char *object_path; object_path = gas_group_get_object_path (group); if (object_path != NULL) { g_warning ("GasGroupManager: %s has no groupname ""(object path: %s, gid: %d)", DescribeGroup (group),object_path, (int) gas_group_get_gid (group)); } else { g_warning ("GasGroupManager: %s has no groupname (gid: %d)", DescribeGroup (group),(int) gas_group_get_gid (group)); } g_object_unref (group); goto out; } if (groupname_in_exclude_list (manager, name)) { g_debug ("GasGroupManager: excluding group '%s'", name); g_object_unref (group); goto out; } old_group = lookup_group_by_name (manager, name); if (old_group == NULL) { g_debug ("GasGroupManager: %s was not yet known, adding it", gas_group_get_group_name (group)); add_group (manager, group); } else { _gas_group_load_from_group (old_group, group); } g_object_unref (group); out: if (priv->new_groups_inhibiting_load == NULL) { g_debug ("GasGroupManager: no pending groups, trying to set loaded property"); set_is_loaded (manager, TRUE); } else { g_debug ("GasGroupManager: not all groups loaded yet"); } } static GasGroup *find_new_group_with_object_path (GasGroupManager *manager, const char *object_path) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GSList *node; g_assert (object_path != NULL); for (node = priv->new_groups; node != NULL; node = node->next) { GasGroup *group = GAS_GROUP (node->data); const char *group_object_path = gas_group_get_object_path (group); if (g_strcmp0 (group_object_path, object_path) == 0) { return group; } } return NULL; } static GasGroup *add_new_group_for_object_path (const char *object_path, GasGroupManager *manager) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GasGroup *group; group = g_hash_table_lookup (priv->groups_by_object_path, object_path); if (group != NULL) { g_debug ("GasGroupManager: tracking existing %s with object path %s", DescribeGroup (group), object_path); return group; } group = find_new_group_with_object_path (manager, object_path); if (group != NULL) { g_debug ("GasGroupManager: tracking existing (but very recently added) %s with object path %s", DescribeGroup (group), object_path); return group; } group = create_new_group (manager); _gas_group_update_from_object_path (group, object_path); g_hash_table_replace (priv->groups_by_object_path, g_strdup (object_path), g_object_ref (group)); return group; } static void new_group_add_in_group_admin_service (GDBusProxy *proxy, const char *object_path, gpointer data) { GasGroupManager *manager = GAS_GROUP_MANAGER (data); GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); if (!priv->is_loaded) { g_debug ("GasGroupManager: ignoring new group in group_admin service with object path %s since not loaded yet", object_path); return; } add_new_group_for_object_path (object_path, manager); } static void old_group_removed_in_group_admin_service (GDBusProxy *proxy, const char *object_path, gpointer data) { GasGroupManager *manager = GAS_GROUP_MANAGER (data); GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GasGroup *group ; GSList *node; group = g_hash_table_lookup (priv->groups_by_object_path, object_path); if (group == NULL) { g_debug ("GasGroupManager: ignoring untracked group %s", object_path); return; } node = g_slist_find (priv->new_groups, group); if (node != NULL) { g_signal_handlers_disconnect_by_func (group, on_new_group_loaded, manager); g_object_unref (group); priv->new_groups = g_slist_delete_link (priv->new_groups, node); } remove_group (manager,group); } static void on_find_group_by_name_finished (GObject *object, GAsyncResult *result, gpointer data) { UserGroupAdmin *proxy = USER_GROUP_ADMIN (object); GasGroupManagerFetchGroupRequest *request = data; GError *error = NULL; char *group; if (!user_group_admin_call_find_group_by_name_finish(proxy, &group, result, &error)) { give_up (request->manager, request); return; } request->object_path = group; request->state++; fetch_group_incrementally (request); } static void on_find_group_by_id_finished (GObject *object, GAsyncResult *result, gpointer data) { UserGroupAdmin *proxy = USER_GROUP_ADMIN (object); GasGroupManagerFetchGroupRequest *request = data; GError *error = NULL; char *group; if (!user_group_admin_call_find_group_by_id_finish(proxy, &group, result, &error)) { give_up (request->manager, request); return; } request->object_path = group; request->state++; fetch_group_incrementally (request); } static void find_group_in_group_admin_service (GasGroupManager *manager, GasGroupManagerFetchGroupRequest *request) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); switch (request->type) { case GAS_GROUP_MANAGER_FETCH_GROUP_FROM_GROUPNAME_REQUEST: user_group_admin_call_find_group_by_name (priv->group_admin_proxy, request->name, NULL, on_find_group_by_name_finished, request); break; case GAS_GROUP_MANAGER_FETCH_GROUP_FROM_ID_REQUEST: user_group_admin_call_find_group_by_id (priv->group_admin_proxy, request->gid, NULL, on_find_group_by_id_finished, request); break; default: break; } } static void set_is_loaded (GasGroupManager *manager, gboolean is_loaded) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); if (priv->is_loaded != is_loaded) { priv->is_loaded = is_loaded; g_object_notify (G_OBJECT (manager), "is-loaded"); } } static void load_groups_paths (GasGroupManager *manager, const char * const * group_paths) { int i; GasGroup *group; GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); if (g_strv_length ((char **) group_paths) > 0) { for (i = 0; group_paths[i] != NULL; i++) { group = add_new_group_for_object_path (group_paths[i], manager); if (!priv->is_loaded) { priv->new_groups_inhibiting_load = g_slist_prepend (priv->new_groups_inhibiting_load, group); } } } } static void load_included_groupnames (GasGroupManager *manager) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GSList *l; for (l = priv->include_groupnames; l != NULL; l = l->next) { g_debug ("GasGroupManager: Adding included group %s", (char *)l->data); load_group (manager, l->data); } } static void give_up (GasGroupManager *manager, GasGroupManagerFetchGroupRequest *request) { request->type = GAS_GROUP_MANAGER_FETCH_GROUP_FROM_GROUPNAME_REQUEST; request->state = GAS_GROUP_MANAGER_GET_GROUP_STATE_UNFETCHED; } static void on_group_manager_maybe_ready_for_request (GasGroupManager *manager, GParamSpec *pspec, GasGroupManagerFetchGroupRequest *request) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); if (!priv->is_loaded) { return; } g_signal_handlers_disconnect_by_func (manager, on_group_manager_maybe_ready_for_request, request); request->state++; fetch_group_incrementally (request); } static void free_fetch_group_request (GasGroupManagerFetchGroupRequest *request,gpointer userdata) { GasGroupManager *manager = request->manager; GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); g_object_set_data (G_OBJECT (request->group), "fetch-user-request", NULL); priv->fetch_group_requests = g_slist_remove (priv->fetch_group_requests, request); if (request->type == GAS_GROUP_MANAGER_FETCH_GROUP_FROM_GROUPNAME_REQUEST) { g_free (request->name); } g_free (request->object_path); g_free (request->description); g_object_unref (manager); g_slice_free (GasGroupManagerFetchGroupRequest, request); } static void fetch_group_incrementally (GasGroupManagerFetchGroupRequest *request) { GasGroupManager *manager = request->manager; GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); switch (request->state) { case GAS_GROUP_MANAGER_GET_GROUP_STATE_WAIT_FOR_LOADED: if (priv->is_loaded) { request->state++; fetch_group_incrementally (request); } else { g_signal_connect (manager, "notify::is-loaded", G_CALLBACK (on_group_manager_maybe_ready_for_request), request); } break; case GAS_GROUP_MANAGER_GET_GROUP_STATE_ASK_GROUP_SERVICE: if (priv->group_admin_proxy == NULL) { give_up (manager, request); } else { find_group_in_group_admin_service (manager, request); } break; case GAS_GROUP_MANAGER_GET_GROUP_STATE_FETCHED: _gas_group_update_from_object_path (request->group, request->object_path); break; case GAS_GROUP_MANAGER_GET_GROUP_STATE_UNFETCHED: break; default: g_assert_not_reached (); } if (request->state == GAS_GROUP_MANAGER_GET_GROUP_STATE_FETCHED || request->state == GAS_GROUP_MANAGER_GET_GROUP_STATE_UNFETCHED) { free_fetch_group_request (request,NULL); } } static void fetch_group_with_groupname_from_group_admin_service (GasGroupManager *manager, GasGroup *group, const char *name) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GasGroupManagerFetchGroupRequest *request; request = g_slice_new0 (GasGroupManagerFetchGroupRequest); request->manager = g_object_ref (manager); request->type = GAS_GROUP_MANAGER_FETCH_GROUP_FROM_GROUPNAME_REQUEST; request->name = g_strdup (name); request->group = group; request->state = GAS_GROUP_MANAGER_GET_GROUP_STATE_UNFETCHED + 1; request->description = g_strdup_printf ("group '%s'", request->name); priv->fetch_group_requests = g_slist_prepend (priv->fetch_group_requests, request); g_object_set_data (G_OBJECT (group), "fetch-user-request", request); fetch_group_incrementally (request); } static void fetch_group_with_id_from_group_admin_service (GasGroupManager *manager, GasGroup *group, gid_t id) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GasGroupManagerFetchGroupRequest *request; request = g_slice_new0 (GasGroupManagerFetchGroupRequest); request->manager = g_object_ref (manager); request->type = GAS_GROUP_MANAGER_FETCH_GROUP_FROM_ID_REQUEST; request->gid = id; request->group = group; request->state = GAS_GROUP_MANAGER_GET_GROUP_STATE_UNFETCHED + 1; request->description = g_strdup_printf ("group with id %lu", (gulong) request->gid); priv->fetch_group_requests = g_slist_prepend (priv->fetch_group_requests, request); g_object_set_data (G_OBJECT (group), "fetch-group-request", request); fetch_group_incrementally (request); } GasGroup *gas_group_manager_get_group (GasGroupManager *manager, const char *name) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GasGroup *group; g_return_val_if_fail (GAS_IS_GROUP_MANAGER (manager), NULL); g_return_val_if_fail (name != NULL && name[0] != '\0', NULL); group = lookup_group_by_name (manager,name); if (group == NULL) { group = create_new_group (manager); if (priv->group_admin_proxy != NULL) { fetch_group_with_groupname_from_group_admin_service (manager,group,name); } } return group; } static void load_group (GasGroupManager *manager,const char *name) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GasGroup *group; GError *error = NULL; char *object_path = NULL; g_return_if_fail (GAS_IS_GROUP_MANAGER (manager)); g_return_if_fail (name != NULL && name[0] != '\0'); group = lookup_group_by_name (manager,name); if (group == NULL) { g_debug ("GasGroupManager: trying to track new gropu with name %s",name); group = create_new_group (manager); } user_group_admin_call_find_group_by_name_sync (priv->group_admin_proxy, name, &object_path, NULL, &error); _gas_group_update_from_object_path (group, object_path); } GasGroup * gas_group_manager_get_group_by_id (GasGroupManager *manager, gid_t id) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GasGroup *group; gchar *object_path = NULL; g_return_val_if_fail (GAS_IS_GROUP_MANAGER (manager), NULL); object_path = g_strdup_printf ("/org/group/admin/Group%lu", (gulong) id); group = g_hash_table_lookup (priv->groups_by_object_path, object_path); if (group != NULL) { return g_object_ref (group); } else { group = create_new_group (manager); if (priv->group_admin_proxy != NULL) { fetch_group_with_id_from_group_admin_service (manager,group, id); } } return group; } static void listify_hash_values_hfunc (gpointer key, gpointer value, gpointer user_data) { GSList **list = user_data; *list = g_slist_prepend (*list, value); } GSList * gas_group_manager_list_groups (GasGroupManager *manager) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GSList *retval = NULL; g_return_val_if_fail (GAS_IS_GROUP_MANAGER (manager), NULL); load_groups (manager); g_hash_table_foreach (priv->normal_groups_by_name,listify_hash_values_hfunc,&retval); return g_slist_sort (retval, (GCompareFunc) gas_group_collate); } static GSList * slist_deep_copy (const GSList *list) { GSList *retval; GSList *l; if (list == NULL) return NULL; retval = g_slist_copy ((GSList *) list); for (l = retval; l != NULL; l = l->next) { l->data = g_strdup (l->data); } return retval; } static void load_groups (GasGroupManager *manager) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GError *error = NULL; g_auto(GStrv) group_paths = NULL; gboolean could_list = FALSE; if (!ensure_group_admin_proxy (manager)) { g_print("check group_admin_proxy fail !!!\r\n"); return; } could_list = user_group_admin_call_list_cached_groups_sync (priv->group_admin_proxy, &group_paths, NULL, &error); if (!could_list) { g_print ("GasGroupManager: ListCachedGroups failed: %s", error->message); return; } load_groups_paths (manager, (const char * const *) group_paths); load_included_groupnames (manager); priv->list_cached_groups_done = TRUE; } static void gas_group_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GasGroupManager *manager = GAS_GROUP_MANAGER (object); GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); switch (prop_id) { case PROP_IS_LOADED: g_value_set_boolean (value, priv->is_loaded); break; case PROP_INCLUDE_GROUPNAMES_LIST: g_value_set_pointer (value, priv->include_groupnames); break; case PROP_EXCLUDE_GROUPNAMES_LIST: g_value_set_pointer (value, priv->exclude_groupnames); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void set_include_groupnames (GasGroupManager *manager, GSList *list) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); if (priv->include_groupnames != NULL) { g_slist_foreach (priv->include_groupnames, (GFunc) g_free_list_data, NULL); g_slist_free (priv->include_groupnames); } priv->include_groupnames = slist_deep_copy (list); } static void set_exclude_groupnames (GasGroupManager *manager, GSList *list) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); if (priv->exclude_groupnames != NULL) { g_slist_foreach (priv->exclude_groupnames, (GFunc) g_free_list_data, NULL); g_slist_free (priv->exclude_groupnames); } priv->exclude_groupnames = slist_deep_copy (list); } static void gas_group_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GasGroupManager *self; self = GAS_GROUP_MANAGER (object); switch (prop_id) { case PROP_INCLUDE_GROUPNAMES_LIST: set_include_groupnames (self, g_value_get_pointer (value)); break; case PROP_EXCLUDE_GROUPNAMES_LIST: set_exclude_groupnames (self, g_value_get_pointer (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gas_group_manager_class_init (GasGroupManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gas_group_manager_finalize; object_class->get_property = gas_group_manager_get_property; object_class->set_property = gas_group_manager_set_property; g_object_class_install_property (object_class, PROP_IS_LOADED, g_param_spec_boolean ("is-loaded", "Is loaded", "Determines whether or not the manager object is loaded and ready to read from.", FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_INCLUDE_GROUPNAMES_LIST, g_param_spec_pointer ("include-groupnames-list", "Include groupnames list", "Groupnames who are specifically included", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_EXCLUDE_GROUPNAMES_LIST, g_param_spec_pointer ("exclude-groupames-list", "Exclude groupnames list", "Groupnames who are specifically excluded", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); signals [GROUP_ADDED] = g_signal_new ("group-added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GasGroupManagerClass, group_added), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GAS_TYPE_GROUP); signals [GROUP_REMOVED] = g_signal_new ("group-removed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GasGroupManagerClass,group_removed), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GAS_TYPE_GROUP); signals [GROUP_CHANGED] = g_signal_new ("group-changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GasGroupManagerClass,group_changed), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GAS_TYPE_GROUP); } static gboolean ensure_group_admin_proxy (GasGroupManager *manager) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GError *error = NULL; if (priv->group_admin_proxy != NULL) { return TRUE; } priv->group_admin_proxy = user_group_admin_proxy_new_sync (priv->connection, G_DBUS_PROXY_FLAGS_NONE, GROUPADMIN_NAME, GROUPADMIN_PATH, NULL, &error); if (error != NULL) { g_print("GasGroupManager: getting account proxy failed: %s", error->message); g_error_free(error); return FALSE; } g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->group_admin_proxy), G_MAXINT); g_signal_connect (priv->group_admin_proxy, "group-added", G_CALLBACK (new_group_add_in_group_admin_service), manager); g_signal_connect (priv->group_admin_proxy, "group-deleted", G_CALLBACK (old_group_removed_in_group_admin_service), manager); return TRUE; } static GHashTable *CreateHashNewTable(void ) { return g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref); } static void gas_group_manager_init (GasGroupManager *manager) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GError *error = NULL; priv->normal_groups_by_name = CreateHashNewTable(); priv->groups_by_object_path = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (priv->connection == NULL) { if (error != NULL) { g_warning ("Failed to connect to the D-Bus daemon: %s", error->message); g_error_free (error); } else { g_warning ("Failed to connect to the D-Bus daemon"); } return; } ensure_group_admin_proxy (manager); } static void gas_group_manager_finalize (GObject *object) { GasGroupManager *manager = GAS_GROUP_MANAGER (object); GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GSList *node; GasGroup *group; GSList *next_node; g_slist_foreach (priv->fetch_group_requests, (GFunc) free_fetch_group_request, NULL); g_slist_free (priv->fetch_group_requests); g_slist_free (priv->new_groups_inhibiting_load); node = priv->new_groups; while (node != NULL) { group = GAS_GROUP (node->data); next_node = node->next; g_signal_handlers_disconnect_by_func (group, on_new_group_loaded, manager); g_object_unref (group); priv->new_groups = g_slist_delete_link (priv->new_groups, node); node = next_node; } if (priv->exclude_groupnames != NULL) { g_slist_foreach (priv->exclude_groupnames, (GFunc) g_free_list_data, NULL); g_slist_free (priv->exclude_groupnames); } if (priv->include_groupnames != NULL) { g_slist_foreach (priv->include_groupnames, (GFunc) g_free_list_data, NULL); g_slist_free (priv->include_groupnames); } if (priv->group_admin_proxy != NULL) { g_object_unref (priv->group_admin_proxy); } g_hash_table_destroy (priv->normal_groups_by_name); g_hash_table_destroy (priv->groups_by_object_path); } GasGroupManager *gas_group_manager_get_default (void) { if (group_manager_object == NULL) { group_manager_object = g_object_new (GAS_TYPE_GROUP_MANAGER, NULL); g_object_add_weak_pointer (group_manager_object, (gpointer *) &group_manager_object); } return GAS_GROUP_MANAGER (group_manager_object); } gboolean gas_group_manager_no_service (GasGroupManager *manager) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); return priv->group_admin_proxy == NULL; } GasGroup *gas_group_manager_create_group (GasGroupManager *manager, const char *name, GError **error) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GError *local_error = NULL; gboolean res; gchar *path = NULL; GasGroup *group; res = user_group_admin_call_create_group_sync (priv->group_admin_proxy, name, &path, NULL, &local_error); if (!res) { return NULL; } group = add_new_group_for_object_path (path, manager); return group; } static void gas_group_manager_async_complete_handler (GObject *source, GAsyncResult *result, gpointer user_data) { GTask *task = user_data; g_task_return_pointer (task, g_object_ref (result), g_object_unref); g_object_unref (task); } void gas_group_manager_create_group_async (GasGroupManager *manager, const char *name, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GTask *task; g_return_if_fail (GAS_IS_GROUP_MANAGER (manager)); g_return_if_fail (priv->group_admin_proxy != NULL); task = g_task_new (G_OBJECT (manager), cancellable, callback, user_data); user_group_admin_call_create_group (priv->group_admin_proxy, name, cancellable, gas_group_manager_async_complete_handler, task); } GasGroup *gas_group_manager_create_group_finish (GasGroupManager *manager, GAsyncResult *result, GError **error) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GAsyncResult *inner_result; GasGroup *group = NULL; gchar *path = NULL; GError *remote_error = NULL; inner_result = g_task_propagate_pointer (G_TASK (result), error); if (inner_result == NULL) { return FALSE; } if (user_group_admin_call_create_group_finish (priv->group_admin_proxy, &path, inner_result, &remote_error)) { group = add_new_group_for_object_path (path, manager); } if (remote_error) { g_dbus_error_strip_remote_error (remote_error); g_propagate_error (error, remote_error); } return group; } gboolean gas_group_manager_delete_group (GasGroupManager *manager, GasGroup *group, GError **error) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GError *local_error = NULL; g_return_val_if_fail (GAS_IS_GROUP_MANAGER (manager), FALSE); g_return_val_if_fail (GAS_IS_GROUP (group), FALSE); g_return_val_if_fail (priv->group_admin_proxy != NULL, FALSE); if (!user_group_admin_call_delete_group_sync (priv->group_admin_proxy, gas_group_get_gid (group), NULL, &local_error)) { return FALSE; } return TRUE; } void gas_group_manager_delete_group_async (GasGroupManager *manager, GasGroup *group, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GTask *task; g_return_if_fail (GAS_IS_GROUP_MANAGER (manager)); g_return_if_fail (GAS_IS_GROUP (group)); g_return_if_fail (priv->group_admin_proxy != NULL); task = g_task_new (G_OBJECT (manager), cancellable, callback, user_data); user_group_admin_call_delete_group (priv->group_admin_proxy, gas_group_get_gid (group), cancellable, gas_group_manager_async_complete_handler, task); } gboolean gas_group_manager_delete_group_finish (GasGroupManager *manager, GAsyncResult *result, GError **error) { GasGroupManagerPrivate *priv = gas_group_manager_get_instance_private (manager); GAsyncResult *inner_result; gboolean success; GError *remote_error = NULL; inner_result = g_task_propagate_pointer (G_TASK (result), error); if (inner_result == NULL) { return FALSE; } success = user_group_admin_call_delete_group_finish (priv->group_admin_proxy, inner_result, &remote_error); if (remote_error) { g_dbus_error_strip_remote_error (remote_error); g_propagate_error (error, remote_error); } return success; } group-service-1.4.0/src/libgroupservice/gas-group-manager.h000066400000000000000000000120641435122003400237630ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __GAS_GROUP_MANAGER_H__ #define __GAS_GROUP_MANAGER_H__ #include #include #include "gas-group.h" G_BEGIN_DECLS #define GAS_TYPE_GROUP_MANAGER (gas_group_manager_get_type ()) #define GAS_GROUP_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GAS_TYPE_GROUP_MANAGER, GasGroupManager)) #define GAS_GROUP_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GAS_TYPE_GROUP_MANAGER, GasGroupManagerClass)) #define GAS_IS_GROUP_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GAS_TYPE_GROUP_MANAGER)) #define GAS_IS_GROUP_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GAS_TYPE_GROUP_MANAGER)) #define GAS_GROUP_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GAS_TYPE_GROUP_MANAGER, GasGroupManagerClass)) typedef struct _GasGroupManager GasGroupManager; typedef struct _GasGroupManagerClass GasGroupManagerClass; struct _GasGroupManager { GObject parent; /*< private >*/ gpointer deprecated; }; struct _GasGroupManagerClass { GObjectClass parent_class; void (* group_added) (GasGroupManager *GroupManager, GasGroup *group); void (* group_removed) (GasGroupManager *GroupManager, GasGroup *group); void (* group_is_logged_in_changed) (GasGroupManager *GroupManager, GasGroup *group); void (* group_changed) (GasGroupManager *GropuManager, GasGroup *group); }; GType gas_group_manager_get_type (void); GasGroupManager * gas_group_manager_get_default (void); gboolean gas_group_manager_no_service (GasGroupManager *manager); GSList * gas_group_manager_list_groups (GasGroupManager *manager); GasGroup * gas_group_manager_get_group (GasGroupManager *manager, const char *name); GasGroup * gas_group_manager_get_group_by_id (GasGroupManager *manager, uid_t id); GasGroup * gas_group_manager_create_group (GasGroupManager *manager, const char *name, GError **error); void gas_group_manager_create_group_async (GasGroupManager *manager, const gchar *name, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data); GasGroup * gas_group_manager_create_group_finish (GasGroupManager *manager, GAsyncResult *result, GError **error); gboolean gas_group_manager_delete_group (GasGroupManager *manager, GasGroup *group, GError **error); void gas_group_manager_delete_group_async (GasGroupManager *manager, GasGroup *group, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data); gboolean gas_group_manager_delete_group_finish (GasGroupManager *manager, GAsyncResult *result, GError **error); #if GLIB_CHECK_VERSION(2, 44, 0) G_DEFINE_AUTOPTR_CLEANUP_FUNC (GasGroupManager, g_object_unref) #endif G_END_DECLS #endif group-service-1.4.0/src/libgroupservice/gas-group-private.h000066400000000000000000000020041435122003400240140ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __GAS_GROUP_PRIVATE_H_ #define __GAS_GROUP_PRIVATE_H_ #include #include "gas-group.h" G_BEGIN_DECLS void _gas_group_update_from_object_path (GasGroup *group, const char *object_path); G_END_DECLS #endif group-service-1.4.0/src/libgroupservice/gas-group.c000066400000000000000000000340611435122003400223470ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include "gas-group-private.h" #include "group-list-generated.h" #define GAS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAS_TYPE_GROUP, GasGroupClass)) #define GAS_IS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAS_TYPE_GROUP)) #define GAS_GROUP_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), GAS_TYPE_GROUP, GasGRoupClass)) #define GROUP_NAME "org.group.admin" #define GROUP_LSIT_INTERFACE "org.group.admin.list" enum { PROP_0, PROP_GID, PROP_GROUP_NAME, PROP_LOCAL_GROUP, PROP_IS_LOADED }; enum { CHANGED, LAST_SIGNAL }; struct _GasGroup { GObject parent; GDBusConnection *connection; UserGroupList *group_proxy; guint is_loaded : 1; }; struct _GasGroupClass { GObjectClass parent_class; }; static void gas_group_finalize (GObject *object); static guint signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE (GasGroup, gas_group, G_TYPE_OBJECT) static void gas_group_get_property (GObject *object, guint param_id, GValue *value, GParamSpec *pspec) { GasGroup *group; const char *property_name; group = GAS_GROUP (object); switch (param_id) { case PROP_IS_LOADED: g_value_set_boolean (value, group->is_loaded); break; default: if (group->group_proxy != NULL) { property_name = g_param_spec_get_name (pspec); g_object_get_property (G_OBJECT (group->group_proxy), property_name, value); } break; } } static void gas_group_class_init (GasGroupClass *class) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (class); gobject_class->finalize = gas_group_finalize; gobject_class->get_property = gas_group_get_property; g_object_class_install_property (gobject_class, PROP_GROUP_NAME, g_param_spec_string ("group-name", "Group Name", "The group name ", NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, PROP_GID, g_param_spec_int ("gid", "Group ID", "The GID for this group.", 0, G_MAXINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, PROP_IS_LOADED, g_param_spec_boolean ("is-loaded", "Is loaded", "Determines whether or not the group object is loaded and ready to read from.", FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, PROP_LOCAL_GROUP, g_param_spec_boolean ("local-group", "Local Group", "Local Group", FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); signals [CHANGED] = g_signal_new ("changed", G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } static void gas_group_init (GasGroup *group) { g_autoptr(GError) error = NULL; group->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (group->connection == NULL) { g_warning ("Couldn't connect to system bus: %s", error->message); } } static void gas_group_finalize (GObject *object) { GasGroup *group; group = GAS_GROUP (object); if (group->group_proxy != NULL) { g_object_unref (group->group_proxy); } if (group->connection != NULL) { g_object_unref (group->connection); } } static void set_is_loaded (GasGroup *group,gboolean is_loaded) { if (group->is_loaded != is_loaded) { group->is_loaded = is_loaded; g_object_notify (G_OBJECT (group), "is-loaded"); } } static void reload_proxy(GasGroup *group) { const char *object_path; g_autoptr(GError) error = NULL; UserGroupList *group_proxy; object_path = gas_group_get_object_path(group); group_proxy = user_group_list_proxy_new_sync (group->connection, G_DBUS_PROXY_FLAGS_NONE, GROUP_NAME, object_path, NULL, &error); if (!group_proxy) { g_warning ("Couldn't create group-admin proxy: %s", error->message); return; } group->group_proxy = group_proxy; } int gas_group_collate (GasGroup *group1,GasGroup *group2) { const char *str1; const char *str2; g_return_val_if_fail (GAS_IS_GROUP (group1), 0); g_return_val_if_fail (GAS_IS_GROUP (group2), 0); str1 = gas_group_get_group_name (group1); str2 = gas_group_get_group_name (group2); if (str1 == NULL && str2 != NULL) { return -1; } if (str1 != NULL && str2 == NULL) { return 1; } if (str1 == NULL && str2 == NULL) { return 0; } return g_utf8_collate (str1, str2); } char const **gas_group_get_group_users (GasGroup *group) { g_return_val_if_fail (GAS_IS_GROUP (group), NULL); if (group->group_proxy == NULL) return NULL; return user_group_list_get_users(group->group_proxy); } gboolean gas_group_is_local_group(GasGroup *group) { g_return_val_if_fail (GAS_IS_GROUP (group), FALSE); if (group->group_proxy == NULL) { return FALSE; } return user_group_list_get_local_group(group->group_proxy); } gboolean gas_group_is_primary_group(GasGroup *group) { g_return_val_if_fail (GAS_IS_GROUP (group), FALSE); if (group->group_proxy == NULL) { return FALSE; } return user_group_list_get_primary_group(group->group_proxy); } const char * gas_group_get_group_name (GasGroup *group) { g_return_val_if_fail (GAS_IS_GROUP (group), NULL); if (group->group_proxy == NULL) return NULL; return user_group_list_get_group_name(group->group_proxy); } gboolean gas_group_user_is_group (GasGroup *group,const char *user) { char const **users; int i = 0; g_return_val_if_fail (GAS_IS_GROUP (group), FALSE); g_return_val_if_fail (user != NULL,FALSE); g_return_val_if_fail (getpwnam(user) != NULL,FALSE); g_return_val_if_fail (USER_GROUP_IS_LIST (group->group_proxy),FALSE); users = gas_group_get_group_users(group); while(users[i] != NULL) { if(g_strcmp0(users[i],user) == 0) return TRUE; i++; } return FALSE; } const char * gas_group_get_object_path (GasGroup *group) { g_return_val_if_fail (GAS_IS_GROUP (group), NULL); if (group->group_proxy == NULL) return NULL; return g_dbus_proxy_get_object_path (G_DBUS_PROXY (group->group_proxy)); } gid_t gas_group_get_gid (GasGroup *group) { g_return_val_if_fail (GAS_IS_GROUP (group), -1); if (group->group_proxy == NULL) return -1; return user_group_list_get_gid(group->group_proxy); } static void on_group_proxy_changed (GasGroup *group) { g_signal_emit (group, signals[CHANGED], 0); } void _gas_group_load_from_group (GasGroup *group, GasGroup *group_to_copy) { if (!group_to_copy->is_loaded) { return; } group->group_proxy = g_object_ref (group_to_copy->group_proxy); g_signal_connect_object (group->group_proxy, "changed", G_CALLBACK (on_group_proxy_changed), group, G_CONNECT_SWAPPED); set_is_loaded (group, TRUE); } void _gas_group_update_from_object_path (GasGroup *group, const char *object_path) { UserGroupList *group_proxy; g_autoptr(GError) error = NULL; g_return_if_fail (GAS_IS_GROUP (group)); g_return_if_fail (object_path != NULL); g_return_if_fail (gas_group_get_object_path (group) == NULL); group_proxy = user_group_list_proxy_new_sync (group->connection, G_DBUS_PROXY_FLAGS_NONE, GROUP_NAME, object_path, NULL, &error); if (!group_proxy) { g_warning ("Couldn't create group-admin proxy: %s", error->message); return; } group->group_proxy = group_proxy; g_signal_connect_object (group->group_proxy, "changed", G_CALLBACK (on_group_proxy_changed), group, G_CONNECT_SWAPPED); g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (group->group_proxy), INT_MAX); set_is_loaded (group, TRUE); } gboolean gas_group_is_loaded (GasGroup *group) { return group->is_loaded; } void gas_group_set_group_name (GasGroup *group,const char *name) { g_autoptr(GError) error = NULL; guint i = 0; g_return_if_fail (GAS_IS_GROUP (group)); g_return_if_fail (name != NULL); g_return_if_fail (USER_GROUP_IS_LIST (group->group_proxy)); g_return_if_fail (group->group_proxy != NULL); while (!user_group_list_call_change_group_name_sync (group->group_proxy, name, NULL, &error)) { usleep(20000); reload_proxy(group); error = NULL; if(i++ >= 5) { g_warning ("set_group_name call failed: %s", error->message); return; } } } void gas_group_set_group_id (GasGroup *group,uint gid) { g_autoptr(GError) error = NULL; guint i = 0; g_return_if_fail (GAS_IS_GROUP (group)); g_return_if_fail (USER_GROUP_IS_LIST (group->group_proxy)); while (!user_group_list_call_change_group_id_sync (group->group_proxy, gid, NULL, &error)) { usleep(20000); reload_proxy(group); error = NULL; if(i++ >= 5) { g_warning ("set_group_id call failed: %s", error->message); return; } } } void gas_group_add_user_group (GasGroup *group,const char *name) { g_autoptr(GError) error = NULL; g_return_if_fail (GAS_IS_GROUP (group)); g_return_if_fail (name != NULL); g_return_if_fail (USER_GROUP_IS_LIST (group->group_proxy)); g_return_if_fail (group->group_proxy != NULL); g_return_if_fail (getpwnam (name) != NULL); if (!user_group_list_call_add_user_to_group_sync (group->group_proxy, name, NULL, &error)) { g_warning ("add user to group call failed: %s", error->message); return; } } void gas_group_remove_user_group (GasGroup *group,const char *name) { g_autoptr(GError) error = NULL; guint i = 0; g_return_if_fail (GAS_IS_GROUP (group)); g_return_if_fail (name != NULL); g_return_if_fail (USER_GROUP_IS_LIST (group->group_proxy)); g_return_if_fail (getpwnam (name) != NULL); while (!user_group_list_call_remove_user_from_group_sync(group->group_proxy, name, NULL, &error)) { usleep(20000); reload_proxy(group); error = NULL; if(i++ >= 5) { g_warning ("remove user from group call failed: %s", error->message); return; } } } group-service-1.4.0/src/libgroupservice/gas-group.h000066400000000000000000000054631435122003400223600ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __GAS_GROUP_H__ #define __GAS_GROUP_H__ #include #include #include G_BEGIN_DECLS #define GAS_TYPE_GROUP (gas_group_get_type ()) #define GAS_GROUP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GAS_TYPE_GROUP, GasGroup)) #define GAS_IS_GROUP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GAS_TYPE_GROUP)) typedef struct _GasGroup GasGroup; typedef struct _GasGroupClass GasGroupClass; GType gas_group_get_type (void) G_GNUC_CONST; const char *gas_group_get_object_path (GasGroup *Group); gid_t gas_group_get_gid (GasGroup *Group); const char *gas_group_get_group_name (GasGroup *Group); gboolean gas_group_is_local_group (GasGroup *Group); gboolean gas_group_is_primary_group (GasGroup *Group); gboolean gas_group_user_is_group (GasGroup *Group, const char *user); char const ** gas_group_get_group_users (GasGroup *Group); gint gas_group_collate (GasGroup *Group1, GasGroup *Group2); gboolean gas_group_is_loaded (GasGroup *group); void gas_group_set_group_name (GasGroup *group, const char *name); void gas_group_set_group_id (GasGroup *group, uint gid); void gas_group_remove_user_group (GasGroup *group, const char *user); void gas_group_add_user_group (GasGroup *group, const char *user); void _gas_group_load_from_group (GasGroup *group, GasGroup *group_to_copy); #if GLIB_CHECK_VERSION(2, 44, 0) G_DEFINE_AUTOPTR_CLEANUP_FUNC (GasGroup, g_object_unref) #endif G_END_DECLS #endif group-service-1.4.0/src/libgroupservice/gas.h000066400000000000000000000015441435122003400212220ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #define __GAS_H__ #include #include #include #endif group-service-1.4.0/src/libgroupservice/meson.build000066400000000000000000000040641435122003400224410ustar00rootroot00000000000000pkg = import('pkgconfig') libgroupsservice_dir = meson.current_source_dir() #subdir = gas_id.to_lower() subdir = 'libgroupservice' headers = files( 'gas-group.h', 'gas-group-manager.h', ) install_headers( headers + ['gas.h'], install_dir: join_paths(gas_pkgincludedir, subdir), ) sources = files( 'gas-group.c', 'gas-group-manager.c', ) enum_types = 'gas-group-enum-types' enum_sources = gnome.mkenums( enum_types, sources: headers, c_template: enum_types + '.c.template', h_template: enum_types + '.h.template', install_header: true, install_dir: join_paths(gas_pkgincludedir, subdir), ) dbus_sources = [] deps = [ crypt_dep, gio_unix_dep, glib_dep, libaccounts_generated_dep, ] symbol_map = join_paths(meson.current_source_dir(), 'symbol.map') ldflags = cc.get_supported_link_arguments('-Wl,--version-script,@0@'.format(symbol_map)) libgroupservice = shared_library( gas_name, sources: sources + enum_sources + dbus_sources, version: libversion, include_directories: top_srcdir, dependencies: deps, c_args: '-DG_LOG_DOMAIN="@0@"'.format(meson.project_name()), link_args: ldflags, link_depends: symbol_map, install: true, ) libaccountsservice_dep = declare_dependency( sources: enum_sources[1], include_directories: include_directories('.'), dependencies: [gio_dep, glib_dep], link_with: libgroupservice, ) pkg.generate( libgroupservice, name: 'Group Service', description: 'Client Library for communicating with group service', filebase: gas_name, subdirs: gas_api_name, variables: [ 'exec_prefix=${prefix}', 'datadir=${prefix}/' + get_option('datadir'), 'interfacesdir=${datadir}/group-service/interfaces', ], ) #if get_option('introspection') # gnome.generate_gir( # libgroupservice, # sources: sources + headers + [enum_sources[1]], # includes: ['GObject-2.0', 'Gio-2.0'], # dependencies: libaccountsservice_dep, # namespace: 'Group Service', # nsversion: gas_api_version, # identifier_prefix: gas_id, # header: join_paths(subdir, 'gas.h'), # install: true, # ) #endif group-service-1.4.0/src/libgroupservice/symbol.map000066400000000000000000000000341435122003400222740ustar00rootroot00000000000000{ local: _*; }; group-service-1.4.0/src/main.c000066400000000000000000000050641435122003400161640ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include "group-server.h" #define NAME_TO_CLAIM "org.group.admin" #define PACKAGE "group-service" #define LOCALEDIR "/usr/share/locale/" static GMainLoop *loop = NULL; static gboolean SignalQuit (gpointer data) { g_main_loop_quit (data); return FALSE; } static void AcquiredCallback (GDBusConnection *Connection, const gchar *name, gpointer UserData) { Manage *manage; manage = manage_new(); if (manage == NULL) { g_printerr ("Failed to initialize daemon manage\n"); g_main_loop_quit (loop); return; } if(RegisterGroupManage (manage) < 0) { printf("error !!!\r\n");; } } static void NameLostCallback (GDBusConnection *connection, const gchar *name, gpointer user_data) { printf("Lost Lost !!!!\r\n"); g_main_loop_quit (loop); } int main (int argc, char *argv[]) { guint OwnID; bind_textdomain_codeset (PACKAGE, "UTF-8"); setlocale (LC_ALL, ""); #if !GLIB_CHECK_VERSION (2, 35, 3) g_type_init (); #endif OwnID = g_bus_own_name (G_BUS_TYPE_SYSTEM, NAME_TO_CLAIM, G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT, AcquiredCallback, NULL, NameLostCallback, NULL, NULL); loop = g_main_loop_new (NULL, FALSE); g_unix_signal_add (SIGINT, SignalQuit, loop); g_unix_signal_add (SIGTERM, SignalQuit, loop); g_main_loop_run (loop); g_bus_unown_name(OwnID); g_main_loop_unref (loop); return 0; } group-service-1.4.0/src/meson.build000066400000000000000000000022161435122003400172320ustar00rootroot00000000000000gnome = import('gnome') sources = [] gdbus_headers = [] ifaces = [ ['group-generated', 'org.group.', 'admin'], ['group-list-generated', 'org.group.admin.','list'], ] foreach iface: ifaces gdbus_sources = gnome.gdbus_codegen( iface[0], join_paths(data_dir, iface[1] + iface[2] + '.xml'), interface_prefix: iface[1], namespace: 'UserGroup', ) sources += gdbus_sources gdbus_headers += gdbus_sources[1] endforeach deps = [ gio_dep, gio_unix_dep, ] libaccounts_generated = static_library( 'group-generated', sources: sources, include_directories: top_srcdir, dependencies: deps, ) libaccounts_generated_dep = declare_dependency( sources: gdbus_headers, include_directories: include_directories('.'), dependencies: gio_dep, link_with: libaccounts_generated, ) sources = files( 'main.c', 'group.c', 'group-server.c', 'util.c', ) deps = [ gio_unix_dep, glib_dep, libaccounts_generated_dep, polkit_gobject_dep, ] executable( 'group-admin-daemon', sources, include_directories: top_srcdir, dependencies: deps, install: true, install_dir: gas_libexecdir, ) subdir('libgroupservice') group-service-1.4.0/src/types.h000066400000000000000000000015201435122003400164020ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __TYPES_H__ #define __TYPES_H__ typedef struct Manage Manage; typedef struct Group Group; #endif group-service-1.4.0/src/util.c000066400000000000000000000204621435122003400162140ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "config.h" #include #include #include #include #include #include #include #include #include "util.h" static gchar * get_cmdline_of_pid (GPid pid) { gchar *ret; g_autofree gchar *filename = NULL; g_autofree gchar *contents = NULL; gsize contents_len; g_autoptr(GError) error = NULL; guint n; filename = g_strdup_printf ("/proc/%d/cmdline", (int) pid); if (!g_file_get_contents (filename, &contents, &contents_len, &error)) { g_warning ("Error opening `%s': %s", filename, error->message); return NULL; } /* The kernel uses '\0' to separate arguments - replace those with a space. */ for (n = 0; n < contents_len - 1; n++) { if (contents[n] == '\0') contents[n] = ' '; } ret = g_strdup (contents); g_strstrip (ret); return ret; } static gboolean get_caller_pid (GDBusMethodInvocation *context, GPid *pid) { g_autoptr(GVariant) reply = NULL; g_autoptr(GError) error = NULL; guint32 pid_as_int; reply = g_dbus_connection_call_sync (g_dbus_method_invocation_get_connection (context), "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "GetConnectionUnixProcessID", g_variant_new ("(s)", g_dbus_method_invocation_get_sender (context)), G_VARIANT_TYPE ("(u)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (reply == NULL) { g_warning ("Could not talk to message bus to find uid of sender %s: %s", g_dbus_method_invocation_get_sender (context), error->message); return FALSE; } g_variant_get (reply, "(u)", &pid_as_int); *pid = pid_as_int; return TRUE; } void sys_log (GDBusMethodInvocation *context, const gchar *format, ...) { va_list args; g_autofree gchar *msg = NULL; va_start (args, format); msg = g_strdup_vprintf (format, args); va_end (args); if (context) { PolkitSubject *subject; g_autofree gchar *cmdline = NULL; g_autofree gchar *id = NULL; GPid pid = 0; gint uid = -1; g_autofree gchar *tmp = NULL; subject = polkit_system_bus_name_new (g_dbus_method_invocation_get_sender (context)); id = polkit_subject_to_string (subject); if (get_caller_pid (context, &pid)) { cmdline = get_cmdline_of_pid (pid); } else { pid = 0; cmdline = NULL; } if (cmdline != NULL) { if (get_caller_uid (context, &uid)) { tmp = g_strdup_printf ("request by %s [%s pid:%d uid:%d]: %s", id, cmdline, (int) pid, uid, msg); } else { tmp = g_strdup_printf ("request by %s [%s pid:%d]: %s", id, cmdline, (int) pid, msg); } } else { if (get_caller_uid (context, &uid) && pid != 0) { tmp = g_strdup_printf ("request by %s [pid:%d uid:%d]: %s", id, (int) pid, uid, msg); } else if (pid != 0) { tmp = g_strdup_printf ("request by %s [pid:%d]: %s", id, (int) pid, msg); } else { tmp = g_strdup_printf ("request by %s: %s", id, msg); } } g_free (msg); msg = g_steal_pointer (&tmp); g_object_unref (subject); } syslog (LOG_NOTICE, "%s", msg); } static void get_caller_loginuid (GDBusMethodInvocation *context, gchar *loginuid, gint size) { GPid pid; gint uid; g_autofree gchar *path = NULL; g_autofree gchar *buf = NULL; if (!get_caller_uid (context, &uid)) { uid = getuid (); } if (get_caller_pid (context, &pid)) { path = g_strdup_printf ("/proc/%d/loginuid", (int) pid); } else { path = NULL; } if (path != NULL && g_file_get_contents (path, &buf, NULL, NULL)) { strncpy (loginuid, buf, size); } else { g_snprintf (loginuid, size, "%d", uid); } } static gboolean compat_check_exit_status (int estatus, GError **error) { #if GLIB_CHECK_VERSION(2, 33, 12) return g_spawn_check_wait_status (estatus, error); #else if (!WIFEXITED (estatus)) { g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED, "Exited abnormally"); return FALSE; } if (WEXITSTATUS (estatus) != 0) { g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED, "Exited with code %d", WEXITSTATUS(estatus)); return FALSE; } return TRUE; #endif } static void setup_loginuid (gpointer data) { const char *id = data; int fd,len; fd = open ("/proc/self/loginuid", O_WRONLY); len = write (fd, id, strlen (id)); if(len <= 0 ) { g_warning("write /proc/self/loginuid error!!!\r\n"); } close (fd); } gboolean spawn_with_login_uid (GDBusMethodInvocation *context, const gchar *argv[], GError **error) { gboolean ret = FALSE; gchar loginuid[20]; gint status; g_usleep(2000); get_caller_loginuid (context, loginuid, G_N_ELEMENTS (loginuid)-1); if (!g_spawn_sync (NULL, (gchar**)argv, NULL, 0, setup_loginuid, loginuid, NULL, NULL, &status, error)) goto out; if (!compat_check_exit_status (status, error)) goto out; ret = TRUE; out: return ret; } gboolean get_caller_uid (GDBusMethodInvocation *context, gint *uid) { g_autoptr(GVariant) reply = NULL; g_autoptr(GError) error = NULL; reply = g_dbus_connection_call_sync (g_dbus_method_invocation_get_connection (context), "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "GetConnectionUnixUser", g_variant_new ("(s)", g_dbus_method_invocation_get_sender (context)), G_VARIANT_TYPE ("(u)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (reply == NULL) { g_warning ("Could not talk to message bus to find uid of sender %s: %s", g_dbus_method_invocation_get_sender (context), error->message); return FALSE; } g_variant_get (reply, "(u)", uid); return TRUE; } group-service-1.4.0/src/util.h000066400000000000000000000023361435122003400162210ustar00rootroot00000000000000/* group-service * Copyright (C) 2018 zhuyaliang https://github.com/zhuyaliang/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __UTIL_H__ #define __UTIL_H__ #include G_BEGIN_DECLS void sys_log (GDBusMethodInvocation *context, const gchar *format, ...); gboolean get_caller_uid (GDBusMethodInvocation *context, gint *uid); gboolean spawn_with_login_uid (GDBusMethodInvocation *context, const gchar *argv[], GError **error); G_END_DECLS #endif /* __UTIL_H__ */ group-service-1.4.0/test/000077500000000000000000000000001435122003400152575ustar00rootroot00000000000000group-service-1.4.0/test/main.c000066400000000000000000000053351435122003400163550ustar00rootroot00000000000000#include #include #include static void GroupTest (GasGroup *group,GasGroupManager *GroupManager) { const char *name = NULL; gid_t gid; name = gas_group_get_group_name(group); gid = gas_group_get_gid(group); if(name == NULL) { printf("Failed to get group name !!!\r\n"); return; } printf("group name %s gid %d include %u user \r\n", name, (int)gid, g_strv_length((gchar **)gas_group_get_group_users(group))); } int main(void) { GasGroupManager *GroupManager; GasGroup *group; GasGroup *new_group; GError *error = NULL; GSList *list, *l; int i = 0; int count = 0; GroupManager = gas_group_manager_get_default (); if(GroupManager == NULL) { printf("Failed initialization group !!!\r\n"); return 1; } if( gas_group_manager_no_service(GroupManager) == TRUE) { printf("Query Service Failure Service !!!\r\n"); return 1; } list = gas_group_manager_list_groups (GroupManager); count = g_slist_length(list); if(count <= 0 ) { printf("No group found !!!\r\n"); return 1; } printf("There are %d group\r\n",count); new_group = gas_group_manager_create_group(GroupManager, "test-group-gas-21", &error); if(new_group == NULL) { if(error != NULL) { printf("Failed to create new group %s !!!\r\n",error->message); g_error_free (error); } else { printf("Failed to create new group !!!\r\n"); } return 1; } printf("Cretae new group %s success\r\n",gas_group_get_group_name(new_group)); /* User is a local user name and can populate the test according to the actual situation */ //gas_group_add_user_group(new_group,"user"); //gas_group_remove_user_group(new_group,"user"); gas_group_set_group_name(new_group,"test-group-gas-22"); printf("Change the group name to %s\r\n",gas_group_get_group_name(new_group)); for(l = list; l ; l = l->next,i++) { group = l->data; GroupTest(group,GroupManager); } if(gas_group_manager_delete_group(GroupManager,new_group,&error) == FALSE) { if(error != NULL) { printf("Failed to delete old group %s !!!\r\n",error->message); g_error_free (error); } else { printf("Failed to delete old group !!!\r\n"); } return 1; } printf("Delete Test Group %s Successfully",gas_group_get_group_name(new_group)); return 0; } group-service-1.4.0/test/meson.build000066400000000000000000000002741435122003400174240ustar00rootroot00000000000000testprg = executable('tests', sources : 'main.c', dependencies : [glib_dep], link_with: libgroupservice, include_directories: [top_srcdir, src_subdir], ) test('test1', testprg)