| 1 | /* |
| 2 | The software in this package is distributed under the GNU General |
| 3 | Public License version 2 (with a special exception described below). |
| 4 | |
| 5 | A copy of GNU General Public License (GPL) is included in this distribution, |
| 6 | in the file COPYING.GPL. |
| 7 | |
| 8 | As a special exception, if other files instantiate templates or use macros |
| 9 | or inline functions from this file, or you compile this file and link it |
| 10 | with other works to produce a work based on this file, this file |
| 11 | does not by itself cause the resulting work to be covered |
| 12 | by the GNU General Public License. |
| 13 | |
| 14 | However the source code for this file must still be made available |
| 15 | in accordance with section (3) of the GNU General Public License. |
| 16 | |
| 17 | This exception does not invalidate any other reasons why a work based |
| 18 | on this file might be covered by the GNU General Public License. |
| 19 | */ |
| 20 | /** @file |
| 21 | * @brief provides wrapper and tools for (system) user and group information. |
| 22 | * |
| 23 | * @copyright Intra2net AG |
| 24 | * |
| 25 | * @license commercial |
| 26 | * |
| 27 | * (c) Copyright 2007-2008 by Intra2net AG |
| 28 | */ |
| 29 | |
| 30 | #ifndef _I2N_USERFUNC_HPP_ |
| 31 | #define _I2N_USERFUNC_HPP_ |
| 32 | |
| 33 | #include <vector> |
| 34 | #include <string> |
| 35 | |
| 36 | #include <time.h> |
| 37 | #include <sys/types.h> |
| 38 | |
| 39 | namespace I2n |
| 40 | { |
| 41 | |
| 42 | /** |
| 43 | * @brief structure similar to "struct passwd", but more C++ like. |
| 44 | */ |
| 45 | /// FIXME: Argh, why is this a public struct without accessor functions |
| 46 | struct User |
| 47 | { |
| 48 | std::string Name; |
| 49 | std::string Password; |
| 50 | uid_t Uid; |
| 51 | gid_t Gid; |
| 52 | std::string Gecos; |
| 53 | std::string Homedir; |
| 54 | std::string Shell; |
| 55 | |
| 56 | User(); |
| 57 | User(const std::string& name); |
| 58 | User(const char* name); |
| 59 | User(uid_t uid); |
| 60 | void clear(); |
| 61 | |
| 62 | bool is_valid() const; |
| 63 | |
| 64 | operator bool() const { return is_valid(); } |
| 65 | }; // eo struct User |
| 66 | |
| 67 | |
| 68 | |
| 69 | /** |
| 70 | * @brief structure similar to "struct group", but more C++ like. |
| 71 | */ |
| 72 | /// FIXME: Argh, why is this a public struct without accessor functions |
| 73 | struct Group |
| 74 | { |
| 75 | std::string Name; |
| 76 | std::string Password; |
| 77 | gid_t Gid; |
| 78 | std::vector< std::string > Members; |
| 79 | |
| 80 | Group(); |
| 81 | Group(const std::string& name); |
| 82 | Group(const char* name); |
| 83 | Group(gid_t gid); |
| 84 | void clear(); |
| 85 | |
| 86 | bool is_valid() const; |
| 87 | |
| 88 | operator bool() const { return is_valid(); } |
| 89 | }; // eo struct Group |
| 90 | |
| 91 | bool get_user(const std::string& name, User& result); |
| 92 | bool get_user(uid_t uid, User& result); |
| 93 | |
| 94 | User get_user(const std::string& name); |
| 95 | User get_user(uid_t uid); |
| 96 | |
| 97 | bool get_group(const std::string& name, Group& result); |
| 98 | bool get_group(gid_t gid, Group& result); |
| 99 | |
| 100 | Group get_group(const std::string& name); |
| 101 | Group get_group(gid_t gid); |
| 102 | |
| 103 | } // eo namespace I2n |
| 104 | |
| 105 | #endif |