2928
|
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 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include <string> |
|
28 |
|
29 #ifdef HAVE_SYS_TYPES_H |
|
30 #include <sys/types.h> |
|
31 #endif |
|
32 |
2933
|
33 #include "oct-passwd.h" |
2928
|
34 |
|
35 #include "defun-dld.h" |
|
36 #include "error.h" |
|
37 #include "gripes.h" |
|
38 #include "help.h" |
|
39 #include "oct-map.h" |
|
40 #include "ov.h" |
|
41 #include "oct-obj.h" |
|
42 #include "utils.h" |
|
43 |
|
44 // Password file functions. (Why not?) |
|
45 |
|
46 static octave_value |
2933
|
47 mk_pw_map (const octave_passwd& pw) |
2928
|
48 { |
|
49 octave_value retval; |
|
50 |
|
51 if (pw) |
|
52 { |
|
53 Octave_map m; |
|
54 |
2933
|
55 m ["name"] = pw.name (); |
|
56 m ["passwd"] = pw.passwd (); |
|
57 m ["uid"] = static_cast<double> (pw.uid ()); |
|
58 m ["gid"] = static_cast<double> (pw.gid ()); |
|
59 m ["gecos"] = pw.gecos (); |
|
60 m ["dir"] = pw.dir (); |
|
61 m ["shell"] = pw.shell (); |
2928
|
62 |
|
63 retval = m; |
|
64 } |
|
65 else |
|
66 retval = 0.0; |
|
67 |
|
68 return retval; |
|
69 } |
|
70 |
|
71 DEFUN_DLD (getpwent, args, , |
|
72 "getpwent ()\n\ |
|
73 \n\ |
|
74 Read an entry from the password-file stream, opening it if necessary.") |
|
75 { |
|
76 octave_value retval; |
|
77 |
|
78 int nargin = args.length (); |
|
79 |
|
80 if (nargin == 0) |
2933
|
81 retval = mk_pw_map (octave_passwd::getpwent ()); |
2928
|
82 else |
|
83 print_usage ("getpwent"); |
|
84 |
|
85 return retval; |
|
86 } |
|
87 |
|
88 DEFUN_DLD (getpwuid, args, , |
|
89 "getpwuid (UID)\n\ |
|
90 \n\ |
|
91 Search for a password entry with a matching user ID.") |
|
92 { |
|
93 octave_value retval; |
|
94 |
|
95 int nargin = args.length (); |
|
96 |
|
97 if (nargin == 1) |
|
98 { |
|
99 double dval = args(0).double_value (); |
|
100 |
|
101 if (! error_state) |
|
102 { |
|
103 if (D_NINT (dval) == dval) |
|
104 { |
|
105 uid_t uid = static_cast<uid_t> (dval); |
|
106 |
2933
|
107 retval = mk_pw_map (octave_passwd::getpwuid (uid)); |
2928
|
108 } |
|
109 else |
|
110 error ("getpwuid: argument must be an integer"); |
|
111 } |
|
112 } |
|
113 else |
|
114 print_usage ("getpwuid"); |
|
115 |
|
116 return retval; |
|
117 } |
|
118 |
|
119 DEFUN_DLD (getpwnam, args, , |
|
120 "getpwnam (NAME)\n\ |
|
121 \n\ |
|
122 Search for password entry with a matching username.") |
|
123 { |
|
124 octave_value retval; |
|
125 |
|
126 int nargin = args.length (); |
|
127 |
|
128 if (nargin == 1) |
|
129 { |
|
130 string s = args(0).string_value (); |
|
131 |
|
132 if (! error_state) |
2933
|
133 retval = mk_pw_map (octave_passwd::getpwnam (s.c_str ())); |
2928
|
134 } |
|
135 else |
|
136 print_usage ("getpwnam"); |
|
137 |
|
138 return retval; |
|
139 } |
|
140 |
|
141 DEFUN_DLD (setpwent, args, , |
|
142 "setpwent ()\n\ |
|
143 \n\ |
|
144 Rewind the password-file stream.") |
|
145 { |
|
146 octave_value retval; |
|
147 |
|
148 int nargin = args.length (); |
|
149 |
|
150 if (nargin == 0) |
2933
|
151 octave_passwd::setpwent (); |
2928
|
152 else |
|
153 print_usage ("setpwent"); |
|
154 |
|
155 return retval; |
|
156 } |
|
157 |
|
158 DEFUN_DLD (endpwent, args, , |
|
159 "endpwent ()\n\ |
|
160 \n\ |
|
161 Close the password-file stream.") |
|
162 { |
|
163 octave_value retval; |
|
164 |
|
165 int nargin = args.length (); |
|
166 |
|
167 if (nargin == 0) |
2933
|
168 octave_passwd::endpwent (); |
2928
|
169 else |
|
170 print_usage ("endpwent"); |
|
171 |
|
172 return retval; |
|
173 } |
|
174 |
|
175 /* |
|
176 ;;; Local Variables: *** |
|
177 ;;; mode: C++ *** |
|
178 ;;; End: *** |
|
179 */ |