oct-passwd.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_passwd_h)
00024 #define octave_passwd_h 1
00025 
00026 #include <string>
00027 
00028 #include <sys/types.h>
00029 
00030 class
00031 OCTAVE_API
00032 octave_passwd
00033 {
00034 public:
00035 
00036   octave_passwd (void)
00037     : pw_name (), pw_passwd (), pw_uid (0), pw_gid (0), pw_gecos (),
00038       pw_dir (), pw_shell (), valid (false)
00039   { }
00040 
00041   octave_passwd (const octave_passwd& pw)
00042     : pw_name (pw.pw_name), pw_passwd (pw.pw_passwd),
00043       pw_uid (pw.pw_uid), pw_gid (pw.pw_gid), pw_gecos (pw.pw_gecos),
00044       pw_dir (pw.pw_dir), pw_shell (pw.pw_shell), valid (pw.valid)
00045   { }
00046 
00047   octave_passwd& operator = (const octave_passwd& pw)
00048   {
00049     if (this != &pw)
00050       {
00051         pw_name = pw.pw_name;
00052         pw_passwd = pw.pw_passwd;
00053         pw_uid = pw.pw_uid;
00054         pw_gid = pw.pw_gid;
00055         pw_gecos = pw.pw_gecos;
00056         pw_dir = pw.pw_dir;
00057         pw_shell = pw.pw_shell;
00058         valid = pw.valid;
00059       }
00060 
00061     return *this;
00062   }
00063 
00064   ~octave_passwd (void) { }
00065 
00066   std::string name (void) const;
00067 
00068   std::string passwd (void) const;
00069 
00070   uid_t uid (void) const;
00071 
00072   gid_t gid (void) const;
00073 
00074   std::string gecos (void) const;
00075 
00076   std::string dir (void) const;
00077 
00078   std::string shell (void) const;
00079 
00080   bool ok (void) const { return valid; }
00081 
00082   operator bool () const { return ok (); }
00083 
00084   static octave_passwd getpwent (void);
00085   static octave_passwd getpwent (std::string& msg);
00086 
00087   static octave_passwd getpwuid (uid_t uid);
00088   static octave_passwd getpwuid (uid_t uid, std::string& msg);
00089 
00090   static octave_passwd getpwnam (const std::string& nm);
00091   static octave_passwd getpwnam (const std::string& nm, std::string& msg);
00092 
00093   static int setpwent (void);
00094   static int setpwent (std::string& msg);
00095 
00096   static int endpwent (void);
00097   static int endpwent (std::string& msg);
00098 
00099 private:
00100 
00101   // User name.
00102   std::string pw_name;
00103 
00104   // Encrypted password.
00105   std::string pw_passwd;
00106 
00107   // Numeric user id.
00108   uid_t pw_uid;
00109 
00110   // Numeric group id.
00111   gid_t pw_gid;
00112 
00113   // Miscellaneous junk.
00114   std::string pw_gecos;
00115 
00116   // Home directory.
00117   std::string pw_dir;
00118 
00119   // Login shell.
00120   std::string pw_shell;
00121 
00122   // Flag that says whether we have been properly initialized.
00123   bool valid;
00124 
00125   // This is how we will create an octave_passwd object from a pointer
00126   // to a struct passwd.
00127   octave_passwd (void *p, std::string& msg);
00128 
00129   void gripe_invalid (void) const;
00130 };
00131 
00132 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines