user.cpp
资源名称:warftpd.zip [点击查看]
上传用户:surprise9
上传日期:2007-01-04
资源大小:426k
文件大小:23k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // This is part of the WAR SOFTWARE SERIES initiated by Jarle Aase
- // Copyright 1996 by Jarle Aase. All rights reserved.
- // See the "War Software Series Licende Agreement" for details concerning
- // use and distribution.
- // ---
- // This source code, executables and programs containing source code or
- // binaries or proprietetary technology from the War Software Series are
- // NOT alloed used, viewed or tested by any governmental agencies in
- // any countries. This includes the government, departments, police,
- // military etc.
- // ---
- // This file is intended for use with Tab space = 2
- // Created and maintained in MSVC Developer Studio
- // ---
- // NAME : user.cpp
- // PURPOSE : User management
- // PROGRAM :
- // DATE : Sept. 28 1996
- // AUTHOR : Jarle Aase
- // ---
- // REVISION HISTORY
- //
- #include "stdafx.h"
- #include "WarDaemon.h"
- #include "User.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- CUsr *CUsr::m_pUserMngr = NULL;
- LPCSTR CUsr::m_pIniFile = ".\User.ini";
- CLog *CUsr::m_Log = NULL;
- int CUsr::m_NextUserNum;
- CUsr::CUsr()
- {
- m_pUserMngr = this;
- }
- CUsr::~CUsr()
- {
- m_pUserMngr = NULL;
- m_Log = NULL;
- }
- BOOL CUsr::Create(CLog *Log)
- {
- m_Log = Log;
- ::GetIniItem(NULL, m_pIniFile, "@hdr@", "Next", m_NextUserNum, 0);
- if (!m_NextUserNum)
- {
- int sSystem, cSysAdmin, cUser, cVisitor;
- m_NextUserNum++;
- LogMsg(LOGF_SYSTEM,"Creating new user database.");
- // Create user database
- int User;
- sSystem = User = AddUser(UT_SYSTEM, "System", 2, USERPRI_ANON);
- if (!User)
- {
- LogMsg(LOGF_ERROR,"Failed to create System.");
- return FALSE;
- }
- SetParam(User,"Home","/");
- SetParam(User,"Root","/");
- SetParam(User,"RemoteAdmin Access", TRUE);
- SetParam(User,"FTP Access", TRUE);
- SetParam(User,"IP Shitlist", "*.gov;*.mil;*.gov.*;*.mil.*");
- SetParam(User,"Enable IP Shitlist", TRUE);
- SetParam(User,"Umask", 22);
- User = cVisitor = AddUser(UT_CLASS, "Visitor", TRUE, USERPRI_ANON);
- SetParam(User,"FTP Access", TRUE);
- SetParam(User,"AssignFilesTo", "LocalAdmin");
- User = cUser = AddUser(UT_CLASS, "User", FALSE, USERPRI_ANON);
- SetParam(User,"FTP Access", TRUE);
- User = cSysAdmin = AddUser(UT_CLASS, "Sysadmin", 2, USERPRI_ANON);
- SetParam(User,"FTP Access", TRUE);
- SetParam(User,"RemoteAdmin Access", TRUE);
- User = AddUser(UT_USER,"Anonymous", TRUE, USERPRI_ANON);
- SetParam(User,"Class", cVisitor);
- SetParam(User,"PWmode", PW_EMAIL);
- CreateAlias("Anonymous", "ftp");
- CreateAlias("Anonymous", "guest");
- User = AddUser(UT_GROUP,"Ftp", FALSE, USERPRI_ANON);
- SetParam(User,"Class", cUser);
- SetParam(User,"FTP Access", TRUE);
- // Create system user for maintainance
- User = AddUser(UT_USER, "LocalAdmin", 2, USERPRI_ADMIN);
- if (!User)
- {
- LogMsg(LOGF_ERROR,"Failed to create Local Admin user.");
- return FALSE;
- }
- SetParam(User,"Class", cSysAdmin);
- SetParam(User,"PWmode", PW_NORMAL);
- SetParam(User,"Home","/");
- SetParam(User,"Root","/");
- SetParam(User,"Administrator",TRUE);
- SetParam(User,"Local Only",TRUE);
- SetParam(User,"Password","sd&jkfhw387r");
- SetParam(User,"RemoteAdmin Access",TRUE);
- SetParam(User,"FTP Access",TRUE);
- // Create support user for maintainance
- User = AddUser(UT_USER, "SupportAdmin", TRUE, USERPRI_ADMIN);
- if (!User)
- {
- LogMsg(LOGF_ERROR,"Failed to create Support Admin user.");
- return FALSE;
- }
- SetParam(User,"Class", cSysAdmin);
- SetParam(User,"PWmode", PW_NORMAL);
- SetParam(User,"Home","/");
- SetParam(User,"Root","/");
- SetParam(User,"Administrator",TRUE);
- SetParam(User,"Password","sd&jkfhw387r");
- SetParam(User,"RemoteAdmin Access",FALSE);
- SetParam(User,"FTP Access",FALSE);
- }
- return TRUE;
- }
- BOOL CUsr::CreateAlias(LPCSTR Name, LPCSTR Alias)
- {
- int OrgUser = FindUser(UT_USER, Name), User;
- if (FindUser(UT_USER, Alias))
- {
- LogMsg(LOGF_WARNINGS,"Failed to create alias '%s' for user '%s'. Alias name exist.",
- Alias, Name);
- return FALSE;
- }
- if (!OrgUser)
- {
- LogMsg(LOGF_WARNINGS,"Failed to create alias '%s' for user '%s'. User not found.",
- Alias, Name);
- return FALSE;
- }
- CString cBuf;
- if ((User = AddUser(UT_USER, Alias)) == INVALID_USER_VALUE)
- return FALSE;
- SetParam(User, "Alias to", OrgUser);
- LogMsg(LOGF_SYSTEM,"Created alias name '%s' for user '%s'", Alias, Name);
- return TRUE;
- }
- void CUsr::SetParam(int UserNum, LPCSTR Key, LPCSTR Value)
- {
- CString cSection;
- char buf[128];
- // Special cases
- if (Value && *Value && !stricmp(Key, "password"))
- {
- Value = crypt(Value, "