2934
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
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 |
|
33 octave_passwd |
|
34 { |
|
35 public: |
|
36 |
|
37 octave_passwd (void) |
|
38 : pw_name (), pw_passwd (), pw_uid (0), pw_gid (0), pw_gecos (), |
|
39 pw_dir (), pw_shell (), valid (false) |
|
40 { } |
|
41 |
|
42 octave_passwd (const octave_passwd& pw) |
|
43 : pw_name (pw.pw_name), pw_passwd (pw.pw_passwd), |
|
44 pw_uid (pw.pw_uid), pw_gid (pw.pw_gid), pw_gecos (pw.pw_gecos), |
|
45 pw_dir (pw.pw_dir), pw_shell (pw.pw_shell), valid (pw.valid) |
|
46 { } |
|
47 |
|
48 octave_passwd& operator = (const octave_passwd& pw) |
2937
|
49 { |
|
50 if (this != &pw) |
|
51 { |
|
52 pw_name = pw.pw_name; |
|
53 pw_passwd = pw.pw_passwd; |
|
54 pw_uid = pw.pw_uid; |
|
55 pw_gid = pw.pw_gid; |
|
56 pw_gecos = pw.pw_gecos; |
|
57 pw_dir = pw.pw_dir; |
|
58 pw_shell = pw.pw_shell; |
|
59 valid = pw.valid; |
|
60 } |
2934
|
61 |
2937
|
62 return *this; |
|
63 } |
2934
|
64 |
|
65 ~octave_passwd (void) { } |
|
66 |
3504
|
67 std::string name (void) const; |
2934
|
68 |
3504
|
69 std::string passwd (void) const; |
2934
|
70 |
|
71 uid_t uid (void) const; |
|
72 |
|
73 gid_t gid (void) const; |
|
74 |
3504
|
75 std::string gecos (void) const; |
2934
|
76 |
3504
|
77 std::string dir (void) const; |
2934
|
78 |
3504
|
79 std::string shell (void) const; |
2934
|
80 |
|
81 bool ok (void) const { return valid; } |
|
82 |
3145
|
83 operator bool () const { return ok (); } |
2934
|
84 |
|
85 static octave_passwd getpwent (void); |
3504
|
86 static octave_passwd getpwent (std::string& msg); |
2934
|
87 |
|
88 static octave_passwd getpwuid (uid_t uid); |
3504
|
89 static octave_passwd getpwuid (uid_t uid, std::string& msg); |
2934
|
90 |
3504
|
91 static octave_passwd getpwnam (const std::string& nm); |
|
92 static octave_passwd getpwnam (const std::string& nm, std::string& msg); |
2934
|
93 |
2937
|
94 static int setpwent (void); |
3504
|
95 static int setpwent (std::string& msg); |
2934
|
96 |
2937
|
97 static int endpwent (void); |
3504
|
98 static int endpwent (std::string& msg); |
2934
|
99 |
|
100 private: |
|
101 |
|
102 // User name. |
3504
|
103 std::string pw_name; |
2934
|
104 |
|
105 // Encrypted password. |
3504
|
106 std::string pw_passwd; |
2934
|
107 |
|
108 // Numeric user id. |
|
109 uid_t pw_uid; |
|
110 |
|
111 // Numeric group id. |
|
112 gid_t pw_gid; |
|
113 |
|
114 // Miscellaneous junk. |
3504
|
115 std::string pw_gecos; |
2934
|
116 |
|
117 // Home directory. |
3504
|
118 std::string pw_dir; |
2934
|
119 |
|
120 // Login shell. |
3504
|
121 std::string pw_shell; |
2934
|
122 |
|
123 // Flag that says whether we have been properly initialized. |
|
124 bool valid; |
|
125 |
|
126 // This is how we will create an octave_passwd object from a pointer |
|
127 // to a struct passwd. |
3504
|
128 octave_passwd (void *p, std::string& msg); |
2934
|
129 |
|
130 void gripe_invalid (void) const; |
|
131 }; |
|
132 |
|
133 #endif |
|
134 |
|
135 /* |
|
136 ;;; Local Variables: *** |
|
137 ;;; mode: C++ *** |
|
138 ;;; End: *** |
|
139 */ |