TekUserUnixRW.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Kevin McBride                                   *
00003  *   kevin@planetsaphire.com                                               *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Library General Public License as       *
00007  *   published by the Free Software Foundation; either version 2 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU Library General Public     *
00016  *   License along with this program; if not, write to the                 *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #define LIBTEKLTI_EXPORT (1)
00021 
00022 #ifndef _cplusplus
00023 #define _cplusplus
00024 #endif /* _cplusplus */
00025 
00026 #include "teklti.h"
00027 
00028 MKTEKUUID(UTekUserUnixRW, "76184080-3E87-11DA-9E50-000BDBC434D9")
00029 MKTEKDEBUGSTRING(DBTekUserUnixRW, "TekUserUnixRW")
00030 
00031 
00040 TekUserUnixRW::TekUserUnixRW()
00041 {
00042       TEKSTD_IMPLEMENT_INTERFACE(UTekUser)
00043       TEKSTD_IMPLEMENT_INTERFACE(UTekUserUnixRW)
00044       TEKSTD_IMPLEMENT_ENDBASE
00045 
00046       memset(&this->Priv_UserInfo, '\0', sizeof(struct TekUserInfo));
00047 }
00048 
00049 
00053 TekUserUnixRW::~TekUserUnixRW()
00054 {
00055       if ( this->Priv_UserInfo.TekUserInfo_Description != NULL )
00056             ucharempty(this->Priv_UserInfo.TekUserInfo_Description);
00057       if ( this->Priv_UserInfo.TekUserInfo_Username != NULL )
00058             ucharempty(this->Priv_UserInfo.TekUserInfo_Username);
00059       if ( this->Priv_UserInfo.TekUserInfo_HomeDir != NULL )
00060             ucharempty(this->Priv_UserInfo.TekUserInfo_HomeDir);
00061 }
00062 
00063 
00069 TEKERR TekUserUnixRW::put_TekUserInfo(struct TekUserInfo * SUInfo)
00070 {
00071       if ( SUInfo == NULL )
00072             memset(&this->Priv_UserInfo, '\0', sizeof(struct TekUserInfo));
00073       else
00074             memcpy(&this->Priv_UserInfo, SUInfo, sizeof(struct TekUserInfo));
00075 
00076       return TEKERR_OK;
00077 }
00078 
00084 TEKERR TekUserUnixRW::get_Description(uchar_t** RetVal)
00085 {
00086 #ifndef     NO_SIZE_T_CHECKS
00087       if ( RetVal == NULL )
00088             return TEKERR_POINTER;
00089 #endif      /* NO_SIZE_T_CHECKS */
00090 
00091       /* Duplicate the uchar. */
00092       *RetVal = uchardup(this->Priv_UserInfo.TekUserInfo_Description);
00093 
00094       /* Return to caller. */
00095       return TEKERR_OK;
00096 }
00097 
00103 TEKERR TekUserUnixRW::get_GroupID(gid_t * RetVal)
00104 {
00105 #ifndef     NO_SIZE_T_CHECKS
00106       if ( RetVal == NULL )
00107             return TEKERR_POINTER;
00108 #endif      /* NO_SIZE_T_CHECKS */
00109 
00110       /* Set the group ID. */
00111       *RetVal = this->Priv_UserInfo.TekUserInfo_GroupID;
00112 
00113       /* Return to caller. */
00114       return TEKERR_OK;
00115 }
00116 
00122 TEKERR TekUserUnixRW::get_HomeDir(uchar_t ** RetVal)
00123 {
00124 #ifndef     NO_SIZE_T_CHECKS
00125       if ( RetVal == NULL )
00126             return TEKERR_POINTER;
00127 #endif      /* NO_SIZE_T_CHECKS */
00128 
00129       /* Duplicate the uchar. */
00130       *RetVal = uchardup(this->Priv_UserInfo.TekUserInfo_HomeDir);
00131 
00132       /* Return to caller. */
00133       return TEKERR_OK;
00134 }
00135 
00141 TEKERR TekUserUnixRW::get_UserID(uid_t * RetVal)
00142 {
00143 #ifndef     NO_SIZE_T_CHECKS
00144       if ( RetVal == NULL )
00145             return TEKERR_POINTER;
00146 #endif      /* NO_SIZE_T_CHECKS */
00147 
00148       /* Set the group ID. */
00149       *RetVal = this->Priv_UserInfo.TekUserInfo_UserID;
00150 
00151       /* Return to caller. */
00152       return TEKERR_OK;
00153 }
00154 
00160 TEKERR TekUserUnixRW::get_Username(uchar_t ** RetVal)
00161 {
00162 #ifndef     NO_SIZE_T_CHECKS
00163       if ( RetVal == NULL )
00164             return TEKERR_POINTER;
00165 #endif      /* NO_SIZE_T_CHECKS */
00166 
00167       /* Duplicate the uchar. */
00168       *RetVal = uchardup(this->Priv_UserInfo.TekUserInfo_Username);
00169 
00170       /* Return to caller. */
00171       return TEKERR_OK;
00172 }
00173 
00174 
00181 TEKERR TekUserUnixRW::put_Description(const uchar_t * NewDescription)
00182 {
00183 #ifndef     NO_SIZE_T_CHECKS
00184       if ( NewDescription == NULL )
00185             return TEKERR_POINTER;
00186 #endif      /* NO_SIZE_T_CHECKS */
00187 
00188       /* Make sure our uchar_t is destroyed. */
00189       if ( this->Priv_UserInfo.TekUserInfo_Description != NULL )
00190             ucharempty(this->Priv_UserInfo.TekUserInfo_Description);
00191 
00192       /* Duplicate the user's uchar_t. */
00193       this->Priv_UserInfo.TekUserInfo_Description =
00194             uchardup(NewDescription);
00195       /* Test the result. */
00196       if ( this->Priv_UserInfo.TekUserInfo_Description == NULL )
00197             return TEKERR_MEMORY;
00198 
00199       /* Return to caller. */
00200       return TEKERR_OK;
00201 }
00202 
00208 TEKERR TekUserUnixRW::put_GroupID(gid_t NewGroupID)
00209 {
00210       return TEKERR_NOTIMPL;
00211 }
00212 
00213 
00219 TEKERR TekUserUnixRW::put_HomeDir(const uchar_t * NewHomeDir)
00220 {
00221 #ifndef     NO_SIZE_T_CHECKS
00222       if ( NewHomeDir == NULL )
00223             return TEKERR_POINTER;
00224 #endif      /* NO_SIZE_T_CHECKS */
00225 
00226       /* Make sure our uchar_t is destroyed. */
00227       if ( this->Priv_UserInfo.TekUserInfo_HomeDir != NULL )
00228             ucharempty(this->Priv_UserInfo.TekUserInfo_HomeDir);
00229 
00230       /* Duplicate the user's uchar_t. */
00231       this->Priv_UserInfo.TekUserInfo_HomeDir =
00232             uchardup(NewHomeDir);
00233       /* Test the result. */
00234       if ( this->Priv_UserInfo.TekUserInfo_HomeDir == NULL )
00235             return TEKERR_MEMORY;
00236 
00237       /* Return to caller. */
00238       return TEKERR_OK;
00239 }
00240 
00241 
00250 TEKERR TekUserUnixRW::put_Password(uchar_t * NewPassword)
00251 {
00252       return TEKERR_NOTIMPL;
00253 }
00254 
00255 
00261 TEKERR TekUserUnixRW::put_UserID(uid_t NewID)
00262 {
00263       return TEKERR_NOTIMPL;
00264 }
00265 
00266 
00272 TEKERR TekUserUnixRW::put_Username(const uchar_t * NewUsername)
00273 {
00274 #ifndef     NO_SIZE_T_CHECKS
00275       if ( NewUsername == NULL )
00276             return TEKERR_POINTER;
00277 #endif      /* NO_SIZE_T_CHECKS */
00278 
00279       /* Make sure our uchar_t is destroyed. */
00280       if ( this->Priv_UserInfo.TekUserInfo_Username != NULL )
00281             ucharempty(this->Priv_UserInfo.TekUserInfo_Username);
00282 
00283       /* Duplicate the user's uchar_t. */
00284       this->Priv_UserInfo.TekUserInfo_Username =
00285             uchardup(NewUsername);
00286       /* Test the result. */
00287       if ( this->Priv_UserInfo.TekUserInfo_Username == NULL )
00288             return TEKERR_MEMORY;
00289 
00290       /* Return to caller. */
00291       return TEKERR_OK;
00292 }
00293 
00299 TEKERR TekUserUnixRW::Save()
00300 {
00301       TekUserDB * PrivDB;  /* Holds the DB instance pointer. */
00302 
00303       /* Set up the DB. */
00304       PrivDB = (TekUserDB *)this->Priv_UserInfo.TekUserInfo_DB;
00305 
00306 #ifndef     NO_INTERNAL_NULL_CHECKS
00307       /* Check to see if the parameter was NULL. */
00308       if ( PrivDB == NULL )
00309             return TEKERR_FAIL;
00310 #endif      /* NO_INTERNAL_NULL_CHECKS */
00311 
00312       /* Write outselves out. */
00313       PrivDB->WriteUser(this);
00314 
00315       /* Return to caller. */
00316       return TEKERR_OK;
00317 }
00318 
SourceForge.net Logo  Technical Library Template Interface Project Page