2934
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 2000, 2005, 2006, 2007 John W. Eaton |
2934
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
2934
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
2934
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_passwd_h) |
|
24 #define octave_passwd_h 1 |
|
25 |
|
26 #include <string> |
|
27 |
|
28 #ifdef HAVE_SYS_TYPES_H |
|
29 #include <sys/types.h> |
|
30 #endif |
|
31 |
|
32 class |
6108
|
33 OCTAVE_API |
2934
|
34 octave_passwd |
|
35 { |
|
36 public: |
|
37 |
|
38 octave_passwd (void) |
|
39 : pw_name (), pw_passwd (), pw_uid (0), pw_gid (0), pw_gecos (), |
|
40 pw_dir (), pw_shell (), valid (false) |
|
41 { } |
|
42 |
|
43 octave_passwd (const octave_passwd& pw) |
|
44 : pw_name (pw.pw_name), pw_passwd (pw.pw_passwd), |
|
45 pw_uid (pw.pw_uid), pw_gid (pw.pw_gid), pw_gecos (pw.pw_gecos), |
|
46 pw_dir (pw.pw_dir), pw_shell (pw.pw_shell), valid (pw.valid) |
|
47 { } |
|
48 |
|
49 octave_passwd& operator = (const octave_passwd& pw) |
2937
|
50 { |
|
51 if (this != &pw) |
|
52 { |
|
53 pw_name = pw.pw_name; |
|
54 pw_passwd = pw.pw_passwd; |
|
55 pw_uid = pw.pw_uid; |
|
56 pw_gid = pw.pw_gid; |
|
57 pw_gecos = pw.pw_gecos; |
|
58 pw_dir = pw.pw_dir; |
|
59 pw_shell = pw.pw_shell; |
|
60 valid = pw.valid; |
|
61 } |
2934
|
62 |
2937
|
63 return *this; |
|
64 } |
2934
|
65 |
|
66 ~octave_passwd (void) { } |
|
67 |
3504
|
68 std::string name (void) const; |
2934
|
69 |
3504
|
70 std::string passwd (void) const; |
2934
|
71 |
|
72 uid_t uid (void) const; |
|
73 |
|
74 gid_t gid (void) const; |
|
75 |
3504
|
76 std::string gecos (void) const; |
2934
|
77 |
3504
|
78 std::string dir (void) const; |
2934
|
79 |
3504
|
80 std::string shell (void) const; |
2934
|
81 |
|
82 bool ok (void) const { return valid; } |
|
83 |
3145
|
84 operator bool () const { return ok (); } |
2934
|
85 |
|
86 static octave_passwd getpwent (void); |
3504
|
87 static octave_passwd getpwent (std::string& msg); |
2934
|
88 |
|
89 static octave_passwd getpwuid (uid_t uid); |
3504
|
90 static octave_passwd getpwuid (uid_t uid, std::string& msg); |
2934
|
91 |
3504
|
92 static octave_passwd getpwnam (const std::string& nm); |
|
93 static octave_passwd getpwnam (const std::string& nm, std::string& msg); |
2934
|
94 |
2937
|
95 static int setpwent (void); |
3504
|
96 static int setpwent (std::string& msg); |
2934
|
97 |
2937
|
98 static int endpwent (void); |
3504
|
99 static int endpwent (std::string& msg); |
2934
|
100 |
|
101 private: |
|
102 |
|
103 // User name. |
3504
|
104 std::string pw_name; |
2934
|
105 |
|
106 // Encrypted password. |
3504
|
107 std::string pw_passwd; |
2934
|
108 |
|
109 // Numeric user id. |
|
110 uid_t pw_uid; |
|
111 |
|
112 // Numeric group id. |
|
113 gid_t pw_gid; |
|
114 |
|
115 // Miscellaneous junk. |
3504
|
116 std::string pw_gecos; |
2934
|
117 |
|
118 // Home directory. |
3504
|
119 std::string pw_dir; |
2934
|
120 |
|
121 // Login shell. |
3504
|
122 std::string pw_shell; |
2934
|
123 |
|
124 // Flag that says whether we have been properly initialized. |
|
125 bool valid; |
|
126 |
|
127 // This is how we will create an octave_passwd object from a pointer |
|
128 // to a struct passwd. |
3504
|
129 octave_passwd (void *p, std::string& msg); |
2934
|
130 |
|
131 void gripe_invalid (void) const; |
|
132 }; |
|
133 |
|
134 #endif |
|
135 |
|
136 /* |
|
137 ;;; Local Variables: *** |
|
138 ;;; mode: C++ *** |
|
139 ;;; End: *** |
|
140 */ |