GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
oct-password.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_oct_passwd_h)
27#define octave_oct_passwd_h 1
28
29#include "octave-config.h"
30
31#include <string>
32
33#include <sys/types.h>
34
36
38
40{
41public:
42
44 : m_name (), m_passwd (), m_uid (0), m_gid (0), m_gecos (),
45 m_dir (), m_shell (), m_valid (false)
46 { }
47
48 password (const password& pw)
49 : m_name (pw.m_name), m_passwd (pw.m_passwd),
50 m_uid (pw.m_uid), m_gid (pw.m_gid), m_gecos (pw.m_gecos),
51 m_dir (pw.m_dir), m_shell (pw.m_shell), m_valid (pw.m_valid)
52 { }
53
54 password& operator = (const password& pw)
55 {
56 if (this != &pw)
57 {
58 m_name = pw.m_name;
59 m_passwd = pw.m_passwd;
60 m_uid = pw.m_uid;
61 m_gid = pw.m_gid;
62 m_gecos = pw.m_gecos;
63 m_dir = pw.m_dir;
64 m_shell = pw.m_shell;
65 m_valid = pw.m_valid;
66 }
67
68 return *this;
69 }
70
71 ~password () = default;
72
73 std::string name () const;
74
75 std::string passwd () const;
76
77 uid_t uid () const;
78
79 gid_t gid () const;
80
81 std::string gecos () const;
82
83 std::string dir () const;
84
85 std::string shell () const;
86
87 bool ok () const { return m_valid; }
88
89 operator bool () const { return ok (); }
90
91 static password getpwent ();
92 static password getpwent (std::string& msg);
93
94 static password getpwuid (uid_t uid);
95 static password getpwuid (uid_t uid, std::string& msg);
96
97 static password getpwnam (const std::string& nm);
98 static password getpwnam (const std::string& nm, std::string& msg);
99
100 static int setpwent ();
101 static int setpwent (std::string& msg);
102
103 static int endpwent ();
104 static int endpwent (std::string& msg);
105
106private:
107
108 // User name.
109 std::string m_name;
110
111 // Encrypted password.
112 std::string m_passwd;
113
114 // Numeric user id.
115 uid_t m_uid;
116
117 // Numeric group id.
118 gid_t m_gid;
119
120 // Miscellaneous junk.
121 std::string m_gecos;
122
123 // Home directory.
124 std::string m_dir;
125
126 // Login shell.
127 std::string m_shell;
128
129 // Flag that says whether we have been properly initialized.
130 bool m_valid;
131
132 // This is how we will create a password object from a pointer
133 // to a struct passwd.
134 password (void *p, std::string& msg);
135};
136
137OCTAVE_END_NAMESPACE(sys)
138OCTAVE_END_NAMESPACE(octave)
139
140#endif
~password()=default
password(const password &pw)
bool ok() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define OCTAVE_API
Definition main.in.cc:55