メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

oct-passwd.cc

解説を見る。
00001 /*
00002 
00003 Copyright (C) 1996, 1997 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 2, or (at your option) any
00010 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, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #ifdef HAVE_SYS_TYPES_H
00028 #include <sys/types.h>
00029 #endif
00030 
00031 #ifdef HAVE_PWD_H
00032 #include <pwd.h>
00033 #endif
00034 
00035 #include "lo-error.h"
00036 #include "oct-passwd.h"
00037 
00038 #define NOT_SUPPORTED(nm) \
00039   nm ": not supported on this system"
00040 
00041 std::string
00042 octave_passwd::name (void) const
00043 {
00044   if (! ok ())
00045     gripe_invalid ();
00046 
00047   return pw_name;
00048 }
00049 
00050 std::string
00051 octave_passwd::passwd (void) const
00052 {
00053   if (! ok ())
00054     gripe_invalid ();
00055 
00056   return pw_passwd;
00057 }
00058 
00059 uid_t
00060 octave_passwd::uid (void) const
00061 {
00062   if (! ok ())
00063     gripe_invalid ();
00064 
00065   return pw_uid;
00066 }
00067 
00068 gid_t
00069 octave_passwd::gid (void) const
00070 {
00071   if (! ok ())
00072     gripe_invalid ();
00073 
00074   return pw_gid;
00075 }
00076 
00077 std::string
00078 octave_passwd::gecos (void) const
00079 {
00080   if (! ok ())
00081     gripe_invalid ();
00082 
00083   return pw_gecos;
00084 }
00085 
00086 std::string
00087 octave_passwd::dir (void) const
00088 {
00089   if (! ok ())
00090     gripe_invalid ();
00091 
00092   return pw_dir;
00093 }
00094 
00095 std::string
00096 octave_passwd::shell (void) const
00097 {
00098   if (! ok ())
00099     gripe_invalid ();
00100 
00101   return pw_shell;
00102 }
00103 
00104 octave_passwd
00105 octave_passwd::getpwent (void)
00106 {
00107   std::string msg;
00108   return getpwent (msg);
00109 }
00110 
00111 octave_passwd
00112 octave_passwd::getpwent (std::string& msg)
00113 {
00114 #if defined HAVE_GETPWENT
00115   msg = std::string ();
00116   return octave_passwd (::getpwent (), msg);
00117 #else
00118   msg = NOT_SUPPORTED ("getpwent");
00119   return octave_passwd ();
00120 #endif
00121 }
00122 
00123 octave_passwd
00124 octave_passwd::getpwuid (uid_t uid)
00125 {
00126   std::string msg;
00127   return getpwuid (uid, msg);
00128 }
00129 
00130 octave_passwd
00131 octave_passwd::getpwuid (uid_t uid, std::string& msg)
00132 {
00133 #if defined (HAVE_GETPWUID)
00134   msg = std::string ();
00135   return octave_passwd (::getpwuid (uid), msg);
00136 #else
00137   msg = NOT_SUPPORTED ("getpwuid");
00138   return octave_passwd ();
00139 #endif
00140 }
00141 
00142 octave_passwd
00143 octave_passwd::getpwnam (const std::string& nm)
00144 {
00145   std::string msg;
00146   return getpwnam (nm, msg);
00147 }
00148 
00149 octave_passwd
00150 octave_passwd::getpwnam (const std::string& nm, std::string& msg)
00151 {
00152 #if defined (HAVE_GETPWNAM)
00153   msg = std::string ();
00154   return octave_passwd (::getpwnam (nm.c_str ()), msg);
00155 #else
00156   msg = NOT_SUPPORTED ("getpwnam");
00157   return octave_passwd ();
00158 #endif
00159 }
00160 
00161 int
00162 octave_passwd::setpwent (void)
00163 {
00164   std::string msg;
00165   return setpwent (msg);
00166 }
00167 
00168 int
00169 octave_passwd::setpwent (std::string& msg)
00170 {
00171 #if defined (HAVE_SETPWENT)
00172   msg = std::string ();
00173   ::setpwent ();
00174   return 0;
00175 #else
00176   msg = NOT_SUPPORTED ("setpwent");
00177   return -1;
00178 #endif
00179 }
00180 
00181 int
00182 octave_passwd::endpwent (void)
00183 {
00184   std::string msg;
00185   return endpwent (msg);
00186 }
00187 
00188 int
00189 octave_passwd::endpwent (std::string& msg)
00190 {
00191 #if defined (HAVE_ENDPWENT)
00192   msg = std::string ();
00193   ::endpwent ();
00194   return 0;
00195 #else
00196   msg = NOT_SUPPORTED ("endpwent");
00197   return -1;
00198 #endif
00199 }
00200 
00201 octave_passwd::octave_passwd (void *p, std::string& msg)
00202   : pw_name (), pw_passwd (), pw_uid (0), pw_gid (0), pw_gecos (),
00203     pw_dir (), pw_shell (), valid (false)
00204 {
00205 #if defined (HAVE_PWD_H)
00206   msg = std::string ();
00207 
00208   if (p)
00209     {
00210       struct passwd *pw = static_cast<struct passwd *> (p);
00211 
00212       pw_name = pw->pw_name;
00213       pw_passwd = pw->pw_passwd;
00214       pw_uid = pw->pw_uid;
00215       pw_gid = pw->pw_gid;
00216       pw_gecos = pw->pw_gecos;
00217       pw_dir = pw->pw_dir;
00218       pw_shell = pw->pw_shell;
00219 
00220       valid = true;
00221     }
00222 #else
00223   msg = NOT_SUPPORTED ("password functions");
00224 #endif
00225 }
00226 
00227 void
00228 octave_passwd::gripe_invalid (void) const
00229 {
00230   (*current_liboctave_error_handler) ("invalid password object");
00231 }
00232 
00233 /*
00234 ;;; Local Variables: ***
00235 ;;; mode: C++ ***
00236 ;;; End: ***
00237 */

Wed Dec 29 11:52:09 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送