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