GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oct-passwd.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_oct_passwd_h)
24 #define octave_oct_passwd_h 1
25 
26 #include "octave-config.h"
27 
28 #include <string>
29 
30 #include <sys/types.h>
31 
32 namespace octave
33 {
34  namespace sys
35  {
36  class
37  OCTAVE_API
38  password
39  {
40  public:
41 
42  password (void)
43  : m_name (), m_passwd (), m_uid (0), m_gid (0), m_gecos (),
44  m_dir (), m_shell (), valid (false)
45  { }
46 
47  password (const password& pw)
48  : m_name (pw.m_name), m_passwd (pw.m_passwd),
49  m_uid (pw.m_uid), m_gid (pw.m_gid), m_gecos (pw.m_gecos),
50  m_dir (pw.m_dir), m_shell (pw.m_shell), valid (pw.valid)
51  { }
52 
53  password& operator = (const password& pw)
54  {
55  if (this != &pw)
56  {
57  m_name = pw.m_name;
58  m_passwd = pw.m_passwd;
59  m_uid = pw.m_uid;
60  m_gid = pw.m_gid;
61  m_gecos = pw.m_gecos;
62  m_dir = pw.m_dir;
63  m_shell = pw.m_shell;
64  valid = pw.valid;
65  }
66 
67  return *this;
68  }
69 
70  ~password (void) { }
71 
72  std::string name (void) const;
73 
74  std::string passwd (void) const;
75 
76  uid_t uid (void) const;
77 
78  gid_t gid (void) const;
79 
80  std::string gecos (void) const;
81 
82  std::string dir (void) const;
83 
84  std::string shell (void) const;
85 
86  bool ok (void) const { return valid; }
87 
88  operator bool () const { return ok (); }
89 
90  static password getpwent (void);
91  static password getpwent (std::string& msg);
92 
93  static password getpwuid (uid_t uid);
94  static password getpwuid (uid_t uid, std::string& msg);
95 
96  static password getpwnam (const std::string& nm);
97  static password getpwnam (const std::string& nm, std::string& msg);
98 
99  static int setpwent (void);
100  static int setpwent (std::string& msg);
101 
102  static int endpwent (void);
103  static int endpwent (std::string& msg);
104 
105  private:
106 
107  // User name.
109 
110  // Encrypted password.
112 
113  // Numeric user id.
114  uid_t m_uid;
115 
116  // Numeric group id.
117  gid_t m_gid;
118 
119  // Miscellaneous junk.
121 
122  // Home directory.
124 
125  // Login shell.
127 
128  // Flag that says whether we have been properly initialized.
129  bool valid;
130 
131  // This is how we will create a password object from a pointer
132  // to a struct passwd.
133  password (void *p, std::string& msg);
134  };
135  }
136 }
137 
138 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
139 
140 OCTAVE_DEPRECATED ("use 'octave::sys::password' instead")
141 typedef octave::sys::password octave_passwd;
142 
143 #endif
144 
145 #endif
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
std::string m_passwd
Definition: oct-passwd.h:111
std::string m_gecos
Definition: oct-passwd.h:120
password(const password &pw)
Definition: oct-passwd.h:47
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
is false
Definition: cellfun.cc:398
bool ok(void) const
Definition: oct-passwd.h:86
p
Definition: lu.cc:138
std::string m_shell
Definition: oct-passwd.h:126
std::string m_name
Definition: oct-passwd.h:108
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854