Mercurial > octave
annotate liboctave/system/oct-passwd.h @ 21729:815b2f500fab
use namespace for system password wrapper class
* oct-passwd.h, oct-passwd.cc: Put password class in octave::sys
namespace. Change all uses.
(octave_passwd): Now a deprecated typedef for octave::sys::password.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 18 May 2016 13:11:15 -0400 |
parents | 1473547f50f5 |
children | 11af9c03400c |
rev | line source |
---|---|
2934 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
3 Copyright (C) 1996-2015 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 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
23 #if ! defined (octave_oct_passwd_h) |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
24 #define octave_oct_passwd_h 1 |
2934 | 25 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21102
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21102
diff
changeset
|
27 |
2934 | 28 #include <string> |
29 | |
30 #include <sys/types.h> | |
31 | |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
32 namespace |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
33 octave |
2934 | 34 { |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
35 namespace |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
36 sys |
2937 | 37 { |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
38 class |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
39 OCTAVE_API |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
40 password |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
41 { |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
42 public: |
2934 | 43 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
44 password (void) |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
45 : m_name (), m_passwd (), m_uid (0), m_gid (0), m_gecos (), |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
46 m_dir (), m_shell (), valid (false) |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
47 { } |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
48 |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
49 password (const password& pw) |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
50 : m_name (pw.m_name), m_passwd (pw.m_passwd), |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
51 m_uid (pw.m_uid), m_gid (pw.m_gid), m_gecos (pw.m_gecos), |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
52 m_dir (pw.m_dir), m_shell (pw.m_shell), valid (pw.valid) |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
53 { } |
2934 | 54 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
55 password& operator = (const password& pw) |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
56 { |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
57 if (this != &pw) |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
58 { |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
59 m_name = pw.m_name; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
60 m_passwd = pw.m_passwd; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
61 m_uid = pw.m_uid; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
62 m_gid = pw.m_gid; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
63 m_gecos = pw.m_gecos; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
64 m_dir = pw.m_dir; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
65 m_shell = pw.m_shell; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
66 valid = pw.valid; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
67 } |
2934 | 68 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
69 return *this; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
70 } |
2934 | 71 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
72 ~password (void) { } |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
73 |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
74 std::string name (void) const; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
75 |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
76 std::string passwd (void) const; |
2934 | 77 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
78 uid_t uid (void) const; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
79 |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
80 gid_t gid (void) const; |
2934 | 81 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
82 std::string gecos (void) const; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
83 |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
84 std::string dir (void) const; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
85 |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
86 std::string shell (void) const; |
2934 | 87 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
88 bool ok (void) const { return valid; } |
2934 | 89 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
90 operator bool () const { return ok (); } |
2934 | 91 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
92 static password getpwent (void); |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
93 static password getpwent (std::string& msg); |
2934 | 94 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
95 static password getpwuid (uid_t uid); |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
96 static password getpwuid (uid_t uid, std::string& msg); |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
97 |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
98 static password getpwnam (const std::string& nm); |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
99 static password getpwnam (const std::string& nm, std::string& msg); |
2934 | 100 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
101 static int setpwent (void); |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
102 static int setpwent (std::string& msg); |
2934 | 103 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
104 static int endpwent (void); |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
105 static int endpwent (std::string& msg); |
2934 | 106 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
107 private: |
2934 | 108 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
109 // User name. |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
110 std::string m_name; |
2934 | 111 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
112 // Encrypted password. |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
113 std::string m_passwd; |
2934 | 114 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
115 // Numeric user id. |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
116 uid_t m_uid; |
2934 | 117 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
118 // Numeric group id. |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
119 gid_t m_gid; |
2934 | 120 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
121 // Miscellaneous junk. |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
122 std::string m_gecos; |
2934 | 123 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
124 // Home directory. |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
125 std::string m_dir; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
126 |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
127 // Login shell. |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
128 std::string m_shell; |
2934 | 129 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
130 // Flag that says whether we have been properly initialized. |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
131 bool valid; |
2934 | 132 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
133 // This is how we will create a password object from a pointer |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
134 // to a struct passwd. |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
135 password (void *p, std::string& msg); |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
136 }; |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
137 } |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
138 } |
2934 | 139 |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
140 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
141 |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
142 OCTAVE_DEPRECATED ("use octave::sys::password instead") |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
143 typedef octave::sys::password octave_passwd; |
2934 | 144 |
145 #endif | |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
146 |
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
147 #endif |