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