int BackupStoreAccountsControl::HousekeepAccountNow(int32_t ID)
{
	std::string rootDir;
	int discSetNum;
	std::auto_ptr<UnixUser> user; // used to reset uid when we return

	if(!OpenAccount(ID, rootDir, discSetNum, user,
		NULL /* housekeeping locks the account itself */))
	{
		BOX_ERROR("Failed to open account " << BOX_FORMAT_ACCOUNT(ID)
			<< " for housekeeping.");
		return 1;
	}

	HousekeepStoreAccount housekeeping(ID, rootDir, discSetNum, NULL);
	bool success = housekeeping.DoHousekeeping();

	if(!success)
	{
		BOX_ERROR("Failed to lock account " << BOX_FORMAT_ACCOUNT(ID)
			<< " for housekeeping: perhaps a client is "
			"still connected?");
		return 1;
	}
	else
	{
		BOX_TRACE("Finished housekeeping on account " <<
			BOX_FORMAT_ACCOUNT(ID));
		return 0;
	}
}
int BackupStoreAccountsControl::SetAccountName(int32_t ID, const std::string& rNewAccountName)
{
	std::string rootDir;
	int discSetNum;
	std::auto_ptr<UnixUser> user; // used to reset uid when we return
	NamedLock writeLock;

	if(!OpenAccount(ID, rootDir, discSetNum, user, &writeLock))
	{
		BOX_ERROR("Failed to open account " << BOX_FORMAT_ACCOUNT(ID)
			<< " to change name.");
		return 1;
	}

	// Load the info
	std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(ID,
		rootDir, discSetNum, false /* Read/Write */));

	info->SetAccountName(rNewAccountName);
	
	// Save
	info->Save();

	BOX_NOTICE("Account " << BOX_FORMAT_ACCOUNT(ID) <<
		" name changed to " << rNewAccountName);

	return 0;
}
int BackupStoreAccountsControl::CheckAccount(int32_t ID, bool FixErrors, bool Quiet,
	bool ReturnNumErrorsFound)
{
	std::string rootDir;
	int discSetNum;
	std::auto_ptr<UnixUser> user; // used to reset uid when we return
	NamedLock writeLock;

	if(!OpenAccount(ID, rootDir, discSetNum, user,
		FixErrors ? &writeLock : NULL)) // don't need a write lock if not making changes
	{
		BOX_ERROR("Failed to open account " << BOX_FORMAT_ACCOUNT(ID)
			<< " for checking.");
		return 1;
	}

	// Check it
	BackupStoreCheck check(rootDir, discSetNum, ID, FixErrors, Quiet);
	check.Check();

	if(ReturnNumErrorsFound)
	{
		return check.GetNumErrorsFound();
	}
	else
	{
		return check.ErrorsFound() ? 1 : 0;
	}
}
int BackupStoreAccountsControl::SetLimit(int32_t ID, const char *SoftLimitStr,
	const char *HardLimitStr)
{
	std::string rootDir;
	int discSetNum;
	std::auto_ptr<UnixUser> user; // used to reset uid when we return
	NamedLock writeLock;

	if(!OpenAccount(ID, rootDir, discSetNum, user, &writeLock))
	{
		BOX_ERROR("Failed to open account " << BOX_FORMAT_ACCOUNT(ID)
			<< " to change limits.");
		return 1;
	}
	
	// Load the info
	std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(ID, rootDir,
		discSetNum, false /* Read/Write */));

	// Change the limits
	int blocksize = BlockSizeOfDiscSet(discSetNum);
	int64_t softlimit = SizeStringToBlocks(SoftLimitStr, blocksize);
	int64_t hardlimit = SizeStringToBlocks(HardLimitStr, blocksize);
	CheckSoftHardLimits(softlimit, hardlimit);
	info->ChangeLimits(softlimit, hardlimit);
	
	// Save
	info->Save();

	BOX_NOTICE("Limits on account " << BOX_FORMAT_ACCOUNT(ID) <<
		" changed to " << softlimit << " soft, " <<
		hardlimit << " hard.");

	return 0;
}
void Application::Admin_select()
{
	y -= 3;
	ClientData data;	// 고객 정보 임시 저장장소
	account temp;	// 계좌 임시 저장소
	switch(y)
	{
	case 1:
		data.GetClientData();		// 고객 정보 입력
		m_ClientList.InsertItem(data); // 고객 추가 함수
		data.PutClientData();	// 고객 정부 화면 출력
		break;
	case 2:
		DeleteClient();	// 고객 리스트 제거 함수
		break;
	case 3:
		if(!SearchList(data))	// 고객 검색
			break;
		data.PutClientData();	// 고객정보 화면에 띄우기
		break;
	case 4:
		OpenAccount();	// 계좌 열기
		break;
	case 5:
		if(!SearchList(data))	// 고객 검색
			break;
		data.CloseAccount();
		break;
	case 6:
		return;
	}
}
Example #6
0
// SendCommand
//   Pops up a Custinfo dialog or sends an exit command to Custinfo
// Assumptions:
//   Custinfo is running.  For a dialog, either the account is
//   specified in the call or the correct account is already open in
//   Custinfo.
// Returns:
//   TRUE if able to post the message.
//   FALSE if failed to post the message.
// Error messages:
//   Internal error message when function returns FALSE.
// Side affects:
//   Pops up a Custinfo dialog or exits Custinfo.
BOOL CCustinfoDriverApp::SendCommand(CArborCommandLineInfo::Flag flag)
{
   UINT message;

   if (flag == CArborCommandLineInfo::dialog)
   {
      if (!m_CmdInfo.m_sAccountid.IsEmpty() && !OpenAccount())
      {
         return FALSE;
      }

      message = GetDialogMessage();
   }
   else if (flag == CArborCommandLineInfo::exit)
   {
      message = ci_ipc::uAPP_EXIT;
   }
   else
   {
      ErrorMessage(__FILE__, __LINE__, "Unknown command.");
      return FALSE;
   }

   if (!ci_ipc::FindCustInfo())
   {
      if (flag != CArborCommandLineInfo::exit)
      {
         if (m_CmdInfo.m_sUsermessage.IsEmpty())
         {
            UserMessage(m_sUsermessage);
         }
         else
         {
            UserMessage(m_CmdInfo.m_sUsermessage);
         }
      }

      return FALSE;
   }

   if (!ci_ipc::DoIPC(message))
   {
      if (flag != CArborCommandLineInfo::exit)
      {
         ErrorMessage(__FILE__, __LINE__, "Unable to process request.");
      }

      return FALSE;
   }

   return TRUE;
}
int BackupStoreAccountsControl::SetAccountEnabled(int32_t ID, bool enabled)
{
	std::string rootDir;
	int discSetNum;
	std::auto_ptr<UnixUser> user; // used to reset uid when we return
	NamedLock writeLock;

	if(!OpenAccount(ID, rootDir, discSetNum, user, &writeLock))
	{
		BOX_ERROR("Failed to open account " << BOX_FORMAT_ACCOUNT(ID)
			<< " to change enabled flag.");
		return 1;
	}
	
	// Load it in
	std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(ID,
		rootDir, discSetNum, false /* ReadOnly */));
	info->SetAccountEnabled(enabled);
	info->Save();
	return 0;
}
int BackupStoreAccountsControl::PrintAccountInfo(int32_t ID)
{
	std::string rootDir;
	int discSetNum;
	std::auto_ptr<UnixUser> user; // used to reset uid when we return

	if(!OpenAccount(ID, rootDir, discSetNum, user,
		NULL /* no write lock needed for this read-only operation */))
	{
		BOX_ERROR("Failed to open account " << BOX_FORMAT_ACCOUNT(ID)
			<< " to display info.");
		return 1;
	}
	
	// Load it in
	std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(ID,
		rootDir, discSetNum, true /* ReadOnly */));

	return BackupAccountControl::PrintAccountInfo(*info,
		BlockSizeOfDiscSet(discSetNum));
}
int BackupStoreAccountsControl::DeleteAccount(int32_t ID, bool AskForConfirmation)
{
	std::string rootDir;
	int discSetNum;
	std::auto_ptr<UnixUser> user; // used to reset uid when we return
	NamedLock writeLock;

	// Obtain a write lock, as the daemon user
	if(!OpenAccount(ID, rootDir, discSetNum, user, &writeLock))
	{
		BOX_ERROR("Failed to open account " << BOX_FORMAT_ACCOUNT(ID)
			<< " for deletion.");
		return 1;
	}

	// Check user really wants to do this
	if(AskForConfirmation)
	{
		BOX_WARNING("Really delete account " << 
			BOX_FORMAT_ACCOUNT(ID) << "? (type 'yes' to confirm)");
		char response[256];
		if(::fgets(response, sizeof(response), stdin) == 0 || ::strcmp(response, "yes\n") != 0)
		{
			BOX_NOTICE("Deletion cancelled.");
			return 0;
		}
	}
	
	// Back to original user, but write lock is maintained
	user.reset();

	std::auto_ptr<BackupStoreAccountDatabase> db(
		BackupStoreAccountDatabase::Read(
			mConfig.GetKeyValue("AccountDatabase")));

	// Delete from account database
	db->DeleteEntry(ID);
	
	// Write back to disc
	db->Write();
	
	// Remove the store files...

	// First, become the user specified in the config file
	std::string username;
	{
		const Configuration &rserverConfig(mConfig.GetSubConfiguration("Server"));
		if(rserverConfig.KeyExists("User"))
		{
			username = rserverConfig.GetKeyValue("User");
		}
	}

	// Become the right user
	if(!username.empty())
	{
		// Username specified, change...
		user.reset(new UnixUser(username));
		user->ChangeProcessUser(true /* temporary */);
		// Change will be undone when user goes out of scope
	}

	// Secondly, work out which directories need wiping
	std::vector<std::string> toDelete;
	RaidFileController &rcontroller(RaidFileController::GetController());
	RaidFileDiscSet discSet(rcontroller.GetDiscSet(discSetNum));
	for(RaidFileDiscSet::const_iterator i(discSet.begin()); i != discSet.end(); ++i)
	{
		if(std::find(toDelete.begin(), toDelete.end(), *i) == toDelete.end())
		{
			toDelete.push_back((*i) + DIRECTORY_SEPARATOR + rootDir);
		}
	}

	// NamedLock will throw an exception if it can't delete the lockfile,
	// which it can't if it doesn't exist. Now that we've deleted the account,
	// nobody can open it anyway, so it's safe to unlock.
	writeLock.ReleaseLock();

	int retcode = 0;

	// Thirdly, delete the directories...
	for(std::vector<std::string>::const_iterator d(toDelete.begin()); d != toDelete.end(); ++d)
	{
		BOX_NOTICE("Deleting store directory " << (*d) << "...");
		// Just use the rm command to delete the files
		std::string cmd("rm -rf ");
		cmd += *d;
		// Run command
		if(::system(cmd.c_str()) != 0)
		{
			BOX_ERROR("Failed to delete files in " << (*d) <<
				", delete them manually.");
			retcode = 1;
		}
	}
	
	// Success!
	return retcode;
}
Example #10
0
BOOL CCustinfoDriverApp::InitInstance()
{
   InitArborLocale();

   // Parse and validate command line
   ParseCommandLine(m_CmdInfo);

   if (ValidateCommandLine())
   {
      BOOL continue_processing = TRUE;

      // Process command line instructions
      if (m_CmdInfo.m_sApplication.IsEmpty() &&
          m_CmdInfo.m_sDialog.IsEmpty() &&
          m_CmdInfo.m_sAccountid.IsEmpty() &&
          !m_CmdInfo.m_bExit)
      {
         ErrorMessage(__FILE__, __LINE__, "Unknown command.");
         continue_processing = FALSE;
      }

      // Exit the Application
      if (m_CmdInfo.m_bExit)
      {
         int count = 0;
         while (count++ < 100 && ci_ipc::FindCustInfo())
         {
            continue_processing = SendCommand(CArborCommandLineInfo::exit);
            Sleep(500);
         }
         if (count >= 100)
         {
            continue_processing = FALSE;
         }
      }

      // Start Application
      if (continue_processing && !m_CmdInfo.m_sApplication.IsEmpty())
      {
         if (m_CmdInfo.m_sApplication == m_sAppNames[custinfo])
         {
            if (!ci_ipc::FindCustInfo())
            {
               // Only attempt to start the app if its not already running.
               continue_processing = StartApp();
               // Wait for us to Find the application before continuing.
               if (continue_processing)
               {
                  int count = 0;
                  while (count++ < 100 && !ci_ipc::FindCustInfo())
                  {
                     Sleep(500);
                  }
                  if (count >= 100)
                  {
                     continue_processing = FALSE;
                  }
                  else
                  {
                     Sleep(1000);
                  }
               }
            }
         }
         else
         {
            continue_processing = StartApp();
         }
      }

      // Open Account
      if (continue_processing && !m_CmdInfo.m_sAccountid.IsEmpty())
      {
         continue_processing = OpenAccount();
      }

      // Switch to a Specific Dialog
      if (continue_processing && !m_CmdInfo.m_sDialog.IsEmpty())
      {
         continue_processing = SendCommand(CArborCommandLineInfo::dialog);
      }
   }

   DeleteArborLocale();

   return TRUE;
}