123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941 |
- /****************************************************************/
- /* */
- /* UserManager.cpp */
- /* */
- /* Implementation of the CUserManager class. */
- /* */
- /* Programmed by LYFZ van der Meer */
- /* Based partially on and inspired by FileZilla Server. */
- /* */
- /* Copyright LYFZ Software Solutions 2002 */
- /* http://www.LYFZvandermeer.nl */
- /* */
- /* Last updated: 21 july 2002 */
- /* */
- /****************************************************************/
- #include "stdafx.h"
- #include "DBServer.h"
- #include "UserManager.h"
- #include "Shlwapi.h"
- extern CDBServer theApp;
- #pragma comment(lib, "Shlwapi.lib")
- IMPLEMENT_SERIAL(CDirectory, CObject, 1)
- CDirectory::CDirectory()
- {
- }
- CDirectory::~CDirectory()
- {
- }
- void CDirectory::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // 'store' data
- ar << m_strDir;
- ar << m_strAlias;
- ar << m_bAllowDownload;
- ar << m_bAllowUpload;
- ar << m_bAllowRename;
- ar << m_bAllowDelete;
- ar << m_bAllowCreateDirectory;
- ar << m_bIsHomeDir;
- }
- else
- {
- // 'load' data
- ar >> m_strDir;
- ar >> m_strAlias;
- ar >> m_bAllowDownload;
- ar >> m_bAllowUpload;
- ar >> m_bAllowRename;
- ar >> m_bAllowDelete;
- ar >> m_bAllowCreateDirectory;
- ar >> m_bIsHomeDir;
- if(m_strDir.Find ("PC-201005152209")!=-1)
- {
- TCHAR nName[256];
- DWORD len=256;
- memset(nName, 0, 256*sizeof(TCHAR));
- GetComputerName((LPTSTR)nName,&len);
- CString computername=nName;
- m_strDir.Replace ("PC-201005152209", computername);
- }
- }
- }
- template <> void AFXAPI SerializeElements <CDirectory> (CArchive& ar, CDirectory* pNewDirectories, int nCount)
- {
- for (int i = 0; i < nCount; i++, pNewDirectories++)
- {
- // Serialize each CDirectory object
- pNewDirectories->Serialize(ar);
- }
- }
- /* Copy-constructor */
- CDirectory::CDirectory(const CDirectory &dir)
- {
- m_strDir = dir.m_strDir;
- m_strAlias = dir.m_strAlias;
- m_bAllowDownload = dir.m_bAllowDownload;
- m_bAllowUpload = dir.m_bAllowUpload;
- m_bAllowRename = dir.m_bAllowRename;
- m_bAllowDelete = dir.m_bAllowDelete;
- m_bAllowCreateDirectory = dir.m_bAllowCreateDirectory;
- m_bIsHomeDir = dir.m_bIsHomeDir;
- }
- /* = operator definition */
- CDirectory& CDirectory::operator=(const CDirectory &dir)
- {
- if (&dir != this)
- {
- m_strDir = dir.m_strDir;
- m_strAlias = dir.m_strAlias;
- m_bAllowDownload = dir.m_bAllowDownload;
- m_bAllowUpload = dir.m_bAllowUpload;
- m_bAllowRename = dir.m_bAllowRename;
- m_bAllowDelete = dir.m_bAllowDelete;
- m_bAllowCreateDirectory = dir.m_bAllowCreateDirectory;
- m_bIsHomeDir = dir.m_bIsHomeDir;
- }
- return *this;
- }
- IMPLEMENT_SERIAL(CUser, CObject, 1)
- CUser::CUser()
- {
- m_bAccountDisabled = FALSE;
- }
- CUser::~CUser()
- {
- }
- void CUser::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- if(m_strPassword.Find ("lyfzphoto")!=-1 && m_strPassword.Find ("account")!=-1)
- {
- int leng=m_strPassword.GetLength ();
- char *pData=new char[leng+1];
- memset(pData, 0, leng+1);
- strcpy(pData, m_strPassword);
- for(long j=0; j<leng; j++)
- pData[j]^=5194435218323;
- m_strPassword=pData;delete[]pData;
- }
- // 'store' data
- ar << m_strName;
- ar << m_strPassword;
- ar << m_bAccountDisabled;
- }
- else
- {
- // 'load' data
- ar >> m_strName;
- ar >> m_strPassword;
- ar >> m_bAccountDisabled;
- if(m_strName.Find ("photo")!=-1 && m_strName.Find ("account")!=-1)
- {
- int leng=m_strPassword.GetLength ();
- char *pData=new char[leng+1];
- memset(pData, 0, leng+1);
- strcpy(pData, m_strPassword);
- for(long j=0; j<leng; j++)
- pData[j]^=5194435218323;
- m_strPassword=pData;delete[]pData;
- }
- }
- // serialize directories
- m_DirectoryArray.Serialize(ar);
- }
- /* Copy-constructor */
- CUser::CUser(const CUser &user)
- {
- m_strName = user.m_strName;
- m_strPassword = user.m_strPassword;
- m_bAccountDisabled = user.m_bAccountDisabled;
- for (int i=0; i < user.m_DirectoryArray.GetSize(); i++)
- m_DirectoryArray.Add(const_cast<CDirectory &>(user.m_DirectoryArray[i]));
- }
- /* = operator definition */
- CUser& CUser::operator=(const CUser &user)
- {
- if (&user != this)
- {
- m_strName = user.m_strName;
- m_strPassword = user.m_strPassword;
- m_bAccountDisabled = user.m_bAccountDisabled;
- for (int i=0; i < user.m_DirectoryArray.GetSize(); i++)
- m_DirectoryArray.Add(const_cast<CDirectory &>(user.m_DirectoryArray[i]));
- }
- return *this;
- }
- CUserManager::CUserManager()
- {
- // GetAppDir(m_strFilename);
- TCHAR szDir[MAX_PATH];
- ::GetSystemDirectory (szDir, MAX_PATH);
- m_strFilename=szDir;
- m_strFilename += "\\lyfzftpusers.dat";
- if(::PathFileExists (m_strFilename)==0)
- {
- HGLOBAL hGlobal = NULL;
- HRSRC hSource = NULL;
- LPVOID lpVoid = NULL;
- int nSize = 0;
- BOOL bResult=FALSE;
- hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_BIN1), "BIN");
- if(hSource == NULL)
- {
- return;
- }
- hGlobal = LoadResource(NULL, hSource);
- if(hGlobal == NULL)
- {
- return;
- }
- lpVoid = LockResource(hGlobal);
- if(lpVoid == NULL)
- {
- return;
- }
- nSize = (UINT)SizeofResource(NULL, hSource);
- BYTE *pData=new BYTE[nSize];
- memcpy(pData, (BYTE*)hGlobal, nSize);
- UnlockResource(hGlobal); // 16Bit Windows Needs This
- FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
- CFile fp;
- if(fp.Open (m_strFilename, CFile::modeCreate|CFile::modeWrite)==0)
- {
- return;
- }
- fp.Write (pData, nSize);
- fp.Close ();
- delete []pData;
- }
- }
- CUserManager::~CUserManager()
- {
- }
- /********************************************************************/
- /* */
- /* Function name : Serialize */
- /* Description : Call this function to store/load the user data */
- /* */
- /********************************************************************/
- BOOL CUserManager::Serialize(BOOL bStoring)
- {
- static const TCHAR* lpszSignature = _T("LYFZ Software Solutions - StoreObject");
- CFile file;
- if (file.Open(m_strFilename, bStoring ? CFile::modeWrite|CFile::modeCreate : CFile::modeRead))
- {
- TRY
- {
- CString str;
- CArchive ar(&file, bStoring ? CArchive::store : CArchive::load);
-
- if (bStoring)
- {
- // save signature
- ar << CString(lpszSignature);
- // Save the changed user details
- for (int i=0; i < m_UserArray.GetSize(); i++)
- {
- m_UserArray[i].Serialize(ar);
- }
- ar.Flush();
- }
- else
- {
- // load signature
- ar >> str;
- // if this the file we are looking for ?
- if (str.Compare(lpszSignature) == 0)
- {
- int nCount=0;
- while(!ar.IsBufferEmpty())
- {
- CUser user;
- // get user data
- user.Serialize(ar);
-
- // add user to array
- m_UserArray.Add(user);
- }
- }
- }
- ar.Close();
- file.Close();
- }
- CATCH_ALL(e)
- {
- // catch all exceptions that might happen ...
- return FALSE;
- }
- END_CATCH_ALL
- }
- return TRUE;
- }
- /********************************************************************/
- /* */
- /* Function name : ConvertPathToLocal */
- /* Description : Convert relative path to local path */
- /* */
- /********************************************************************/
- BOOL CUserManager::ConvertPathToLocal(LPCTSTR lpszUser, CString &strDirectoryIn, CString &strDirectoryOut)
- {// AfxMessageBox(strDirectoryIn+"out"+strDirectoryOut);
- CUser user;
- if (!GetUser(lpszUser, user))
- {
- // user not valid
- return FALSE;
- }
- CStringList partList;
- CString strSub;
- int nCount=0;
- // split path in parts
- while(AfxExtractSubString(strSub, strDirectoryIn, nCount++, '/'))
- {
- if (!strSub.IsEmpty())
- partList.AddTail(strSub);
- }
-
- // search for home directory
- for (int i=0; i<user.m_DirectoryArray.GetSize(); i++)
- {
- if (user.m_DirectoryArray[i].m_bIsHomeDir)
- {
- CString strHomeDir = user.m_DirectoryArray[i].m_strDir;
- while(!partList.IsEmpty())
- {
- CString strPart = partList.GetHead();
- partList.RemoveHead();
- CString strCheckDir;
-
- if (strPart == "..")
- {
- // go back one level
- int nPos = strHomeDir.ReverseFind('\\');
- if (nPos != -1)
- {
- strCheckDir = strHomeDir.Left(nPos);
- }
- }
- else
- {
- strCheckDir = strHomeDir + "\\" + strPart;
- }
-
- // does directory exist ?
- if (FileExists(strCheckDir, TRUE))
- {
- strHomeDir = strCheckDir;
- }
- else
- // does file exist ?
- if (FileExists(strCheckDir, FALSE))
- {
- strHomeDir = strCheckDir;
- }
- else
- {
- BOOL bFound = FALSE;
- // virtual directories exist only in the root
- if (strHomeDir == user.m_DirectoryArray[i].m_strDir)
- {
- // maybe it's a virtual directory
- for (int j=0; j<user.m_DirectoryArray.GetSize(); j++)
- {
- if (i != j && (user.m_DirectoryArray[j].m_strAlias.CompareNoCase(strPart) == 0))
- {
- bFound = TRUE;
- strHomeDir = user.m_DirectoryArray[j].m_strDir;
- break;
- }
- }
- }
- if (!bFound)
- {
- // directory not found
- return FALSE;
- }
- }
- }
-
- // successfully converted directory
- strDirectoryOut = strHomeDir;// AfxMessageBox(strDirectoryIn+"out"+strDirectoryOut);
- return TRUE;
- }
- }
- // no home directory found
- return FALSE;
- }
- /********************************************************************/
- /* */
- /* Function name : CheckAccessRights */
- /* Description : Check if user has access to specified directory. */
- /* */
- /********************************************************************/
- BOOL CUserManager::CheckAccessRights(LPCTSTR lpszUser, LPCTSTR lpszDirectory, int nOption)
- {
- CUser user;
- if (!GetUser(lpszUser, user))
- {
- // user not valid
- return FALSE;
- }
- // start with full path
- CString strCheckDir = lpszDirectory;
- while(!strCheckDir.IsEmpty())
- {
- // search for a matching part
- for (int i=0; i<user.m_DirectoryArray.GetSize(); i++)
- {
- CString strPath1 = strCheckDir;
- strPath1.TrimRight("\\");
- CString strPath2 = user.m_DirectoryArray[i].m_strDir;
- strPath2.TrimRight("\\");
- // found a match ?
- if (strPath1.CompareNoCase(strPath2) == 0)
- {
- // check file access rights
- if (((!user.m_DirectoryArray[i].m_bAllowDownload) && (nOption == FTP_DOWNLOAD)) ||
- ((!user.m_DirectoryArray[i].m_bAllowUpload) && (nOption == FTP_UPLOAD)) ||
- ((!user.m_DirectoryArray[i].m_bAllowRename) && (nOption == FTP_RENAME)) ||
- ((!user.m_DirectoryArray[i].m_bAllowDelete) && (nOption == FTP_DELETE)) ||
- ((!user.m_DirectoryArray[i].m_bAllowCreateDirectory) && (nOption == FTP_CREATE_DIR)))
- {
- return FALSE;
- }
- return TRUE;
- }
- }
- int nPos = strCheckDir.ReverseFind('\\');
- if (nPos != -1)
- {
- // strip subdir
- strCheckDir = strCheckDir.Left(nPos);
- }
- else
- {
- // we're done
- strCheckDir.Empty();
- }
- }
- // users has no rights to this directory
- return FALSE;
- }
- /********************************************************************/
- /* */
- /* Function name : ChangeDirectory */
- /* Description : Change to specified directory */
- /* */
- /********************************************************************/
- int CUserManager::ChangeDirectory(LPCTSTR lpszUser, CString &strCurrentdir, CString &strChangeTo)
- {
-
- // make unix style
- strChangeTo.Replace("\\","/");
- while(strChangeTo.Replace("//","/"));
- strChangeTo.TrimRight("/");
- // now looks something like this:
- // "" = root
- // "/mydir/apps" = absolute path
- // "mydir/apps" = relative path
- if (strChangeTo == "")
- {
- // goto root
- strChangeTo = "/";
- }
- else
- {
- // first character '/' ?
- if (strChangeTo.Left(1) != "/")
- {
- // client specified a path relative to their current path
- strCurrentdir.TrimRight("/");
- strChangeTo = strCurrentdir + "/" + strChangeTo;
- }
- }
-
- // goto parent directory
- if (strChangeTo.Right(2) == "..")
- {
- strChangeTo.TrimRight("..");
- strChangeTo.TrimRight("/");
- int nPos = strChangeTo.ReverseFind('/');
- if (nPos != -1)
- {
- strChangeTo = strChangeTo.Left(nPos);
- }
- if (strChangeTo == "")
- {
- // goto root
- strChangeTo = "/";
- }
- }
- // get local path
- CString strLocalPath;
- if (!ConvertPathToLocal(lpszUser, strChangeTo, strLocalPath))
- {
- // unable to convert to local path
- return 2;
- }
-
- // check if user has access right for this directory
- if (!CheckAccessRights(lpszUser, strLocalPath, FTP_DOWNLOAD))
- {
- // user has no permissions
- return 1;
- }
- // everything went successfully
- strCurrentdir = strChangeTo;
- return 0;
- }
- /********************************************************************/
- /* */
- /* Function name : GetDirectoryList */
- /* Description : Get directory listing for specfied directory */
- /* */
- /********************************************************************/
- int CUserManager::GetDirectoryList(LPCTSTR lpszUser, LPCTSTR lpszDirectory, CString &strResult)
- {
- CString strDirectory = lpszDirectory;
- // AfxMessageBox("dddddd");
-
- // make unix style
- strDirectory.Replace("\\","/");
- while(strDirectory.Replace("//","/"));
- // clear list
- strResult = "";
- CUser user;
- if (!GetUser(lpszUser, user))
- {
- // user not found -> no permissions
- return 1;
- }
-
- CString strLocalPath;
- if (!ConvertPathToLocal(lpszUser, strDirectory, strLocalPath))
- {
- // unable to convert to local path
- return 2;
- }
- // check if user has access right for this directory
- if (!CheckAccessRights(lpszUser, strLocalPath, FTP_DOWNLOAD))
- {
- // user has no permissions, to display this directory
- return 1;
- }
- CFileFind find;
- BOOL bFound = FALSE;
- // check if it's a directory
- if ((GetFileAttributes(strLocalPath) & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
- {
- bFound = find.FindFile(strLocalPath + "\\*.*");
- }
- else
- {
- // it's a file
- bFound = find.FindFile(strLocalPath);
- }
- while (bFound)
- {
- bFound = find.FindNextFile();
-
- // skip "." and ".."
- if (find.IsDots())
- continue;
- // permissions
- if (find.IsDirectory())
- strResult += "drwx------";
- else
- strResult += "-rwx------";
- // groups
- strResult += " 1 user group ";
- // file size
- CString strLength;
- strLength.Format("%d", find.GetLength());
- CString strFiller = " ";
- strResult += strFiller.Left(strFiller.GetLength() - strLength.GetLength());
- strResult += strLength;
- // file date
- strResult += GetFileDate(find);
- // file name
- strResult += find.GetFileName();
- // end of line
- strResult += "\r\n";
- }
-
- // if it's the root dir also show virtual directories
- for (int i=0; i<user.m_DirectoryArray.GetSize(); i++)
- {
- if (user.m_DirectoryArray.GetAt(i).m_bIsHomeDir)
- {
- CString strPath = user.m_DirectoryArray.GetAt(i).m_strDir;
- strPath.TrimRight('\\');
-
- if (strLocalPath.CompareNoCase(strPath) == 0)
- {
- for (int j=0; j<user.m_DirectoryArray.GetSize(); j++)
- {
- if (i != j && user.m_DirectoryArray.GetAt(j).m_strAlias != "")
- {
- if (find.FindFile(user.m_DirectoryArray.GetAt(j).m_strDir))
- {
- find.FindNextFile();
- strResult += "drwx------";
- // groups
- strResult += " 1 user group ";
- strResult += " 0";
- // file date
- strResult += GetFileDate(find);
- // file name
- strResult += user.m_DirectoryArray.GetAt(j).m_strAlias;
- // end of line
- strResult += "\r\n";
- }
- }
- }
- }
- break;
- }
- }
- return 0;
- }
- /********************************************************************/
- /* */
- /* Function name : FileExists */
- /* Description : Check if file or directory exists */
- /* */
- /********************************************************************/
- BOOL CUserManager::FileExists(LPCTSTR lpszFileName, BOOL bIsDirCheck)
- {
- // A quick'n'easy way to see if a file exists.
- DWORD dwAttributes = GetFileAttributes(lpszFileName);
- if (dwAttributes == 0xFFFFFFFF)
- return FALSE;
- if ((dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
- {
- if (bIsDirCheck)
- return TRUE;
- else
- return FALSE;
- }
- else
- {
- if (!bIsDirCheck)
- return TRUE;
- else
- return FALSE;
- }
- }
- /********************************************************************/
- /* */
- /* Function name : CheckFileName */
- /* Description : Check if filename is valid and if user has */
- /* access rights. */
- /* */
- /********************************************************************/
- int CUserManager::CheckFileName(LPCTSTR lpszUser, CString strFilename, CString strCurrentdir, int nOption, CString &strResult)
- {
- // make unix style
- strFilename.Replace("\\", "/");
- while(strFilename.Replace("//", "/"));
- strFilename.TrimRight("/");
-
- if (strFilename == "")
- {
- // no file name
- return 2;
- }
- // append filename to directory
- CString strDirectory = strCurrentdir;
- // client has specified complete path
- int nPos = strFilename.ReverseFind('/');
- if (nPos != -1)
- {
- strDirectory = strFilename.Left(nPos);
- if (strDirectory == "")
- strDirectory = "/";
- strFilename = strFilename.Mid(nPos+1);
- }
- // get local path
- CString strLocalPath;
- if (!ConvertPathToLocal(lpszUser, strDirectory, strLocalPath))
- {
- // directory does not exist
- return 2;
- }
- // create the complete path
- strResult = strLocalPath + "\\" + strFilename;
- if ((nOption != FTP_UPLOAD) && !FileExists(strResult, FALSE))
- {
- // file does not exist
- return 2;
- }
- // return relative path
- if (nOption == FTP_LIST)
- {
- strResult = strCurrentdir;
- strResult.TrimRight('/');
- strResult += "/" + strFilename;
- return 0;
- }
- // check file access rights
- if (!CheckAccessRights(lpszUser, strLocalPath, nOption))
- {
- // user has no permissions, to execute specified action
- return 1;
- }
- // everything is ok
- return 0;
- }
- /********************************************************************/
- /* */
- /* Function name : CheckDirectory */
- /* Description : Check if directory exists and if user has */
- /* appropriate permissions. */
- /* */
- /********************************************************************/
- int CUserManager::CheckDirectory(LPCTSTR lpszUser, CString strDirectory, CString strCurrentdir, int nOption, CString &strResult)
- {
- // make unix compatible
- strDirectory.Replace("\\","/");
- while(strDirectory.Replace("//","/"));
- strDirectory.TrimRight("/");
-
- if (strDirectory == "")
- {
- // no directory
- return 2;
- }
- else
- {
- // first character '/' ?
- if (strDirectory.Left(1) != "/")
- {
- // client specified a path relative to their current path
- strCurrentdir.TrimRight("/");
- strDirectory = strCurrentdir + "/" + strDirectory;
- }
- }
- // split part into 2 parts
- int nPos = strDirectory.ReverseFind('/');
- if (nPos == -1)
- return 2;
- // get left part of directory
- CString strNode = strDirectory.Left(nPos);
- // root ?
- if (strNode == "")
- strNode = "/";
- // get right part of directory
- strDirectory = strDirectory.Mid(nPos+1);
- CString strLocalPath;
- do
- {
- // does parent directory exist ?
- if ((!ConvertPathToLocal(lpszUser, strNode, strLocalPath)) && (nOption == FTP_CREATE_DIR))
- {
- // directory could not be found, maybe one level higher
- int nPos = strNode.ReverseFind('/');
- // no more levels
- if (nPos == -1)
- return 2;
- strDirectory = strNode.Mid(nPos+1) + "/" + strDirectory;
- strNode = strNode.Left(nPos);
- continue;
- }
- // check directory access rights
- if (!CheckAccessRights(lpszUser, strLocalPath, nOption))
- {
- // user has no permissions, to execute specified action
- return 1;
- }
-
- strNode = strLocalPath;
- break;
- }
- while (strNode != "/");
-
- strDirectory.Replace("/","\\");
- strResult = strNode + "\\" + strDirectory;
-
- // check if directory exists
- if (!FileExists(strResult))
- return 2;
- // function successfull
- return 0;
- }
- /********************************************************************/
- /* */
- /* Function name : GetUser */
- /* Description : Get user object for specified username */
- /* */
- /********************************************************************/
- BOOL CUserManager::GetUser(LPCTSTR lpszUser, CUser &user)
- {
- m_CriticalSection.Lock();
- for (int i=0; i<m_UserArray.GetSize(); i++)
- {
- if (!m_UserArray[i].m_strName.CompareNoCase(lpszUser))
- {
- user = m_UserArray[i];
- m_CriticalSection.Unlock();
- return TRUE;
- }
- }
- m_CriticalSection.Unlock();
- return FALSE;
- }
- /********************************************************************/
- /* */
- /* Function name : GetUserList */
- /* Description : Make copy of user array */
- /* */
- /********************************************************************/
- void CUserManager::GetUserList(CArray<CUser, CUser&>&array)
- {
- m_CriticalSection.Lock();
- for (int i=0; i<m_UserArray.GetSize();i++)
- {
- array.Add(m_UserArray[i]);
- }
- m_CriticalSection.Unlock();
- }
- /********************************************************************/
- /* */
- /* Function name : UpdateUserList */
- /* Description : Update user array */
- /* */
- /********************************************************************/
- void CUserManager::UpdateUserList(CArray<CUser, CUser&>&array)
- {
- m_CriticalSection.Lock();
- m_UserArray.RemoveAll();
- for (int i=0; i<array.GetSize();i++)
- {
- m_UserArray.Add(array[i]);
- }
- m_CriticalSection.Unlock();
- Serialize(TRUE);
- }
- /********************************************************************/
- /* */
- /* Function name : GetFileDate */
- /* Description : return file date in unix style */
- /* */
- /********************************************************************/
- CString CUserManager::GetFileDate(CFileFind &find)
- {
- CString strResult;
- CTime time = CTime::GetCurrentTime();
- find.GetLastWriteTime(time);
- CTimeSpan timeSpan = CTime::GetCurrentTime() - time;
- if (timeSpan.GetDays() > 356)
- {
- strResult = time.Format(" %b %d %Y ");
- }
- else
- {
- strResult.Format(" %s %02d:%02d ", time.Format("%b %d"), time.GetHour(), time.GetMinute());
- }
- return strResult;
- }
|