GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-password.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2022 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
35namespace octave
36{
37 namespace sys
38 {
39 class
42 {
43 public:
44
45 password (void)
46 : m_name (), m_passwd (), m_uid (0), m_gid (0), m_gecos (),
47 m_dir (), m_shell (), m_valid (false)
48 { }
49
50 password (const password& pw)
51 : m_name (pw.m_name), m_passwd (pw.m_passwd),
52 m_uid (pw.m_uid), m_gid (pw.m_gid), m_gecos (pw.m_gecos),
53 m_dir (pw.m_dir), m_shell (pw.m_shell), m_valid (pw.m_valid)
54 { }
55
56 password& operator = (const password& pw)
57 {
58 if (this != &pw)
59 {
60 m_name = pw.m_name;
61 m_passwd = pw.m_passwd;
62 m_uid = pw.m_uid;
63 m_gid = pw.m_gid;
64 m_gecos = pw.m_gecos;
65 m_dir = pw.m_dir;
66 m_shell = pw.m_shell;
67 m_valid = pw.m_valid;
68 }
69
70 return *this;
71 }
72
73 ~password (void) = default;
74
75 std::string name (void) const;
76
77 std::string passwd (void) const;
78
79 uid_t uid (void) const;
80
81 gid_t gid (void) const;
82
83 std::string gecos (void) const;
84
85 std::string dir (void) const;
86
87 std::string shell (void) const;
88
89 bool ok (void) const { return m_valid; }
90
91 operator bool () const { return ok (); }
92
93 static password getpwent (void);
94 static password getpwent (std::string& msg);
95
96 static password getpwuid (uid_t uid);
97 static password getpwuid (uid_t uid, std::string& msg);
98
99 static password getpwnam (const std::string& nm);
100 static password getpwnam (const std::string& nm, std::string& msg);
101
102 static int setpwent (void);
103 static int setpwent (std::string& msg);
104
105 static int endpwent (void);
106 static int endpwent (std::string& msg);
107
108 private:
109
110 // User name.
111 std::string m_name;
112
113 // Encrypted password.
114 std::string m_passwd;
115
116 // Numeric user id.
117 uid_t m_uid;
118
119 // Numeric group id.
120 gid_t m_gid;
121
122 // Miscellaneous junk.
123 std::string m_gecos;
124
125 // Home directory.
126 std::string m_dir;
127
128 // Login shell.
129 std::string m_shell;
130
131 // Flag that says whether we have been properly initialized.
133
134 // This is how we will create a password object from a pointer
135 // to a struct passwd.
136 password (void *p, std::string& msg);
137 };
138 }
139}
140
141#endif
bool ok(void) const
Definition: oct-password.h:89
~password(void)=default
password(const password &pw)
Definition: oct-password.h:50
QString name
#define OCTAVE_API
Definition: main.in.cc:55