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 |
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 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
2937
|
27 #ifdef HAVE_SYS_TYPES_H |
|
28 #include <sys/types.h> |
|
29 #endif |
|
30 |
2934
|
31 #ifdef HAVE_PWD_H |
|
32 #include <pwd.h> |
|
33 #endif |
|
34 |
|
35 #include "lo-error.h" |
|
36 #include "oct-passwd.h" |
|
37 |
2937
|
38 #define NOT_SUPPORTED(nm) \ |
4062
|
39 nm ": not supported on this system" |
2937
|
40 |
3504
|
41 std::string |
2934
|
42 octave_passwd::name (void) const |
|
43 { |
|
44 if (! ok ()) |
|
45 gripe_invalid (); |
|
46 |
|
47 return pw_name; |
|
48 } |
|
49 |
3504
|
50 std::string |
2934
|
51 octave_passwd::passwd (void) const |
|
52 { |
|
53 if (! ok ()) |
|
54 gripe_invalid (); |
|
55 |
|
56 return pw_passwd; |
|
57 } |
|
58 |
|
59 uid_t |
|
60 octave_passwd::uid (void) const |
|
61 { |
|
62 if (! ok ()) |
|
63 gripe_invalid (); |
|
64 |
|
65 return pw_uid; |
|
66 } |
|
67 |
|
68 gid_t |
|
69 octave_passwd::gid (void) const |
|
70 { |
|
71 if (! ok ()) |
|
72 gripe_invalid (); |
|
73 |
|
74 return pw_gid; |
|
75 } |
|
76 |
3504
|
77 std::string |
2934
|
78 octave_passwd::gecos (void) const |
|
79 { |
|
80 if (! ok ()) |
|
81 gripe_invalid (); |
|
82 |
|
83 return pw_gecos; |
|
84 } |
|
85 |
3504
|
86 std::string |
2934
|
87 octave_passwd::dir (void) const |
|
88 { |
|
89 if (! ok ()) |
|
90 gripe_invalid (); |
|
91 |
|
92 return pw_dir; |
|
93 } |
|
94 |
3504
|
95 std::string |
2934
|
96 octave_passwd::shell (void) const |
|
97 { |
|
98 if (! ok ()) |
|
99 gripe_invalid (); |
|
100 |
|
101 return pw_shell; |
|
102 } |
|
103 |
|
104 octave_passwd |
|
105 octave_passwd::getpwent (void) |
|
106 { |
3504
|
107 std::string msg; |
2937
|
108 return getpwent (msg); |
|
109 } |
|
110 |
|
111 octave_passwd |
3504
|
112 octave_passwd::getpwent (std::string& msg) |
2937
|
113 { |
|
114 #if defined HAVE_GETPWENT |
3504
|
115 msg = std::string (); |
2937
|
116 return octave_passwd (::getpwent (), msg); |
2934
|
117 #else |
2937
|
118 msg = NOT_SUPPORTED ("getpwent"); |
2934
|
119 return octave_passwd (); |
|
120 #endif |
|
121 } |
|
122 |
|
123 octave_passwd |
|
124 octave_passwd::getpwuid (uid_t uid) |
|
125 { |
3504
|
126 std::string msg; |
2937
|
127 return getpwuid (uid, msg); |
|
128 } |
|
129 |
|
130 octave_passwd |
3504
|
131 octave_passwd::getpwuid (uid_t uid, std::string& msg) |
2937
|
132 { |
|
133 #if defined (HAVE_GETPWUID) |
3504
|
134 msg = std::string (); |
2937
|
135 return octave_passwd (::getpwuid (uid), msg); |
2934
|
136 #else |
2937
|
137 msg = NOT_SUPPORTED ("getpwuid"); |
2934
|
138 return octave_passwd (); |
|
139 #endif |
|
140 } |
|
141 |
|
142 octave_passwd |
3504
|
143 octave_passwd::getpwnam (const std::string& nm) |
2934
|
144 { |
3504
|
145 std::string msg; |
2937
|
146 return getpwnam (nm, msg); |
|
147 } |
|
148 |
|
149 octave_passwd |
3504
|
150 octave_passwd::getpwnam (const std::string& nm, std::string& msg) |
2937
|
151 { |
|
152 #if defined (HAVE_GETPWNAM) |
3504
|
153 msg = std::string (); |
2937
|
154 return octave_passwd (::getpwnam (nm.c_str ()), msg); |
2934
|
155 #else |
2937
|
156 msg = NOT_SUPPORTED ("getpwnam"); |
2934
|
157 return octave_passwd (); |
|
158 #endif |
|
159 } |
|
160 |
2937
|
161 int |
2934
|
162 octave_passwd::setpwent (void) |
|
163 { |
3504
|
164 std::string msg; |
2937
|
165 return setpwent (msg); |
|
166 } |
|
167 |
|
168 int |
3504
|
169 octave_passwd::setpwent (std::string& msg) |
2937
|
170 { |
|
171 #if defined (HAVE_SETPWENT) |
3504
|
172 msg = std::string (); |
2934
|
173 ::setpwent (); |
2937
|
174 return 0; |
2934
|
175 #else |
2937
|
176 msg = NOT_SUPPORTED ("setpwent"); |
|
177 return -1; |
2934
|
178 #endif |
|
179 } |
|
180 |
2937
|
181 int |
2934
|
182 octave_passwd::endpwent (void) |
|
183 { |
3504
|
184 std::string msg; |
2937
|
185 return endpwent (msg); |
|
186 } |
|
187 |
|
188 int |
3504
|
189 octave_passwd::endpwent (std::string& msg) |
2937
|
190 { |
|
191 #if defined (HAVE_ENDPWENT) |
3504
|
192 msg = std::string (); |
2934
|
193 ::endpwent (); |
2937
|
194 return 0; |
2934
|
195 #else |
2937
|
196 msg = NOT_SUPPORTED ("endpwent"); |
|
197 return -1; |
2934
|
198 #endif |
|
199 } |
|
200 |
3504
|
201 octave_passwd::octave_passwd (void *p, std::string& msg) |
2934
|
202 : pw_name (), pw_passwd (), pw_uid (0), pw_gid (0), pw_gecos (), |
|
203 pw_dir (), pw_shell (), valid (false) |
|
204 { |
2937
|
205 #if defined (HAVE_PWD_H) |
3504
|
206 msg = std::string (); |
2937
|
207 |
2934
|
208 if (p) |
|
209 { |
|
210 struct passwd *pw = static_cast<struct passwd *> (p); |
|
211 |
|
212 pw_name = pw->pw_name; |
|
213 pw_passwd = pw->pw_passwd; |
|
214 pw_uid = pw->pw_uid; |
|
215 pw_gid = pw->pw_gid; |
|
216 pw_gecos = pw->pw_gecos; |
|
217 pw_dir = pw->pw_dir; |
|
218 pw_shell = pw->pw_shell; |
|
219 |
|
220 valid = true; |
|
221 } |
2937
|
222 #else |
|
223 msg = NOT_SUPPORTED ("password functions"); |
2934
|
224 #endif |
|
225 } |
|
226 |
|
227 void |
|
228 octave_passwd::gripe_invalid (void) const |
|
229 { |
|
230 (*current_liboctave_error_handler) ("invalid password object"); |
|
231 } |
|
232 |
|
233 /* |
|
234 ;;; Local Variables: *** |
|
235 ;;; mode: C++ *** |
|
236 ;;; End: *** |
|
237 */ |