GNU Octave  3.8.0
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-2013 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 <string>
27 
28 #include <sys/types.h>
29 
30 class
31 OCTAVE_API
33 {
34 public:
35 
37  : pw_name (), pw_passwd (), pw_uid (0), pw_gid (0), pw_gecos (),
38  pw_dir (), pw_shell (), valid (false)
39  { }
40 
42  : pw_name (pw.pw_name), pw_passwd (pw.pw_passwd),
43  pw_uid (pw.pw_uid), pw_gid (pw.pw_gid), pw_gecos (pw.pw_gecos),
44  pw_dir (pw.pw_dir), pw_shell (pw.pw_shell), valid (pw.valid)
45  { }
46 
47  octave_passwd& operator = (const octave_passwd& pw)
48  {
49  if (this != &pw)
50  {
51  pw_name = pw.pw_name;
52  pw_passwd = pw.pw_passwd;
53  pw_uid = pw.pw_uid;
54  pw_gid = pw.pw_gid;
55  pw_gecos = pw.pw_gecos;
56  pw_dir = pw.pw_dir;
57  pw_shell = pw.pw_shell;
58  valid = pw.valid;
59  }
60 
61  return *this;
62  }
63 
64  ~octave_passwd (void) { }
65 
66  std::string name (void) const;
67 
68  std::string passwd (void) const;
69 
70  uid_t uid (void) const;
71 
72  gid_t gid (void) const;
73 
74  std::string gecos (void) const;
75 
76  std::string dir (void) const;
77 
78  std::string shell (void) const;
79 
80  bool ok (void) const { return valid; }
81 
82  operator bool () const { return ok (); }
83 
84  static octave_passwd getpwent (void);
85  static octave_passwd getpwent (std::string& msg);
86 
87  static octave_passwd getpwuid (uid_t uid);
88  static octave_passwd getpwuid (uid_t uid, std::string& msg);
89 
90  static octave_passwd getpwnam (const std::string& nm);
91  static octave_passwd getpwnam (const std::string& nm, std::string& msg);
92 
93  static int setpwent (void);
94  static int setpwent (std::string& msg);
95 
96  static int endpwent (void);
97  static int endpwent (std::string& msg);
98 
99 private:
100 
101  // User name.
102  std::string pw_name;
103 
104  // Encrypted password.
105  std::string pw_passwd;
106 
107  // Numeric user id.
108  uid_t pw_uid;
109 
110  // Numeric group id.
111  gid_t pw_gid;
112 
113  // Miscellaneous junk.
114  std::string pw_gecos;
115 
116  // Home directory.
117  std::string pw_dir;
118 
119  // Login shell.
120  std::string pw_shell;
121 
122  // Flag that says whether we have been properly initialized.
123  bool valid;
124 
125  // This is how we will create an octave_passwd object from a pointer
126  // to a struct passwd.
127  octave_passwd (void *p, std::string& msg);
128 
129  void gripe_invalid (void) const;
130 };
131 
132 #endif